Java 类org.springframework.boot.env.EnumerableCompositePropertySource 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigFileApplicationListener.java   
public static void finishAndRelocate(MutablePropertySources propertySources) {
    String name = APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME;
    ConfigurationPropertySources removed = (ConfigurationPropertySources) propertySources
            .get(name);
    if (removed != null) {
        for (PropertySource<?> propertySource : removed.sources) {
            if (propertySource instanceof EnumerableCompositePropertySource) {
                EnumerableCompositePropertySource composite = (EnumerableCompositePropertySource) propertySource;
                for (PropertySource<?> nested : composite.getSource()) {
                    propertySources.addAfter(name, nested);
                    name = nested.getName();
                }
            }
            else {
                propertySources.addAfter(name, propertySource);
            }
        }
        propertySources.remove(APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME);
    }
}
项目:spring-boot-concourse    文件:ConfigFileApplicationListener.java   
public static void finishAndRelocate(MutablePropertySources propertySources) {
    String name = APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME;
    ConfigurationPropertySources removed = (ConfigurationPropertySources) propertySources
            .get(name);
    if (removed != null) {
        for (PropertySource<?> propertySource : removed.sources) {
            if (propertySource instanceof EnumerableCompositePropertySource) {
                EnumerableCompositePropertySource composite = (EnumerableCompositePropertySource) propertySource;
                for (PropertySource<?> nested : composite.getSource()) {
                    propertySources.addAfter(name, nested);
                    name = nested.getName();
                }
            }
            else {
                propertySources.addAfter(name, propertySource);
            }
        }
        propertySources.remove(APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME);
    }
}
项目:contestparser    文件:ConfigFileEnvironmentPostProcessor.java   
public static void finishAndRelocate(MutablePropertySources propertySources) {
    ConfigurationPropertySources removed = (ConfigurationPropertySources) propertySources
            .get(ConfigurationPropertySources.NAME);
    String name = ConfigurationPropertySources.NAME;
    if (removed != null) {
        for (PropertySource<?> propertySource : removed.sources) {
            if (propertySource instanceof EnumerableCompositePropertySource) {
                EnumerableCompositePropertySource composite = (EnumerableCompositePropertySource) propertySource;
                for (PropertySource<?> nested : composite.getSource()) {
                    propertySources.addAfter(name, nested);
                    name = nested.getName();
                }
            }
            else {
                propertySources.addAfter(name, propertySource);
            }
        }
        propertySources.remove(ConfigurationPropertySources.NAME);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigFileApplicationListenerTests.java   
@Test
public void yamlSetsProfiles() throws Exception {
    this.initializer.setSearchNames("testsetprofiles");
    this.initializer.postProcessEnvironment(this.environment, this.application);
    assertThat(this.environment.getActiveProfiles()).containsExactly("dev");
    String property = this.environment.getProperty("my.property");
    assertThat(this.environment.getActiveProfiles()).contains("dev");
    assertThat(property).isEqualTo("fromdevprofile");
    ConfigurationPropertySources propertySource = (ConfigurationPropertySources) this.environment
            .getPropertySources()
            .get(ConfigFileApplicationListener.APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME);
    Collection<org.springframework.core.env.PropertySource<?>> sources = propertySource
            .getSource();
    assertThat(sources).hasSize(2);
    List<String> names = new ArrayList<String>();
    for (org.springframework.core.env.PropertySource<?> source : sources) {
        if (source instanceof EnumerableCompositePropertySource) {
            for (org.springframework.core.env.PropertySource<?> nested : ((EnumerableCompositePropertySource) source)
                    .getSource()) {
                names.add(nested.getName());
            }
        }
        else {
            names.add(source.getName());
        }
    }
    assertThat(names).contains(
            "applicationConfig: [classpath:/testsetprofiles.yml]#dev",
            "applicationConfig: [classpath:/testsetprofiles.yml]");
}
项目:spring-boot-concourse    文件:ConfigFileApplicationListenerTests.java   
@Test
public void yamlSetsProfiles() throws Exception {
    this.initializer.setSearchNames("testsetprofiles");
    this.initializer.postProcessEnvironment(this.environment, this.application);
    assertThat(this.environment.getActiveProfiles()).containsExactly("dev");
    String property = this.environment.getProperty("my.property");
    assertThat(this.environment.getActiveProfiles()).contains("dev");
    assertThat(property).isEqualTo("fromdevprofile");
    ConfigurationPropertySources propertySource = (ConfigurationPropertySources) this.environment
            .getPropertySources()
            .get(ConfigFileApplicationListener.APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME);
    Collection<org.springframework.core.env.PropertySource<?>> sources = propertySource
            .getSource();
    assertThat(sources).hasSize(2);
    List<String> names = new ArrayList<String>();
    for (org.springframework.core.env.PropertySource<?> source : sources) {
        if (source instanceof EnumerableCompositePropertySource) {
            for (org.springframework.core.env.PropertySource<?> nested : ((EnumerableCompositePropertySource) source)
                    .getSource()) {
                names.add(nested.getName());
            }
        }
        else {
            names.add(source.getName());
        }
    }
    assertThat(names).contains(
            "applicationConfig: [classpath:/testsetprofiles.yml]#dev",
            "applicationConfig: [classpath:/testsetprofiles.yml]");
}
项目:contestparser    文件:ConfigFileEnvironmentPostProcessorTests.java   
@Test
public void yamlSetsProfiles() throws Exception {
    this.initializer.setSearchNames("testsetprofiles");
    this.initializer.postProcessEnvironment(this.environment, this.application);
    assertEquals("dev", StringUtils
            .arrayToCommaDelimitedString(this.environment.getActiveProfiles()));
    String property = this.environment.getProperty("my.property");
    assertThat(Arrays.asList(this.environment.getActiveProfiles()), contains("dev"));
    assertThat(property, equalTo("fromdevprofile"));
    ConfigurationPropertySources propertySource = (ConfigurationPropertySources) this.environment
            .getPropertySources().get("applicationConfigurationProperties");
    Collection<org.springframework.core.env.PropertySource<?>> sources = propertySource
            .getSource();
    assertEquals(2, sources.size());
    List<String> names = new ArrayList<String>();
    for (org.springframework.core.env.PropertySource<?> source : sources) {
        if (source instanceof EnumerableCompositePropertySource) {
            for (org.springframework.core.env.PropertySource<?> nested : ((EnumerableCompositePropertySource) source)
                    .getSource()) {
                names.add(nested.getName());
            }
        }
        else {
            names.add(source.getName());
        }
    }
    assertThat(names,
            contains("applicationConfig: [classpath:/testsetprofiles.yml]#dev",
                    "applicationConfig: [classpath:/testsetprofiles.yml]"));
}