From 747a0bc63e35762675bb894825cbd7871e59e43a Mon Sep 17 00:00:00 2001 From: Aleksandar Kostadinov Date: Wed, 13 Dec 2017 17:31:54 +0200 Subject: [PATCH] use older API until newer is merged see https://github.com/jenkinsci/script-security-plugin/pull/169 --- pom.xml | 2 +- .../logstash/LogstashScriptProcessor.java | 25 +++---------------- .../plugins/logstash/LogstashWriterTest.java | 1 + 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 2eb144a7..53eb2eea 100644 --- a/pom.xml +++ b/pom.xml @@ -132,7 +132,7 @@ org.jenkins-ci.plugins script-security - 1.37-SNAPSHOT + 1.37 diff --git a/src/main/java/jenkins/plugins/logstash/LogstashScriptProcessor.java b/src/main/java/jenkins/plugins/logstash/LogstashScriptProcessor.java index 61f7fb53..a0cf545a 100644 --- a/src/main/java/jenkins/plugins/logstash/LogstashScriptProcessor.java +++ b/src/main/java/jenkins/plugins/logstash/LogstashScriptProcessor.java @@ -68,10 +68,6 @@ public class LogstashScriptProcessor implements LogstashPayloadProcessor{ @Nonnull private final ClassLoader classLoader; - /** Script prepared for execution */ - @Nonnull - private final SecureGroovyScript.PreparedScript preparedScript; - public LogstashScriptProcessor(SecureGroovyScript script, OutputStream consoleOut) { this.script = script; this.consoleOut = consoleOut; @@ -83,11 +79,6 @@ public LogstashScriptProcessor(SecureGroovyScript script, OutputStream consoleOu // not sure what the diff is compared to getClass().getClassLoader(); final Jenkins jenkins = Jenkins.getInstance(); classLoader = jenkins.getPluginManager().uberClassLoader; - try { - preparedScript = script.prepare(classLoader, binding); - } catch (Exception e) { - throw new RuntimeException("Error preparing log processor groovy script.", e); - } } /** @@ -110,22 +101,14 @@ private void buildLogPrintln(Object o) throws IOException { @Override public JSONObject process(JSONObject payload) throws Exception { binding.setVariable("payload", payload); - preparedScript.run(); - Object processedPayload = binding.getVariable("payload"); - if (processedPayload != null && !(processedPayload instanceof JSONObject)) { - throw new ClassCastException("script returned " + processedPayload.getClass().getName() + " instead of JSONObject"); - } - return (JSONObject) processedPayload; + script.evaluate(classLoader, binding); + return (JSONObject) binding.getVariable("payload"); } @Override public JSONObject finish() throws Exception { - try { - buildLogPrintln("Tearing down Script Log Processor.."); - return process(null); - } finally { - preparedScript.cleanUp(); - } + buildLogPrintln("Tearing down Script Log Processor.."); + return process(null); } /** diff --git a/src/test/java/jenkins/plugins/logstash/LogstashWriterTest.java b/src/test/java/jenkins/plugins/logstash/LogstashWriterTest.java index 071633cb..8121e237 100644 --- a/src/test/java/jenkins/plugins/logstash/LogstashWriterTest.java +++ b/src/test/java/jenkins/plugins/logstash/LogstashWriterTest.java @@ -283,6 +283,7 @@ public void writeProcessedSuccess() throws Exception { "}"; SecureGroovyScript script = new SecureGroovyScript(scriptString, true, null); + script.configuringWithNonKeyItem(); LogstashScriptProcessor processor = new LogstashScriptProcessor(script, errorBuffer); LogstashWriter writer = createLogstashWriter(mockBuild, errorBuffer, "http://my-jenkins-url", mockDao, mockBuildData, processor); errorBuffer.reset();