public void readConfigFile(RepairnatorConfig config) throws RepairnatorConfigException { String currentDir = System.getProperty("user.dir"); InputStream inputStream; try { inputStream = new FileInputStream(currentDir+File.separator+FILENAME); } catch (FileNotFoundException e) { logger.info("Cannot find "+FILENAME+" file in current directory. It will use the default one."); inputStream = getClass().getClassLoader().getResourceAsStream(FILENAME); if (inputStream == null) { throw new RepairnatorConfigException("Cannot load default "+FILENAME+" from resources."); } } try { Properties properties = this.readPropertiesFromInputStream(inputStream); setConfigurationFromProperties(properties, config); } catch (IOException e) { logger.error("Error while reading the config.ini file. ",e); throw new RepairnatorConfigException("Error while reading the "+FILENAME+" file", e); } }
private void setConfigurationFromProperties(Properties properties, RepairnatorConfig config) throws RepairnatorConfigException { try { config.setPush(Boolean.parseBoolean(properties.getProperty("push"))); config.setWorkspacePath(properties.getProperty("workspacePath")); config.setZ3solverPath(properties.getProperty("z3path")); config.setOutputPath(properties.getProperty("jsonOutputPath")); config.setPushRemoteRepo(properties.getProperty("pushRemoteRepo")); } catch (Exception e) { logger.error("Error while setting config values from properties."); throw new RepairnatorConfigException("Error while setting config values from properties.", e); } }