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 2009/01/25 17:41:57 UTC

svn commit: r737536 - in /maven/plugins/trunk/maven-invoker-plugin/src: it/script-context/ it/script-context/src/ it/script-context/src/it/ it/script-context/src/it/beanshell/ it/script-context/src/it/groovy/ main/java/org/apache/maven/plugin/invoker/ ...

Author: bentmann
Date: Sun Jan 25 16:41:57 2009
New Revision: 737536

URL: http://svn.apache.org/viewvc?rev=737536&view=rev
Log:
[MINVOKER-79] Allow to easily pass data from the pre-build hook script to the post-build hook script

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/pom.xml   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/pom.xml   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/setup.bsh   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/verify.bsh   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/pom.xml   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/setup.groovy   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/verify.groovy   (with props)
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/verify.bsh   (with props)
Modified:
    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

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/pom.xml?rev=737536&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/pom.xml (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/pom.xml Sun Jan 25 16:41:57 2009
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.invoker</groupId>
+  <artifactId>script-context</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>
+    Test that the hook scripts can share information via a map in the global variable "context" (MINVOKER-79).
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <pomIncludes>
+            <pomInclude>*/pom.xml</pomInclude>
+          </pomIncludes>
+          <preBuildHookScript>setup</preBuildHookScript>
+          <postBuildHookScript>verify</postBuildHookScript>
+          <goals>
+            <goal>validate</goal>
+          </goals>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/pom.xml?rev=737536&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/pom.xml (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/pom.xml Sun Jan 25 16:41:57 2009
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>test</groupId>
+  <artifactId>beanshell</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+</project>

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/setup.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/setup.bsh?rev=737536&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/setup.bsh (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/setup.bsh Sun Jan 25 16:41:57 2009
@@ -0,0 +1,9 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+context.put( "touchFile", new File( basedir, "touch.txt" ) );
+
+System.out.println( context );
+
+return true;

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/setup.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/setup.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/verify.bsh?rev=737536&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/verify.bsh (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/verify.bsh Sun Jan 25 16:41:57 2009
@@ -0,0 +1,10 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+System.out.println( context );
+
+File touchFile = context.get( "touchFile" );
+touchFile.createNewFile();
+
+return true;

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/beanshell/verify.bsh
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/pom.xml?rev=737536&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/pom.xml (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/pom.xml Sun Jan 25 16:41:57 2009
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>test</groupId>
+  <artifactId>groovy</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+</project>

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/setup.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/setup.groovy?rev=737536&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/setup.groovy (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/setup.groovy Sun Jan 25 16:41:57 2009
@@ -0,0 +1,9 @@
+import java.io.*
+import java.util.*
+import java.util.regex.*
+
+context.put( "touchFile", new File( basedir, "touch.txt" ) )
+
+println context
+
+return true

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/setup.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/setup.groovy
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/verify.groovy?rev=737536&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/verify.groovy (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/verify.groovy Sun Jan 25 16:41:57 2009
@@ -0,0 +1,10 @@
+import java.io.*
+import java.util.*
+import java.util.regex.*
+
+println context
+
+File touchFile = context.get( "touchFile" )
+touchFile.createNewFile()
+
+return true

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/verify.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/src/it/groovy/verify.groovy
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/verify.bsh?rev=737536&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/verify.bsh (added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/verify.bsh Sun Jan 25 16:41:57 2009
@@ -0,0 +1,21 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+File touchFile;
+
+touchFile = new File( basedir, "src/it/beanshell/touch.txt" );
+System.out.println( "Checking for existence of touch file: " + touchFile );
+if ( !touchFile.exists() )
+{
+    throw new FileNotFoundException( "Did not find marker file: " + touchFile );
+}
+
+touchFile = new File( basedir, "src/it/groovy/touch.txt" );
+System.out.println( "Checking for existence of touch file: " + touchFile );
+if ( !touchFile.exists() )
+{
+    throw new FileNotFoundException( "Did not find marker file: " + touchFile );
+}
+
+return true;

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/verify.bsh
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/script-context/verify.bsh
------------------------------------------------------------------------------
    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=737536&r1=737535&r2=737536&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 Sun Jan 25 16:41:57 2009
@@ -1097,10 +1097,12 @@
 
         Properties systemProperties = getTestProperties( basedir );
 
+        Map context = new LinkedHashMap();
+
         FileLogger logger = setupLogger( basedir );
         try
         {
-            runScript( "pre-build script", basedir, preBuildHookScript, logger );
+            runScript( "pre-build script", basedir, preBuildHookScript, context, logger );
 
             final InvocationRequest request = new DefaultInvocationRequest();
 
@@ -1180,7 +1182,7 @@
                 verify( result, invocationIndex, invokerProperties, logger );
             }
 
-            runScript( "post-build script", basedir, postBuildHookScript, logger );
+            runScript( "post-build script", basedir, postBuildHookScript, context, logger );
         }
         finally
         {
@@ -1323,12 +1325,13 @@
      * @param basedir The base directory of the project, must not be <code>null</code>.
      * @param relativeScriptPath The path to the script relative to the project base directory, may be <code>null</code>
      *            to skip the script execution.
+     * @param context The key-value storage used to share information between hook scripts, may be <code>null</code>.
      * @param logger The logger to redirect the script output to, may be <code>null</code> to use stdout/stderr.
      * @throws MojoExecutionException If an I/O error occurred while reading the script file.
      * @throws BuildFailureException If the script did not return <code>true</code> of threw an exception.
      */
     private void runScript( final String scriptDescription, final File basedir, final String relativeScriptPath,
-                            final FileLogger logger )
+                            final Map context, final FileLogger logger )
         throws MojoExecutionException, BuildFailureException
     {
         if ( relativeScriptPath == null )
@@ -1348,6 +1351,7 @@
         Map globalVariables = new HashMap();
         globalVariables.put( "basedir", basedir );
         globalVariables.put( "localRepositoryPath", localRepositoryPath );
+        globalVariables.put( "context", context );
 
         PrintStream out = ( logger != null ) ? logger.getPrintStream() : null;
 

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=737536&r1=737535&r2=737536&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 Sun Jan 25 16:41:57 2009
@@ -1,5 +1,5 @@
  ------
- Using a Post Build Script
+ Using a Post-Build Script
  ------
  Paul Gier
  ------
@@ -26,7 +26,7 @@
  ~~ NOTE: For help with the syntax of this file, see:
  ~~ http://maven.apache.org/doxia/references/apt-format.html
 
-Using a Post Build Script
+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 {{{http://www.beanshell.org/}BeanShell}} or {{{http://groovy.codehaus.org/}Groovy}} script. The name of the
@@ -65,7 +65,7 @@
 </project>
 -------------------
 
-  Here is an example post build BeanShell script (<<<verify.bsh>>>) that checks for the existence of a JAR file after
+  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 throws an exception which causes the Invoker Plugin to
   log that the build failed. More precisely, any return value which does not equal <<<true>>> will be interpreted as a
   failure condition. And of course, if the script exists abnormally due to an exception, the plugin will flag the
@@ -83,11 +83,11 @@
 return true;
 -------------------
 
-  Complementary to the post build hook script, you can also create a pre build hook script that will be run before
+  Complementary to the post-build hook script, you can also create a pre-build hook script that will be run before
   the invocation of Maven. This can be used to do some preparations for the build.
 
-  To allow the scripts to locate files from the test project, the following global variables will be defined by the
-  Invoker Plugin before running the script:
+  To allow the scripts to access some useful data about the test project, the following global variables will be
+  defined by the Invoker Plugin before running the script:
 
 *--------------------------+----------------------+-----------------------------------------------------------+--------+
 || Name                    || Type                || Description                                              || Since |
@@ -96,4 +96,6 @@
 *--------------------------+----------------------+-----------------------------------------------------------+--------+
 | <<<localRepositoryPath>>>| <<<java.io.File>>>   | The absolute path to the local repository used for the Maven invocation on the test project. | 1.3   |
 *--------------------------+----------------------+-----------------------------------------------------------+--------+
+| <<<context>>>            | <<<java.util.Map>>>  | The storage of key-value pairs used to pass data from the pre-build hook script to the post-build hook script. | 1.4   |
+*--------------------------+----------------------+-----------------------------------------------------------+--------+
   
\ No newline at end of file