Skip to content

Commit

Permalink
use older API until newer is merged
Browse files Browse the repository at this point in the history
  • Loading branch information
akostadinov committed Dec 21, 2017
1 parent f69b2de commit 747a0bc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.37-SNAPSHOT</version>
<version>1.37</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

/**
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 747a0bc

Please sign in to comment.