org.apache.commons.configuration2.tree.OverrideCombiner Java Examples
The following examples show how to use
org.apache.commons.configuration2.tree.OverrideCombiner.
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: PlatformConfigReader.java From obevo with Apache License 2.0 | 5 votes |
public ImmutableHierarchicalConfiguration readPlatformProperties(RichIterable<String> configPackages) { MutableList<PropertyInput> prioritizedProperties = readConfigPackages(configPackages); validate(prioritizedProperties); // order properties by priority: higher-numbered files will replace properties of lower-numbered files prioritizedProperties.sortThisBy(new Function<PropertyInput, Integer>() { @Override public Integer valueOf(PropertyInput propertyInput1) { return propertyInput1.getPriority(); } }).reverseThis(); // needs to be reversed as CombinedConfiguration takes the higher-priority files first // merge properties CombinedConfiguration combinedConfiguration = new CombinedConfiguration(new OverrideCombiner()); for (HierarchicalConfiguration<ImmutableNode> properties : prioritizedProperties.collect(new Function<PropertyInput, HierarchicalConfiguration<ImmutableNode>>() { @Override public HierarchicalConfiguration<ImmutableNode> valueOf(PropertyInput propertyInput) { return propertyInput.getProps(); } })) { combinedConfiguration.addConfiguration(properties); } // remove the configPriority property combinedConfiguration.clearTree(PROP_CONFIG_PRIORITY); return combinedConfiguration; }
Example #2
Source File: AbstractEnvironmentEnricher.java From obevo with Apache License 2.0 | 5 votes |
@Override public ImmutableCollection<E> readSystem(final HierarchicalConfiguration sysCfg, final FileObject sourcePath) { final Platform systemDbPlatform = dbPlatformConfiguration.valueOf(sysCfg.getString("type")); // Check for dbEnvironments first for backwards-compatibility ImmutableList<HierarchicalConfiguration> envConfigs = iterConfigMutable(sysCfg, "environments.dbEnvironment"); if (envConfigs.isEmpty()) { envConfigs = iterConfigMutable(sysCfg, "environments.environment"); } ImmutableList<E> envList = envConfigs.collect(new Function<HierarchicalConfiguration, E>() { @Override public E valueOf(HierarchicalConfiguration envCfg) { E dbEnv = AbstractEnvironmentEnricher.this.createNewEnv(); // combining the sys and env configurations before passing to downstream methods so that we can support only having env configs passed in CombinedConfiguration combinedConfiguration = new CombinedConfiguration(new OverrideCombiner()); combinedConfiguration.addConfiguration(envCfg); combinedConfiguration.addConfiguration(sysCfg); combinedConfiguration.setExpressionEngine(sysCfg.getExpressionEngine()); AbstractEnvironmentEnricher.this.enrich(dbEnv, combinedConfiguration, sourcePath, systemDbPlatform); AbstractEnvironmentEnricher.this.createEnv(dbEnv, combinedConfiguration, systemDbPlatform); return dbEnv; } }); CollectionUtil.verifyNoDuplicates(envList, new Function<E, Object>() { @Override public Object valueOf(E e) { return e.getName(); } }, "Invalid configuration from " + sourcePath + "; not expecting duplicate env names"); return envList; }
Example #3
Source File: StudioConfigurationImpl.java From studio with GNU General Public License v3.0 | 5 votes |
private HierarchicalConfiguration<ImmutableNode> loadGlobalRepoConfig() { if (config.containsKey(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG)) { Path globalRepoOverrideConfigLocation = Paths.get(config.getString(REPO_BASE_PATH), config.getString(GLOBAL_REPO_PATH), config.getString(STUDIO_CONFIG_GLOBAL_REPO_OVERRIDE_CONFIG)); FileSystemResource fsr = new FileSystemResource(globalRepoOverrideConfigLocation.toFile()); if (fsr.exists()) { ZonedDateTime lastModified = null; try { lastModified = Instant.ofEpochMilli(fsr.lastModified()).atZone(UTC); if ((lastModifiedGlobalRepoConfig == null) || lastModified.isAfter(lastModifiedGlobalRepoConfig)) { YamlConfiguration globalRepoOverrideConfig = new YamlConfiguration(); try (InputStream in = fsr.getInputStream()) { globalRepoOverrideConfig.setExpressionEngine(getExpressionEngine()); globalRepoOverrideConfig.read(in); if (!globalRepoOverrideConfig.isEmpty()) { logger.debug("Loaded additional configuration from location: {0} \n {1}", fsr.getPath(), globalRepoOverrideConfig); } globalRepoConfig = globalRepoOverrideConfig; } if (!globalRepoConfig.isEmpty()) { CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner()); combinedConfig.setExpressionEngine(getExpressionEngine()); combinedConfig.addConfiguration(globalRepoConfig); combinedConfig.addConfiguration(systemConfig); config = combinedConfig; } lastModifiedGlobalRepoConfig = lastModified; } } catch (IOException | ConfigurationException e) { logger.error("Failed to load studio configuration from: " + fsr.getPath(), e); } } } return config; }
Example #4
Source File: TestCombinedConfiguration.java From commons-configuration with Apache License 2.0 | 5 votes |
/** * Tests whether a combined configuration can be copied to an XML * configuration. This test is related to CONFIGURATION-445. */ @Test public void testCombinedCopyToXML() throws ConfigurationException { final XMLConfiguration x1 = new XMLConfiguration(); x1.addProperty("key1", "value1"); x1.addProperty("key1[@override]", "USER1"); x1.addProperty("key2", "value2"); x1.addProperty("key2[@override]", "USER2"); final XMLConfiguration x2 = new XMLConfiguration(); x2.addProperty("key2", "value2.2"); x2.addProperty("key2[@override]", "USER2"); config.setNodeCombiner(new OverrideCombiner()); config.addConfiguration(x2); config.addConfiguration(x1); XMLConfiguration x3 = new XMLConfiguration(config); assertEquals("Wrong element value", "value2.2", x3.getString("key2")); assertEquals("Wrong attribute value", "USER2", x3.getString("key2[@override]")); final StringWriter w = new StringWriter(); new FileHandler(x3).save(w); final String s = w.toString(); x3 = new XMLConfiguration(); new FileHandler(x3).load(new StringReader(s)); assertEquals("Wrong element value after load", "value2.2", x3.getString("key2")); assertEquals("Wrong attribute value after load", "USER2", x3.getString("key2[@override]")); }
Example #5
Source File: CombinedConfigurationBuilder.java From commons-configuration with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} This implementation processes the definition configuration * in order to * <ul> * <li>initialize the resulting {@code CombinedConfiguration}</li> * <li>determine the builders for all configuration sources</li> * <li>populate the resulting {@code CombinedConfiguration}</li> * </ul> */ @Override protected void initResultInstance(final CombinedConfiguration result) throws ConfigurationException { super.initResultInstance(result); currentConfiguration = result; final HierarchicalConfiguration<?> config = getDefinitionConfiguration(); if (config.getMaxIndex(KEY_COMBINER) < 0) { // No combiner defined => set default result.setNodeCombiner(new OverrideCombiner()); } setUpCurrentParameters(); initNodeCombinerListNodes(result, config, KEY_OVERRIDE_LIST); registerConfiguredProviders(config); setUpCurrentXMLParameters(); currentXMLParameters.setFileSystem(initFileSystem(config)); initSystemProperties(config, getBasePath()); registerConfiguredLookups(config, result); configureEntityResolver(config, currentXMLParameters); setUpParentInterpolator(currentConfiguration, config); final ConfigurationSourceData data = getSourceData(); final boolean createBuilders = data.getChildBuilders().isEmpty(); final List<ConfigurationBuilder<? extends Configuration>> overrideBuilders = data.createAndAddConfigurations(result, data.getOverrideSources(), data.overrideBuilders); if (createBuilders) { data.overrideBuilders.addAll(overrideBuilders); } if (!data.getUnionSources().isEmpty()) { final CombinedConfiguration addConfig = createAdditionalsConfiguration(result); result.addConfiguration(addConfig, ADDITIONAL_NAME); initNodeCombinerListNodes(addConfig, config, KEY_ADDITIONAL_LIST); final List<ConfigurationBuilder<? extends Configuration>> unionBuilders = data.createAndAddConfigurations(addConfig, data.unionDeclarations, data.unionBuilders); if (createBuilders) { data.unionBuilders.addAll(unionBuilders); } } result.isEmpty(); // this sets up the node structure currentConfiguration = null; }