Skip to content

Commit

Permalink
Fix JENKINS-22344 and JENKINS-22451
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Aug 15, 2014
1 parent da904ff commit bdec2df
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
26 changes: 20 additions & 6 deletions src/main/java/hudson/plugins/msbuild/MsBuildBuilder.java
Expand Up @@ -6,10 +6,8 @@
import hudson.tasks.Builder;
import hudson.tools.ToolInstallation;
import hudson.util.ArgumentListBuilder;
import hudson.util.QuotedStringTokenizer;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Map;
Expand Down Expand Up @@ -82,7 +80,7 @@ public boolean getUnstableIfWarnings() {
}

public MsBuildInstallation getMsBuild() {
DescriptorImpl descriptor = (DescriptorImpl)getDescriptor();
DescriptorImpl descriptor = (DescriptorImpl) getDescriptor();
for (MsBuildInstallation i : descriptor.getInstallations()) {
if (msBuildName != null && i.getName().equals(msBuildName))
return i;
Expand Down Expand Up @@ -194,16 +192,32 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen

@Override
public Descriptor<Builder> getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
return (DescriptorImpl) super.getDescriptor();
}

/**
* Tokenize a set of arguments, preserving quotes.
*
* @param args
* @return
* @return
*/
static String[] tokenizeArgs(String args) {
return Util.tokenize(args);

if (args == null) {
return null;
}

final String[] tokenize = Util.tokenize(args);

if (tokenize == null) {
return null;
}

if (args != null && args.endsWith("\\")) {
tokenize[tokenize.length - 1] = tokenize[tokenize.length - 1] + "\\";
}

return tokenize;
}

@Extension
Expand Down
20 changes: 15 additions & 5 deletions src/test/java/hudson/plugins/msbuild/MsBuildBuilderTest.java
@@ -1,19 +1,20 @@
package hudson.plugins.msbuild;

import org.junit.Test;
import static org.junit.Assert.*;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
*
* @author Jonathan Zimmerman
*/
public class MsBuildBuilderTest {

@Test
public void shouldStripQuotedArguments() {
final String quotedPlatform = "/p:Platform=\"Any CPU\"";
final String strippedPlatform = "/p:Platform=Any CPU";

String[] tokenizedArgs = MsBuildBuilder.tokenizeArgs(quotedPlatform);
assertNotNull(tokenizedArgs);
assertEquals(1, tokenizedArgs.length);
Expand All @@ -23,11 +24,20 @@ public void shouldStripQuotedArguments() {
@Test
public void shouldSplitArguments() {
final String arguments = "/t:Build /p:Configuration=Debug";

String[] tokenizedArgs = MsBuildBuilder.tokenizeArgs(arguments);
assertNotNull(tokenizedArgs);
assertEquals(2, tokenizedArgs.length);
assertEquals("/t:Build", tokenizedArgs[0]);
assertEquals("/p:Configuration=Debug", tokenizedArgs[1]);
}

@Test
public void endEscapedCharacter() {
final String oneArgumentsWithEndBackslash = "\\\\RemoteServerName\\OfficialBuilds\\Published\\";
String[] tokenizedArgs = MsBuildBuilder.tokenizeArgs(oneArgumentsWithEndBackslash);
assertEquals(1, tokenizedArgs.length);
assertEquals(oneArgumentsWithEndBackslash, tokenizedArgs[0]);
}

}

0 comments on commit bdec2df

Please sign in to comment.