Skip to content

Commit

Permalink
Merge pull request #29 from chichimotsu/develop
Browse files Browse the repository at this point in the history
Add 'chcp' command for windows environment to fix character corruption.
  • Loading branch information
marshall777 authored Feb 16, 2017
2 parents 304472d + 2899401 commit cf602de
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/java/hudson/plugins/msbuild/MsBuildBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
import java.nio.charset.Charset;

/**
* @author kyle.sweeney@valtech.com
Expand Down Expand Up @@ -192,7 +193,11 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
}

if (!launcher.isUnix()) {
args.prepend("cmd.exe", "/C", "\"");
final int cpi = getCodePageIdentifier(build.getCharset());
if(cpi != 0)
args.prepend("cmd.exe", "/C", "\"", "chcp", String.valueOf(cpi), "&&");
else
args.prepend("cmd.exe", "/C", "\"");
args.add("\"", "&&", "exit", "%%ERRORLEVEL%%");
}

Expand Down Expand Up @@ -315,4 +320,28 @@ public MsBuildInstallation.DescriptorImpl getToolDescriptor() {
return ToolInstallation.all().get(MsBuildInstallation.DescriptorImpl.class);
}
}

private static int getCodePageIdentifier(Charset charset) {
final String s_charset = charset.name();
if(s_charset.equalsIgnoreCase("utf-8")) // Unicode
return 65001;
else if(s_charset.equalsIgnoreCase("ibm437")) // US
return 437;
else if(s_charset.equalsIgnoreCase("ibm850")) // OEM Multilingual Latin 1
return 850;
else if(s_charset.equalsIgnoreCase("ibm852")) // OEM Latin2
return 852;
else if(s_charset.equalsIgnoreCase("shift_jis") || s_charset.equalsIgnoreCase("windows-31j"))//Japanese
return 932;
else if(s_charset.equalsIgnoreCase("us-ascii")) // US-ASCII
return 20127;
else if(s_charset.equalsIgnoreCase("euc-jp")) // Japanese
return 20932;
else if(s_charset.equalsIgnoreCase("iso-8859-1")) // Latin 1
return 28591;
else if(s_charset.equalsIgnoreCase("iso-8859-2")) // Latin 2
return 28592;
else
return 0;
}
}

0 comments on commit cf602de

Please sign in to comment.