geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r462740 - /geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java
Date Wed, 11 Oct 2006 09:04:25 GMT
Author: jdillon
Date: Wed Oct 11 02:04:24 2006
New Revision: 462740

URL: http://svn.apache.org/viewvc?view=rev&rev=462740
Log:
Allow loading peer scripts

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=462740&r1=462739&r2=462740
==============================================================================
--- 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
Wed Oct 11 02:04:24 2006
@@ -19,31 +19,28 @@
 
 package org.apache.geronimo.genesis.plugins.script;
 
-import org.apache.geronimo.genesis.MojoSupport;
-import org.apache.geronimo.genesis.util.ArtifactItem;
-import org.apache.geronimo.genesis.util.ExpressionParser;
-
 import java.io.File;
 import java.io.InputStream;
-
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.util.List;
 import java.util.ArrayList;
-import java.util.Properties;
-import java.util.Map;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
 
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import groovy.lang.GroovyClassLoader;
+import groovy.lang.GroovyObject;
+import groovy.lang.GroovyResourceLoader;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.project.MavenProject;
 
-import groovy.lang.GroovyClassLoader;
-import groovy.lang.GroovyObject;
-import groovy.lang.GroovyRuntimeException;
-import groovy.lang.MissingPropertyException;
+import org.apache.geronimo.genesis.MojoSupport;
+import org.apache.geronimo.genesis.util.ArtifactItem;
+import org.apache.geronimo.genesis.util.ExpressionParser;
 
 /**
  * Executes a <a href="http://groovy.codehaus.org">Groovy</a> script.
@@ -72,6 +69,15 @@
     private ArtifactItem[] classpath = null;
 
     //
+    // TODO: Make this a scriptpath
+    //
+    
+    /**
+     * @parameter expression="${basedir}/src/main/script"
+     */
+    private File scriptDirectory = null;
+
+    //
     // Maven components
     //
     
@@ -86,7 +92,7 @@
      * @readonly
      * @required
      */
-    protected ArtifactRepository artifactRepository = null;
+    private ArtifactRepository artifactRepository = null;
 
     //
     // MojoSupport Hooks
@@ -134,9 +140,28 @@
         //
         // TODO: Investigate using GroovyScript instead of this...
         //
-        
+
         URLClassLoader cl = new URLClassLoader(_urls, parent);
         GroovyClassLoader loader = new GroovyClassLoader(cl);
+        loader.setResourceLoader(new GroovyResourceLoader()
+        {
+            // Allow peer scripts to be loaded
+            public URL loadGroovySource(final String classname) throws MalformedURLException
{
+                String resource = classname.replace('.', '/');
+                if (!resource.startsWith("/")) {
+                    resource = "/" + resource;
+                }
+                resource = resource + ".groovy";
+
+                File file = new File(scriptDirectory, resource);
+                if (file.exists()) {
+                    return file.toURL();
+                }
+                else {
+                    return null;
+                }
+            }
+        });
         
         Class groovyClass;
         



Mime
View raw message