maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r651733 - in /maven/plugins/trunk/maven-invoker-plugin/src: main/java/org/apache/maven/plugin/invoker/InvokerMojo.java test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
Date Fri, 25 Apr 2008 22:58:18 GMT
Author: bentmann
Date: Fri Apr 25 15:58:14 2008
New Revision: 651733

URL: http://svn.apache.org/viewvc?rev=651733&view=rev
Log:
[MINVOKER-6] Add current's project test classpath to the Bean Shell interpreter classpath

Modified:
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InvokerMojo.java
    maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java

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=651733&r1=651732&r2=651733&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
Fri Apr 25 15:58:14 2008
@@ -73,6 +73,7 @@
  * outputting the results to the command line.
  *
  * @goal run
+ * @requiresDependencyResolution test
  * @since 1.0
  *
  * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
@@ -366,8 +367,16 @@
      * @since 1.2
      */
     private Settings settings;    
-    
-    
+
+    /**
+     * A flag whether the test class path of the project under test should be added to the
class path of the BeanShell
+     * scripts.
+     * 
+     * @parameter expression="${invoker.addTestClassPath}" default-value="false"
+     * @since 1.2
+     */
+    private boolean addTestClassPath;
+
 
     public void execute()
         throws MojoExecutionException, MojoFailureException
@@ -912,6 +921,25 @@
         if ( script.exists() )
         {
             final Interpreter engine = new Interpreter();
+
+            if ( addTestClassPath )
+            {
+                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 );
+                }
+            }
 
             PrintStream origOut = System.out;
             PrintStream origErr = System.err;

Modified: maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java?rev=651733&r1=651732&r2=651733&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
(original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/test/java/org/apache/maven/plugin/invoker/InvokerMojoTest.java
Fri Apr 25 15:58:14 2008
@@ -22,9 +22,11 @@
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.apache.maven.settings.Settings;
 import org.apache.maven.shared.invoker.Invoker;
 import org.codehaus.plexus.util.FileUtils;
@@ -72,6 +74,9 @@
             FileUtils.deleteDirectory( cloneProjectsTo );
         }
         //cloneProjectsTo.getParent()
+        MavenProjectStub project = new MavenProjectStub();
+        project.setTestClasspathElements( Collections.EMPTY_LIST );
+        setVariableValueToObject( invokerMojo, "project", project );
         setVariableValueToObject( invokerMojo, "cloneProjectsTo", cloneProjectsTo );
         setVariableValueToObject( invokerMojo, "postBuildHookScript", "verify.bsh" );
         setVariableValueToObject( invokerMojo, "settings", new Settings() );



Mime
View raw message