package jsr223.docker.compose;

import jsr223.docker.compose.utils.DockerComposeUtilities;
import processbuilder.SingletonProcessBuilderFactory;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DockerComposeScriptEngineFactory implements ScriptEngineFactory {

    // Script engine parameters
    private static final String NAME = "docker-compose";
    private static final String ENGINE = "docker-compose";
    private static final String ENGINE_VERSION = "0.0.1";
    private static final String LANGUAGE = "yaml";

    private static final Map<String, Object> parameters = new HashMap<>();

    public DockerComposeScriptEngineFactory() {
        // This is the entrypoint of the script engine
        // configure the logger here, quick and dirty
        org.apache.log4j.PropertyConfigurator.configure(getClass()
        .getClassLoader().getResourceAsStream("config/log/scriptengines.properties"));

        parameters.put(ScriptEngine.NAME, this.NAME);
        parameters.put(ScriptEngine.ENGINE_VERSION, this.ENGINE_VERSION);
        parameters.put(ScriptEngine.LANGUAGE, this.LANGUAGE);
        parameters.put(ScriptEngine.ENGINE, this.ENGINE);
        parameters.put(ScriptEngine.LANGUAGE_VERSION,
                DockerComposeUtilities.
                getDockerComposeVersion(SingletonProcessBuilderFactory.getInstance()));

    }


    @Override
    public String getEngineName() {
        return (String) parameters.get(ScriptEngine.NAME);
    }

    @Override
    public String getEngineVersion() {
        return (String) parameters.get(ScriptEngine.ENGINE_VERSION);
    }

    @Override
    public List<String> getExtensions() {
        return Arrays.asList("yml", "yaml");
    }

    @Override
    public List<String> getMimeTypes() {
        return Arrays.asList("text/yaml");
    }

    @Override
    public List<String> getNames() {
        return Arrays.asList("docker-compose", "fig");
    }

    @Override
    public String getLanguageName() {
        return (String) parameters.get(ScriptEngine.LANGUAGE);
    }

    @Override
    public String getLanguageVersion() {
        return (String) parameters.get(ScriptEngine.LANGUAGE_VERSION);
    }

    @Override
    public Object getParameter(String key) {
        return parameters.get(key);
    }

    @Override
    public String getMethodCallSyntax(String obj, String m, String... args) {
        return null;
    }

    @Override
    public String getOutputStatement(String toDisplay) {
        return null;
    }

    @Override
    public String getProgram(String... statements) {
        return null;
    }

    @Override
    public ScriptEngine getScriptEngine() {
        return new DockerComposeScriptEngine();
    }
}

@@ -721,24 +721,121 @@
 shMap%3C%3E();%0A%0A
+    private static final String log4jConfigurationFile = %22config/log/scriptengines.properties%22;%0A%0A
     public D
@@ -979,16 +979,34 @@
 d dirty%0A
+        try %7B%0A    
         
@@ -1072,16 +1072,20 @@
         
+    
 .getClas
@@ -1118,48 +1118,262 @@
 eam(
-%22config/log/scriptengines.properties%22));
+log4jConfigurationFile));%0A        %7D catch (NullPointerException e) %7B%0A            System.err.println(%22Log4j configuration file not found: %22+ log4jConfigurationFile +%0A            %22. Any output for the docker-compose script engine is disabled.%22);%0A        %7D%0A
 %0A%0A  

Add log4j to the scriptengine, to better see occurring errors. Change the classpath to the proactive home path.