Search in sources :

Example 46 with Environment

use of org.springframework.core.env.Environment in project spring-boot by spring-projects.

the class AutoConfigurationImportSelector method getExcludeAutoConfigurationsProperty.

/**
 * Returns the auto-configurations excluded by the
 * {@code spring.autoconfigure.exclude} property.
 * @return excluded auto-configurations
 * @since 2.3.2
 */
protected List<String> getExcludeAutoConfigurationsProperty() {
    Environment environment = getEnvironment();
    if (environment == null) {
        return Collections.emptyList();
    }
    if (environment instanceof ConfigurableEnvironment) {
        Binder binder = Binder.get(environment);
        return binder.bind(PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE, String[].class).map(Arrays::asList).orElse(Collections.emptyList());
    }
    String[] excludes = environment.getProperty(PROPERTY_NAME_AUTOCONFIGURE_EXCLUDE, String[].class);
    return (excludes != null) ? Arrays.asList(excludes) : Collections.emptyList();
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Environment(org.springframework.core.env.Environment)

Example 47 with Environment

use of org.springframework.core.env.Environment in project midpoint by Evolveum.

the class MidPointApplication method initializeSchrodinger.

private void initializeSchrodinger() {
    if (applicationContext == null) {
        return;
    }
    Environment environment = applicationContext.getEnvironment();
    if (environment == null) {
        return;
    }
    String value = environment.getProperty(MidpointConfiguration.MIDPOINT_SCHRODINGER_PROPERTY);
    boolean enabled = Boolean.parseBoolean(value);
    if (enabled) {
        LOGGER.info("Schrodinger plugin enabled");
        getComponentInitializationListeners().add(new SchrodingerComponentInitListener());
    }
}
Also used : Environment(org.springframework.core.env.Environment) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SchrodingerComponentInitListener(com.evolveum.midpoint.web.util.SchrodingerComponentInitListener)

Example 48 with Environment

use of org.springframework.core.env.Environment in project dubbo by alibaba.

the class DubboConfigBeanDefinitionConflictApplicationListener method resolveUniqueApplicationConfigBean.

/**
 * Resolve the unique {@link ApplicationConfig} Bean
 * @param registry {@link BeanDefinitionRegistry} instance
 * @param beanFactory {@link ConfigurableListableBeanFactory} instance
 * @see EnableDubboConfig
 */
private void resolveUniqueApplicationConfigBean(BeanDefinitionRegistry registry, ListableBeanFactory beanFactory) {
    String[] beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
    if (beansNames.length < 2) {
        // If the number of ApplicationConfig beans is less than two, return immediately.
        return;
    }
    Environment environment = beanFactory.getBean(ENVIRONMENT_BEAN_NAME, Environment.class);
    // Remove ApplicationConfig Beans that are configured by "dubbo.application.*"
    Stream.of(beansNames).filter(beansName -> isConfiguredApplicationConfigBeanName(environment, beansName)).forEach(registry::removeBeanDefinition);
    beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
    if (beansNames.length > 1) {
        throw new IllegalStateException(String.format("There are more than one instances of %s, whose bean definitions : %s", ApplicationConfig.class.getSimpleName(), Stream.of(beansNames).map(registry::getBeanDefinition).collect(Collectors.toList())));
    }
}
Also used : Ordered(org.springframework.core.Ordered) Logger(org.slf4j.Logger) ENVIRONMENT_BEAN_NAME(org.springframework.context.ConfigurableApplicationContext.ENVIRONMENT_BEAN_NAME) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) LoggerFactory(org.slf4j.LoggerFactory) BeanFactoryUtils(org.springframework.beans.factory.BeanFactoryUtils) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) ApplicationListener(org.springframework.context.ApplicationListener) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Objects(java.util.Objects) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Stream(java.util.stream.Stream) Environment(org.springframework.core.env.Environment) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) EnableDubboConfig(org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig) BeanFactoryUtils.beanNamesForTypeIncludingAncestors(org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) Environment(org.springframework.core.env.Environment)

Example 49 with Environment

use of org.springframework.core.env.Environment in project cas by apereo.

the class CasConfigurationPropertiesEnvironmentManager method getStandaloneProfileConfigurationFile.

/**
 * Gets standalone profile configuration file.
 *
 * @param environment the environment
 * @return the standalone profile configuration file
 */
public File getStandaloneProfileConfigurationFile(final Environment environment) {
    val values = new LinkedHashSet<>(RelaxedPropertyNames.forCamelCase(PROPERTY_CAS_STANDALONE_CONFIGURATION_FILE).getValues());
    values.add(PROPERTY_CAS_STANDALONE_CONFIGURATION_FILE);
    return values.stream().map(key -> environment.getProperty(key, File.class)).filter(Objects::nonNull).findFirst().orElse(null);
}
Also used : lombok.val(lombok.val) LinkedHashSet(java.util.LinkedHashSet) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Arrays(java.util.Arrays) Getter(lombok.Getter) Environment(org.springframework.core.env.Environment) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) ConfigurationPropertiesBindingPostProcessor(org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor) ApplicationContext(org.springframework.context.ApplicationContext) RelaxedPropertyNames(org.apereo.cas.configuration.support.RelaxedPropertyNames) File(java.io.File) LinkedHashSet(java.util.LinkedHashSet) Objects(java.util.Objects)

Example 50 with Environment

use of org.springframework.core.env.Environment in project cas by apereo.

the class DefaultCasConfigurationPropertiesSourceLocator method getAllPossibleExternalConfigDirFilenames.

/**
 * Make a list of files that will be processed in order where the last one processed wins.
 * Profiles are added after base property names like {@code application.properties}, {@code cas.properties},
 * {@code CAS.properties} so that the profiles will override the base properties.
 * <p>
 * Profiles are processed in order so that the last profile list (e.g. in {@code spring.active.profiles}) will override the
 * the first profile.
 * <p>
 * Where multiple filenames with same base name and different extensions exist, the priority is yaml, yml, properties.
 */
private List<File> getAllPossibleExternalConfigDirFilenames(final Environment environment, final File configDirectory, final List<String> profiles) {
    val applicationName = casConfigurationPropertiesEnvironmentManager.getApplicationName(environment);
    val configName = casConfigurationPropertiesEnvironmentManager.getConfigurationName(environment);
    val appNameLowerCase = applicationName.toLowerCase();
    val appConfigNames = CollectionUtils.wrapList("application", appNameLowerCase, applicationName, configName);
    val fileNames = appConfigNames.stream().distinct().flatMap(appName -> EXTENSIONS.stream().map(ext -> new File(configDirectory, String.format("%s.%s", appName, ext)))).filter(File::exists).collect(Collectors.toList());
    fileNames.addAll(profiles.stream().flatMap(profile -> EXTENSIONS.stream().flatMap(ext -> PROFILE_PATTERNS.stream().map(pattern -> new File(configDirectory, String.format(pattern, profile, ext))))).filter(File::exists).collect(Collectors.toList()));
    fileNames.addAll(profiles.stream().map(profile -> EXTENSIONS.stream().map(ext -> appConfigNames.stream().map(appName -> new File(configDirectory, String.format("%s-%s.%s", appName, profile, ext))).filter(File::exists).collect(Collectors.toList())).flatMap(List::stream).collect(Collectors.toList())).flatMap(List::stream).collect(Collectors.toList()));
    val groovyFile = new File(configDirectory, appNameLowerCase.concat(".groovy"));
    FunctionUtils.doIf(groovyFile.exists(), o -> fileNames.add(groovyFile)).accept(groovyFile);
    return fileNames;
}
Also used : lombok.val(lombok.val) Arrays(java.util.Arrays) Unchecked(org.jooq.lambda.Unchecked) ResourceLoader(org.springframework.core.io.ResourceLoader) PropertySource(org.springframework.core.env.PropertySource) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) FileSystemResource(org.springframework.core.io.FileSystemResource) Collectors(java.util.stream.Collectors) ConfigurationPropertiesLoaderFactory(org.apereo.cas.configuration.loader.ConfigurationPropertiesLoaderFactory) File(java.io.File) CompositePropertySource(org.springframework.core.env.CompositePropertySource) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Environment(org.springframework.core.env.Environment) CollectionUtils(org.apereo.cas.util.CollectionUtils) Optional(java.util.Optional) CasConfigurationPropertiesSourceLocator(org.apereo.cas.configuration.api.CasConfigurationPropertiesSourceLocator) Resource(org.springframework.core.io.Resource) List(java.util.List) File(java.io.File)

Aggregations

Environment (org.springframework.core.env.Environment)161 Test (org.junit.jupiter.api.Test)68 StandardEnvironment (org.springframework.core.env.StandardEnvironment)30 EnvironmentVariableUtility (com.synopsys.integration.alert.environment.EnvironmentVariableUtility)26 MockEnvironment (org.springframework.mock.env.MockEnvironment)24 SpringApplication (org.springframework.boot.SpringApplication)21 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)19 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)19 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)19 HashMap (java.util.HashMap)13 ResourceLoader (org.springframework.core.io.ResourceLoader)13 Collectors (java.util.stream.Collectors)11 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)10 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 MutablePropertySources (org.springframework.core.env.MutablePropertySources)8 AlertConstants (com.synopsys.integration.alert.api.common.model.AlertConstants)7 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)7 EnvironmentVariableMockingUtil (com.synopsys.integration.alert.test.common.EnvironmentVariableMockingUtil)7 Map (java.util.Map)7 Predicate (java.util.function.Predicate)7