You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/10/11 02:59:16 UTC

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

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);
 



Re: svn commit: r462651 - /geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java

Posted by Jason Dillon <ja...@planet57.com>.
I dunno... I might have to come up with some more magic to get the  
tck to run.

But its probably not going to be anything I would consider awesome...  
unless I can figure out how to make Maven go down to the store and  
buy me some beer :-P

--jason


On Oct 11, 2006, at 12:28 AM, Jacek Laskowski wrote:

> On 10/11/06, Jason Dillon <ja...@planet57.com> wrote:
>
>> Its not quite as interesting as you might think ;-)
>
> But the next time it's going to be something really awesome, isn't  
> it? ;-)
>
> Jacek
>
> -- 
> Jacek Laskowski
> http://www.laskowski.net.pl


Re: svn commit: r462651 - /geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On 10/11/06, Jason Dillon <ja...@planet57.com> wrote:

> Its not quite as interesting as you might think ;-)

But the next time it's going to be something really awesome, isn't it? ;-)

Jacek

-- 
Jacek Laskowski
http://www.laskowski.net.pl

Re: svn commit: r462651 - /geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java

Posted by Jason Dillon <ja...@planet57.com>.
See GroovyMojo.java line 181.

Its not quite as interesting as you might think ;-)

--jason


On Oct 10, 2006, at 11:24 PM, Jacek Laskowski wrote:

> On 10/11/06, jdillon@apache.org <jd...@apache.org> wrote:
>> 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
>
> Where is the change described as 'Register pom alias for project'? I
> can't seem to find it. Could you describe what it is for? It reads
> quite interesting ;-)
>
> Jacek
>
> -- 
> Jacek Laskowski
> http://www.laskowski.net.pl


Re: svn commit: r462651 - /geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On 10/11/06, jdillon@apache.org <jd...@apache.org> wrote:
> 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

Where is the change described as 'Register pom alias for project'? I
can't seem to find it. Could you describe what it is for? It reads
quite interesting ;-)

Jacek

-- 
Jacek Laskowski
http://www.laskowski.net.pl