private void configurePlugins ( final File fDir ) throws PluginConfigurationException { LOG . trace ( "READING PLUGIN CONFIGURATION FROM DIRECTORY {}" , fDir . getName ( ) ) ; StreamManager streamMgr = new StreamManager ( ) ; File [ ] vfJars = fDir . listFiles ( JAR_FILE_FILTER ) ; if ( vfJars == null || vfJars . length == 0 ) { return ; } // Initializing classloader List < URL > vUrls = new ArrayList < URL > ( vfJars . length ) ; ClassLoader ul = null ; for ( int j = 0 ; j < vfJars . length ; j ++ ) { try { vUrls . add ( vfJars [ j ] . toURI ( ) . toURL ( ) ) ; } catch ( MalformedURLException e ) { // should never happen throw new IllegalStateException ( e . getMessage ( ) , e ) ; } } ul = new JNRPEClassLoader ( vUrls ) ; try { for ( File file : vfJars ) { JarFile jarFile = null ; try { jarFile = new JarFile ( file ) ; JarEntry entry = jarFile . getJarEntry ( "plugin.xml" ) ; if ( entry == null ) { entry = jarFile . getJarEntry ( "jnrpe_plugins.xml" ) ; } if ( entry == null ) { // The jar do not contain a jnrpe_plugins.xml nor a // plugin.xml file... continue ; } InputStream in = streamMgr . handle ( jarFile . getInputStream ( entry ) ) ; PluginRepositoryUtil . loadFromXmlPluginPackageDefinitions ( this , ul , in ) ; in . close ( ) ; } catch ( Exception e ) { LOG . error ( "Skipping plugin package contained in file '{}' because of the following error : {}" , new String [ ] { file . getName ( ) , e . getMessage ( ) } , e ) ; } finally { try { jarFile . close ( ) ; } catch ( Exception e ) { // Intentionally ignored... LOG . warn ( "An error has occurred closing jar file '{}'" , file . getName ( ) , e ) ; } } } } finally { streamMgr . closeAll ( ) ; } }
Loads all the plugins definitions from the given directory .