private Set < String > getPackagesForScanning ( WARArchive deployment ) { final Set < String > packages = new TreeSet <> ( ) ; if ( indexView != null ) { DotName dotName = DotName . createSimple ( Api . class . getName ( ) ) ; Collection < AnnotationInstance > instances = indexView . getAnnotations ( dotName ) ; instances . forEach ( ai -> { AnnotationTarget target = ai . target ( ) ; if ( target . kind ( ) == AnnotationTarget . Kind . CLASS ) { extractAndAddPackageInfo ( target . asClass ( ) , packages , indexView ) ; } } ) ; // Scan for all top level resources. dotName = DotName . createSimple ( Path . class . getName ( ) ) ; instances = indexView . getAnnotations ( dotName ) ; instances . forEach ( ai -> { AnnotationTarget target = ai . target ( ) ; switch ( target . kind ( ) ) { case CLASS : extractAndAddPackageInfo ( target . asClass ( ) , packages , indexView ) ; break ; case METHOD : extractAndAddPackageInfo ( target . asMethod ( ) . declaringClass ( ) , packages , indexView ) ; break ; default : // Do nothing. Probably log something here? } } ) ; // Reduce the packages to just about what is required. Set < String > tmp = new HashSet <> ( packages ) ; Iterator < String > itr = packages . iterator ( ) ; while ( itr . hasNext ( ) ) { String current = itr . next ( ) ; boolean remove = false ; if ( current . startsWith ( "org.wildfly.swarm" ) ) { remove = true ; } else { // Search through the list to see if a parent package has already been included in the list. for ( String s : tmp ) { if ( s . length ( ) < current . length ( ) && current . startsWith ( s ) ) { remove = true ; break ; } } } if ( remove ) { itr . remove ( ) ; } } } else { // // Existing default behavior. // String packageName = null ; for ( Map . Entry < ArchivePath , Node > entry : deployment . getContent ( ) . entrySet ( ) ) { final ArchivePath key = entry . getKey ( ) ; if ( key . get ( ) . endsWith ( ".class" ) ) { String parentPath = key . getParent ( ) . get ( ) ; parentPath = parentPath . replaceFirst ( "/" , "" ) ; String parentPackage = parentPath . replaceFirst ( ".*/classes/" , "" ) ; parentPackage = parentPackage . replaceAll ( "/" , "." ) ; if ( parentPackage . startsWith ( "org.wildfly.swarm" ) ) { SwaggerMessages . MESSAGES . ignoringPackage ( parentPackage ) ; } else { packageName = parentPackage ; break ; } } } packages . add ( packageName ) ; } return packages ; }
Get the packages that should be scanned by Swagger . This method attempts to determine the root packages by leveraging the IndexView of the deployment . If the IndexView is unavailable then this method will fallback to the scanning the classes manually .