<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello</p>
    <p>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 `<font
        face="monospace">javax.tools.JavaCompiler</font>` interface
      instead. It works well, but I'm having an issue with the `<font
        face="monospace">--patch-module</font>` option (for compiling
      the tests of modular projects). My understanding is that the
      modules to patch should be specified by a code like below:</p>
    <blockquote>
      <pre>JavaCompiler compiler = ...;
try (StandardJavaFileManager fm = getStandardFileManager(...)) {
    String module = ...;
    List<Path> testSources = List.of(...); // A single directory
    fm.setLocationForModule(StandardLocation.PATCH_MODULE_PATH, module, testSources);
}
</pre>
    </blockquote>
    <p>However, it results in an <font face="monospace">UnsupportedOperationException</font>
      thrown by `<font face="monospace">com.sun.tools.javac.file.Locations.PatchModulesLocationHandler</font>`.
      The source code is as below:</p>
    <blockquote>
      <pre>@Override // defined by LocationHandler
void setPathsForModule(String moduleName, Iterable<? extends Path> files) throws IOException {
    throw new UnsupportedOperationException(); // not yet
}
</pre>
    </blockquote>
    <p>The "not yet" comment gives the impression that this method is
      intended to be implemented, is that right? A workaround is to put
      `<font face="monospace">--patch-module</font>` in the options
      passed as the `<font face="monospace">options</font>` argument in
      the call to `<font face="monospace">JavaCompiler.getTask(...)</font>`.
      But a call to `<font face="monospace">compiler.isSupportedOption("--patch-module")</font>`
      returns -1, meaning that it should not be allowed. I noticed that
      if I ignore this information and put a `<font face="monospace">--patch-module</font>`
      option anyway, it works. But isn't it a violation of <font
        face="monospace">JavaCompiler</font> API contract? The Javadoc
      said that it should throw <font face="monospace">IllegalArgumentException</font>
      if any option is invalid.</p>
    <p>Thanks,</p>
    <p>    Martin<br>
    </p>
    <pre>[1] <a class="moz-txt-link-freetext" href="https://github.com/Geomatys/maven-compiler-plugin/wiki">https://github.com/Geomatys/maven-compiler-plugin/wiki</a>

</pre>
  </body>
</html>