Skip to content

Commit

Permalink
GRAILS-4403 - deal with empty events file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Brown committed Apr 7, 2009
1 parent 0132b66 commit 3dfc143
Showing 1 changed file with 22 additions and 18 deletions.
Expand Up @@ -66,7 +66,7 @@ protected void loadEventHooks(BuildSettings buildSettings) {
if(buildSettings!=null) {
loadEventsScript( findEventsScript(new File(buildSettings.getUserHome(),".grails/scripts")) );
loadEventsScript( findEventsScript(new File(buildSettings.getBaseDir(), "scripts")) );

for (Resource pluginBase : GrailsPluginUtils.getPluginDirectories()) {
try {
loadEventsScript( findEventsScript(new File(pluginBase.getFile(), "scripts")) );
Expand All @@ -81,24 +81,29 @@ protected void loadEventHooks(BuildSettings buildSettings) {
public void loadEventsScript(File eventScript) {
if(eventScript!=null) {
try {
Script script = (Script) classLoader.parseClass(eventScript).newInstance();
script.setBinding(new Binding(this.binding.getVariables()) {
@Override
public void setVariable(String var, Object o) {
final Matcher matcher = EVENT_NAME_PATTERN.matcher(var);
if(matcher.matches() && (o instanceof Closure)) {
String eventName = matcher.group(1);
List<Closure> hooks = globalEventHooks.get(eventName);
if(hooks == null) {
hooks = new ArrayList<Closure>();
globalEventHooks.put(eventName, hooks);
Class scriptClass = classLoader.parseClass(eventScript);
if(scriptClass != null) {
Script script = (Script) scriptClass.newInstance();
script.setBinding(new Binding(this.binding.getVariables()) {
@Override
public void setVariable(String var, Object o) {
final Matcher matcher = EVENT_NAME_PATTERN.matcher(var);
if(matcher.matches() && (o instanceof Closure)) {
String eventName = matcher.group(1);
List<Closure> hooks = globalEventHooks.get(eventName);
if(hooks == null) {
hooks = new ArrayList<Closure>();
globalEventHooks.put(eventName, hooks);
}
hooks.add((Closure) o);
}
hooks.add((Closure) o);
super.setVariable(var, o);
}
super.setVariable(var, o);
}
});
script.run();
});
script.run();
} else {
System.err.println("Could not load event script (script may be empty): " + eventScript);
}
}

catch (Throwable e) {
Expand All @@ -108,7 +113,6 @@ public void setVariable(String var, Object o) {
}

}

}

protected File findEventsScript(File dir) {
Expand Down

0 comments on commit 3dfc143

Please sign in to comment.