From 3f1da2414360e23ce058c7747e7ce694a39ba64c Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 18 Mar 2021 17:27:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8A=A0=E8=BD=BD=E5=A4=96=E9=83=A8js?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=A2=9E=E5=8A=A0=20Nashorn=20JavaS?= =?UTF-8?q?cript=E5=BC=95=E6=93=8E=E5=88=87=E6=8D=A2=E5=88=B0GraalVM=20?= =?UTF-8?q?=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/processors/MsJSR223Processor.java | 6 ++++++ .../request/processors/post/MsJSR223PostProcessor.java | 6 ++++++ .../request/processors/pre/MsJSR223PreProcessor.java | 10 ++++++++++ .../scenario/common/Jsr233ProcessorContent.vue | 5 +++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java index ba03b6a7a0..10136f6356 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/MsJSR223Processor.java @@ -46,6 +46,12 @@ public class MsJSR223Processor extends MsTestElement { processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); processor.setProperty("cacheKey", "true"); processor.setProperty("scriptLanguage", this.getScriptLanguage()); + if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("nashornScript")) { + processor.setProperty("scriptLanguage", "nashorn"); + } + if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("graalVMScript")) { + processor.setProperty("scriptLanguage", "javascript"); + } processor.setProperty("script", this.getScript()); final HashTree jsr223PreTree = tree.add(processor); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java index cdf5ec9dd9..3172f2855e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJSR223PostProcessor.java @@ -40,6 +40,12 @@ public class MsJSR223PostProcessor extends MsTestElement { processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); processor.setProperty("cacheKey", "true"); processor.setProperty("scriptLanguage", this.getScriptLanguage()); + if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("nashornScript")) { + processor.setProperty("scriptLanguage", "nashorn"); + } + if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("graalVMScript")) { + processor.setProperty("scriptLanguage", "javascript"); + } processor.setProperty("script", this.getScript()); final HashTree jsr223PostTree = tree.add(processor); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java index 48bb6108d2..9cc8b35e56 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJSR223PreProcessor.java @@ -12,6 +12,7 @@ import org.apache.jmeter.modifiers.JSR223PreProcessor; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; +import org.graalvm.polyglot.Context; import java.util.List; @@ -38,6 +39,8 @@ public class MsJSR223PreProcessor extends MsTestElement { } public JSR223PreProcessor getJSR223PreProcessor() { + Context.newBuilder().allowNativeAccess(true).build(); + JSR223PreProcessor processor = new JSR223PreProcessor(); processor.setEnabled(this.isEnable()); if (StringUtils.isNotEmpty(this.getName())) { @@ -49,6 +52,13 @@ public class MsJSR223PreProcessor extends MsTestElement { processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); processor.setProperty("cacheKey", "true"); processor.setProperty("scriptLanguage", this.getScriptLanguage()); + if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("nashornScript")) { + processor.setProperty("scriptLanguage", "nashorn"); + } + if (StringUtils.isNotEmpty(this.getScriptLanguage()) && this.getScriptLanguage().equals("graalVMScript")) { + processor.setProperty("scriptLanguage", "javascript"); + } + processor.setProperty("script", this.getScript()); return processor; } diff --git a/frontend/src/business/components/api/automation/scenario/common/Jsr233ProcessorContent.vue b/frontend/src/business/components/api/automation/scenario/common/Jsr233ProcessorContent.vue index e00edd4aaa..0fdeff80af 100644 --- a/frontend/src/business/components/api/automation/scenario/common/Jsr233ProcessorContent.vue +++ b/frontend/src/business/components/api/automation/scenario/common/Jsr233ProcessorContent.vue @@ -72,13 +72,14 @@ ], isCodeEditAlive: true, languages: [ - 'beanshell', "python", "groovy", "javascript" + 'beanshell', "python", "groovy", "nashornScript","graalVMScript" ], codeEditModeMap: { beanshell: 'java', python: 'python', groovy: 'java', - javascript: 'javascript', + nashornScript: 'javascript', + graalVMScript: 'javascript', } } },