StandardLocation.PATCH_MODULE_PATH unsupported by javax.tools.JavaCompiler?
Martin Desruisseaux
martin.desruisseaux at geomatys.com
Mon Jul 29 17:06:10 UTC 2024
Hello
I'm rewriting the Maven compiler plugin for better support of Java
Module System with Maven 4 [1]. This work removes completely the Plexus
compiler API and uses directly the `javax.tools.JavaCompiler` interface
instead. It works well, but I'm having an issue with the
`--patch-module` option (for compiling the tests of modular projects).
My understanding is that the modules to patch should be specified by a
code like below:
JavaCompiler compiler = ...;
try (StandardJavaFileManager fm = getStandardFileManager(...)) {
String module = ...;
List<Path> testSources = List.of(...); // A single directory
fm.setLocationForModule(StandardLocation.PATCH_MODULE_PATH, module, testSources);
}
However, it results in an UnsupportedOperationException thrown by
`com.sun.tools.javac.file.Locations.PatchModulesLocationHandler`. The
source code is as below:
@Override // defined by LocationHandler
void setPathsForModule(String moduleName, Iterable<? extends Path> files) throws IOException {
throw new UnsupportedOperationException(); // not yet
}
The "not yet" comment gives the impression that this method is intended
to be implemented, is that right? A workaround is to put
`--patch-module` in the options passed as the `options` argument in the
call to `JavaCompiler.getTask(...)`. But a call to
`compiler.isSupportedOption("--patch-module")` returns -1, meaning that
it should not be allowed. I noticed that if I ignore this information
and put a `--patch-module` option anyway, it works. But isn't it a
violation of JavaCompiler API contract? The Javadoc said that it should
throw IllegalArgumentException if any option is invalid.
Thanks,
Martin
[1]https://github.com/Geomatys/maven-compiler-plugin/wiki
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20240729/9b136a55/attachment.htm>
More information about the compiler-dev
mailing list