kongchen / swagger-maven-plugin

JAX-RS & SpringMVC supported maven build plugin, helps you generate Swagger JSON and API document in build phase.
http://kongchen.github.io/swagger-maven-plugin/
Apache License 2.0
763 stars 451 forks source link

Performance issue - JaxrsReader.scanClasspathForTags() will not complete until all classes in classpath are parsed #658

Open tha2015 opened 6 years ago

tha2015 commented 6 years ago

(Sample project is attached. Please run run.bat script to see the issue) demo.zip

My project containing a JAR file which has an incorrect Class-Path entry (which is pointing to "/"). As a result, when I building using this plugin, the plugin will never stop because JaxrsReader.scanClasspathForTags() will try to scan whole drive for classes.

Below is the stack trace when debugging the issue:

....
Reflections.scan(URL) line: 236 
Reflections.scan() line: 203    
Reflections.<init>(Configuration) line: 128 
Reflections.<init>(Object...) line: 169 
Reflections.<init>(String, Scanner...) line: 142    
JaxrsReader.scanClasspathForTags() line: 201    

In the source code, I found the call to new Reflections("") will never stop because of the bad entry in the classpath

    private Map<String, Tag> scanClasspathForTags() {
        Map<String, Tag> tags = new HashMap<String, Tag>();
        for (Class<?> aClass: new Reflections("").getTypesAnnotatedWith(SwaggerDefinition.class)) {

Can you improve the logic to avoid scanning the whole classpath? Even if there is no bad entry in classpath, this logic still has bad performance.

Thanks.

gitomjk commented 4 years ago

Hey @tha2015, @Postremus did you make any progress with this issue? I have the same problem. Tnx

tha2015 commented 4 years ago

I just excluded the jar with bad Class-Path entry to avoid the issue. The prolem is to find which jars are causing issue

gitomjk commented 4 years ago

Thank you for the reply! @tha2015 for the future reference, I solved it by adding param:

com.github.kongchen.swagger.docgen.reader.SwaggerReader

Which sets reader to the SwaggerReader ( the reader that build swagger.json on runtime). It solved the issue.