@Override protected Set<String> doGetActiveProfiles() { Set<String> activeProfiles = super.doGetActiveProfiles(); activeProfiles.add(Environment.getCurrent().getName()); return activeProfiles; }
public static boolean isReloadingAgentEnabled() { if(reloadingAgentEnabled != null) { return reloadingAgentEnabled; } try { Class.forName("org.springsource.loaded.TypeRegistry"); reloadingAgentEnabled = Environment.getCurrent().isReloadEnabled(); } catch (ClassNotFoundException e) { reloadingAgentEnabled = false; } return reloadingAgentEnabled; }
/** * Returns the current environment which is typcally either DEVELOPMENT, PRODUCTION or TEST. * For custom environments CUSTOM type is returned. * * @return The current environment. */ public static Environment getCurrent() { String envName = getEnvironment(); Environment env; if(!isBlank(envName)) { env = getEnvironment(envName); if(env != null) { return env; } } Environment current = cachedCurrentEnvironment.get(); if (current != null) { return current; } return cacheCurrentEnvironment(); }
/** * This method will return true the application is run * * @return True if the development sources are present */ public static boolean isDevelopmentRun() { Environment env = Environment.getCurrent(); return isDevelopmentEnvironmentAvailable() && Boolean.getBoolean(RUN_ACTIVE) && (env == Environment.DEVELOPMENT); }
/** * Takes an environment specific DSL block like: * * <code> * environments { * development {} * production {} * } * </code> * * And returns the closure that relates to the current environment * * @param closure The top level closure * @return The environment specific block or null if non exists */ public static Closure<?> getEnvironmentSpecificBlock(Closure<?> closure) { final Environment env = getCurrent(); return getEnvironmentSpecificBlock(env, closure); }
/** * Takes an environment specific DSL block like: * * <code> * environments { * development {} * production {} * } * </code> * * And executes the closure that relates to the current environment * * @param closure The top level closure * @return The result of the closure execution */ public static Object executeForCurrentEnvironment(Closure<?> closure) { final Environment env = getCurrent(); return executeForEnvironment(env, closure); }
if (!grails.util.Environment.getCurrent().isReloadEnabled() || !proxyIfReloadEnabled) { return sf; LOG.fatal("There was an error configuring the Hibernate second level cache: " + getCauseMessage(e)); LOG.fatal("This is normally due to one of two reasons. Either you have incorrectly specified the cache provider class name in [DataSource.groovy] or you do not have the cache provider on your classpath (eg. runtime (\"net.sf.ehcache:ehcache:1.6.1\"))"); if (grails.util.Environment.isDevelopmentMode()) { System.exit(1);
/** * @see #getCurrent() * @return the current environment */ public static Environment getCurrentEnvironment() { return getCurrent(); }
public String lookupEnvironmentForCommand() { String fallbackEnv = System.getProperty(Environment.KEY) != null ? System.getProperty(Environment.KEY) : Environment.DEVELOPMENT.getName(); String env = CommandLineParser.DEFAULT_ENVS.get(commandName); return env == null ? fallbackEnv : env; }
private static Environment resolveCurrentEnvironment() { String envName = getEnvironment(); if (isBlank(envName)) { Metadata metadata = Metadata.getCurrent(); if (metadata != null) { envName = metadata.getEnvironment(); } if (isBlank(envName)) { return DEVELOPMENT; } } Environment env = getEnvironment(envName); if (env == null) { try { env = Environment.valueOf(envName.toUpperCase()); } catch (IllegalArgumentException e) { // ignore } } if (env == null) { env = Environment.CUSTOM; env.setName(envName); } return env; }
public void callDestroy() { Closure<?> destroy = getDestroyClosure(); if (destroy != null) { Environment.executeForCurrentEnvironment(destroy); } } }
/** * Takes an environment specific DSL block like: * * <code> * environments { * development {} * production {} * } * </code> * * And returns the closure that relates to the specified * * @param env The environment to use * @param closure The top level closure * @return The environment specific block or null if non exists */ public static Closure<?> getEnvironmentSpecificBlock(Environment env, Closure<?> closure) { if (closure == null) { return null; } final EnvironmentBlockEvaluator evaluator = evaluateEnvironmentSpecificBlock(env, closure); return evaluator.getCallable(); }
/** * @return Return true if the environment has been set as a System property */ public static boolean isSystemSet() { return getEnvironment() != null; }
@SuppressWarnings("unused") public Object methodMissing(String name, Object args) { Object[] argsArray = (Object[])args; if (args != null && argsArray.length > 0 && (argsArray[0] instanceof Closure)) { if (current == Environment.CUSTOM && current.getName().equals(name)) { callable = (Closure<?>) argsArray[0]; } return null; } throw new MissingMethodException(name, Environment.class, argsArray); } }
public void callInit(ServletContext servletContext) { Closure<?> init = getInitClosure(); if (init != null) { Class[] parameterTypes = init.getParameterTypes(); if(parameterTypes != null) { init = init.curry(new Object[]{servletContext}); } Environment.executeForCurrentEnvironment(init); } }
/** * Takes an environment specific DSL block like: * * <code> * environments { * development {} * production {} * } * </code> * * And executes the closure that relates to the specified environment * * @param env The environment to use * @param closure The top level closure * @return The result of the closure execution */ public static Object executeForEnvironment(Environment env, Closure<?> closure) { if (closure == null) { return null; } final EnvironmentBlockEvaluator evaluator = evaluateEnvironmentSpecificBlock(env, closure); return evaluator.execute(); }
public String getEnvironment() { boolean useDefaultEnv = environment == null; String env; if (useDefaultEnv && commandName != null) { env = lookupEnvironmentForCommand(); } else { String fallbackEnv = System.getProperty(Environment.KEY) != null ? System.getProperty(Environment.KEY) : Environment.DEVELOPMENT.getName(); env = environment != null ? environment : fallbackEnv; } System.setProperty(Environment.KEY, env); System.setProperty(Environment.DEFAULT, String.valueOf(useDefaultEnv)); return env; }