Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-23997] Allow specify jars in multiple lines in system …
…groovy script
  • Loading branch information
vjuranek committed Jul 28, 2014
1 parent c66961a commit dfa9181
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
39 changes: 31 additions & 8 deletions src/main/java/hudson/plugins/groovy/SystemGroovy.java
@@ -1,20 +1,25 @@
package hudson.plugins.groovy;

import com.thoughtworks.xstream.XStream;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;

import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.*;
import hudson.security.ACL;
import hudson.tasks.Builder;
import hudson.Util;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Hudson;
import hudson.util.Secret;
import hudson.util.VariableResolver;
import hudson.util.XStream2;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import hudson.util.Secret;
import hudson.util.XStream2;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;

Expand All @@ -23,6 +28,8 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import com.thoughtworks.xstream.XStream;

/**
* A Builder which executes system Groovy script in Hudson JVM (similar to HUDSON_URL/script).
*
Expand Down Expand Up @@ -56,7 +63,14 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,

CompilerConfiguration compilerConfig = new CompilerConfiguration();
if (classpath != null) {
compilerConfig.setClasspath(classpath);
EnvVars env = build.getEnvironment(listener);
env.overrideAll(build.getBuildVariables());
VariableResolver<String> vr = new VariableResolver.ByMap<String>(env);
if(classpath.contains("\n")) {
compilerConfig.setClasspathList(parseClassPath(classpath, vr));
} else {
compilerConfig.setClasspath(Util.replaceMacro(classpath,vr));
}
}

// see RemotingDiagnostics.Script
Expand Down Expand Up @@ -94,6 +108,15 @@ public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
// No output. Suppose success.
return true;
}

private List<String> parseClassPath(String classPath, VariableResolver vr) {
List<String> cp = new ArrayList<String>();
StringTokenizer tokens = new StringTokenizer(classPath);
while(tokens.hasMoreTokens()) {
cp.add(Util.replaceMacro(tokens.nextToken(),vr));
}
return cp;
}

@Extension
public static final class DescriptorImpl extends AbstractGroovyDescriptor {
Expand Down
Expand Up @@ -25,7 +25,7 @@
</f:entry>

<f:entry title="${%Classpath}" help="/plugin/groovy/classpath.html" field="classpath">
<f:textbox/>
<f:expandableTextbox/>
</f:entry>
</f:advanced>

Expand Down

0 comments on commit dfa9181

Please sign in to comment.