Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public String execute() {
}
String scriptToRun = new LogicScriptUtil().buildScript(step.getScript());
try {
System.setProperty("nashorn.args", "--language=es6");
ScriptIOBean ioBean = new ScriptRunner().runScript(step.getName(), scriptToRun,
new ScriptEngineManager().getEngineByExtension("js"), inputs, outputLogger);
String action = (String) ioBean.getOutput("action");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void setProductName(String productName) {
}

public ScriptEngine getEngine() {
System.setProperty("nashorn.args", "--language=es6");
return new ScriptEngineManager().getEngineByExtension(FilenameUtils.getExtension(name));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* #L%
*/

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -56,15 +57,18 @@ public class ConfiguredLanguage {
static {
for (String[] row : data) {
try {
System.setProperty("nashorn.args", "--language=es6");
ScriptEngine engineByName = manager.getEngineByName(row[0]);
if (engineByName == null) {
ScriptEngineFactory fact = (ScriptEngineFactory) Class.forName(row[3]).newInstance();
ScriptEngineFactory fact = (ScriptEngineFactory) Class.forName(row[3]).getDeclaredConstructor().newInstance();
manager.registerEngineName(row[0], fact);
}
configuredLanguages.add(new ConfiguredLanguage(row[0], row[1], row[2], row[4]));
extensionSet.addAll(engineByName.getFactory().getExtensions());
} catch (Exception e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
System.out.println("No ScriptEngine for language " + row[0] + " in classpath.");
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
for (ScriptEngineFactory fact : manager.getEngineFactories()) {
System.out.println(fact.getLanguageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* #L%
*/

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
Expand All @@ -26,7 +27,6 @@
import javax.script.ScriptEngineManager;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;

/**
Expand Down Expand Up @@ -55,18 +55,21 @@ public class ConfiguredLanguage {

private static final ScriptEngineManager manager = new ScriptEngineManager();
static {
System.setProperty("nashorn.args", "--language=es6");
for (String[] row : data) {
try {
ScriptEngine engineByName = manager.getEngineByName(row[0]);
if (engineByName == null) {
ScriptEngineFactory fact = (ScriptEngineFactory) Class.forName(row[3]).newInstance();
ScriptEngineFactory fact = (ScriptEngineFactory) Class.forName(row[3]).getDeclaredConstructor().newInstance();
manager.registerEngineName(row[0], fact);
engineByName = manager.getEngineByName(row[0]);
}
configuredLanguages.add(new ConfiguredLanguage(row[0], row[1], row[2], row[4]));
extensionSet.addAll(engineByName.getFactory().getExtensions());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
System.out.println("No ScriptEngine for language " + row[0] + " in classpath.");
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
manager.getEngineFactories().stream().map(ScriptEngineFactory::getLanguageName).forEach(System.out::println);
}
Expand Down Expand Up @@ -95,7 +98,7 @@ public static List<ConfiguredLanguage> getConfiguredLanguages() {
public static ConfiguredLanguage getLanguageByExtension(String scriptName) {
String extension = FilenameUtils.getExtension(scriptName);
ScriptEngine engineByExtension = manager.getEngineByExtension(extension);
return configuredLanguages.stream().filter(lang -> StringUtils.equals(lang.name, engineByExtension.getFactory().getLanguageName())).findFirst().orElse(null);
return configuredLanguages.stream().filter(lang -> lang.name.equals(engineByExtension.getFactory().getLanguageName())).findFirst().orElse(null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public void testScript() {
inputs.put("request", createRequest());
inputs.put("response", createResponse());
try {
System.setProperty("nashorn.args", "--language=es6");
String scriptToRun = new LogicScriptUtil().buildScript(script);
logMap("Variables", vars.getVariableValues(), outputLogger);
outputLogger.logLine(DASHES + " script " + DASHES);
Expand Down