From 971bc350bddfc1d69aa98e4270d80bc02aebe312 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 13 Oct 2020 14:08:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E5=AF=BC=E5=85=A5=E5=86=85=E7=BD=AEpython?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 9 +++++++ .../metersphere/api/jmeter/JMeterService.java | 8 ++---- .../listener/AppStartListener.java | 26 +++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index a1772fb09f..3c1b52b42e 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -490,6 +490,15 @@ src/main/resources/jmeter/lib/ext ApacheJMeter_functions.jar + + org.python + jython-standalone + 2.7.0 + jar + true + src/main/resources/jmeter/lib/ext + jython-standalone.jar + ${project.build.directory}/wars false diff --git a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java index 45e177624d..9ddcd092b5 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java @@ -11,7 +11,7 @@ import org.apache.jmeter.save.SaveService; import org.apache.jmeter.util.JMeterUtils; import org.apache.jmeter.visualizers.backend.BackendListener; import org.apache.jorphan.collections.HashTree; -import org.python.core.Options; + import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; @@ -34,10 +34,6 @@ public class JMeterService { JMeterUtils.setJMeterHome(JMETER_HOME); JMeterUtils.setLocale(LocaleContextHolder.getLocale()); - - //解决无法加载 PyScriptEngineFactory - Options.importSite = false; - try { Object scriptWrapper = SaveService.loadElement(is); HashTree testPlan = getHashTree(scriptWrapper); @@ -51,7 +47,7 @@ public class JMeterService { } } - private String getJmeterHome() { + public String getJmeterHome() { String home = getClass().getResource("/").getPath() + "jmeter"; try { File file = new File(home); diff --git a/backend/src/main/java/io/metersphere/listener/AppStartListener.java b/backend/src/main/java/io/metersphere/listener/AppStartListener.java index e2068d3768..6f25d0fd66 100644 --- a/backend/src/main/java/io/metersphere/listener/AppStartListener.java +++ b/backend/src/main/java/io/metersphere/listener/AppStartListener.java @@ -1,6 +1,10 @@ package io.metersphere.listener; +import io.metersphere.api.jmeter.JMeterService; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.service.ScheduleService; +import org.python.core.Options; +import org.python.util.PythonInterpreter; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; import org.springframework.stereotype.Component; @@ -12,12 +16,16 @@ public class AppStartListener implements ApplicationListener