Java Code Examples for org.apache.commons.configuration2.builder.fluent.Configurations#properties()

The following examples show how to use org.apache.commons.configuration2.builder.fluent.Configurations#properties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SettingsConfiguration.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private static void loadConfig(String path) {
	File file = new File(path);
	try {
		Configurations configs = new Configurations();
		config = configs.properties(file);
	} catch (ConfigurationException cex) {
		System.out.println(cex);
	}
}
 
Example 2
Source File: SettingsConfiguration.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private static void loadConfig(String path) {
	File file = new File(path);
	try {
		Configurations configs = new Configurations();
		config = configs.properties(file);
		new File(instance.getOutputPath()).mkdirs();
	} catch (ConfigurationException cex) {
		log.error(cex);
	}
}
 
Example 3
Source File: GameConfig.java    From 2018-TowerDefence with MIT License 5 votes vote down vote up
public static void initConfig(String configLocation) {
    if (configuration == null) {
        Configurations configurations = new Configurations();

        try {
            configuration = configurations.properties(configLocation);

        } catch (ConfigurationException e) {
            log.error("Unable to initialise configuration, please have a look at the inner exception.", e);
            throw new RuntimeException("Unable to initialise configuration, please have a look at the inner exception.", e);
        }
    }
}
 
Example 4
Source File: Config.java    From bireme with Apache License 2.0 5 votes vote down vote up
/**
 * Read config file and store in {@code Config}.
 *
 * @param configFile the config file.
 * @throws ConfigurationException - if an error occurred when loading the configuration
 * @throws BiremeException - wrap and throw Exception which cannot be handled
 */
public Config(String configFile) throws ConfigurationException, BiremeException {
  Configurations configs = new Configurations();
  config = configs.properties(new File(configFile));

  basicConfig();
  connectionConfig("target");
  dataSourceConfig();

  logConfig();
}
 
Example 5
Source File: Config.java    From bireme with Apache License 2.0 5 votes vote down vote up
private HashMap<String, String> fetchTableMap(String dataSource)
    throws ConfigurationException, BiremeException {
  Configurations configs = new Configurations();
  Configuration tableConfig = null;

  tableConfig = configs.properties(new File(DEFAULT_TABLEMAP_DIR + dataSource + ".properties"));

  String originTable, mappedTable;
  HashMap<String, String> localTableMap = new HashMap<String, String>();
  Iterator<String> tables = tableConfig.getKeys();

  while (tables.hasNext()) {
    originTable = tables.next();
    mappedTable = tableConfig.getString(originTable);

    if (originTable.split("\\.").length != 2 || mappedTable.split("\\.").length != 2) {
      String message = "Wrong format: " + originTable + ", " + mappedTable;
      logger.fatal(message);
      throw new BiremeException(message);
    }

    localTableMap.put(dataSource + "." + originTable, mappedTable);

    if (!tableMap.values().contains(mappedTable)) {
      loadersCount++;
    }
    tableMap.put(dataSource + "." + originTable, mappedTable);
  }

  return localTableMap;
}
 
Example 6
Source File: DoctorKafkaConfig.java    From doctorkafka with Apache License 2.0 5 votes vote down vote up
public DoctorKafkaConfig(String configPath) throws Exception {
  try {
    Configurations configurations = new Configurations();
    configuration = configurations.properties(new File(configPath));
    drkafkaConfiguration = new SubsetConfiguration(configuration, DOCTORKAFKA_PREFIX);
    this.initialize();
  } catch (Exception e) {
    LOG.error("Failed to initialize configuration file {}", configPath, e);
  }
}
 
Example 7
Source File: DocumentationTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
public void swagger2MarkupConfigFromCommonsConfiguration() throws IOException, ConfigurationException {
    Path localSwaggerFile = Paths.get("/path/to/swagger.yaml");

    // tag::swagger2MarkupConfigFromCommonsConfiguration[]
    Configurations configs = new Configurations();
    Configuration configuration = configs.properties("config.properties"); //<1>

    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configuration) //<2>
            .build();

    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(localSwaggerFile)
            .withConfig(config)
            .build();
    // end::swagger2MarkupConfigFromCommonsConfiguration[]
}
 
Example 8
Source File: Schema2MarkupConfigBuilder.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Loads the default properties from the classpath.
 *
 * @return the default properties
 */
public static Configuration getDefaultConfiguration() {
    Configurations configs = new Configurations();
    try {
        return configs.properties(PROPERTIES_DEFAULT);
    } catch (ConfigurationException e) {
        throw new RuntimeException(String.format("Can't load default properties '%s'", PROPERTIES_DEFAULT), e);
    }
}
 
Example 9
Source File: Application.java    From swagger2markup-cli with Apache License 2.0 5 votes vote down vote up
public void run() {

        Swagger2MarkupConfig swagger2MarkupConfig = null;
        if(StringUtils.isNotBlank(configFile)) {
            Configurations configs = new Configurations();
            Configuration config;
            try {
                config = configs.properties(configFile);
            } catch (ConfigurationException e) {
                throw new IllegalArgumentException("Failed to read configFile", e);
            }
            swagger2MarkupConfig = new Swagger2MarkupConfigBuilder(config).build();
        }
        Swagger2MarkupConverter.Builder converterBuilder = Swagger2MarkupConverter.from(URIUtils.create(swaggerInput));
        if(swagger2MarkupConfig != null){
            converterBuilder.withConfig(swagger2MarkupConfig);
        }
        Swagger2MarkupConverter converter = converterBuilder.build();

        if(StringUtils.isNotBlank(outputFile)){
            converter.toFile(Paths.get(outputFile).toAbsolutePath());
        }else if (StringUtils.isNotBlank(outputDir)){
            converter.toFolder(Paths.get(outputDir).toAbsolutePath());
        }else {
            throw new IllegalArgumentException("Either outputFile or outputDir option must be used");
        }
    }
 
Example 10
Source File: GraphFactory.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private static org.apache.commons.configuration2.Configuration getConfiguration(final File configurationFile) {
    if (!configurationFile.isFile())
        throw new IllegalArgumentException(String.format("The location configuration must resolve to a file and [%s] does not", configurationFile));

    try {
        final String fileName = configurationFile.getName();
        final String fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);

        final Configuration conf;
        final Configurations configs = new Configurations();

        switch (fileExtension) {
            case "yml":
            case "yaml":
                final Parameters params = new Parameters();
                final FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
                        new FileBasedConfigurationBuilder<FileBasedConfiguration>(YAMLConfiguration.class).
                                configure(params.fileBased().setFile(configurationFile));

                final org.apache.commons.configuration2.Configuration copy = new org.apache.commons.configuration2.BaseConfiguration();
                ConfigurationUtils.copy(builder.configure(params.fileBased().setFile(configurationFile)).getConfiguration(), copy);
                conf = copy;
                break;
            case "xml":
                conf = configs.xml(configurationFile);
                break;
            default:
                conf = configs.properties(configurationFile);
        }
        return conf;
    } catch (ConfigurationException e) {
        throw new IllegalArgumentException(String.format("Could not load configuration at: %s", configurationFile), e);
    }
}
 
Example 11
Source File: App.java    From DataflowTemplates with Apache License 2.0 4 votes vote down vote up
/**
 * Load the application configuration to start the MySQL CDC connector.
 *
 * This method has the following scenarios:
 *
 * * Get the main properties file:
 *   * If zero arguments are passed, it uses the default properties file location.
 *   * If more than zero arguments are passed, it uses the first argument to get a properties
 *       file.
 * * If necessary, get the password file:
 *   * If the first properties file does not contain the "databasePassword" property, then it
 *       tries to read the second properties file, which only contains the database password.
 *   * If less than 2 arguments are passed, then use the default password file location.
 *   * If 2 arguments are passed, it uses the second argument to get a password file.
 *   * Add the "databasePassword" property from this file to the main configuration.
 *
 * @param args are the arguments passed to the application via the console.
 * @return
 * @throws ConfigurationException
 */
static Configuration getConnectorConfiguration(String[] args)
    throws ConfigurationException {
    Configurations configs = new Configurations();

    String propertiesFile = args.length == 0 ? DEFAULT_PROPERTIES_FILE_LOCATION : args[0];

    Configuration result = configs.properties(new File(propertiesFile));

    if (result.get(Object.class, "databasePassword", MISSING) == MISSING) {
        String passwordFile = args.length < 2 ? PASSWORD_FILE_LOCATION : args[1];

        Configuration passwordConfig = configs.properties(new File(passwordFile));
        result.addProperty("databasePassword", passwordConfig.getString("databasePassword"));
    }

    return result;
}
 
Example 12
Source File: SparkGraphComputer.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final Configurations configs = new Configurations();
    final org.apache.commons.configuration2.Configuration configuration = configs.properties(args[0]);
    new SparkGraphComputer(HadoopGraph.open(configuration)).program(VertexProgram.createVertexProgram(HadoopGraph.open(configuration), configuration)).submit().get();
}