use of grails.util.Environment in project grails-core by grails.
the class DefaultGrailsPlugin method evaluatePluginScopes.
private void evaluatePluginScopes() {
// Damn I wish Java had closures
pluginScopes = evaluateIncludeExcludeProperty(SCOPES, new Closure(this) {
private static final long serialVersionUID = 1;
@Override
public Object call(Object arguments) {
final String scopeName = ((String) arguments).toUpperCase();
try {
return BuildScope.valueOf(scopeName);
} catch (IllegalArgumentException e) {
throw new GrailsConfigurationException("Plugin " + this + " specifies invalid scope [" + scopeName + "]");
}
}
});
pluginEnvs = evaluateIncludeExcludeProperty(ENVIRONMENTS, new Closure(this) {
private static final long serialVersionUID = 1;
@Override
public Object call(Object arguments) {
String envName = (String) arguments;
Environment env = Environment.getEnvironment(envName);
if (env != null)
return env.getName();
return arguments;
}
});
}
use of grails.util.Environment in project grails-core by grails.
the class DefaultGrailsPlugin method evaluateOnChangeListener.
private void evaluateOnChangeListener() {
if (pluginBean.isReadableProperty(ON_SHUTDOWN)) {
onShutdownListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_SHUTDOWN);
}
if (pluginBean.isReadableProperty(ON_CONFIG_CHANGE)) {
onConfigChangeListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_CONFIG_CHANGE);
}
if (pluginBean.isReadableProperty(ON_CHANGE)) {
onChangeListener = (Closure) GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, ON_CHANGE);
}
Environment env = Environment.getCurrent();
final boolean warDeployed = env.isWarDeployed();
final boolean reloadEnabled = env.isReloadEnabled();
if (!((reloadEnabled || !warDeployed))) {
return;
}
Object referencedResources = GrailsClassUtils.getPropertyOrStaticPropertyOrFieldValue(plugin, WATCHED_RESOURCES);
try {
List resourceList = null;
if (referencedResources instanceof String) {
if (LOG.isDebugEnabled()) {
LOG.debug("Configuring plugin " + this + " to watch resources with pattern: " + referencedResources);
}
resourceList = Collections.singletonList(referencedResources.toString());
} else if (referencedResources instanceof List) {
resourceList = (List) referencedResources;
}
if (resourceList == null) {
return;
}
List<String> resourceListTmp = new ArrayList<String>();
final String baseLocation = env.getReloadLocation();
for (Object ref : resourceList) {
String stringRef = ref.toString();
if (warDeployed) {
addBaseLocationPattern(resourceListTmp, baseLocation, stringRef);
} else {
addBaseLocationPattern(resourceListTmp, baseLocation, stringRef);
}
}
watchedResourcePatternReferences = new String[resourceListTmp.size()];
for (int i = 0; i < watchedResourcePatternReferences.length; i++) {
String resRef = resourceListTmp.get(i);
watchedResourcePatternReferences[i] = resRef;
}
watchedResourcePatterns = new WatchPatternParser().getWatchPatterns(Arrays.asList(watchedResourcePatternReferences));
} catch (IllegalArgumentException e) {
if (GrailsUtil.isDevelopmentEnv()) {
LOG.debug("Cannot load plug-in resource watch list from [" + GrailsArrayUtils.toString(watchedResourcePatternReferences) + "]. This means that the plugin " + this + ", will not be able to auto-reload changes effectively. Try running grails upgrade.: " + e.getMessage());
}
}
}
use of grails.util.Environment in project grails-core by grails.
the class DefaultGrailsPlugin method supportsCurrentScopeAndEnvironment.
public boolean supportsCurrentScopeAndEnvironment() {
BuildScope bs = BuildScope.getCurrent();
Environment e = Environment.getCurrent();
return supportsEnvironment(e) && supportsScope(bs);
}
use of grails.util.Environment in project grails-core by grails.
the class EnvironmentAwarePropertySource method initialize.
private void initialize() {
if (propertyNames == null) {
propertyNames = new ArrayList<>();
Environment env = Environment.getCurrent();
String key = "environments." + env.getName();
for (PropertySource propertySource : source) {
if ((propertySource != this) && // plugin default configuration is not allowed to be environment aware (GRAILS-12123)
!propertySource.getName().contains("plugin") && propertySource instanceof EnumerablePropertySource) {
EnumerablePropertySource enumerablePropertySource = (EnumerablePropertySource) propertySource;
for (String propertyName : enumerablePropertySource.getPropertyNames()) {
if (propertyName.startsWith(key) && propertyName.length() > key.length()) {
propertyNames.add(propertyName.substring(key.length() + 1));
}
}
}
}
}
}
use of grails.util.Environment in project grails-core by grails.
the class EnvironmentAwarePropertySource method getProperty.
@Override
public Object getProperty(String name) {
initialize();
if (!propertyNames.contains(name)) {
return null;
}
Environment env = Environment.getCurrent();
String key = "environments." + env.getName() + '.' + name;
for (PropertySource propertySource : source) {
if (propertySource != this) {
Object value = propertySource.getProperty(key);
if (value != null)
return value;
}
}
return null;
}
Aggregations