geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r462651 - /geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java
Date Wed, 11 Oct 2006 00:59:16 GMT
Author: jdillon
Date: Tue Oct 10 17:59:15 2006
New Revision: 462651

URL: http://svn.apache.org/viewvc?view=rev&rev=462651
Log:
Improve exception reporting
Use delegate to allow MavenProject.getProperties() to return resolved props, since 'properties'
is special in Groovy
Add 'script' helper... not sure if there is already something similar
Register pom alias for project

Modified:
    geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java

Modified: geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java?view=diff&rev=462651&r1=462650&r2=462651
==============================================================================
--- geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java
(original)
+++ geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java
Tue Oct 10 17:59:15 2006
@@ -41,6 +41,8 @@
 
 import groovy.lang.GroovyClassLoader;
 import groovy.lang.GroovyObject;
+import groovy.lang.GroovyRuntimeException;
+import groovy.lang.MissingPropertyException;
 
 /**
  * Executes a <a href="http://groovy.codehaus.org">Groovy</a> script.
@@ -137,6 +139,10 @@
             }
         }
 
+        //
+        // TODO: Investigate using GroovyScript instead of this...
+        //
+        
         URLClassLoader cl = new URLClassLoader(_urls, parent);
         GroovyClassLoader loader = new GroovyClassLoader(cl);
         
@@ -154,17 +160,52 @@
         }
         
         GroovyObject groovyObject = (GroovyObject)groovyClass.newInstance();
-        
+
+        // Put int a helper to the script object
+        groovyObject.setProperty("script", groovyObject);
+
+        // Expose logging
         groovyObject.setProperty("log", log);
-        groovyObject.setProperty("project", project);
-        groovyObject.setProperty("properties", resolveProperties(project.getProperties()));
// Force all properties to resolve
 
-        groovyObject.invokeMethod("run", new Object[0]);
+        // Create a delegate to allow getProperites() to be fully resolved
+        MavenProject delegate = new MavenProject(project) {
+            public Properties resolvedProperties;
+
+            public Properties getProperties() {
+                if (resolvedProperties == null) {
+                    resolvedProperties = resolveProperties(project.getProperties());
+                }
+                return resolvedProperties;
+            }
+        };
+        groovyObject.setProperty("project", delegate);
+        groovyObject.setProperty("pom", delegate);
+
+        try {
+            groovyObject.invokeMethod("run", new Object[0]);
+        }
+        catch (MissingPropertyException e) {
+            throw e;
+        }
+        catch (GroovyRuntimeException e) {
+            //
+            // TODO: Log the context of the script (line num, etc) from the ASTNode
+            //
+            
+            // Unroll groovy runtime exceptions, but log the real details too
+            if (log.isDebugEnabled()) {
+                log.debug(e.getMessage(), e);
+            }
+
+            Throwable cause = e.getCause();
+            throw new MojoExecutionException(cause.getMessage(), cause);
+        }
     }
 
     private Properties resolveProperties(final Properties source) {
         Properties props = new Properties();
 
+        // Setup the variables which should be used for resolution
         Map vars = new HashMap();
         vars.put("project", project);
 



Mime
View raw message