You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/08/08 03:01:38 UTC

svn commit: r683781 - in /maven/plugins/trunk/maven-invoker-plugin: ./ src/main/java/org/apache/maven/plugin/invoker/ src/site/apt/ src/site/apt/examples/ src/test/java/org/apache/maven/plugin/invoker/

Author: bentmann
Date: Thu Aug  7 18:01:37 2008
New Revision: 683781

URL: http://svn.apache.org/viewvc?rev=683781&view=rev
Log:
[MINVOKER-7] Add groovy support for pre/post build hook scripts

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreter.java   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreter.java   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptEvaluationException.java   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptInterpreter.java   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreterTest.java   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreterTest.java   (with props)
Modified:
    maven/plugins/trunk/maven-invoker-plugin/pom.xml
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
    maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/post-build-script.apt.vm
    maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt

Modified: maven/plugins/trunk/maven-invoker-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/pom.xml?rev=683781&r1=683780&r2=683781&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-invoker-plugin/pom.xml Thu Aug  7 18:01:37 2008
@@ -87,6 +87,28 @@
       <version>2.0b4</version>
     </dependency>
     <dependency>
+      <groupId>org.codehaus.groovy</groupId>
+      <artifactId>groovy</artifactId>
+      <version>1.5.6</version>
+      <exclusions>
+        <exclusion>
+          <groupId>junit</groupId>
+          <artifactId>junit</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.ant</groupId>
+      <artifactId>ant</artifactId>
+      <version>1.7.1</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.ant</groupId>
+          <artifactId>ant-launcher</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
       <version>1.5.6</version>

Added: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreter.java?rev=683781&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreter.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreter.java Thu Aug  7 18:01:37 2008
@@ -0,0 +1,110 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+/**
+ * Provides a facade to evaluate BeanShell scripts.
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+class BeanShellScriptInterpreter
+    implements ScriptInterpreter
+{
+
+    public Object evaluateScript( String script, List classPath, Map globalVariables, PrintStream scriptOutput )
+        throws ScriptEvaluationException
+    {
+        PrintStream origOut = System.out;
+        PrintStream origErr = System.err;
+
+        try
+        {
+            Interpreter engine = new Interpreter();
+
+            if ( scriptOutput != null )
+            {
+                System.setErr( scriptOutput );
+                System.setOut( scriptOutput );
+                engine.setErr( scriptOutput );
+                engine.setOut( scriptOutput );
+            }
+
+            if ( classPath != null && !classPath.isEmpty() )
+            {
+                for ( Iterator it = classPath.iterator(); it.hasNext(); )
+                {
+                    String path = (String) it.next();
+                    try
+                    {
+                        engine.getClassManager().addClassPath( new File( path ).toURI().toURL() );
+                    }
+                    catch ( IOException e )
+                    {
+                        throw new RuntimeException( "bad class path: " + path, e );
+                    }
+                }
+            }
+
+            if ( globalVariables != null )
+            {
+                for ( Iterator it = globalVariables.keySet().iterator(); it.hasNext(); )
+                {
+                    String variable = (String) it.next();
+                    Object value = globalVariables.get( variable );
+                    try
+                    {
+                        engine.set( variable, value );
+                    }
+                    catch ( EvalError e )
+                    {
+                        throw new ScriptEvaluationException( "Illegal global variable: " + variable + " = " + value,
+                                                             e );
+                    }
+                }
+            }
+
+            try
+            {
+                return engine.eval( script );
+            }
+            catch ( EvalError e )
+            {
+                throw new ScriptEvaluationException( "script evaluation error", e );
+            }
+        }
+        finally
+        {
+            System.setErr( origErr );
+            System.setOut( origOut );
+        }
+    }
+
+}

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreter.java?rev=683781&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreter.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreter.java Thu Aug  7 18:01:37 2008
@@ -0,0 +1,95 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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.
+ */
+
+import groovy.lang.Binding;
+import groovy.lang.GroovyRuntimeException;
+import groovy.lang.GroovyShell;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tools.ant.AntClassLoader;
+import org.codehaus.groovy.control.CompilerConfiguration;
+
+/**
+ * Provides a facade to evaluate Groovy scripts.
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+class GroovyScriptInterpreter
+    implements ScriptInterpreter
+{
+
+    public Object evaluateScript( String script, List classPath, Map globalVariables, PrintStream scriptOutput )
+        throws ScriptEvaluationException
+    {
+        PrintStream origOut = System.out;
+        PrintStream origErr = System.err;
+
+        try
+        {
+            CompilerConfiguration config = new CompilerConfiguration( CompilerConfiguration.DEFAULT );
+
+            if ( scriptOutput != null )
+            {
+                System.setErr( scriptOutput );
+                System.setOut( scriptOutput );
+                config.setOutput( new PrintWriter( scriptOutput ) );
+            }
+
+            ClassLoader loader = null;
+            if ( classPath != null && !classPath.isEmpty() )
+            {
+                AntClassLoader childFirstLoader = new AntClassLoader( getClass().getClassLoader(), false );
+                for ( Iterator it = classPath.iterator(); it.hasNext(); )
+                {
+                    String path = (String) it.next();
+                    childFirstLoader.addPathComponent( new File( path ) );
+                }
+                loader = childFirstLoader;
+            }
+
+            Binding binding = new Binding( globalVariables );
+
+            GroovyShell interpreter = new GroovyShell( loader, binding, config );
+
+            try
+            {
+                return interpreter.evaluate( script );
+            }
+            catch ( GroovyRuntimeException e )
+            {
+                throw new ScriptEvaluationException( "script evaluation error", e );
+            }
+        }
+        finally
+        {
+            System.setErr( origErr );
+            System.setOut( origOut );
+        }
+    }
+
+}

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java?rev=683781&r1=683780&r2=683781&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java Thu Aug  7 18:01:37 2008
@@ -31,8 +31,11 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 import java.util.StringTokenizer;
@@ -65,9 +68,6 @@
 import org.codehaus.plexus.interpolation.MapBasedValueSource;
 import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
 
-import bsh.EvalError;
-import bsh.Interpreter;
-
 /**
  * Searches for integration test Maven projects, and executes each, collecting a log in the project directory, and
  * outputting the results to the command line.
@@ -199,15 +199,23 @@
     private Invoker invoker;
 
     /**
-     * Relative path of a pre-build hook BeanShell script to run prior to executing the build.
-     *
+     * Relative path of a pre-build hook BeanShell or Groovy script to run prior to executing the build. If the file
+     * extension is omitted (e.g. "prebuild"), the plugin searches for the file by trying out the known extensions
+     * ".bsh" and ".groovy".<br>
+     * <br>
+     * <em>Note:</em> Support for Groovy was added in version 1.3 of the plugin.
+     * 
      * @parameter expression="${invoker.preBuildHookScript}" default-value="prebuild.bsh"
      */
     private String preBuildHookScript;
 
     /**
-     * Relative path of a cleanup/verification BeanShell script to run after executing the build.
-     *
+     * Relative path of a cleanup/verification BeanShell or Groovy script to run after executing the build. If the file
+     * extension is omitted (e.g. "verify"), the plugin searches for the file by trying out the known extensions
+     * ".bsh" and ".groovy".<br>
+     * <br>
+     * <em>Note:</em> Support for Groovy was added in version 1.3 of the plugin.
+     * 
      * @parameter expression="${invoker.postBuildHookScript}" default-value="postbuild.bsh"
      */
     private String postBuildHookScript;
@@ -353,6 +361,14 @@
     private boolean addTestClassPath;
 
     /**
+     * The test class path of the project under test.
+     * 
+     * @parameter default-value="${project.testClasspathElements}"
+     * @readonly
+     */
+    private List testClassPath;
+
+    /**
      * The name of an optional test-specific file that contains properties used to configure the invocation of an
      * integration test. This properties file may be used to specify settings for an individual test invocation. Any
      * property present in the file will override the corresponding setting from the plugin configuration. The values of
@@ -386,6 +402,11 @@
      */
     private String invokerPropertiesFile;
 
+    /**
+     * The supported script interpreters, indexed by the file extension of their associated script files.
+     */
+    private Map scriptInterpreters;
+
 
     public void execute()
         throws MojoExecutionException, MojoFailureException
@@ -439,6 +460,10 @@
                                + ", i.e. build is platform dependent!" );
         }
 
+        scriptInterpreters = new LinkedHashMap();
+        scriptInterpreters.put( "bsh", new BeanShellScriptInterpreter() );
+        scriptInterpreters.put( "groovy", new GroovyScriptInterpreter() );
+
         File projectsDir = projectsDirectory;
 
         if ( cloneProjectsTo != null )
@@ -942,27 +967,25 @@
         return testProps;
     }
 
+    private boolean prebuild( final File basedir, final FileLogger logger )
+    {
+        boolean result = true;
+
+        if ( preBuildHookScript != null )
+        {
+            result = runScript( "pre-build script", basedir, preBuildHookScript, logger );
+        }
+
+        return result;
+    }
+
     private boolean verify( final File basedir, final FileLogger logger )
     {
         boolean result = true;
 
         if ( postBuildHookScript != null )
         {
-            try
-            {
-                result = runScript( "verification script", basedir, postBuildHookScript, logger );
-            }
-            catch ( final IOException e )
-            {
-                result = false;
-            }
-            catch ( final EvalError e )
-            {
-                String errorMessage = "error evaluating script " + basedir.getPath() + File.separatorChar
-                    + postBuildHookScript + ", " + e.getMessage();
-                getLog().error( errorMessage, e );
-                result = false;
-            }
+            result = runScript( "verification script", basedir, postBuildHookScript, logger );
         }
 
         return result;
@@ -970,104 +993,109 @@
 
     private boolean runScript( final String scriptDescription, final File basedir, final String relativeScriptPath,
                                final FileLogger logger )
-        throws IOException, EvalError
     {
-        final File script = new File( basedir, relativeScriptPath );
+        final File scriptFile = resolveScript( new File( basedir, relativeScriptPath ) );
 
-        boolean scriptResult = false;
-
-        if ( script.exists() )
+        if ( scriptFile.exists() )
         {
-            final Interpreter engine = new Interpreter();
+            List classPath = addTestClassPath ? testClassPath : Collections.EMPTY_LIST;
+
+            Map globalVariables = new HashMap();
+            globalVariables.put( "basedir", basedir );
+
+            PrintStream out = noLog ? null : logger.getPrintStream();
 
-            if ( addTestClassPath )
+            ScriptInterpreter interpreter = getInterpreter( scriptFile );
+            if ( getLog().isDebugEnabled() )
             {
-                getLog().debug( "Adding test class path to BeanShell interpreter:" );
-                try
-                {
-                    List testClassPath = project.getTestClasspathElements();
-                    for ( Iterator it = testClassPath.iterator(); it.hasNext(); )
-                    {
-                        String path = (String) it.next();
-                        getLog().debug( "  " + path );
-                        engine.getClassManager().addClassPath( new File( path ).toURI().toURL() );
-                    }
-                }
-                catch ( Exception e )
-                {
-                    getLog().error( "Failed to add test class path to BeanShell interpreter", e );
-                }
+                String name = interpreter.getClass().getName();
+                name = name.substring( name.lastIndexOf( '.' ) + 1 );
+                getLog().debug( "Running script with " + name );
             }
 
-            PrintStream origOut = System.out;
-            PrintStream origErr = System.err;
+            String script;
+            try
+            {
+                script = FileUtils.fileRead( scriptFile, encoding );
+            }
+            catch ( IOException e )
+            {
+                String errorMessage =
+                    "error reading " + scriptDescription + " " + basedir.getPath() + File.separatorChar
+                        + postBuildHookScript + ", " + e.getMessage();
+                getLog().error( errorMessage, e );
+                return false;
+            }
 
-            Reader reader = null;
             try
             {
                 if ( !noLog )
                 {
-                    logger.consumeLine( "Running " + scriptDescription + " in: " + script );
-
-                    System.setErr( logger.getPrintStream() );
-                    System.setOut( logger.getPrintStream() );
-
-                    engine.setErr( logger.getPrintStream() );
-                    engine.setOut( logger.getPrintStream() );
+                    logger.consumeLine( "Running " + scriptDescription + " in: " + scriptFile );
                 }
-
-                engine.set( "basedir", basedir );
-
-                reader = newReader( script );
-
-                final Object result = engine.eval( reader );
-
-                scriptResult = Boolean.TRUE.equals( result ) || "true".equals( result );
+                Object result = interpreter.evaluateScript( script, classPath, globalVariables, out );
+                if ( !noLog )
+                {
+                    logger.consumeLine( "Finished " + scriptDescription + " in: " + scriptFile );
+                }
+                return Boolean.TRUE.equals( result ) || "true".equals( result );
             }
-            finally
+            catch ( Exception e )
             {
-                IOUtil.close( reader );
-                System.setErr( origErr );
-                System.setOut( origOut );
+                String errorMessage =
+                    "error evaluating " + scriptDescription + " " + basedir.getPath() + File.separatorChar
+                        + postBuildHookScript + ", " + e.getMessage();
+                getLog().error( errorMessage, e );
+                return false;
             }
 
-            if ( !noLog )
-            {
-                logger.consumeLine( "Finished " + scriptDescription + " in: " + script );
-            }
-        }
-        else
-        {
-            scriptResult = true;
         }
 
-        return scriptResult;
+        return true;
     }
 
-    private boolean prebuild( final File basedir, final FileLogger logger )
+    /**
+     * Gets the effective path to the specified script. For convenience, we allow to specify a script path as "verify"
+     * and have the plugin auto-append the file extension to search for "verify.bsh" and "verify.groovy".
+     * 
+     * @param scriptFile The script file to resolve, may be <code>null</code>.
+     * @return The effective path to the script file or <code>null</code> if the input was <code>null</code>.
+     */
+    private File resolveScript( File scriptFile )
     {
-        boolean result = true;
-
-        if ( preBuildHookScript != null )
+        if ( scriptFile != null && !scriptFile.exists() )
         {
-            try
-            {
-                result = runScript( "pre-build script", basedir, preBuildHookScript, logger );
-            }
-            catch ( final IOException e )
-            {
-                result = false;
-            }
-            catch ( final EvalError e )
+            for ( Iterator it = this.scriptInterpreters.keySet().iterator(); it.hasNext(); )
             {
-                String errorMessage = "error evaluating script " + basedir.getPath() + File.separatorChar
-                    + postBuildHookScript + ", " + e.getMessage();
-                getLog().error( errorMessage, e );
-                result = false;
+                String ext = (String) it.next();
+                File candidateFile = new File( scriptFile.getPath() + '.' + ext );
+                if ( candidateFile.exists() )
+                {
+                    scriptFile = candidateFile;
+                    break;
+                }
             }
         }
+        return scriptFile;
+    }
 
-        return result;
+    /**
+     * Determines the script interpreter for the specified script file by looking at its file extension. In this
+     * context, file extensions are considered case-insensitive. For backward compatibility with plugin versions 1.2-,
+     * the BeanShell interpreter will be used for any unrecognized extension.
+     * 
+     * @param scriptFile The script file for which to determine an interpreter, must not be <code>null</code>.
+     * @return The script interpreter for the file, never <code>null</code>.
+     */
+    private ScriptInterpreter getInterpreter( File scriptFile )
+    {
+        String ext = FileUtils.extension( scriptFile.getName() ).toLowerCase( Locale.ENGLISH );
+        ScriptInterpreter interpreter = (ScriptInterpreter) scriptInterpreters.get( ext );
+        if ( interpreter == null )
+        {
+            interpreter = (ScriptInterpreter) scriptInterpreters.get( "bsh" );
+        }
+        return interpreter;
     }
 
     protected List getGoals( final File basedir )

Added: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptEvaluationException.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptEvaluationException.java?rev=683781&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptEvaluationException.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptEvaluationException.java Thu Aug  7 18:01:37 2008
@@ -0,0 +1,48 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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.
+ */
+
+/**
+ * Signals an error during parsing/evaluation of a script (e.g. a syntax error).
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+class ScriptEvaluationException
+    extends Exception
+{
+
+    /**
+     * The serial version identifier for this class.
+     */
+    private static final long serialVersionUID = 199336743291078393L;
+
+    /**
+     * Creates a new exception with the specified detail message and cause.
+     * 
+     * @param message The detail message, may be <code>null</code>.
+     * @param cause The cause, may be <code>null</code>.
+     */
+    public ScriptEvaluationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+}

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptEvaluationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptEvaluationException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptInterpreter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptInterpreter.java?rev=683781&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptInterpreter.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptInterpreter.java Thu Aug  7 18:01:37 2008
@@ -0,0 +1,53 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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.
+ */
+
+import java.io.PrintStream;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Defines a simple abstraction used to plug-in several script interpreters for the pre-/post-build-hooks. Each
+ * interpretator implementation should be stateless and support reuse.
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+interface ScriptInterpreter
+{
+
+    /**
+     * Evaluates the specified script.
+     * 
+     * @param script The script contents to evalute, must not be <code>null</code>.
+     * @param classPath The additional class path for the script interpreter, may be <code>null</code> or empty if only
+     *            the plugin realm should be used for the script evaluation. If specified, this class path will precede
+     *            the artifacts from the plugin class path.
+     * @param globalVariables The global variables (as a mapping from variable name to value) to define for the script,
+     *            may be <code>null</code> if not used.
+     * @param scriptOutput A print stream to redirect any output from the script to, may be <code>null</code> to use
+     *            stdout/stderr.
+     * @return The return value from the script, can be <code>null</code>
+     * @throws ScriptEvaluationException If the script could not be evaluated.
+     */
+    Object evaluateScript( String script, List classPath, Map globalVariables, PrintStream scriptOutput )
+        throws ScriptEvaluationException;
+
+}

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptInterpreter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/ScriptInterpreter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/post-build-script.apt.vm
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/post-build-script.apt.vm?rev=683781&r1=683780&r2=683781&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/post-build-script.apt.vm (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/site/apt/examples/post-build-script.apt.vm Thu Aug  7 18:01:37 2008
@@ -29,7 +29,7 @@
 Using a Post Build Script
  
   Here is an example of how the Invoker Plugin can be used to run a set
-  of Maven projects and then verify their output with a BeanShell script.
+  of Maven projects and then verify their output with a BeanShell or Groovy script.
   The name of the script file in this case is <<<verify.bsh>>>.
 
 -------------------
@@ -65,7 +65,7 @@
 </project>
 -------------------
 
-  Here is an example post build script (<<<verify.bsh>>>) that checks for the existence 
+  Here is an example post build BeanShell script (<<<verify.bsh>>>) that checks for the existence 
   of a JAR file after the build has run.  If the JAR file does not exist, the
   script returns <<<false>>> which causes the Invoker Plugin to log that the build failed.
   The global variable <<<basedir>>> of type <<<java.io.File>>> can be used to refer to the

Modified: maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt?rev=683781&r1=683780&r2=683781&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/site/apt/index.apt Thu Aug  7 18:01:37 2008
@@ -55,7 +55,7 @@
 
   * {{{examples/install-artifacts.html}Install}} projects artifacts to a local repository before running.
   
-  * {{{examples/post-build-script.html}Run a BeanShell script}} to verify project output.
+  * {{{examples/post-build-script.html}Run a BeanShell or Groovy script}} to verify project output.
   
   * {{{examples/fast-use.html}Fast Invoker Plugin configuration}} to accelerate test execution.
   

Added: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreterTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreterTest.java?rev=683781&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreterTest.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreterTest.java Thu Aug  7 18:01:37 2008
@@ -0,0 +1,61 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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.
+ */
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the BeanShell interpreter facade.
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class BeanShellScriptInterpreterTest
+    extends TestCase
+{
+
+    public void testEvaluateScript()
+        throws Exception
+    {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ScriptInterpreter interpreter = new BeanShellScriptInterpreter();
+        assertEquals( Boolean.TRUE, interpreter.evaluateScript( "System.out.print(\"Test\"); return true;", null,
+                                                                null, new PrintStream( out ) ) );
+        assertEquals( "Test", out.toString() );
+    }
+
+    public void testEvaluateScriptVars()
+        throws Exception
+    {
+        Map vars = new HashMap();
+        vars.put( "testVar", "data" );
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ScriptInterpreter interpreter = new BeanShellScriptInterpreter();
+        assertEquals( Boolean.TRUE, interpreter.evaluateScript( "System.out.print(testVar); return true;", null,
+                                                                vars, new PrintStream( out ) ) );
+        assertEquals( "data", out.toString() );
+    }
+
+}

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/BeanShellScriptInterpreterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreterTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreterTest.java?rev=683781&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreterTest.java (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreterTest.java Thu Aug  7 18:01:37 2008
@@ -0,0 +1,61 @@
+package org.apache.maven.plugin.invoker;
+
+/*
+ * 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.
+ */
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the Groovy interpreter facade.
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class GroovyScriptInterpreterTest
+    extends TestCase
+{
+
+    public void testEvaluateScript()
+        throws Exception
+    {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ScriptInterpreter interpreter = new GroovyScriptInterpreter();
+        assertEquals( Boolean.TRUE, interpreter.evaluateScript( "print \"Test\"\nreturn true", null, null,
+                                                                new PrintStream( out ) ) );
+        assertEquals( "Test", out.toString() );
+    }
+
+    public void testEvaluateScriptVars()
+        throws Exception
+    {
+        Map vars = new HashMap();
+        vars.put( "testVar", "data" );
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ScriptInterpreter interpreter = new GroovyScriptInterpreter();
+        assertEquals( Boolean.TRUE, interpreter.evaluateScript( "print testVar\nreturn true", null, vars,
+                                                                new PrintStream( out ) ) );
+        assertEquals( "data", out.toString() );
+    }
+
+}

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/GroovyScriptInterpreterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision