Skip to content
Permalink
Browse files

Fix JENKINS-22344 and JENKINS-22451

  • Loading branch information
gboissinot committed Aug 15, 2014
1 parent da904ff commit bdec2dfe089d62a80fd0371db605ee9c3ebbe41b
@@ -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;
@@ -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;
@@ -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
@@ -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);
@@ -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.
You can’t perform that action at this time.