<commit_before>/*
 * Copyright 2018 NEOautus Ltd. (http://neoautus.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lucidj.artifactdeployer;

import org.lucidj.api.core.Artifact;
import org.lucidj.api.core.ArtifactDeployer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;

@Component (immediate = true, publicFactory = false)
@Instantiate
@Provides (specifications = HttpServlet.class)
public class DeploySvc extends HttpServlet
{
    @Requires
    private ArtifactDeployer artifactDeployer;

    @ServiceProperty (name="@service.path")
    String service = "/deploy";

    @Override
    public void doGet (HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
    {
        resp.setContentType ("text/plain");
        PrintWriter out = resp.getWriter ();

        if (req.getQueryString () == null)
        {
            // Just the service returns true indicating it exists
            out.write ("true\n");
            return;
        }

        out.write ("### Hello from " + this.getClass ().getName () + " ###\n");
        out.write ("Artifact: " + req.getQueryString () + "\n");

        Artifact artifact = artifactDeployer.getArtifact (req.getQueryString ());

        if (artifact == null)
        {
            try
            {
                artifact = artifactDeployer.installArtifact (req.getQueryString ());
                out.write ("Artifact installed: " + artifact.toString ());
                artifact.update ();
            }
            catch (Exception e)
            {
                out.write ("Exception deploying file: " + e.getMessage ());
            }
        }<commit_msg>Remove stray update().<commit_after>/*
 * Copyright 2018 NEOautus Ltd. (http://neoautus.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lucidj.artifactdeployer;

import org.lucidj.api.core.Artifact;
import org.lucidj.api.core.ArtifactDeployer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;

@Component (immediate = true, publicFactory = false)
@Instantiate
@Provides (specifications = HttpServlet.class)
public class DeploySvc extends HttpServlet
{
    private final static Logger log = LoggerFactory.getLogger (DeploySvc.class);

    @Requires
    private ArtifactDeployer artifactDeployer;

    @ServiceProperty (name="@service.path")
    String service = "/deploy";

    @Override
    public void doGet (HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException
    {
        resp.setContentType ("text/plain");
        PrintWriter out = resp.getWriter ();
        String artifact_file = req.getQueryString ();

        if (artifact_file == null)
        {
            // Just the service returns true indicating it exists
            out.write ("true\n");
            return;
        }

        out.write ("### Hello from " + this.getClass ().getName () + " ###\n");
        out.write ("Artifact: " + artifact_file + "\n");

        log.info ("Install requested: {}", artifact_file);
        Artifact artifact = artifactDeployer.getArtifact (artifact_file);

        if (artifact == null)
        {
            try
            {
                artifact = artifactDeployer.installArtifact (artifact_file);
                out.write ("Artifact installed: " + artifact.toString ());
            }
            catch (Exception e)
            {
                out.write ("Exception deploying file: " + e.getMessage ());
            }
        }
{'fraction_non_alphanumeric': 0.10244171103359648, 'fraction_numerical': 0.003304571323664402, 'mean_word_length': 2.9882869692532945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2498570', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1470, 'n_words': 417}