public void identifyClasses ( final String pluginDirectory ) throws Exception { methodInformation . clear ( ) ; jarInformation . clear ( ) ; try { new FileTraversal ( ) { public void onDirectory ( final File d ) { } public void onFile ( final File f ) { try { // loads class files if ( f . getName ( ) . endsWith ( ".class" ) ) { // get the class name for this path String className = f . getAbsolutePath ( ) ; className = className . replace ( pluginDirectory , "" ) ; className = getClassNameFromPath ( className ) ; logger . info ( "Storing plugin information: {}, {}" , className , f . getName ( ) ) ; ClassInformation classInfo = new ClassInformation ( ) ; classInfo . pluginPath = pluginDirectory ; classInformation . put ( className , classInfo ) ; } else if ( f . getName ( ) . endsWith ( ".jar" ) ) { // loads JAR packages // open up jar and discover files // look for anything with /proxy/ in it // this may discover things we don't need but that is OK try { jarInformation . add ( f . getAbsolutePath ( ) ) ; JarFile jarFile = new JarFile ( f ) ; Enumeration < ? > enumer = jarFile . entries ( ) ; // Use the Plugin-Name manifest entry to match with the provided pluginName String pluginPackageName = jarFile . getManifest ( ) . getMainAttributes ( ) . getValue ( "plugin-package" ) ; if ( pluginPackageName == null ) { return ; } while ( enumer . hasMoreElements ( ) ) { Object element = enumer . nextElement ( ) ; String elementName = element . toString ( ) ; if ( ! elementName . endsWith ( ".class" ) ) { continue ; } String className = getClassNameFromPath ( elementName ) ; if ( className . contains ( pluginPackageName ) ) { logger . info ( "Storing plugin information: {}, {}" , className , f . getAbsolutePath ( ) ) ; ClassInformation classInfo = new ClassInformation ( ) ; classInfo . pluginPath = f . getAbsolutePath ( ) ; classInformation . put ( className , classInfo ) ; } } } catch ( Exception e ) { } } } catch ( Exception e ) { logger . warn ( "Exception caught: {}, {}" , e . getMessage ( ) , e . getCause ( ) ) ; } } } . traverse ( new File ( pluginDirectory ) ) ; } catch ( IOException e ) { throw new Exception ( "Could not identify all plugins: " + e . getMessage ( ) ) ; } }
This loads plugin file information into a hash for lazy loading later on