mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-15 04:22:09 +08:00
Merge branch 'dev' of https://gitee.com/dromara/liteFlow into issue/#I8MW6Q-2
Conflicts: liteflow-core/src/main/java/com/yomahub/liteflow/script/ScriptExecutor.java
This commit is contained in:
@@ -38,8 +38,7 @@ public class GraalJavaScriptExecutor extends ScriptExecutor {
|
||||
@Override
|
||||
public void load(String nodeId, String script) {
|
||||
try {
|
||||
String wrapScript = StrUtil.format("function process(){{}} process();", script);
|
||||
scriptMap.put(nodeId, Source.create("js", wrapScript));
|
||||
scriptMap.put(nodeId, Source.create("js", (CharSequence) compile(script)));
|
||||
}
|
||||
catch (Exception e) {
|
||||
String errorMsg = StrUtil.format("script loading error for node[{}], error msg:{}", nodeId, e.getMessage());
|
||||
@@ -99,4 +98,12 @@ public class GraalJavaScriptExecutor extends ScriptExecutor {
|
||||
return ScriptTypeEnum.JS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object compile(String script) throws Exception {
|
||||
String wrapScript = StrUtil.format("function process(){{}} process();", script);
|
||||
Context context = Context.newBuilder().allowAllAccess(true).engine(engine).build();
|
||||
context.parse(Source.create("js", wrapScript));
|
||||
return wrapScript;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,12 +23,7 @@ public class JavaExecutor extends ScriptExecutor {
|
||||
@Override
|
||||
public void load(String nodeId, String script) {
|
||||
try{
|
||||
IScriptEvaluator se = CompilerFactoryFactory.getDefaultCompilerFactory(this.getClass().getClassLoader()).newScriptEvaluator();
|
||||
se.setTargetVersion(8);
|
||||
se.setReturnType(Object.class);
|
||||
se.setParameters(new String[] {"_meta"}, new Class[] {ScriptExecuteWrap.class});
|
||||
se.cook(convertScript(script));
|
||||
compiledScriptMap.put(nodeId, se);
|
||||
compiledScriptMap.put(nodeId, (IScriptEvaluator) compile(script));
|
||||
}catch (Exception e){
|
||||
String errorMsg = StrUtil.format("script loading error for node[{}],error msg:{}", nodeId, e.getMessage());
|
||||
throw new ScriptLoadException(errorMsg);
|
||||
@@ -66,6 +61,16 @@ public class JavaExecutor extends ScriptExecutor {
|
||||
return ScriptTypeEnum.JAVA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object compile(String script) throws Exception {
|
||||
IScriptEvaluator se = CompilerFactoryFactory.getDefaultCompilerFactory(this.getClass().getClassLoader()).newScriptEvaluator();
|
||||
se.setTargetVersion(8);
|
||||
se.setReturnType(Object.class);
|
||||
se.setParameters(new String[] {"_meta"}, new Class[] {ScriptExecuteWrap.class});
|
||||
se.cook(convertScript(script));
|
||||
return se;
|
||||
}
|
||||
|
||||
private String convertScript(String script){
|
||||
//替换掉public,private,protected等修饰词
|
||||
String script1 = script.replaceAll("public class", "class")
|
||||
|
||||
@@ -13,6 +13,8 @@ import com.yomahub.liteflow.script.exception.ScriptLoadException;
|
||||
import com.yomahub.liteflow.util.CopyOnWriteHashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -41,8 +43,7 @@ public class QLExpressScriptExecutor extends ScriptExecutor {
|
||||
@Override
|
||||
public void load(String nodeId, String script) {
|
||||
try {
|
||||
InstructionSet instructionSet = expressRunner.getInstructionSetFromLocalCache(script);
|
||||
compiledScriptMap.put(nodeId, instructionSet);
|
||||
compiledScriptMap.put(nodeId, (InstructionSet) compile(script));
|
||||
}
|
||||
catch (Exception e) {
|
||||
String errorMsg = StrUtil.format("script loading error for node[{}],error msg:{}", nodeId, e.getMessage());
|
||||
@@ -96,4 +97,9 @@ public class QLExpressScriptExecutor extends ScriptExecutor {
|
||||
return ScriptTypeEnum.QLEXPRESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object compile(String script) throws Exception {
|
||||
return expressRunner.getInstructionSetFromLocalCache(script);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user