geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r462660 - in /geronimo/genesis/trunk/plugins: plugin-support/ plugin-support/src/main/java/org/apache/geronimo/genesis/util/ script-maven-plugin/ script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/ script-maven-plu...
Date Wed, 11 Oct 2006 01:57:42 GMT
Author: jdillon
Date: Tue Oct 10 18:57:41 2006
New Revision: 462660

URL: http://svn.apache.org/viewvc?view=rev&rev=462660
Log:
Moved StringValueParser to plugin-support as ExpressionParser
Moved GroovyMojo code configuration to CodeSource, allows file, url or inline-body
Update script site docs to reflect the changes

Added:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/ExpressionParser.java
  (contents, props changed)
      - copied, changed from r462631, geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/StringValueParser.java
    geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/CodeSource.java
  (with props)
Removed:
    geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/StringValueParser.java
Modified:
    geronimo/genesis/trunk/plugins/plugin-support/pom.xml
    geronimo/genesis/trunk/plugins/script-maven-plugin/pom.xml
    geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/GroovyMojo.java
    geronimo/genesis/trunk/plugins/script-maven-plugin/src/site/apt/usage.apt

Modified: geronimo/genesis/trunk/plugins/plugin-support/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/pom.xml?view=diff&rev=462660&r1=462659&r2=462660
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/pom.xml (original)
+++ geronimo/genesis/trunk/plugins/plugin-support/pom.xml Tue Oct 10 18:57:41 2006
@@ -57,6 +57,12 @@
             <artifactId>commons-logging</artifactId>
             <version>1.0.4</version>
         </dependency>
+
+        <dependency>
+            <groupId>commons-jexl</groupId>
+            <artifactId>commons-jexl</artifactId>
+            <version>1.1</version>
+        </dependency>
     </dependencies>
 
 </project>

Copied: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/ExpressionParser.java
(from r462631, geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/StringValueParser.java)
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/ExpressionParser.java?view=diff&rev=462660&p1=geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/StringValueParser.java&r1=462631&p2=geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/ExpressionParser.java&r2=462660
==============================================================================
--- geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/StringValueParser.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/ExpressionParser.java
Tue Oct 10 18:57:41 2006
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.geronimo.genesis.plugins.script;
+package org.apache.geronimo.genesis.util;
 
 import java.util.Map;
 
@@ -30,17 +30,17 @@
 import org.apache.commons.logging.LogFactory;
 
 /**
- * Handles pasring expressions from a string.
+ * Parses expressions using <a href="http://jakarta.apache.org/commons/jexl/">Commons
Jexl</a>.
  *
  * @version $Rev$ $Date$
  */
-public class StringValueParser
+public class ExpressionParser
 {
-    private static final Log log = LogFactory.getLog(StringValueParser.class);
+    private static final Log log = LogFactory.getLog(ExpressionParser.class);
 
     protected JexlContext context;
 
-    public StringValueParser(final Map vars) {
+    public ExpressionParser(final Map vars) {
         if (vars == null) {
             throw new IllegalArgumentException("vars");
         }
@@ -53,7 +53,7 @@
         }
     }
 
-    public StringValueParser() {
+    public ExpressionParser() {
         this(System.getProperties());
     }
 

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/ExpressionParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/ExpressionParser.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/util/ExpressionParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/genesis/trunk/plugins/script-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/script-maven-plugin/pom.xml?view=diff&rev=462660&r1=462659&r2=462660
==============================================================================
--- geronimo/genesis/trunk/plugins/script-maven-plugin/pom.xml (original)
+++ geronimo/genesis/trunk/plugins/script-maven-plugin/pom.xml Tue Oct 10 18:57:41 2006
@@ -40,7 +40,6 @@
     </description>
     
     <dependencies>
-        
         <dependency>
             <groupId>org.apache.geronimo.genesis.plugins</groupId>
             <artifactId>plugin-support</artifactId>
@@ -53,12 +52,6 @@
             <version>06</version>
         </dependency>
 
-        <dependency>
-            <groupId>commons-jexl</groupId>
-            <artifactId>commons-jexl</artifactId>
-            <version>1.1</version>
-        </dependency>
-
         <!--
         NOTE: Included for AntBuilder support.  Needs to be in the same classloader as groovy-all-1.0-jsr
         -->
@@ -67,7 +60,6 @@
             <artifactId>ant</artifactId>
             <version>1.6.5</version>
         </dependency>
-
     </dependencies>
     
 </project>

Added: geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/CodeSource.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/CodeSource.java?view=auto&rev=462660
==============================================================================
--- geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/CodeSource.java
(added)
+++ geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/CodeSource.java
Tue Oct 10 18:57:41 2006
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.genesis.plugins.script;
+
+import java.net.URL;
+import java.io.File;
+
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * COnfiguration for a scripts code source.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CodeSource
+{
+    private URL url = null;
+
+    private File file = null;
+
+    private String body = null;
+
+    public String toString() {
+        return "{ url: " + url +
+               ", file: " + file +
+               ", body: " + body +
+               " }";
+    }
+
+    public URL getUrl() {
+        return url;
+    }
+
+    public File getFile() {
+        return file;
+    }
+
+    public String getBody() {
+        return body;
+    }
+
+    public void validate() throws MojoExecutionException {
+        if (url == null && file == null && (body == null || body.trim().length()
== 0)) {
+            throw new MojoExecutionException("Must specify one of: file, url or body");
+        }
+
+        int count = 0;
+        if (url != null) {
+            count++;
+        }
+        if (file != null) {
+            count++;
+        }
+        if (body != null) {
+            count++;
+        }
+
+        if (count != 1) {
+            throw new MojoExecutionException("Can only specify one of: file, url or body");
+        }
+    }
+}

Propchange: geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/CodeSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/CodeSource.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/genesis/trunk/plugins/script-maven-plugin/src/main/java/org/apache/geronimo/genesis/plugins/script/CodeSource.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=462660&r1=462659&r2=462660
==============================================================================
--- 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 18:57:41 2006
@@ -21,6 +21,7 @@
 
 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;
@@ -56,26 +57,12 @@
     extends MojoSupport
 {
     /**
-     * The project to create a build for.
-     *
-     * @parameter expression="${project}"
-     * @required
-     */
-    private MavenProject project = null;
-    
-    /**
-     * The code code of the script to execute.
-     *
-     * @parameter
-     */
-    private String code = null;
-    
-    /**
-     * The URL to use as the code of the script to execute.
+     * The source of the script to execute.
      *
      * @parameter
+     * @required
      */
-    private URL codeUrl = null;
+    private CodeSource source = null;
 
     /**
      * Additional artifacts to add to the scripts classpath.
@@ -85,12 +72,14 @@
     private ArtifactItem[] classpath = null;
 
     //
-    // MojoSupport Hooks
+    // Maven components
     //
-
-    protected MavenProject getProject() {
-        return project;
-    }
+    
+    /**
+     * @parameter expression="${project}"
+     * @required
+     */
+    private MavenProject project = null;
 
     /**
      * @parameter expression="${localRepository}"
@@ -99,6 +88,14 @@
      */
     protected ArtifactRepository artifactRepository = null;
 
+    //
+    // MojoSupport Hooks
+    //
+
+    protected MavenProject getProject() {
+        return project;
+    }
+    
     protected ArtifactRepository getArtifactRepository() {
         return artifactRepository;
     }
@@ -108,13 +105,8 @@
     //
     
     protected void doExecute() throws Exception {
-        if (code == null && codeUrl == null) {
-            throw new MojoExecutionException("Need to specify code or codeUrl");
-        }
-        else if (code != null && codeUrl != null) {
-            throw new MojoExecutionException("Can only specify code or codeUrl, not both");
-        }
-        
+        source.validate();
+
         ClassLoader parent = getClass().getClassLoader();
         List urls = new ArrayList();
 
@@ -148,13 +140,20 @@
         
         Class groovyClass;
         
-        if (code != null) {
-            groovyClass = loader.parseClass(code);
+        if (source.getBody() != null) {
+            groovyClass = loader.parseClass(source.getBody());
         }
         else {
-            log.debug("Loading source from: " + codeUrl);
+            URL url;
+            if (source.getFile() != null) {
+                url = source.getFile().toURL();
+            }
+            else {
+                url = source.getUrl();
+            }
+            log.debug("Loading source from: " + url);
             
-            InputStream input = codeUrl.openConnection().getInputStream();
+            InputStream input = url.openConnection().getInputStream();
             groovyClass = loader.parseClass(input);
             input.close();
         }
@@ -209,7 +208,7 @@
         Map vars = new HashMap();
         vars.put("project", project);
 
-        StringValueParser parser = new StringValueParser(vars);
+        ExpressionParser parser = new ExpressionParser(vars);
 
         Iterator iter = source.keySet().iterator();
         while (iter.hasNext()) {

Modified: geronimo/genesis/trunk/plugins/script-maven-plugin/src/site/apt/usage.apt
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/script-maven-plugin/src/site/apt/usage.apt?view=diff&rev=462660&r1=462659&r2=462660
==============================================================================
--- geronimo/genesis/trunk/plugins/script-maven-plugin/src/site/apt/usage.apt (original)
+++ geronimo/genesis/trunk/plugins/script-maven-plugin/src/site/apt/usage.apt Tue Oct 10 18:57:41
2006
@@ -25,11 +25,21 @@
 
 Basic Usage
 
-* Execute a Groovy Script
+ <<NOTE:>> This plugin includes the Ant runtime, so you can use the <<<AntBuilder>>>.
 
- It is easy to execute a Groocy script inline
+* Default Variables
+
+ By default a few variables are bound into the scripts environment:
  
- <<NOTE:>> This plugin includes the Ant runtime, so you can use the AntBuilder.
+  * <<<project>>> - The maven project, with properties pre-resolved
+
+  * <<<pom>>> - Alias for <<<project>>>
+
+  * <<<script>>> - The compiled script object
+
+  * <<<log>>> - The maven plugin logger
+
+* Execute an Inline Groovy Script
 
 +----------+
 <plugin>
@@ -42,23 +52,71 @@
                 <goal>groovy</goal>
             </goals>
             <configuration>
-                <code>
-                    if (project.packaging != "pom") {
-                        def ant = new AntBuilder()
-                        
-                        def dir = "${project.basedir}/target/classes/META-INF"
-                        ant.mkdir(dir: dir)
-                        ant.copy(todir: dir) {
-                            fileset(dir: "${project.basedir}") {
-                                include(name: "LICENSE.txt")
-                                include(name: "NOTICE.txt")
+                <source>
+                    <body>
+                        if (project.packaging != "pom") {
+                            log.info("Copying some stuff...")
+
+                            def ant = new AntBuilder()
+                            
+                            def dir = "${project.basedir}/target/classes/META-INF"
+
+                            ant.mkdir(dir: dir)
+                            ant.copy(todir: dir) {
+                                fileset(dir: "${project.basedir}") {
+                                    include(name: "LICENSE.txt")
+                                    include(name: "NOTICE.txt")
+                                }
                             }
                         }
-                    }
-                </code>
+                    </body>
+                </source>
             </configuration>
         </execution>
     </executions>
 </plugin>
 +----------+
 
+* Execute a Local Groovy Script
+
++----------+
+<plugin>
+    <groupId>org.apache.geronimo.genesis.plugins</groupId>
+    <artifactId>script-maven-plugin</artifactId>
+    <executions>
+        <execution>
+            <phase>generate-resources</phase>
+            <goals>
+                <goal>groovy</goal>
+            </goals>
+            <configuration>
+                <source>
+                    <file>${pom.basedir}/src/main/script/myscript.groovy</file>
+                </source>
+            </configuration>
+        </execution>
+    </executions>
+</plugin>
++----------+
+
+* Execute a Remote Groovy Script
+
++----------+
+<plugin>
+    <groupId>org.apache.geronimo.genesis.plugins</groupId>
+    <artifactId>script-maven-plugin</artifactId>
+    <executions>
+        <execution>
+            <phase>generate-resources</phase>
+            <goals>
+                <goal>groovy</goal>
+            </goals>
+            <configuration>
+                <source>
+                    <url>http://mydomain.com/myscript.groovy</url>
+                </source>
+            </configuration>
+        </execution>
+    </executions>
+</plugin>
++----------+
\ No newline at end of file



Mime
View raw message