private void addProfileToEnvironment(String profile) { for (String activeProfile : this.environment.getActiveProfiles()) { if (activeProfile.equals(profile)) { return; } } this.environment.addActiveProfile(profile); }
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); if (environment.getProperty(STANDALONE_MODE_PROPERTY_NAME, boolean.class, false)) { environment.addActiveProfile(STANDALONE_SPRING_PROFILE); } if (logger.isInfoEnabled()) { logger.info("Spring Environment's active profiles : {} in standalone mode : {}", Arrays.asList(environment.getActiveProfiles()), STANDALONE_MODE ); } }
void addIstioProfile(ConfigurableEnvironment environment) { if (utils.isIstioEnabled()) { if (hasIstioProfile(environment)) { if (LOG.isDebugEnabled()) { LOG.debug("'istio' already in list of active profiles"); } } else { if (LOG.isDebugEnabled()) { LOG.debug("Adding 'istio' to list of active profiles"); } environment.addActiveProfile(ISTIO_PROFILE); } } else { if (LOG.isDebugEnabled()) { LOG.debug("Not running inside kubernetes with istio enabled. Skipping 'istio' profile activation."); } } }
void addKubernetesProfile(ConfigurableEnvironment environment) { if (utils.isInsideKubernetes()) { if (hasKubernetesProfile(environment)) { if (LOG.isDebugEnabled()) { LOG.debug("'kubernetes' already in list of active profiles"); } } else { if (LOG.isDebugEnabled()) { LOG.debug("Adding 'kubernetes' to list of active profiles"); } environment.addActiveProfile(KUBERNETES_PROFILE); } } else { if (LOG.isDebugEnabled()) { LOG.warn( "Not running inside kubernetes. Skipping 'kubernetes' profile activation."); } } }
@Test public void environmentSubclass_withCustomProfileValidation() { ConfigurableEnvironment env = new AbstractEnvironment() { @Override protected void validateProfile(String profile) { super.validateProfile(profile); if (profile.contains("-")) { throw new IllegalArgumentException( "Invalid profile [" + profile + "]: must not contain dash character"); } } }; env.addActiveProfile("validProfile"); // succeeds try { env.addActiveProfile("invalid-profile"); fail("expected validation exception"); } catch (IllegalArgumentException ex) { assertThat(ex.getMessage(), equalTo("Invalid profile [invalid-profile]: must not contain dash character")); } }
@Test public void acceptsProfiles_withProfileExpression() { assertThat(environment.acceptsProfiles(Profiles.of("p1 & p2")), is(false)); environment.addActiveProfile("p1"); assertThat(environment.acceptsProfiles(Profiles.of("p1 & p2")), is(false)); environment.addActiveProfile("p2"); assertThat(environment.acceptsProfiles(Profiles.of("p1 & p2")), is(true)); }
@Test public void acceptsProfiles_withNotOperator() { assertThat(environment.acceptsProfiles("p1"), is(false)); assertThat(environment.acceptsProfiles("!p1"), is(true)); environment.addActiveProfile("p1"); assertThat(environment.acceptsProfiles("p1"), is(true)); assertThat(environment.acceptsProfiles("!p1"), is(false)); }
@Test public void addActiveProfile() { assertThat(environment.getActiveProfiles().length, is(0)); environment.setActiveProfiles("local", "embedded"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("local", "embedded")); assertThat(environment.getActiveProfiles().length, is(2)); environment.addActiveProfile("p1"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("p1")); assertThat(environment.getActiveProfiles().length, is(3)); environment.addActiveProfile("p2"); environment.addActiveProfile("p3"); assertThat(Arrays.asList(environment.getActiveProfiles()), hasItems("p2", "p3")); assertThat(environment.getActiveProfiles().length, is(5)); }
@Override public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) { ((ConfigurableEnvironment) this.environment).addActiveProfile("the-filter-ran"); assertNotNull(this.beanFactory); assertNotNull(this.classLoader); assertNotNull(this.resourceLoader); assertNotNull(this.environment); return false; }
LOG.warn("The use of -Druntime.environment is deprecated in favor of Spring Profiles and will be removed in a future release. To specify a profile as a -D argument use -Dspring.profiles.active as a drop-in replacement" + " for -Druntime.environment. Adding " + deprecatedRuntimeEnvironment + " to the list of active Spring profiles."); env.addActiveProfile(deprecatedRuntimeEnvironment);
@Test public void addActiveProfile_whenActiveProfilesPropertyIsAlreadySet() { ConfigurableEnvironment env = new StandardEnvironment(); assertThat(env.getProperty(ACTIVE_PROFILES_PROPERTY_NAME), nullValue()); env.getPropertySources().addFirst(new MockPropertySource().withProperty(ACTIVE_PROFILES_PROPERTY_NAME, "p1")); assertThat(env.getProperty(ACTIVE_PROFILES_PROPERTY_NAME), equalTo("p1")); env.addActiveProfile("p2"); assertThat(env.getActiveProfiles(), arrayContaining("p1", "p2")); }
@Override public void addActiveProfile(String profile) { delegate.addActiveProfile(profile); }
InitAndIB.constructed = false; root = new XmlWebApplicationContext(); root.getEnvironment().addActiveProfile("rootProfile1"); MockServletContext sc = new MockServletContext(""); root.setServletContext(sc); root.refresh(); XmlWebApplicationContext wac = new XmlWebApplicationContext(); wac.getEnvironment().addActiveProfile("wacProfile1"); wac.setParent(root); wac.setServletContext(sc);
void addKubernetesProfile(ConfigurableEnvironment environment) { Pod current = utils.currentPod().get(); if (current != null) { if (!hasKubernetesProfile(environment)) { environment.addActiveProfile(KUBERNETES_PROFILE); } } if (utils.isInsideKubernetes()) { if (hasKubernetesProfile(environment)) { LOGGER.debug("'kubernetes' already in list of active profiles"); } else { LOGGER.debug("Adding 'kubernetes' to list of active profiles"); environment.addActiveProfile(KUBERNETES_PROFILE); } } else { if (LOGGER.isDebugEnabled()) { LOGGER.warn("Not running inside kubernetes. Skipping 'kuberntes' profile activation."); } } }
static void activateProfile(String profile, ConfigurableEnvironment environment, CloudHolder cloudHolder) { cloudHolder.withCloud( () -> LOGGER.warning(String.format("Skipping '%s' profile activation because not in a cloud", profile)), cloud -> { environment.addActiveProfile(profile); LOGGER.info(String.format("'%s' profile activated", profile)); }); }
void addCloudProfile(ConfigurableEnvironment environment) { if (this.cloudUtils.isInCloud()) { if (hasCloudProfile(environment)) { this.logger.fine("'cloud' already in list of active profiles"); } else { this.logger.info("Adding 'cloud' to list of active profiles"); environment.addActiveProfile(CLOUD_PROFILE); } } else { this.logger.warning("Not running in a cloud. Skipping 'cloud' profile activation."); } }
private void configureStatsCollector(AnnotationConfigWebApplicationContext context, Config config) { if (Boolean.valueOf(config.getRaw().getOrDefault(GA_API_STATS_DISABLE_SETTING_LEGACY, "false"))) { context.getEnvironment().addActiveProfile("stats-null"); } else if (Boolean.valueOf(config.getRaw().getOrDefault(GA_API_STATS_DISABLE_SETTING, "false"))) { context.getEnvironment().addActiveProfile("stats-null"); } else { context.getEnvironment().addActiveProfile("stats-google"); } }
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { if (!event.getEnvironment().resolvePlaceholders("${PROCESS_GUID:}").equals("")) { event.getEnvironment().addActiveProfile("cloud"); event.getEnvironment().addActiveProfile("lattice"); } }
@Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); if (environment.getProperty(STANDALONE_MODE_PROPERTY_NAME, boolean.class, false)) { environment.addActiveProfile(STANDALONE_SPRING_PROFILE); } if (logger.isInfoEnabled()) { logger.info("Spring Environment's active profiles : {} in standalone mode : {}", Arrays.asList(environment.getActiveProfiles()), STANDALONE_MODE ); } }
@Override protected void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); MutablePropertySources propertySources = environment.getPropertySources(); propertySources.addFirst(cmdLinePropertySource(event.getArgs())); String environmentName = environment.getProperty(ENVIRONMENT_PROPERTY); environment.addActiveProfile(environmentName); }