### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.compiler.tool Index: src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java,v retrieving revision 1.12 diff -u -r1.12 EclipseCompilerImpl.java --- src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java 9 Oct 2009 13:01:17 -0000 1.12 +++ src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java 7 Apr 2010 18:26:05 -0000 @@ -206,15 +206,9 @@ } @Override public JavaFileObject getSource() { - try { - if (EclipseCompilerImpl.this.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) { - return EclipseCompilerImpl.this.fileManager.getJavaFileForInput( - StandardLocation.SOURCE_PATH, - new String(originatingFileName), - JavaFileObject.Kind.SOURCE); - } - } catch (IOException e) { - // ignore + File f = new File(new String(originatingFileName)); + if (f.exists()) { + return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null); } return null; } @@ -282,15 +276,9 @@ } @Override public JavaFileObject getSource() { - try { - if (EclipseCompilerImpl.this.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) { - return EclipseCompilerImpl.this.fileManager.getJavaFileForInput( - StandardLocation.SOURCE_PATH, - new String(originatingFileName), - JavaFileObject.Kind.SOURCE); - } - } catch (IOException e) { - // ignore + File f = new File(new String(originatingFileName)); + if (f.exists()) { + return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null); } return null; } #P org.eclipse.jdt.compiler.tool.tests Index: src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java,v retrieving revision 1.22 diff -u -r1.22 CompilerToolTests.java --- src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java 3 Feb 2010 20:46:57 -0000 1.22 +++ src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java 7 Apr 2010 18:26:05 -0000 @@ -26,6 +26,7 @@ import java.util.ServiceLoader; import java.util.Set; +import javax.tools.Diagnostic; import javax.tools.FileObject; import javax.tools.ForwardingJavaFileManager; import javax.tools.JavaCompiler; @@ -65,6 +66,8 @@ suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler3")); suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler4")); suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler5")); + suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler6")); + suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler7")); suite.addTest(new CompilerToolTests("testCleanUp")); return suite; } @@ -688,6 +691,125 @@ assertTrue("delete failed", inputFile.delete()); } + public void testCompilerOneClassWithEclipseCompiler6() { + String tmpFolder = System.getProperty("java.io.tmpdir"); + File packageFolder = new File(tmpFolder, "p"); + if (!packageFolder.mkdirs()) { + return; + } + File inputFile = new File(packageFolder, "X.java"); + BufferedWriter writer = null; + try { + writer = new BufferedWriter(new FileWriter(inputFile)); + writer.write( + "package p;\n" + + "public class X extends File {}"); + writer.flush(); + writer.close(); + } catch (IOException e) { + // ignore + } finally { + if (writer != null) { + try { + writer.close(); + } catch (IOException e) { + // ignore + } + } + } + // System compiler + StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); + List files = new ArrayList(); + files.add(inputFile); + Iterable units = manager.getJavaFileObjectsFromFiles(files); + + List options = new ArrayList(); + options.add("-d"); + options.add(tmpFolder); + options.add("-sourcepath"); + options.add(tmpFolder); + ByteArrayOutputStream errBuffer = new ByteArrayOutputStream(); + PrintWriter err = new PrintWriter(errBuffer); + CompilerInvocationDiagnosticListener compilerInvocationDiagnosticListener = new CompilerInvocationDiagnosticListener(err) { + @Override + public void report(Diagnostic diagnostic) { + JavaFileObject source = diagnostic.getSource(); + assertNotNull("No source", source); + super.report(diagnostic); + } + }; + CompilationTask task = Compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units); + // check the classpath location + Boolean result = task.call(); + err.flush(); + err.close(); + assertFalse(errBuffer.toString().isEmpty()); + assertTrue(compilerInvocationDiagnosticListener.kind != CompilerInvocationDiagnosticListener.NONE); + if (!result.booleanValue()) { + assertFalse("Compilation did not fail", false); + } + // check that the .class file exist for X + assertTrue("delete failed", inputFile.delete()); + assertTrue("delete failed", packageFolder.delete()); + } + + public void testCompilerOneClassWithEclipseCompiler7() { + String tmpFolder = System.getProperty("java.io.tmpdir"); + File inputFile = new File(tmpFolder, "X.java"); + BufferedWriter writer = null; + try { + writer = new BufferedWriter(new FileWriter(inputFile)); + writer.write( + "package p;\n" + + "public class X extends File {}"); + writer.flush(); + writer.close(); + } catch (IOException e) { + // ignore + } finally { + if (writer != null) { + try { + writer.close(); + } catch (IOException e) { + // ignore + } + } + } + // System compiler + StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset()); + List files = new ArrayList(); + files.add(inputFile); + Iterable units = manager.getJavaFileObjectsFromFiles(files); + + List options = new ArrayList(); + options.add("-d"); + options.add(tmpFolder); + options.add("-sourcepath"); + options.add(tmpFolder); + ByteArrayOutputStream errBuffer = new ByteArrayOutputStream(); + PrintWriter err = new PrintWriter(errBuffer); + CompilerInvocationDiagnosticListener compilerInvocationDiagnosticListener = new CompilerInvocationDiagnosticListener(err) { + @Override + public void report(Diagnostic diagnostic) { + JavaFileObject source = diagnostic.getSource(); + assertNotNull("No source", source); + super.report(diagnostic); + } + }; + CompilationTask task = Compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units); + // check the classpath location + Boolean result = task.call(); + err.flush(); + err.close(); + assertFalse(errBuffer.toString().isEmpty()); + assertTrue(compilerInvocationDiagnosticListener.kind != CompilerInvocationDiagnosticListener.NONE); + if (!result.booleanValue()) { + assertFalse("Compilation did not fail", false); + } + // check that the .class file exist for X + assertTrue("delete failed", inputFile.delete()); + } + public void testFileManager() { String tmpFolder = System.getProperty("java.io.tmpdir"); File dir = new File(tmpFolder, "src" + System.currentTimeMillis());