mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-78429 inprocess compiler should respect encoding settings
This commit is contained in:
+9
-3
@@ -16,9 +16,12 @@
|
||||
package com.intellij.compiler.impl.javaCompiler.api;
|
||||
|
||||
import com.intellij.compiler.OutputParser;
|
||||
import com.sun.source.util.*;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.source.util.TaskEvent;
|
||||
import com.sun.source.util.TaskListener;
|
||||
import com.sun.tools.javac.api.JavacTool;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.tools.*;
|
||||
import java.io.File;
|
||||
@@ -49,8 +52,11 @@ class CompAPIDriver {
|
||||
|
||||
private volatile boolean compiling;
|
||||
private static final PrintWriter COMPILER_ERRORS = new PrintWriter(System.err);
|
||||
@Nullable
|
||||
private final String mySourcesEncoding;
|
||||
|
||||
CompAPIDriver() {
|
||||
CompAPIDriver(@Nullable String sourcesEncoding) {
|
||||
mySourcesEncoding = sourcesEncoding;
|
||||
}
|
||||
|
||||
public void compile(List<String> commandLine, List<File> paths, final String outputDir) {
|
||||
@@ -60,7 +66,7 @@ class CompAPIDriver {
|
||||
assert myCompilationResults.isEmpty();
|
||||
JavaCompiler compiler = JavacTool.create(); //use current classloader
|
||||
StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, null);
|
||||
MyFileManager manager = new MyFileManager(this, outputDir, standardFileManager);
|
||||
MyFileManager manager = new MyFileManager(this, outputDir, standardFileManager, mySourcesEncoding);
|
||||
|
||||
Iterable<? extends JavaFileObject> input = manager.getJavaFileObjectsFromFiles(paths);
|
||||
|
||||
|
||||
+15
-1
@@ -141,13 +141,27 @@ public class CompilerAPICompiler implements BackendCompiler {
|
||||
private final ModuleChunk myChunk;
|
||||
private final String myOutputDir;
|
||||
private final CompileContext myCompileContext;
|
||||
private final CompAPIDriver myCompAPIDriver = new CompAPIDriver();
|
||||
private final CompAPIDriver myCompAPIDriver;
|
||||
|
||||
private MyProcess(List<String> commandLine, ModuleChunk chunk, String outputDir, CompileContext compileContext) {
|
||||
myCommandLine = commandLine;
|
||||
myChunk = chunk;
|
||||
myOutputDir = outputDir;
|
||||
myCompileContext = compileContext;
|
||||
myCompAPIDriver = new CompAPIDriver(findEncodingValue(commandLine));
|
||||
}
|
||||
|
||||
private static String findEncodingValue(List<String> commandLine) {
|
||||
boolean found = false;
|
||||
for (String param : commandLine) {
|
||||
if (found) {
|
||||
return param;
|
||||
}
|
||||
if ("-encoding".equalsIgnoreCase(param)) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() {
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
package com.intellij.compiler.impl.javaCompiler.api;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.tools.*;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.SimpleJavaFileObject;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
@@ -26,15 +28,18 @@ import java.io.*;
|
||||
@SuppressWarnings({"Since15"})
|
||||
class JavaIoFile extends SimpleJavaFileObject {
|
||||
private final File myFile;
|
||||
@Nullable
|
||||
private final String myEncoding;
|
||||
|
||||
JavaIoFile(File file, Kind kind) {
|
||||
JavaIoFile(File file, Kind kind, @Nullable String encoding) {
|
||||
super(file.toURI(), kind);
|
||||
myFile = file;
|
||||
myEncoding = encoding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
|
||||
return FileUtil.loadFile(myFile);
|
||||
return FileUtil.loadFile(myFile, myEncoding);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+8
-4
@@ -26,7 +26,9 @@ import com.sun.tools.javac.util.ListBuffer;
|
||||
import gnu.trove.THashSet;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
|
||||
import javax.tools.*;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -40,12 +42,14 @@ class MyFileManager implements StandardJavaFileManager {
|
||||
|
||||
private final String myOutputDir;
|
||||
private final StandardJavaFileManager myStandardFileManager;
|
||||
private final String myEncoding;
|
||||
private final CompAPIDriver myCompAPIDriver;
|
||||
|
||||
MyFileManager(CompAPIDriver compAPIDriver, String outputDir, StandardJavaFileManager standardFileManager) {
|
||||
MyFileManager(CompAPIDriver compAPIDriver, String outputDir, StandardJavaFileManager standardFileManager, String encoding) {
|
||||
myCompAPIDriver = compAPIDriver;
|
||||
myOutputDir = outputDir;
|
||||
myStandardFileManager = standardFileManager;
|
||||
myEncoding = encoding;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +58,7 @@ class MyFileManager implements StandardJavaFileManager {
|
||||
List<JavaFileObject> result = new ArrayList<JavaFileObject>(size);
|
||||
|
||||
for (File file : files) {
|
||||
JavaFileObject fileObject = new JavaIoFile(file, JavaFileObject.Kind.SOURCE);
|
||||
JavaFileObject fileObject = new JavaIoFile(file, JavaFileObject.Kind.SOURCE, myEncoding);
|
||||
result.add(fileObject);
|
||||
}
|
||||
|
||||
@@ -119,7 +123,7 @@ class MyFileManager implements StandardJavaFileManager {
|
||||
if (kind == JavaFileObject.Kind.SOURCE && child.getFileSystem() instanceof JarFileSystem) continue; //for some reasdon javac looks for java files inside jar
|
||||
|
||||
// use VFS to read content inside .jar
|
||||
JavaFileObject fileObject = !child.getPath().contains("!/") ? new JavaIoFile(new File(child.getPath()), kind) : new JavaVirtualFile(child, kind);
|
||||
JavaFileObject fileObject = !child.getPath().contains("!/") ? new JavaIoFile(new File(child.getPath()), kind, myEncoding) : new JavaVirtualFile(child, kind);
|
||||
results.add(fileObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user