diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 573299528348..9c4693d31f7b 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -56,6 +56,7 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.BulkFileListener; @@ -95,6 +96,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.net.InetSocketAddress; +import java.nio.charset.Charset; import java.util.*; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; @@ -154,10 +156,13 @@ public class BuildManager implements ApplicationComponent{ private final BuildMessageDispatcher myMessageDispatcher = new BuildMessageDispatcher(); private volatile int myListenPort = -1; private volatile CmdlineRemoteProto.Message.ControllerMessage.GlobalSettings myGlobals; + @Nullable + private final Charset mySystemCharset; public BuildManager(final ProjectManager projectManager) { IS_UNIT_TEST_MODE = ApplicationManager.getApplication().isUnitTestMode(); myProjectManager = projectManager; + mySystemCharset = CharsetToolkit.getDefaultSystemCharset(); final String systemPath = PathManager.getSystemPath(); File system = new File(systemPath); try { @@ -556,13 +561,7 @@ public class BuildManager implements ApplicationComponent{ return; } myBuildsInProgress.put(projectPath, future); - final Process process = launchBuildProcess(project, myListenPort, sessionId); - final OSProcessHandler processHandler = new OSProcessHandler(process) { - @Override - protected boolean shouldDestroyProcessRecursively() { - return true; - } - }; + final OSProcessHandler processHandler = launchBuildProcess(project, myListenPort, sessionId); final StringBuilder stdErrOutput = new StringBuilder(); processHandler.addProcessListener(new ProcessAdapter() { @Override @@ -685,7 +684,7 @@ public class BuildManager implements ApplicationComponent{ return cmdBuilder.build(); } - private Process launchBuildProcess(Project project, final int port, final UUID sessionId) throws ExecutionException { + private OSProcessHandler launchBuildProcess(Project project, final int port, final UUID sessionId) throws ExecutionException { // choosing sdk with which the build process should be run Sdk projectJdk = null; JavaSdkVersion sdkVersion = null; @@ -804,8 +803,11 @@ public class BuildManager implements ApplicationComponent{ } // javac's VM should use the same default locale that IDEA uses in order for javac to print messages in 'correct' language - String[] propertyNames = {"user.language", "user.country", "user.region"}; - for (String name : propertyNames) { + if (mySystemCharset != null) { + cmdLine.setCharset(mySystemCharset); + cmdLine.addParameter("-D" + CharsetToolkit.FILE_ENCODING_PROPERTY + "=" + mySystemCharset.name()); + } + for (String name : new String[]{"user.language", "user.country", "user.region"}) { final String value = System.getProperty(name); if (value != null) { cmdLine.addParameter("-D" + name + "=" + value); @@ -836,7 +838,14 @@ public class BuildManager implements ApplicationComponent{ cmdLine.setWorkDirectory(workDirectory); - return cmdLine.createProcess(); + final Process process = cmdLine.createProcess(); + + return new OSProcessHandler(process, null, mySystemCharset) { + @Override + protected boolean shouldDestroyProcessRecursively() { + return true; + } + }; } public File getBuildSystemDirectory() { diff --git a/jps/jps-builders/src/org/jetbrains/jps/javac/JavacServerBootstrap.java b/jps/jps-builders/src/org/jetbrains/jps/javac/JavacServerBootstrap.java index ebde1a093772..05a33b5ae65a 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/javac/JavacServerBootstrap.java +++ b/jps/jps-builders/src/org/jetbrains/jps/javac/JavacServerBootstrap.java @@ -56,6 +56,10 @@ public class JavacServerBootstrap { //appendParam(cmdLine, "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009"); // javac's VM should use the same default locale that IDEA uses in order for javac to print messages in 'correct' language + final String encoding = System.getProperty("file.encoding"); + if (encoding != null) { + appendParam(cmdLine, "-Dfile.encoding=" + encoding); + } final String lang = System.getProperty("user.language"); if (lang != null) { //noinspection HardCodedStringLiteral