List of usage examples for org.apache.commons.configuration MapConfiguration MapConfiguration
public MapConfiguration(Map map)
From source file:org.seedstack.seed.core.internal.application.ApplicationPlugin.java
private Configuration buildConfiguration(Props props, Props propsOverride, Map<String, Class<? extends StrLookup>> configurationLookups, String... profiles) { Map<String, String> finalConfiguration = new HashMap<String, String>(); Map<String, String> configurationMap = new HashMap<String, String>(); Map<String, String> configurationOverrideMap = new HashMap<String, String>(); // Extract props to maps props.extractProps(configurationMap, profiles); propsOverride.extractProps(configurationOverrideMap, profiles); // Put defaults to final configuration finalConfiguration.putAll(defaultConfiguration); // Put nominal to final configuration finalConfiguration.putAll(configurationMap); // Apply removal behavior Iterator<Map.Entry<String, String>> overrideIterator = configurationOverrideMap.entrySet().iterator(); while (overrideIterator.hasNext()) { String overrideKey = overrideIterator.next().getKey(); if (overrideKey.startsWith("-")) { finalConfiguration.remove(overrideKey.substring(1)); overrideIterator.remove();/*from ww w. j av a 2 s . com*/ } } // Put override to final configuration finalConfiguration.putAll(configurationOverrideMap); // Convert final configuration to an immutable Apache Commons Configuration MapConfiguration mapConfiguration = new MapConfiguration( new ImmutableMap.Builder<String, Object>().putAll(finalConfiguration).build()); // Register configuration lookups for (Entry<String, Class<? extends StrLookup>> configurationLookup : configurationLookups.entrySet()) { mapConfiguration.getInterpolator().registerLookup(configurationLookup.getKey(), buildStrLookup(configurationLookup.getValue(), mapConfiguration)); } return mapConfiguration; }
From source file:org.seedstack.seed.core.internal.application.SeedConfigLoader.java
private Configuration buildBootstrapConfiguration() { Set<String> resources = Sets.newHashSet(SEED_BOOTSTRAP_PROPS_PATH, SEED_BOOTSTRAP_PROPERTIES_PATH); MapConfiguration globalConfiguration = buildApplicationConfig(resources, null).getValue0(); globalConfiguration.getInterpolator().registerLookup("env", new EnvLookup()); return new MapConfiguration( new ImmutableMap.Builder<String, Object>().putAll(globalConfiguration.getMap()).build()); }
From source file:org.seedstack.seed.core.internal.application.SeedConfigLoader.java
private MapConfiguration buildConfiguration(Props props, Props propsOverride, Map<String, String> defaultConfiguration) { Map<String, String> finalConfiguration = new HashMap<String, String>(); Map<String, String> configurationMap = new HashMap<String, String>(); Map<String, String> configurationOverrideMap = new HashMap<String, String>(); // Extract props to maps props.extractProps(configurationMap, applicationProfiles()); propsOverride.extractProps(configurationOverrideMap, applicationProfiles()); // Put defaults to final configuration if (defaultConfiguration != null) { finalConfiguration.putAll(defaultConfiguration); }//from ww w . j a v a 2 s . c o m // Put nominal to final configuration finalConfiguration.putAll(configurationMap); applyPropertiesRemoval(finalConfiguration, configurationOverrideMap); // Put override to final configuration finalConfiguration.putAll(configurationOverrideMap); // Convert final configuration to an immutable Apache Commons Configuration return new MapConfiguration(new ImmutableMap.Builder<String, Object>().putAll(finalConfiguration).build()); }
From source file:org.seedstack.seed.core.internal.CorePlugin.java
private Configuration loadBootstrapConfiguration() { MapConfiguration globalConfiguration = new MapConfiguration(new HashMap<String, Object>()); ClassLoader classLoader = SeedReflectionUtils.findMostCompleteClassLoader(); if (classLoader == null) { throw SeedException.createNew(CoreErrorCode.UNABLE_TO_FIND_CLASSLOADER); }/*from www .j a v a2 s . co m*/ try { Enumeration<URL> urls = classLoader.getResources(SEED_BOOTSTRAP_PATH); while (urls.hasMoreElements()) { URL url = urls.nextElement(); globalConfiguration.append(new PropertiesConfiguration(url)); } } catch (Exception e) { throw SeedException.wrap(e, CoreErrorCode.UNEXPECTED_EXCEPTION); } return new MapConfiguration( new ImmutableMap.Builder<String, Object>().putAll(globalConfiguration.getMap()).build()); }
From source file:org.seedstack.seed.core.internal.SeedConfigLoader.java
private Configuration buildBootstrapConfiguration() { Set<String> resources = Sets.newHashSet(SEED_BOOTSTRAP_PROPS_PATH, SEED_BOOTSTRAP_PROPERTIES_PATH); MapConfiguration globalConfiguration = buildConfiguration(resources, null).getValue0(); globalConfiguration.getInterpolator().registerLookup("env", new EnvLookup()); return new MapConfiguration( new ImmutableMap.Builder<String, Object>().putAll(globalConfiguration.getMap()).build()); }
From source file:org.seedstack.seed.mail.internal.JavaMailPluginTest.java
@Test public void test_get_plugin_configuration() { configureMocks();/*from w w w .ja va2s . co m*/ when(applicationPlugin.getApplication().getConfiguration()) .thenReturn(new MapConfiguration(new HashMap<String, Object>() { { put("smtp", Session.getInstance(new Properties())); } })); final Configuration pluginConfiguration = mailPlugin.getPluginConfiguration(applicationPlugin); assertThat(pluginConfiguration).isNotNull(); }
From source file:org.seedstack.seed.mail.internal.PropertyFileSessionConfigurerTest.java
@Before public void setUp() throws Exception { Props props = new Props(); Map<String, Object> config = new HashMap<String, Object>(); props.load(PropertyFileSessionConfigurerTest.class.getResourceAsStream("/test.props")); props.extractBaseProps(config);// w w w. j a v a 2 s.c o m Configuration configuration = new MapConfiguration(config); assertThat(config).isNotEmpty(); assertThat(configuration).isNotNull(); SessionConfigurer configurer = new PropertyFileSessionConfigurer( configuration.subset(JavaMailPlugin.CONFIGURATION_PREFIX)); this.sessionsConfig = configurer.doConfigure(); }
From source file:org.sonar.ant.Launcher.java
private Configuration getInitialConfiguration(ProjectDefinition project) { CompositeConfiguration configuration = new CompositeConfiguration(); configuration.addConfiguration(new SystemConfiguration()); configuration.addConfiguration(new EnvironmentConfiguration()); configuration.addConfiguration(new MapConfiguration(project.getProperties())); return configuration; }
From source file:org.sonar.api.batch.AbstractLanguageSensorTest.java
protected Project loadProjectFromPom(File pomFile) throws Exception { MavenProject pom = loadPom(pomFile); Project project = new Project(pom.getGroupId() + ":" + pom.getArtifactId()).setPom(pom) .setConfiguration(new MapConfiguration(pom.getProperties())); project.setFileSystem(new DefaultProjectFileSystem(project)); project.setPom(pom);//from ww w .ja v a 2 s.c om project.setLanguageKey(getLanguage().getKey()); project.setLanguage(getLanguage()); return project; }
From source file:org.sonar.api.batch.AbstractSourceImporterTest.java
@Test public void should_remove_byte_order_mark_character() throws Exception { Project project = mock(Project.class); SensorContext context = mock(SensorContext.class); ProjectFileSystem fileSystem = mock(ProjectFileSystem.class); when(project.getFileSystem()).thenReturn(fileSystem); when(fileSystem.getSourceCharset()).thenReturn(Charset.forName(CharEncoding.UTF_8)); when(project.getConfiguration()).thenReturn(new MapConfiguration(new HashMap<String, String>())); File file = new File(Files.createTempDir(), "Test.java"); Files.write("\uFEFFpublic class Test", file, Charset.defaultCharset()); when(fileSystem.getSourceFiles(any(Language.class))).thenReturn(newArrayList(file)); importer.shouldExecuteOnProject(project); importer.analyse(project, context);// w w w.j a v a2 s.c om verify(context).saveSource(eq(FakeSourceImporter.TEST_RESOURCE), argThat(new ArgumentMatcher<String>() { @Override public boolean matches(Object arg0) { String source = (String) arg0; return !source.contains("\uFEFF"); } })); }