private Map < String , Object > readProperties ( CommandLine commandLine ) throws CliConfigurationException { final Properties properties = new Properties ( ) ; InputStream propertiesStream ; if ( commandLine . hasOption ( "p" ) ) { File propertyFile = new File ( commandLine . getOptionValue ( "p" ) ) ; if ( ! propertyFile . exists ( ) ) { throw new CliConfigurationException ( "Property file given by command line does not exist: " + propertyFile . getAbsolutePath ( ) ) ; } try { propertiesStream = new FileInputStream ( propertyFile ) ; } catch ( FileNotFoundException e ) { throw new CliConfigurationException ( "Cannot open property file." , e ) ; } } else { propertiesStream = Main . class . getResourceAsStream ( "/jqassistant.properties" ) ; } Map < String , Object > result = new HashMap <> ( ) ; if ( propertiesStream != null ) { try { properties . load ( propertiesStream ) ; } catch ( IOException e ) { throw new CliConfigurationException ( "Cannot load properties from file." , e ) ; } for ( String name : properties . stringPropertyNames ( ) ) { result . put ( name , properties . getProperty ( name ) ) ; } } return result ; }
Read the plugin properties file if specified on the command line or if it exists on the class path .