org.apache.commons.configuration2.FileBasedConfiguration Java Examples
The following examples show how to use
org.apache.commons.configuration2.FileBasedConfiguration.
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: CassandraConfigurationReadingTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void provideCassandraConfigurationShouldReturnRightConfigurationFile() throws ConfigurationException { FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters() .fileBased() .setURL(ClassLoader.getSystemResource("configuration-reader-test/cassandra.properties"))); CassandraConfiguration configuration = CassandraConfiguration.from(builder.getConfiguration()); assertThat(configuration) .isEqualTo(CassandraConfiguration.builder() .aclMaxRetry(1) .modSeqMaxRetry(2) .uidMaxRetry(3) .flagsUpdateMessageMaxRetry(4) .flagsUpdateMessageIdMaxRetry(5) .fetchNextPageInAdvanceRow(6) .messageReadChunkSize(7) .expungeChunkSize(8) .blobPartSize(9) .attachmentV2MigrationReadTimeout(10) .messageAttachmentIdsReadTimeout(11) .consistencyLevelRegular("LOCAL_QUORUM") .consistencyLevelLightweightTransaction("LOCAL_SERIAL") .build()); }
Example #2
Source File: TestFileBasedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 6 votes |
/** * Tests whether HomeDirectoryLocationStrategy can be properly initialized * and that it shouldn't throw {@code ConfigurationException} when * everything is correctly in place. Without the code fix for * <a href="https://issues.apache.org/jira/browse/CONFIGURATION-634">CONFIGURATION-634</a>, * this test will throw {@code ConfigurationException} * @throws IOException Shouldn't happen * @throws ConfigurationException Shouldn't happen */ @Test public void testFileBasedConfigurationBuilderWithHomeDirectoryLocationStrategy() throws IOException, ConfigurationException { final String folderName = "test"; final String fileName = "sample.properties"; folder.newFolder(folderName); folder.newFile(folderName + File.separatorChar + fileName); final FileBasedConfigurationBuilder<FileBasedConfiguration> homeDirConfigurationBuilder = new FileBasedConfigurationBuilder<>( PropertiesConfiguration.class); final PropertiesBuilderParameters homeDirProperties = new Parameters().properties(); final HomeDirectoryLocationStrategy strategy = new HomeDirectoryLocationStrategy( folder.getRoot().getAbsolutePath(), true); final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = homeDirConfigurationBuilder.configure(homeDirProperties .setLocationStrategy(strategy).setBasePath(folderName) .setListDelimiterHandler( new DefaultListDelimiterHandler(',')) .setFileName(fileName)); builder.getConfiguration(); }
Example #3
Source File: AliceRecognition.java From carina with Apache License 2.0 | 6 votes |
private AliceRecognition() { try { CombinedConfiguration config = new CombinedConfiguration(new MergeCombiner()); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters().properties().setFileName(ALICE_PROPERTIES)).getConfiguration()); this.enabled = config.getBoolean(ALICE_ENABLED, false); String url = config.getString(ALICE_SERVICE_URL, null); String accessToken = config.getString(ALICE_ACCESS_TOKEN, null); String command = config.getString(ALICE_COMMAND, null); if (enabled && !StringUtils.isEmpty(url) && !StringUtils.isEmpty(accessToken)) { this.client = new AliceClient(url, command); this.client.setAuthToken(accessToken); this.enabled = this.client.isAvailable(); } } catch (Exception e) { LOGGER.error("Unable to initialize Alice: " + e.getMessage(), e); } }
Example #4
Source File: GraphFactory.java From tinkerpop with Apache License 2.0 | 5 votes |
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 #5
Source File: PropertiesProvider.java From james-project with Apache License 2.0 | 5 votes |
private Configuration getConfiguration(File propertiesFile) throws ConfigurationException { FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(new Parameters() .fileBased() .setListDelimiterHandler(new DefaultListDelimiterHandler(COMMA)) .setFile(propertiesFile)); return new DelegatedPropertiesConfiguration(COMMA_STRING, builder.getConfiguration()); }
Example #6
Source File: LdapConfig.java From ranger with Apache License 2.0 | 5 votes |
public void updateInputPropFile(String ldapUrl, String bindDn, String bindPassword, String userSearchBase, String userSearchFilter, String authUser, String authPass) { try { Parameters params = new Parameters(); FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.fileBased().setFileName(CONFIG_FILE)); FileBasedConfiguration config = builder.getConfiguration(); // Update properties in memory and update the file as well prop.setProperty(LGSYNC_LDAP_URL, ldapUrl); prop.setProperty(LGSYNC_LDAP_BIND_DN, bindDn); prop.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword); prop.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase); prop.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter); prop.setProperty(AUTH_USERNAME, authUser); prop.setProperty(AUTH_PASSWORD, authPass); config.setProperty(LGSYNC_LDAP_URL, ldapUrl); config.setProperty(LGSYNC_LDAP_BIND_DN, bindDn); //config.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword); config.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase); config.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter); config.setProperty(AUTH_USERNAME, authUser); //config.setProperty(AUTH_PASSWORD, authPass); builder.save(); } catch (ConfigurationException e) { System.out.println("Failed to update " + CONFIG_FILE + ": " + e); } }
Example #7
Source File: Configurations.java From commons-configuration with Apache License 2.0 | 2 votes |
/** * Creates a {@code FileBasedConfigurationBuilder} for the specified * configuration class and initializes it with the file to be loaded. * * @param configClass the configuration class * @param file the file to be loaded * @param <T> the type of the configuration to be constructed * @return the new {@code FileBasedConfigurationBuilder} */ public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder( final Class<T> configClass, final File file) { return createFileBasedBuilder(configClass, fileParams(file)); }
Example #8
Source File: Configurations.java From commons-configuration with Apache License 2.0 | 2 votes |
/** * Creates a {@code FileBasedConfigurationBuilder} for the specified * configuration class and initializes it with the URL to the file to be * loaded. * * @param configClass the configuration class * @param url the URL to be loaded * @param <T> the type of the configuration to be constructed * @return the new {@code FileBasedConfigurationBuilder} */ public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder( final Class<T> configClass, final URL url) { return createFileBasedBuilder(configClass, fileParams(url)); }
Example #9
Source File: Configurations.java From commons-configuration with Apache License 2.0 | 2 votes |
/** * Creates a {@code FileBasedConfigurationBuilder} for the specified * configuration class and initializes it with the path to the file to be * loaded. * * @param configClass the configuration class * @param path the path to the file to be loaded * @param <T> the type of the configuration to be constructed * @return the new {@code FileBasedConfigurationBuilder} */ public <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> fileBasedBuilder( final Class<T> configClass, final String path) { return createFileBasedBuilder(configClass, fileParams(path)); }
Example #10
Source File: Configurations.java From commons-configuration with Apache License 2.0 | 2 votes |
/** * Creates an instance of the specified file-based configuration class from * the content of the given file. This is a convenience method which can be * used if no builder is needed for managing the configuration object. * (Although, behind the scenes a builder is created). * * @param configClass the configuration class * @param file the file to be loaded * @param <T> the type of the configuration to be constructed * @return a {@code FileBasedConfiguration} object initialized from this * file * @throws ConfigurationException if an error occurred when loading the * configuration */ public <T extends FileBasedConfiguration> T fileBased(final Class<T> configClass, final File file) throws ConfigurationException { return fileBasedBuilder(configClass, file).getConfiguration(); }
Example #11
Source File: Configurations.java From commons-configuration with Apache License 2.0 | 2 votes |
/** * Creates an instance of the specified file-based configuration class from * the content of the given URL. This is a convenience method which can be * used if no builder is needed for managing the configuration object. * (Although, behind the scenes a builder is created). * * @param configClass the configuration class * @param url the URL to be loaded * @param <T> the type of the configuration to be constructed * @return a {@code FileBasedConfiguration} object initialized from this * file * @throws ConfigurationException if an error occurred when loading the * configuration */ public <T extends FileBasedConfiguration> T fileBased(final Class<T> configClass, final URL url) throws ConfigurationException { return fileBasedBuilder(configClass, url).getConfiguration(); }
Example #12
Source File: Configurations.java From commons-configuration with Apache License 2.0 | 2 votes |
/** * Creates an instance of the specified file-based configuration class from * the content of the file identified by the given path. This is a * convenience method which can be used if no builder is needed for managing * the configuration object. (Although, behind the scenes a builder is * created). * * @param configClass the configuration class * @param path the path to the file to be loaded * @param <T> the type of the configuration to be constructed * @return a {@code FileBasedConfiguration} object initialized from this * file * @throws ConfigurationException if an error occurred when loading the * configuration */ public <T extends FileBasedConfiguration> T fileBased(final Class<T> configClass, final String path) throws ConfigurationException { return fileBasedBuilder(configClass, path).getConfiguration(); }
Example #13
Source File: Configurations.java From commons-configuration with Apache License 2.0 | 2 votes |
/** * Creates a configured builder for a file-based configuration of the * specified type. * * @param configClass the configuration class * @param <T> the type of the configuration to be constructed * @return the newly created builder * @since 2.6 */ private <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> createFileBasedBuilder( final Class<T> configClass) { return new FileBasedConfigurationBuilder<>(configClass); }
Example #14
Source File: Configurations.java From commons-configuration with Apache License 2.0 | 2 votes |
/** * Creates a configured builder for a file-based configuration of the * specified type. * * @param configClass the configuration class * @param params the parameters object for configuring the builder * @param <T> the type of the configuration to be constructed * @return the newly created builder */ private <T extends FileBasedConfiguration> FileBasedConfigurationBuilder<T> createFileBasedBuilder( final Class<T> configClass, final FileBasedBuilderParameters params) { return createFileBasedBuilder(configClass).configure(params); }