public static Option configurationFolder ( File folder , String extension ) { if ( ! folder . exists ( ) ) { throw new TestContainerException ( "folder " + folder + " does not exits" ) ; } List < Option > options = new ArrayList < Option > ( ) ; File [ ] files = folder . listFiles ( ) ; for ( File file : files ) { if ( file . isDirectory ( ) ) { continue ; } String name = file . getName ( ) ; if ( ! name . endsWith ( extension ) ) { continue ; } else { name = name . substring ( 0 , name . length ( ) - extension . length ( ) ) ; } String [ ] split = name . split ( "-" ) ; org . ops4j . pax . exam . cm . internal . ConfigurationProvisionOption cfg = new org . ops4j . pax . exam . cm . internal . ConfigurationProvisionOption ( split [ 0 ] , new HashMap < String , Object > ( ) ) ; cfg . factory ( split . length > 1 ) ; Properties properties = new Properties ( ) ; try { FileInputStream stream = new FileInputStream ( file ) ; try { properties . load ( stream ) ; } finally { stream . close ( ) ; } } catch ( IOException e ) { throw new TestContainerException ( "can't read configuration file " + file , e ) ; } Set < String > names = properties . stringPropertyNames ( ) ; for ( String key : names ) { cfg . put ( key , properties . getProperty ( key ) ) ; } options . add ( cfg . asOption ( ) ) ; } return CoreOptions . composite ( options . toArray ( new Option [ 0 ] ) ) ; }
read all configuration files from a folder and transform them into configuration options