0

I am trying to test out some code that works with Java Doc, it is used under the maven-javadoc-plugin. I am trying to get it to work under jdk11. I am after an implementation of RootDoc which I can use when running tests.

Currently the tests use EasyDoclet which gives me a RootDoc like so:

EasyDoclet easyDoclet = new EasyDoclet(new File("dir"), "com.foo.bar");
RootDoc rootDoc = easyDoclet.getRootDoc()

However I could not get this to work under jdk11.

The first issue I had was tools.jar is missing so I changed my pom.xml to have:

<dependency>
    <groupId>org.seamless</groupId>
    <artifactId>seamless-javadoc</artifactId>
    <version>1.1.1</version>
    <exclusions>
        <exclusion>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
        </exclusion>
    </exclusions> 
</dependency>
<!-- maybe this will get what ever was in tools.jar -->
<dependency>
    <groupId>com.github.olivergondza</groupId>
    <artifactId>maven-jdk-tools-wrapper</artifactId>
    <version>0.1</version>
</dependency>

This lead to many instances of:

java.lang.NoClassDefFoundError: com/sun/tools/javadoc/PublicMessager

The PublicMessager class seems to exist to make public some constructors, I am not sure why it exists under the com.sun.tools package. I tried to make a copy of this class: public static class PublicMessager extends

com.sun.tools.javadoc.main.Messager {

    public PublicMessager(Context context, String s) {
        super(context, s);
    }

    public PublicMessager(Context context, String s, PrintWriter printWriter, PrintWriter printWriter1, PrintWriter printWriter2) {
        super(context, s, printWriter, printWriter1, printWriter2);
    }
}

And the error message changes to:

java.lang.IllegalAccessError: superclass access check failed: class com.fun.javadoc.FooBar$PublicMessager (in unnamed module @0x4abdb505) cannot access class com.sun.tools.javadoc.main.Messager (in module jdk.javadoc) because module jdk.javadoc does not export com.sun.tools.javadoc.main to unnamed module @0x4abdb50

I exposed jdk.javadoc to the unnamed module using:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Dfile.encoding=UTF-8</argLine>
                <argLine>--add-opens=jdk.javadoc/com.sun.tools.javadoc.main=ALL-UNNAMED</argLine>
            </configuration>
        </plugin>
    </plugins>
</build>

This meant that my custom version of PublicMessager would no longer have the errors shown however the version from seamless under com.sun.tools could not be found. I made my own version of EasyDoclet which used my PublicMessager however it turned out that the following two classes are missing:

import com.sun.tools.javadoc.JavadocTool;
import com.sun.tools.javadoc.ModifierFilter;

At this point I am not sure what to do. halp!

Perhaps an alternative would be to instead find the jdk11 equivalent of RootDoc which I think is DocletEnvironment and then some how get an implementation of that, I have no idea how to get an implementation of DocletEnvironment.

Alan Bateman
  • 5,283
  • 1
  • 20
  • 25
Luke
  • 884
  • 8
  • 21
  • Have you considered moving to the supported API for javadoc instead of using undocumented/unsupported internal classes. Here's the API: https://docs.oracle.com/en/java/javase/11/docs/api/jdk.javadoc/module-summary.html – Alan Bateman Dec 28 '18 at 10:27
  • I am giving it a go, however it is not easy for example if I wanted to get the documentation of a `@tag` i could just do `FieldDoc#tags("tagName")` and then call `Tag#text`. In this supported API I think I would need to implement my own version of `DocTreeVisitor` which seems excessive. – Luke Dec 31 '18 at 02:47

0 Answers0