Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-28148] Whitespaces in toolLocations #28

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions client/src/main/java/hudson/plugins/swarm/Options.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package hudson.plugins.swarm;

import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.spi.MapOptionHandler;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
*
Expand Down Expand Up @@ -55,8 +57,12 @@ public class Options {
)
public String mode = ModeOptionHandler.NORMAL;

@Option(name = "-toolLocations", usage = "Whitespace-separated list of tool locations to be defined on this slave. A tool location is specified as 'toolName:location'")
public List<String> toolLocations = new ArrayList<String>();
@Option(
name = "-t", aliases = "--toolLocation",
usage = "A tool location to be defined on this slave. It is specified as 'toolName=location'",
handler = MapOptionHandler.class
)
public Map<String,String> toolLocations;

@Option(name = "-username", usage = "The Jenkins username for authentication")
public String username;
Expand Down
9 changes: 6 additions & 3 deletions client/src/main/java/hudson/plugins/swarm/SwarmClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
Expand Down Expand Up @@ -54,6 +53,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Random;

Expand Down Expand Up @@ -305,15 +305,18 @@ protected void createSwarmSlave(Candidate target) throws IOException, Interrupte
// but immediately a 403 (Forbidden)

String labelStr = StringUtils.join(options.labels, ' ');
String toolLocationsStr = StringUtils.join(options.toolLocations, ' ');
StringBuilder toolLocationBuilder = new StringBuilder();
for (Entry<String, String> toolLocation : options.toolLocations.entrySet()){
toolLocationBuilder.append(param("toolLocation",toolLocation.getKey()+":"+toolLocation.getValue()));
}

PostMethod post = new PostMethod(target.url
+ "/plugin/swarm/createSlave?name=" + options.name
+ "&executors=" + options.executors
+ param("remoteFsRoot", options.remoteFsRoot.getAbsolutePath())
+ param("description", options.description)
+ param("labels", labelStr)
+ param("toolLocations", toolLocationsStr)
+ toolLocationBuilder.toString()
+ "&secret=" + target.secret
+ param("mode", options.mode.toUpperCase(Locale.ENGLISH))
+ param("hash", hash)
Expand Down
12 changes: 6 additions & 6 deletions plugin/src/main/java/hudson/plugins/swarm/PluginImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import hudson.tools.ToolLocationNodeProperty;
import hudson.tools.ToolLocationNodeProperty.ToolLocation;
import jenkins.model.Jenkins;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.ArrayUtils;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
Expand Down Expand Up @@ -41,7 +41,7 @@ public class PluginImpl extends Plugin {
*/
public void doCreateSlave(StaplerRequest req, StaplerResponse rsp, @QueryParameter String name, @QueryParameter String description, @QueryParameter int executors,
@QueryParameter String remoteFsRoot, @QueryParameter String labels, @QueryParameter String secret, @QueryParameter Node.Mode mode,
@QueryParameter String toolLocations, @QueryParameter(fixEmpty = true) String hash) throws IOException {
@QueryParameter(fixEmpty = true) String hash) throws IOException {

if (!getSwarmSecret().equals(secret)) {
rsp.setStatus(SC_FORBIDDEN);
Expand All @@ -53,8 +53,9 @@ public void doCreateSlave(StaplerRequest req, StaplerResponse rsp, @QueryParamet

jenkins.checkPermission(SlaveComputer.CREATE);

String[] toolLocations = req.getParameterValues("toolLocation");
List<ToolLocationNodeProperty> nodeProperties = Lists.newArrayList();
if (StringUtils.isNotBlank(toolLocations)) {
if (!ArrayUtils.isEmpty(toolLocations)) {
List<ToolLocation> parsedToolLocations = parseToolLocations(toolLocations);
nodeProperties = Lists.newArrayList(new ToolLocationNodeProperty(parsedToolLocations));
}
Expand Down Expand Up @@ -115,11 +116,10 @@ public void doCreateSlave(StaplerRequest req, StaplerResponse rsp, @QueryParamet
}
}

private List<ToolLocation> parseToolLocations(String toolLocations) {
private List<ToolLocation> parseToolLocations(String[] toolLocations) {
List<ToolLocationNodeProperty.ToolLocation> result = Lists.newArrayList();

String[] toolLocsArray = toolLocations.split(" ");
for (String toolLocKeyValue : toolLocsArray) {
for (String toolLocKeyValue : toolLocations) {
boolean found = false;
// Limit the split on only the first occurence
// of ':', so that the tool location path can
Expand Down