diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java index e6a90dc9ab92..08305785073f 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java @@ -387,6 +387,11 @@ public class BackendCompilerWrapper { process.destroy(); exitValue = process.exitValue(); } + catch (Error e) { + process.destroy(); + exitValue = process.exitValue(); + throw e; + } finally { if (CompileDriver.ourDebugMode) { System.out.println("Compiler exit code is " + exitValue); diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompAPIDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompAPIDriver.java index dc81ab806f56..5891af40f1cc 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompAPIDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/CompAPIDriver.java @@ -58,7 +58,8 @@ class CompAPIDriver { assert myCompilationResults.isEmpty(); JavaCompiler compiler = JavacTool.create(); //use current classloader - MyFileManager manager = new MyFileManager(this, outputDir); + StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, null); + MyFileManager manager = new MyFileManager(this, outputDir, standardFileManager); Iterable input = manager.getJavaFileObjectsFromFiles(paths); diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/MyFileManager.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/MyFileManager.java index 166145e53965..162d20414cfa 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/MyFileManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/api/MyFileManager.java @@ -22,8 +22,7 @@ import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.SmartList; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.DefaultFileManager; +import com.sun.tools.javac.util.ListBuffer; import gnu.trove.THashSet; import gnu.trove.TObjectHashingStrategy; @@ -36,17 +35,17 @@ import java.util.*; /** * @author cdr */ -@SuppressWarnings({"Since15"}) -class MyFileManager extends DefaultFileManager { +class MyFileManager implements StandardJavaFileManager { private static final Logger LOG = Logger.getInstance("#com.intellij.compiler.impl.javaCompiler.api.MyFileManager"); private final String myOutputDir; + private final StandardJavaFileManager myStandardFileManager; private final CompAPIDriver myCompAPIDriver; - MyFileManager(CompAPIDriver compAPIDriver, String outputDir) { - super(new Context(), false, null); + MyFileManager(CompAPIDriver compAPIDriver, String outputDir, StandardJavaFileManager standardFileManager) { myCompAPIDriver = compAPIDriver; myOutputDir = outputDir; + myStandardFileManager = standardFileManager; } @Override @@ -76,11 +75,17 @@ class MyFileManager extends DefaultFileManager { return createUri("file:///" + outputDir.replace('\\','/') + "/" + name.replace('.', '/') + JavaFileObject.Kind.CLASS.extension); } + @Override public Iterable list(Location location, String packageName, Set kinds, boolean recurse) throws IOException { if (recurse) { - return super.list(location, packageName, kinds, recurse); + throw new IllegalArgumentException(); } + return findInside(location, packageName, kinds, false); + } + + private List findInside(Location location, String packageName, Set kinds, boolean lookForFile) + throws IOException { Iterable path = getLocation(location); if (path == null) return Collections.emptyList(); @@ -96,11 +101,20 @@ class MyFileManager extends DefaultFileManager { } VirtualFile virtualFile = StringUtil.isEmptyOrSpaces(subdirectory) ? dir : dir.findFileByRelativePath(subdirectory); if (virtualFile == null) continue; - - if (!virtualFile.isDirectory()) continue; - for (VirtualFile child : virtualFile.getChildren()) { - JavaFileObject.Kind kind = getKind("."+child.getExtension()); - if (kinds.contains(kind)) { + + VirtualFile[] children; + if (lookForFile) { + if (!virtualFile.isDirectory()) { + children = new VirtualFile[]{virtualFile}; + } + else continue; + } + else { + children = virtualFile.getChildren(); + } + for (VirtualFile child : children) { + JavaFileObject.Kind kind = getKind("." + child.getExtension()); + if (kinds == null || kinds.contains(kind)) { if (results == null) results = new SmartList(); if (kind == JavaFileObject.Kind.SOURCE && child.getFileSystem() instanceof JarFileSystem) continue; //for some reasdon javac looks for java files inside jar @@ -117,7 +131,7 @@ class MyFileManager extends DefaultFileManager { if (LOG.isDebugEnabled()) { // for testing consistency - Collection c = (Collection)super.list(location, packageName, kinds, recurse); + Collection c = (Collection)myStandardFileManager.list(location, packageName, kinds, false); Collection sup = new HashSet(c); assert sup.size() == c.size(); assert new HashSet(c).equals(sup); @@ -142,8 +156,102 @@ class MyFileManager extends DefaultFileManager { return ret; } + private static JavaFileObject.Kind getKind(String name) { + if (name.endsWith(JavaFileObject.Kind.CLASS.extension)) + return JavaFileObject.Kind.CLASS; + else if (name.endsWith(JavaFileObject.Kind.SOURCE.extension)) + return JavaFileObject.Kind.SOURCE; + else if (name.endsWith(JavaFileObject.Kind.HTML.extension)) + return JavaFileObject.Kind.HTML; + else + return JavaFileObject.Kind.OTHER; + } + + @Override public String inferBinaryName(Location location, JavaFileObject file) { return FileUtil.getNameWithoutExtension(new File(file.getName()).getName()); } + + ////////// delegates + @Override + public int isSupportedOption(String option) { + return myStandardFileManager.isSupportedOption(option); + } + + @Override + public void close() throws IOException { + myStandardFileManager.close(); + } + + @Override + public void flush() throws IOException { + myStandardFileManager.flush(); + } + + @Override + public boolean handleOption(String current, Iterator remaining) { + return myStandardFileManager.handleOption(current, remaining); + } + + @Override + public ClassLoader getClassLoader(Location location) { + return myStandardFileManager.getClassLoader(location); + } + + @Override + public boolean isSameFile(FileObject a, FileObject b) { + if (a instanceof FileVirtualObject && b instanceof FileVirtualObject) { + return a.equals(b); + } + return myStandardFileManager.isSameFile(a, b); + } + + public Iterable getJavaFileObjects(File... files) { + return getJavaFileObjectsFromFiles(Arrays.asList(files)); + } + + public Iterable getJavaFileObjects(String... names) { + return getJavaFileObjectsFromStrings(Arrays.asList(names)); + } + public Iterable getJavaFileObjectsFromStrings(Iterable names) { + ListBuffer files = new ListBuffer(); + for (String name : names) { + files.append(new File(name)); + } + return getJavaFileObjectsFromFiles(files.toList()); + } + + public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException { + List result = findInside(location, className, kind == null ? null : Collections.singleton(kind), true); + if (!result.isEmpty()) { + return result.get(0); + } + return null; + } + + @Override + public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { + return getJavaFileForInput(location, packageName + "/" + relativeName, null); + } + + @Override + public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { + return getJavaFileForOutput(location, packageName + "/" + relativeName, null, null); + } + + @Override + public Iterable getLocation(Location location) { + return myStandardFileManager.getLocation(location); + } + + @Override + public void setLocation(Location location, Iterable path) throws IOException { + myStandardFileManager.setLocation(location, path); + } + + @Override + public boolean hasLocation(Location location) { + return myStandardFileManager.hasLocation(location); + } }