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

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigurationPropertiesBindingPostProcessor.java   
private PropertySources loadPropertySources(String[] locations,
        boolean mergeDefaultSources) {
    try {
        PropertySourcesLoader loader = new PropertySourcesLoader();
        for (String location : locations) {
            Resource resource = this.resourceLoader
                    .getResource(this.environment.resolvePlaceholders(location));
            String[] profiles = this.environment.getActiveProfiles();
            for (int i = profiles.length; i-- > 0;) {
                String profile = profiles[i];
                loader.load(resource, profile);
            }
            loader.load(resource);
        }
        MutablePropertySources loaded = loader.getPropertySources();
        if (mergeDefaultSources) {
            for (PropertySource<?> propertySource : this.propertySources) {
                loaded.addLast(propertySource);
            }
        }
        return loaded;
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:haven-platform    文件:DefaultParser.java   
@Override
public void parse(File file, ContainerCreationContext context) {
    try {
        ContainerSource arg = new ContainerSource();
        PropertySourcesLoader loader = new PropertySourcesLoader();
        loader.load(new FileSystemResource(file));
        MutablePropertySources loaded = loader.getPropertySources();
        PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<>(arg);

        factory.setPropertySources(loaded);
        factory.setConversionService(defaultConversionService);
        factory.bindPropertiesToTarget();
        arg.getInclude().forEach(a -> parse(new File(file.getParent(), a), context));
        context.addCreateContainerArg(arg);
    } catch (Exception e) {
        log.error("can't parse configuration", e.getMessage());
    }
}
项目:spring-boot-concourse    文件:ConfigurationPropertiesBindingPostProcessor.java   
private PropertySources loadPropertySources(String[] locations,
        boolean mergeDefaultSources) {
    try {
        PropertySourcesLoader loader = new PropertySourcesLoader();
        for (String location : locations) {
            Resource resource = this.resourceLoader
                    .getResource(this.environment.resolvePlaceholders(location));
            String[] profiles = this.environment.getActiveProfiles();
            for (int i = profiles.length; i-- > 0;) {
                String profile = profiles[i];
                loader.load(resource, profile);
            }
            loader.load(resource);
        }
        MutablePropertySources loaded = loader.getPropertySources();
        if (mergeDefaultSources) {
            for (PropertySource<?> propertySource : this.propertySources) {
                loaded.addLast(propertySource);
            }
        }
        return loaded;
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:contestparser    文件:ConfigurationPropertiesBindingPostProcessor.java   
private PropertySources loadPropertySources(String[] locations,
        boolean mergeDefaultSources) {
    try {
        PropertySourcesLoader loader = new PropertySourcesLoader();
        for (String location : locations) {
            Resource resource = this.resourceLoader
                    .getResource(this.environment.resolvePlaceholders(location));
            String[] profiles = this.environment.getActiveProfiles();
            for (int i = profiles.length; i-- > 0;) {
                String profile = profiles[i];
                loader.load(resource, profile);
            }
            loader.load(resource);
        }
        MutablePropertySources loaded = loader.getPropertySources();
        if (mergeDefaultSources) {
            for (PropertySource<?> propertySource : this.propertySources) {
                loaded.addLast(propertySource);
            }
        }
        return loaded;
    }
    catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ConfigFileApplicationListener.java   
public void load() throws IOException {
    this.propertiesLoader = new PropertySourcesLoader();
    this.activatedProfiles = false;
    this.profiles = Collections.asLifoQueue(new LinkedList<Profile>());
    this.processedProfiles = new LinkedList<Profile>();

    // Pre-existing active profiles set via Environment.setActiveProfiles()
    // are additional profiles and config files are allowed to add more if
    // they want to, so don't call addActiveProfiles() here.
    Set<Profile> initialActiveProfiles = initializeActiveProfiles();
    this.profiles.addAll(getUnprocessedActiveProfiles(initialActiveProfiles));
    if (this.profiles.isEmpty()) {
        for (String defaultProfileName : this.environment.getDefaultProfiles()) {
            Profile defaultProfile = new Profile(defaultProfileName, true);
            if (!this.profiles.contains(defaultProfile)) {
                this.profiles.add(defaultProfile);
            }
        }
    }

    // The default profile for these purposes is represented as null. We add it
    // last so that it is first out of the queue (active profiles will then
    // override any settings in the defaults when the list is reversed later).
    this.profiles.add(null);

    while (!this.profiles.isEmpty()) {
        Profile profile = this.profiles.poll();
        for (String location : getSearchLocations()) {
            if (!location.endsWith("/")) {
                // location is a filename already, so don't search for more
                // filenames
                load(location, null, profile);
            }
            else {
                for (String name : getSearchNames()) {
                    load(location, name, profile);
                }
            }
        }
        this.processedProfiles.add(profile);
    }

    addConfigurationProperties(this.propertiesLoader.getPropertySources());
}
项目:spring-boot-concourse    文件:ConfigFileApplicationListener.java   
public void load() throws IOException {
    this.propertiesLoader = new PropertySourcesLoader();
    this.activatedProfiles = false;
    this.profiles = Collections.asLifoQueue(new LinkedList<String>());
    this.processedProfiles = new LinkedList<String>();

    // Pre-existing active profiles set via Environment.setActiveProfiles()
    // are additional profiles and config files are allowed to add more if
    // they want to, so don't call addActiveProfiles() here.
    Set<String> initialActiveProfiles = initializeActiveProfiles();
    this.profiles.addAll(getUnprocessedActiveProfiles(initialActiveProfiles));
    if (this.profiles.isEmpty()) {
        for (String defaultProfile : this.environment.getDefaultProfiles()) {
            if (!this.profiles.contains(defaultProfile)) {
                this.profiles.add(defaultProfile);
            }
        }
    }

    // The default profile for these purposes is represented as null. We add it
    // last so that it is first out of the queue (active profiles will then
    // override any settings in the defaults when the list is reversed later).
    this.profiles.add(null);

    while (!this.profiles.isEmpty()) {
        String profile = this.profiles.poll();
        for (String location : getSearchLocations()) {
            if (!location.endsWith("/")) {
                // location is a filename already, so don't search for more
                // filenames
                load(location, null, profile);
            }
            else {
                for (String name : getSearchNames()) {
                    load(location, name, profile);
                }
            }
        }
        this.processedProfiles.add(profile);
    }

    addConfigurationProperties(this.propertiesLoader.getPropertySources());
}
项目:contestparser    文件:ConfigFileEnvironmentPostProcessor.java   
public void load() throws IOException {
    this.propertiesLoader = new PropertySourcesLoader();
    this.profiles = Collections.asLifoQueue(new LinkedList<String>());
    this.processedProfiles = new LinkedList<String>();
    this.activatedProfiles = false;

    Set<String> initialActiveProfiles = null;
    if (this.environment.containsProperty(ACTIVE_PROFILES_PROPERTY)) {
        // Any pre-existing active profiles set via property sources (e.g. System
        // properties) take precedence over those added in config files.
        initialActiveProfiles = maybeActivateProfiles(
                this.environment.getProperty(ACTIVE_PROFILES_PROPERTY));
    }
    // Pre-existing active profiles set via Environment.setActiveProfiles()
    // are additional profiles and config files are allowed to add more if
    // they want to, so don't call addActiveProfiles() here.
    List<String> list = filterEnvironmentProfiles(initialActiveProfiles != null
            ? initialActiveProfiles : Collections.<String>emptySet());
    // Reverse them so the order is the same as from getProfilesForValue()
    // (last one wins when properties are eventually resolved)
    Collections.reverse(list);
    this.profiles.addAll(list);

    if (this.profiles.isEmpty()) {
        for (String defaultProfile : this.environment.getDefaultProfiles()) {
            if (!this.profiles.contains(defaultProfile)) {
                this.profiles.add(defaultProfile);
            }
        }
    }

    // The default profile for these purposes is represented as null. We add it
    // last so that it is first out of the queue (active profiles will then
    // override any settings in the defaults when the list is reversed later).
    this.profiles.add(null);

    while (!this.profiles.isEmpty()) {
        String profile = this.profiles.poll();
        for (String location : getSearchLocations()) {
            if (!location.endsWith("/")) {
                // location is a filename already, so don't search for more
                // filenames
                load(location, null, profile);
            }
            else {
                for (String name : getSearchNames()) {
                    load(location, name, profile);
                }
            }
        }
        this.processedProfiles.add(profile);
    }

    addConfigurationProperties(this.propertiesLoader.getPropertySources());
}