private Map < String , List < String > > findImplementations ( ClassLoader loader , List < Class < ? > > interfaceClasses ) throws MojoExecutionException { Map < String , List < String > > serviceImplementations = new HashMap < String , List < String > > ( ) ; for ( String interfaceClassName : getServices ( ) ) { serviceImplementations . put ( interfaceClassName , new ArrayList < String > ( ) ) ; } getLog ( ) . info ( "Scanning generated classes for implementations..." ) ; File classFolder = getClassFolder ( ) ; List < String > classNames = listCompiledClasses ( classFolder ) ; // List<String> classNames = listCompiledClassesRegex( classFolder ); for ( String className : classNames ) { try { if ( getLog ( ) . isDebugEnabled ( ) ) { getLog ( ) . debug ( "checking class: " + className ) ; } Class < ? > cls = loader . loadClass ( className ) ; int mods = cls . getModifiers ( ) ; if ( ! cls . isAnonymousClass ( ) && ! cls . isInterface ( ) && ! cls . isEnum ( ) && ! Modifier . isAbstract ( mods ) && Modifier . isPublic ( mods ) ) { for ( Class < ? > interfaceCls : interfaceClasses ) { if ( ! interfaceCls . equals ( cls ) && interfaceCls . isAssignableFrom ( cls ) ) { // if the includes section isn't empty, we need to respect the choice and only include the items that are shown there. if ( includes == null || includes . length == 0 ) { serviceImplementations . get ( interfaceCls . getName ( ) ) . add ( className ) ; } else { for ( String include : includes ) { if ( SelectorUtils . match ( include , className ) ) { serviceImplementations . get ( interfaceCls . getName ( ) ) . add ( className ) ; } } } } } } } catch ( ClassNotFoundException e1 ) { getLog ( ) . warn ( e1 ) ; } catch ( NoClassDefFoundError e2 ) { getLog ( ) . warn ( e2 ) ; } } // in the next iteration we start to process with the excludes if ( excludes != null && excludes . length != 0 ) { Set < Entry < String , List < String > > > entrySet = serviceImplementations . entrySet ( ) ; for ( Entry < String , List < String > > entry : entrySet ) { classNames = entry . getValue ( ) ; ListIterator < String > classNamesIter = classNames . listIterator ( ) ; while ( classNamesIter . hasNext ( ) ) { String className = classNamesIter . next ( ) ; for ( String exclude : excludes ) { if ( SelectorUtils . match ( exclude , className ) ) { classNamesIter . remove ( ) ; break ; } } } } } return serviceImplementations ; }
Finds all implementations of interfaces in a folder