Skip to content

Commit

Permalink
[FIXED JENKINS-23617] Improve parsing of paramaters passed to groovy …
Browse files Browse the repository at this point in the history
…binary
  • Loading branch information
vjuranek committed Jul 6, 2014
1 parent 7d7972b commit 800175f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Expand Up @@ -44,6 +44,11 @@
<version>1.4</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.2</version>
</dependency>
</dependencies>

<repositories>
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/hudson/plugins/groovy/Groovy.java
Expand Up @@ -25,6 +25,7 @@
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;

import org.apache.commons.exec.CommandLine;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

Expand Down Expand Up @@ -282,10 +283,10 @@ protected List<String> buildCommandLine(AbstractBuild build, BuildListener liste
}

//Add groovy parameters
if(parameters != null) {
StringTokenizer tokens = new StringTokenizer(parameters);
while(tokens.hasMoreTokens()) {
list.add(Util.replaceMacro(tokens.nextToken(),vr));
if(parameters != null && !parameters.isEmpty()) {
String[] args = parseGroovyCmdLine(parameters);
for(String arg : args) {
list.add(Util.replaceMacro(arg, vr));
}
}

Expand All @@ -310,6 +311,21 @@ protected List<String> buildCommandLine(AbstractBuild build, BuildListener liste
return list;

}

/**
* Parse parameters to be passed as arguments to the groovy binary
*
*/
private String[] parseGroovyCmdLine(String line) {
CommandLine cmdLine = CommandLine.parse(line);
String[] parsedArgs = cmdLine.getArguments();
String[] args = new String[parsedArgs.length + 1];
args[0] = cmdLine.getExecutable(); //as we pass only arguments, this is actually the first argument
if(parsedArgs.length > 0) {
System.arraycopy(parsedArgs, 0, args, 1, parsedArgs.length);
}
return args;
}


public String getCommand() {
Expand Down

0 comments on commit 800175f

Please sign in to comment.