Example usage for org.springframework.core.env Environment acceptsProfiles

List of usage examples for org.springframework.core.env Environment acceptsProfiles

Introduction

In this page you can find the example usage for org.springframework.core.env Environment acceptsProfiles.

Prototype

boolean acceptsProfiles(Profiles profiles);

Source Link

Document

Return whether the #getActiveProfiles() active profiles match the given Profiles predicate.

Usage

From source file:ru.mystamps.web.config.LiquibaseConfig.java

private static String getActiveContexts(Environment env) {
    if (env.acceptsProfiles("test")) {
        return "scheme, init-data, test-data";
    } else {/*from w ww  .ja va  2 s. c  o m*/
        // see also duplicate definition at pom.xml
        return "scheme, init-data, prod-data";
    }
}

From source file:com.indeed.imhotep.web.config.IQLEnv.java

public static boolean isSpringProfileSet(Environment environment) {
    for (IQLEnv env : IQLEnv.values()) {
        if (environment.acceptsProfiles(env.id)) {
            return true;
        }// w w w .j  a va2s.co m
    }

    return false;
}

From source file:com.indeed.imhotep.web.config.IQLEnv.java

public static IQLEnv fromSpring(Environment environment) {
    for (IQLEnv env : IQLEnv.values()) {
        if (environment.acceptsProfiles(env.id)) {
            return env;
        }//  w  ww  . j a v  a  2s.com
    }
    //TODO should this return null instead?
    return PROD; // default
}

From source file:de.metas.ui.web.vaadin.VaadinClientApplication.java

/**
 * Returns <code>true</code> if the testing profile is active.<br>
 * Activate it by adding <code>spring.profiles.include=testing</code> to the application properties.
 * <p>/*from  w w w.j  av a 2  s .  c  o  m*/
 * Thx to http://stackoverflow.com/questions/9267799/how-do-you-get-current-active-default-environment-profile-programatically-in-spr
 *
 * @return
 */
public static boolean isTesting() {
    final ApplicationContext context = VaadinClientApplication.context;
    if (context == null) {
        return false; // guard against NPE
    }
    final Environment environment = context.getEnvironment();
    if (environment == null) {
        return false; // guard against NPE
    }
    return environment.acceptsProfiles(PROFILE_NAME_TESTING);
}

From source file:com.github.nblair.web.ProfileConditionalDelegatingFilterProxy.java

/**
 * Returns true if all the required profiles are active in the environment.
 * /*from w w w.  j av  a  2 s .  c  o  m*/
 * Note, even though {@link Environment#acceptsProfiles(String...)} is multi-valued, we have
 * to check each profile individually because ENvironment's method will return true if any of the arguments
 * are valid (not necessarily all).
 * 
 * @see Environment#acceptsProfiles(String...)
 * @return true if all {@link #getRequiredProfiles()} are active
 */
protected boolean requiredProfilesAreActive() {
    if (requiredProfiles.length == 0) {
        return true;
    }
    Environment environment = findWebApplicationContext().getEnvironment();
    for (String profile : requiredProfiles) {
        if (!environment.acceptsProfiles(profile)) {
            return false;
        }
    }
    return true;
}

From source file:alfio.config.MvcConfiguration.java

@Bean
public ViewResolver getViewResolver(Environment env) throws Exception {
    MustacheViewResolver viewResolver = new MustacheViewResolver();
    viewResolver.setSuffix("");
    viewResolver.setTemplateFactory(getTemplateFactory());
    viewResolver.setOrder(1);/*from w w  w  .j  a v  a  2 s  .  c o  m*/
    //disable caching if we are in dev mode
    viewResolver.setCache(env.acceptsProfiles(Initializer.PROFILE_LIVE));
    viewResolver.setContentType("text/html;charset=UTF-8");
    return viewResolver;
}

From source file:piecework.config.EmbeddedLdapConfiguration.java

@Bean(destroyMethod = "destroy")
public ApacheDSContainer directoryServer(Environment env) throws Exception {

    File workingDirectory = new File(
            System.getProperty("java.io.tmpdir") + File.separator + "piecework-standalone-directory");
    FileUtils.deleteDirectory(workingDirectory);

    String ldifs = LDIF_LOCATION;

    if (env.acceptsProfiles("test"))
        ldifs = TEST_LDIF_LOCATION;/*from w w  w.  ja v a 2 s  .c o m*/

    ApacheDSContainer container = new ApacheDSContainer(ROOT, ldifs);
    container.setPort(port);
    container.setWorkingDirectory(workingDirectory);

    return container;
}