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

Add 'chcp' command for windows environment to fix character corruption. #29

Merged
merged 3 commits into from
Feb 16, 2017
Merged
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
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;
}
}