sdaschner / jaxrs-analyzer

Creates REST documentation for JAX-RS projects
Apache License 2.0
320 stars 101 forks source link

Error in test compilation after Jax-Analyzer #109

Open rmpestano opened 7 years ago

rmpestano commented 7 years ago

Hi guys,

I am getting an error in test compilation (maven) phase when I use JaxRS Analyzer. The error is:

[INFO] Compiling 2 source files to /home/PROCERGS.REDERS/rafael-pestano/projetos/cdi-crud/target/test-classes
An exception has occurred in the compiler (1.8.0_121). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.IllegalAccessError: tried to access method com.sun.tools.javac.parser.LazyDocCommentTable.<init>(Lcom/sun/tools/javac/parser/ParserFactory;)V from class com.sun.tools.javac.parser.JavacParser
    at com.sun.tools.javac.parser.JavacParser.newDocCommentTable(JavacParser.java:179)
    at com.sun.tools.javac.parser.JavacParser.<init>(JavacParser.java:166)
    at com.sun.tools.javac.parser.ParserFactory.newParser(ParserFactory.java:85)
    at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:627)
    at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:665)
    at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:950)

It looks like the byte code or javadoc analysis made test classes in an inconsistent state.

If I execute JaxRS analisys after test compilation then I got no error:

 <executions>
                    <execution>
                      <phase>package</phase> 
                        <goals>
                            <goal>analyze-jaxrs</goal>
                        </goals>
                        <configuration>
                            <backend>swagger</backend>
                            <resourcesDir>${project.build.finalName}/apidocs</resourcesDir>
                        </configuration>
                    </execution>
                </executions>

Also if I delete test classes I got no error ;)

Here is a simple maven project which reproduces the error, just do a clean package:

cdi-crud.zip

sdaschner commented 7 years ago

Thanks for issuing this. Actually that error was introduced in the last version, I'm wondering why I dind't find it earlier...

@rmpestano @wumpz: Could you please retry with the latest 0.14-SNAPSHOT version from the Maven central snapshot repositories?

sdaschner commented 7 years ago

The error has to do with the tools.jar, that is loaded into the class path since the JavaDoc analysis. Somehow the Java compiler get's confused with that. Changed the Maven plugin phase to process-test-classes so that it runs after the test compilation.

rmpestano commented 7 years ago

:+1:

wumpz commented 7 years ago

Could not test your actual 14.0-SNAPSHOT, but forcing the plugin to run in phase process-test-classes did the trick.

<plugin>
    <groupId>com.sebastian-daschner</groupId>
    <artifactId>jaxrs-analyzer-maven-plugin</artifactId>
    <version>0.13</version>
    <executions>
        <execution>
            <phase>process-test-classes</phase>
            <goals><goal>analyze-jaxrs</goal></goals>
            <configuration>
                <backend>swagger</backend>
            </configuration>
        </execution>
    </executions>
</plugin>
sdaschner commented 7 years ago

Great!

Yes, you would temporarily need the Maven Central Snapshot repositories:

<pluginRepositories>
    <pluginRepository>
        <id>ossrh-snapshots</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>
sdaschner commented 7 years ago

Since that version is (more or less) broken, I'm just about to release 0.14.

sdaschner commented 7 years ago

Thanks a lot for testing!

wumpz commented 7 years ago

Unfortunately this will not work in multimodule maven projects. The issue is only defered to the next module. So no solution yet. Please reopen this issue.

sdaschner commented 7 years ago

Hmm... So somehow the tools.jar dependency leads to confusion of the compiles (test) classes which doesn't make any sense to me. @rmpestano any ideas?

Unfortunately the whole JavaDoc processing introduced a lot of instabilities, the way the Parser-"API" is called is just very unfortunate :-( AFAIK there is no easy alternative for JavaDoc comment parsing...

rmpestano commented 7 years ago

Hi guys, I also don't know the javadoc internals, have you looked into swagger doclet for some inspiration?

sdaschner commented 7 years ago

Yeah, they use just a "normal" Doclet, run with maven-javadoc-plugin, but we need to run is as part of the Analyzer... I was even thinking about writing an own (small) JavaDoc parser, at this point -- with all the introduced error -- that might even be simpler...

rmpestano commented 7 years ago

Looks like JavaParser library can do some javadoc (and comments) parsing, see here: https://github.com/javaparser/javaparser/issues/325

Maybe it helps

sdaschner commented 7 years ago

Yes, I guess that's is a viable option...

Funnily one of my first attempts when I started the Analysis algorithm was to parse the AST from the code, but then I switched to Bytecode analysis for a couple of reasons. Now partially back (for JavaDocs) :-)

ppasler commented 7 years ago

So will there be a solution in v15?

spartan2015 commented 7 years ago

I also have this compilation problem.

I found that removing the call to addToSystemClassLoader(lib) in ProjectAnalyzer constructor solves this for me.

ppasler commented 7 years ago

@spartan2015 would you mind opening a PR? @sdaschner are you still mainting this?

spartan2015 commented 7 years ago

done

sdaschner commented 7 years ago

2a293a900ee2ab4cd0a533fcd7f68962d84735a7 added better JavaDoc parsing using the JavaParser (thanks @rmpestano for the hint!). This now removed the tools.jar and it's unstable dependency-tinkering. Please test with the 0.17-SNAPSHOT version (Maven's staging repositories needed for that). Will publish that afterwards.

florianli commented 6 years ago

I had the same compilation problem in a multi-module project. Switching to 0.17-SNAPSHOT solved it.