mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-15 04:22:09 +08:00
新增一个验证脚本的方法
This commit is contained in:
@@ -33,8 +33,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());
|
||||
@@ -84,4 +83,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,12 +19,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);
|
||||
@@ -52,6 +47,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.List;
|
||||
import java.util.Map;
|
||||
@@ -40,8 +42,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());
|
||||
@@ -85,4 +86,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