diff --git a/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH954/module-info.java b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958/module-info.java similarity index 100% rename from org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH954/module-info.java rename to org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958/module-info.java diff --git a/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH954/org/example/impl/AddNumbers.java b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958/org/example/impl/AddNumbers.java similarity index 100% rename from org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH954/org/example/impl/AddNumbers.java rename to org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958/org/example/impl/AddNumbers.java diff --git a/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_2/module-info.java b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_2/module-info.java new file mode 100644 index 00000000000..277a588f25d --- /dev/null +++ b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_2/module-info.java @@ -0,0 +1,4 @@ +module GH958_2 { + requires GH958_mod; + requires org.example.adder; +} \ No newline at end of file diff --git a/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_2/org/example2/Main.java b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_2/org/example2/Main.java new file mode 100644 index 00000000000..b41f4c7bb0a --- /dev/null +++ b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_2/org/example2/Main.java @@ -0,0 +1,13 @@ +package org.example2; + +import org.example.regular.Foo; +import org.example.adder.Adder; + +public class Main { + Foo foo; + public static void main(String[] args) { + int a = 123; + int b = 456; + System.out.println(new Adder().add(a, b)); + } +} diff --git a/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/automod_GH954.jar b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_automod.jar similarity index 100% rename from org.eclipse.jdt.compiler.tool.tests/resources/module_locations/automod_GH954.jar rename to org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_automod.jar diff --git a/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_mod.jar b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_mod.jar new file mode 100644 index 00000000000..2198d53df8d Binary files /dev/null and b/org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_mod.jar differ diff --git a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolJava9Tests.java b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolJava9Tests.java index 1f5bc902d60..945cb40ec70 100644 --- a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolJava9Tests.java +++ b/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolJava9Tests.java @@ -991,15 +991,41 @@ public static JavaFileManager demote(JavaFileManager fileManager) { ); } } - public void testGH954() throws Exception { + public void testGH958() throws Exception { File classOutput = new File(_tmpFolder); JavaCompiler compiler = new EclipseCompiler(); StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, null); - List classPath = List.of(new File("resources/module_locations/automod_GH954.jar")); - List sourcePath = List.of(new File("resources/module_locations/GH954")); - standardFileManager.setLocation(StandardLocation.CLASS_PATH, classPath); - standardFileManager.setLocation(StandardLocation.MODULE_PATH, classPath); + List modulePath = List.of(new File("resources/module_locations/GH958_automod.jar")); + List sourcePath = List.of(new File("resources/module_locations/GH958")); + standardFileManager.setLocation(StandardLocation.MODULE_PATH, modulePath); + standardFileManager.setLocation(StandardLocation.SOURCE_PATH, sourcePath); + standardFileManager.setLocation(StandardLocation.CLASS_OUTPUT, List.of(classOutput)); + + // Make ECJ think we don't inherit StandardJavaFileManager by wrapping it. + JavaFileManager demotedFileManager = DemotingFileManagerProxy.demote(standardFileManager); + Iterable compilationUnits = demotedFileManager.list(StandardLocation.SOURCE_PATH, "", Set.of(JavaFileObject.Kind.SOURCE), true); + + CompilationTask task = compiler.getTask( + null, + demotedFileManager, + null, + List.of("--release", "11", "-verbose"), + List.of(), + compilationUnits + ); + + assertTrue(task.call()); + } + public void testGH958_2modules() throws Exception { + File classOutput = new File(_tmpFolder); + JavaCompiler compiler = new EclipseCompiler(); + StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, null); + + List modulesPath = List.of(new File("resources/module_locations/GH958_automod.jar"), + new File("resources/module_locations/GH958_mod.jar")); + List sourcePath = List.of(new File("resources/module_locations/GH958_2")); + standardFileManager.setLocation(StandardLocation.MODULE_PATH, modulesPath); standardFileManager.setLocation(StandardLocation.SOURCE_PATH, sourcePath); standardFileManager.setLocation(StandardLocation.CLASS_OUTPUT, List.of(classOutput)); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java index 6642493b526..29380861496 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Set; import javax.tools.JavaFileManager; -import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileObject; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; @@ -160,20 +159,12 @@ public char[][][] findTypeNames(String aQualifiedPackageName, String moduleName) public void initialize() throws IOException { if (this.jrt != null) { this.jrt.initialize(); - } else if (this.location.isModuleOrientedLocation()) { - Iterable> locationsForModules = this.fileManager.listLocationsForModules(this.location); - for (Set locs: locationsForModules) { - for (Location loc : locs) { - if (loc instanceof LocationWrapper wrapper) { - for (Path locPath : wrapper.getPaths()) { - File file = locPath.toFile(); - IModule mod = ModuleFinder.scanForModule(this, file, null, true, null); - if (mod != null) { - return; - } - } - } - } + } else if (this.location instanceof LocationWrapper wrapper) { + for (Path locPath : wrapper.getPaths()) { + File file = locPath.toFile(); + IModule mod = ModuleFinder.scanForModule(this, file, null, true, null); + if (mod != null) + return; } } } @@ -294,21 +285,8 @@ public boolean hasAnnotationFileFor(String qualifiedTypeName) { public Collection getModuleNames(Collection limitModules) { if (this.jrt != null) return this.jrt.getModuleNames(limitModules); - if (this.location.isModuleOrientedLocation()) { - Set moduleNames = new HashSet<>(); - try { - for (Set locs : this.fileManager.listLocationsForModules(this.location)) { - for (Location loc : locs) { - String moduleName = this.fileManager.inferModuleName(loc); - if (moduleName != null) - moduleNames.add(moduleName); - } - } - return moduleNames; - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + if (this.module != null) { + return Collections.singletonList(String.valueOf(this.module.name())); } return Collections.emptyList(); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java index 3ebe575228d..90389871bd0 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java @@ -36,6 +36,7 @@ import java.util.Locale; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.stream.Stream; import javax.annotation.processing.Processor; import javax.tools.Diagnostic; @@ -727,12 +728,31 @@ protected void handleLocations() { fileSystemClasspaths.add(classpath); } if (this.fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH)) { - classpath = new ClasspathJsr199(this.fileManager, StandardLocation.MODULE_SOURCE_PATH); - fileSystemClasspaths.add(classpath); + // FIXME: ClasspathJsr199 doesn't really support source files + try { + Iterable> locationsForModules = this.fileManager.listLocationsForModules(StandardLocation.MODULE_SOURCE_PATH); + for (Set locs: locationsForModules) { + for (Location loc : locs) { + classpath = new ClasspathJsr199(this.fileManager, loc); + fileSystemClasspaths.add(classpath); + } + } + } catch (IOException e) { + this.logger.logException(e); + } } if (this.fileManager.hasLocation(StandardLocation.MODULE_PATH)) { - classpath = new ClasspathJsr199(this.fileManager, StandardLocation.MODULE_PATH); - fileSystemClasspaths.add(classpath); + try { + Iterable> locationsForModules = this.fileManager.listLocationsForModules(StandardLocation.MODULE_PATH); + for (Set locs: locationsForModules) { + for (Location loc : locs) { + classpath = new ClasspathJsr199(this.fileManager, loc); + fileSystemClasspaths.add(classpath); + } + } + } catch (IOException e) { + this.logger.logException(e); + } } classpath = new ClasspathJsr199(this.fileManager, StandardLocation.CLASS_PATH); fileSystemClasspaths.add(classpath);