-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] [JSR-199] ECJ cannot resolve JPMS modules if using a user-provi…
…ded file manager (#3446) ClasspathJsr199: + change to 1 ClasspathJsr199 per module + various additions for handling modules + capability to handle sources + implement listPackages() using JavaFileObjects ModuleFinder: + find automatic modules, too + allow invocation without a parser for binary-only scans EclipseFileManager: + allow scanning all packages (by specifying an empty package name) + establish symmetry between setLocation() and setLocationFromPaths() + catch disruptive IAE from ModuleFinder.scanForModule() More fixes: + encoding: pass through from Main.compilerOptions + consistently extract module and pass it into CUs and class readers + implement module extraction from JavaFileObject (src & class) + detect initial / duplicate source files by JavaFileObject, not path + fix arg passing in ProblemReporter.invalidPackageReference() Tests: + implement package matching in InMemoryJavaFileManager.list() + test with two module dependencies (one auto, one regular) Fixes #958
- Loading branch information
1 parent
ff88cfa
commit 4716533
Showing
18 changed files
with
476 additions
and
102 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module org.example { | ||
requires org.example.adder; | ||
} |
11 changes: 11 additions & 0 deletions
11
...jdt.compiler.tool.tests/resources/module_locations/GH958/org/example/impl/AddNumbers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.example.impl; | ||
|
||
import org.example.adder.Adder; | ||
|
||
public class AddNumbers { | ||
public static void main(String[] args) { | ||
int a = 123; | ||
int b = 456; | ||
System.out.println(new Adder().add(a, b)); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_2/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module GH958_2 { | ||
requires GH958_mod; | ||
requires org.example.adder; | ||
} |
13 changes: 13 additions & 0 deletions
13
...eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_2/org/example2/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
Binary file added
BIN
+1.48 KB
org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_automod.jar
Binary file not shown.
Binary file added
BIN
+2.35 KB
org.eclipse.jdt.compiler.tool.tests/resources/module_locations/GH958_mod.jar
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2006, 2018 BEA Systems, Inc. | ||
* Copyright (c) 2006, 2024 BEA Systems, Inc. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
|
@@ -19,6 +19,7 @@ | |
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import javax.annotation.processing.Filer; | ||
import javax.annotation.processing.FilerException; | ||
|
@@ -28,8 +29,12 @@ | |
import javax.tools.JavaFileManager; | ||
import javax.tools.JavaFileManager.Location; | ||
import javax.tools.JavaFileObject; | ||
import javax.tools.JavaFileObject.Kind; | ||
import javax.tools.StandardLocation; | ||
import org.eclipse.jdt.internal.compiler.batch.ClasspathJsr199; | ||
import org.eclipse.jdt.internal.compiler.batch.Main; | ||
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; | ||
import org.eclipse.jdt.internal.compiler.env.IModule; | ||
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; | ||
|
||
/** | ||
|
@@ -43,13 +48,32 @@ public class BatchFilerImpl implements Filer { | |
protected final BatchProcessingEnvImpl _env; | ||
protected final JavaFileManager _fileManager; | ||
protected final HashSet<URI> _createdFiles; | ||
protected String _moduleName; | ||
protected String _encoding; | ||
|
||
public BatchFilerImpl(BaseAnnotationProcessorManager dispatchManager, BatchProcessingEnvImpl env) | ||
public BatchFilerImpl(BaseAnnotationProcessorManager dispatchManager, BatchProcessingEnvImpl env, Main main) | ||
{ | ||
this._dispatchManager = dispatchManager; | ||
this._fileManager = env._fileManager; | ||
this._env = env; | ||
this._createdFiles = new HashSet<>(); | ||
this._encoding = main.getDefaultEncoding(); | ||
if (this._fileManager.hasLocation(StandardLocation.SOURCE_PATH)) { | ||
try { | ||
for (JavaFileObject javaFileObject : this._fileManager.list(StandardLocation.SOURCE_PATH, "", //$NON-NLS-1$ | ||
Collections.singleton(Kind.SOURCE), false)) { | ||
if (javaFileObject.getName().equals(IModule.MODULE_INFO_JAVA)) { | ||
IModule module = ClasspathJsr199.extractModuleFromFileObject(javaFileObject, main::getNewParser, null, this._encoding); | ||
if (module != null) | ||
this._moduleName = String.valueOf(module.name()); | ||
break; | ||
} | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stephan-herrmann
Author
Contributor
|
||
main.logger.logException(e); | ||
} | ||
} | ||
} | ||
|
||
public void addNewUnit(ICompilationUnit unit) { | ||
|
@@ -74,7 +98,7 @@ public JavaFileObject createClassFile(CharSequence name, | |
} | ||
|
||
this._createdFiles.add(uri); | ||
return new HookedJavaFileObject(jfo, jfo.getName(), name.toString(), this); | ||
return new HookedJavaFileObject(jfo, jfo.getName(), name.toString(), this, this._moduleName, this._encoding); | ||
} | ||
|
||
/* (non-Javadoc) | ||
|
@@ -146,7 +170,13 @@ public JavaFileObject createSourceFile(CharSequence name, | |
if (typeElement != null) { | ||
throw new FilerException("Source file already exists : " + moduleAndPkgString); //$NON-NLS-1$ | ||
} | ||
Location location = mod == null ? StandardLocation.SOURCE_OUTPUT : this._fileManager.getLocationForModule(StandardLocation.SOURCE_OUTPUT, mod); | ||
Location location; | ||
if (mod == null) { | ||
location = StandardLocation.SOURCE_OUTPUT; | ||
mod = this._moduleName; | ||
} else { | ||
location = this._fileManager.getLocationForModule(StandardLocation.SOURCE_OUTPUT, mod); | ||
} | ||
JavaFileObject jfo = this._fileManager.getJavaFileForOutput(location, name.toString(), JavaFileObject.Kind.SOURCE, null); | ||
URI uri = jfo.toUri(); | ||
if (this._createdFiles.contains(uri)) { | ||
|
@@ -155,7 +185,7 @@ public JavaFileObject createSourceFile(CharSequence name, | |
|
||
this._createdFiles.add(uri); | ||
// hook the file object's writers to create compilation unit and add to addedUnits() | ||
return new HookedJavaFileObject(jfo, jfo.getName(), name.toString(), this); | ||
return new HookedJavaFileObject(jfo, jfo.getName(), name.toString(), this, mod, this._encoding); | ||
} | ||
|
||
/* (non-Javadoc) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
@stephan-herrmann did you intentionally add the printStackTrace here?