Skip to content

Commit

Permalink
Merge branch 'JENKINS-30348'
Browse files Browse the repository at this point in the history
  • Loading branch information
daspilker committed Oct 4, 2015
2 parents 161ce5c + 98ad52a commit ea8254a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 40 deletions.
2 changes: 2 additions & 0 deletions docs/Home.md
Expand Up @@ -49,6 +49,8 @@ Have a look at the [Jenkins Job DSL Gradle example](https://github.com/sheehan/j
deprecated, see [Migration](Migration#migrating-to-139)
* Fixed `StackOverflowError` when using `downstreamParameterized` publisher
([JENKINS-30504](https://issues.jenkins-ci.org/browse/JENKINS-30504))
* Fixed problem with additional classpath
([JENKINS-30348](https://issues.jenkins-ci.org/browse/JENKINS-30348))
* Allow to abort DSL processing
* Improved console output
* Added support for the [Cron Column Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Cron+Column+Plugin)
Expand Down
Expand Up @@ -11,6 +11,7 @@
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.codehaus.groovy.runtime.InvokerHelper;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
Expand Down Expand Up @@ -38,53 +39,63 @@ public static JobParent runDslEngineForParent(ScriptRequest scriptRequest, JobMa

// Otherwise baseScript won't take effect
GroovyClassLoader cl = new GroovyClassLoader(parentClassLoader, config);
try {
GroovyScriptEngine engine = new GroovyScriptEngine(scriptRequest.getUrlRoots(), cl);
try {
engine.setConfig(config);

Binding binding = createBinding(jobManagement);

JobParent jp;
try {
Script script;
if (scriptRequest.getBody() != null) {
jobManagement.getOutputStream().println("Processing provided DSL script");
Class cls = engine.getGroovyClassLoader().parseClass(scriptRequest.getBody(), "script");
script = InvokerHelper.createScript(cls, binding);
} else {
jobManagement.getOutputStream().printf("Processing DSL script %s\n", scriptRequest.getLocation());
if (!isValidScriptName(scriptRequest.getLocation())) {
jobManagement.logDeprecationWarning(
"script names may only contain letters, digits and underscores, but may not start with a digit; support for arbitrary names",
scriptRequest.getLocation(),
-1
);
}
script = engine.createScript(scriptRequest.getLocation(), binding);
}
assert script instanceof JobParent;

GroovyScriptEngine engine = new GroovyScriptEngine(scriptRequest.getUrlRoots(), cl);

engine.setConfig(config);
jp = (JobParent) script;
jp.setJm(jobManagement);

Binding binding = createBinding(jobManagement);
binding.setVariable("jobFactory", jp);

JobParent jp;
try {
Script script;
if (scriptRequest.getBody() != null) {
jobManagement.getOutputStream().println("Processing provided DSL script");
Class cls = engine.getGroovyClassLoader().parseClass(scriptRequest.getBody(), "script");
script = InvokerHelper.createScript(cls, binding);
} else {
jobManagement.getOutputStream().printf("Processing DSL script %s\n", scriptRequest.getLocation());
if (!isValidScriptName(scriptRequest.getLocation())) {
jobManagement.logDeprecationWarning(
"script names may only contain letters, digits and underscores, but may not start with a digit; support for arbitrary names",
scriptRequest.getLocation(),
-1
);
try {
script.run();
} catch (DslScriptException e) {
throw e;
} catch (RuntimeException e) {
throw new DslScriptException(e.getMessage(), e);
}
} catch (CompilationFailedException e) {
throw new DslException(e.getMessage(), e);
} catch (ResourceException e) {
throw new IOException("Unable to run script", e);
} catch (ScriptException e) {
throw new IOException("Unable to run script", e);
}
return jp;
} finally {
if (engine.getGroovyClassLoader() instanceof Closeable) {
((Closeable) engine.getGroovyClassLoader()).close();
}
script = engine.createScript(scriptRequest.getLocation(), binding);
}
assert script instanceof JobParent;

jp = (JobParent) script;
jp.setJm(jobManagement);

binding.setVariable("jobFactory", jp);

try {
script.run();
} catch (DslScriptException e) {
throw e;
} catch (RuntimeException e) {
throw new DslScriptException(e.getMessage(), e);
} finally {
if (cl instanceof Closeable) {
((Closeable) cl).close();
}
} catch (CompilationFailedException e) {
throw new DslException(e.getMessage(), e);
} catch (ResourceException e) {
throw new IOException("Unable to run script", e);
} catch (ScriptException e) {
throw new IOException("Unable to run script", e);
}
return jp;
}

private static boolean isValidScriptName(String scriptFile) {
Expand Down

0 comments on commit ea8254a

Please sign in to comment.