Author: olamy
Date: Tue Dec 21 21:05:04 2010
New Revision: 1051652

URL: http://svn.apache.org/viewvc?rev=1051652&view=rev
Log:
[MINVOKER-112] duplicate script classpath entries are not filtered out, can 
cause ClassCastException.
Submitted by luke w patterson

Added:
    maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/pom.xml
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/pom.xml
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/postbuild.bsh
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/prebuild.bsh
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/pom.xml
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/postbuild.groovy
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/prebuild.groovy
   (with props)
    
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/verify.bsh
   (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/AbstractInvokerMojo.java

Modified: maven/plugins/trunk/maven-invoker-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/pom.xml?rev=1051652&r1=1051651&r2=1051652&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-invoker-plugin/pom.xml Tue Dec 21 21:05:04 2010
@@ -56,6 +56,12 @@ under the License.
     <mavenVersion>2.0.6</mavenVersion>
     <doxiaVersion>1.1.4</doxiaVersion>
     <doxia-sitetoolsVersion>1.1.4</doxia-sitetoolsVersion>
+    <beanshell-groupId>org.beanshell</beanshell-groupId>
+    <beanshell-artifactId>bsh</beanshell-artifactId>
+    <beanshell-version>2.0b4</beanshell-version>
+    <groovy-groupId>org.codehaus.groovy</groovy-groupId>
+    <groovy-artifactId>groovy</groovy-artifactId>
+    <groovy-version>1.5.6</groovy-version>
   </properties>
 
   <dependencies>
@@ -125,14 +131,14 @@ under the License.
     </dependency>
 
     <dependency>
-      <groupId>org.beanshell</groupId>
-      <artifactId>bsh</artifactId>
-      <version>2.0b4</version>
+      <groupId>${beanshell-groupId}</groupId>
+      <artifactId>${beanshell-artifactId}</artifactId>
+      <version>${beanshell-version}</version>
     </dependency>
     <dependency>
-      <groupId>org.codehaus.groovy</groupId>
-      <artifactId>groovy</artifactId>
-      <version>1.5.6</version>
+      <groupId>${groovy-groupId}</groupId>
+      <artifactId>${groovy-artifactId}</artifactId>
+      <version>${groovy-version}</version>
       <exclusions>
         <exclusion>
           <groupId>junit</groupId>

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/pom.xml?rev=1051652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/pom.xml
 Tue Dec 21 21:05:04 2010
@@ -0,0 +1,81 @@
+<?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-classpath-duplicates</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+  <description>Test to check that script classpath entries duplicated between 
${project.testClasspathElements} and ${plugin.artifacts} are 
removed</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>@beanshell-groupId@</groupId>
+      <artifactId>@beanshell-artifactId@</artifactId>
+      <version>@beanshell-version@</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>@groovy-groupId@</groupId>
+      <artifactId>@groovy-artifactId@</artifactId>
+      <version>@groovy-version@</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-invoker-plugin</artifactId>
+        <version>@pom.version@</version>
+        <configuration>
+          <addTestClassPath>true</addTestClassPath>
+          <debug>true</debug>
+          <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+          <pomIncludes>
+            <pomInclude>*</pomInclude>
+          </pomIncludes>
+          <goals>
+            <goal>validate</goal>
+          </goals>
+        </configuration>
+        <executions>
+          <execution>
+            <id>integration-test</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

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

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

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/pom.xml?rev=1051652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/pom.xml
 Tue Dec 21 21:05:04 2010
@@ -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-classpath-duplicates/src/it/beanshell/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/postbuild.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/postbuild.bsh?rev=1051652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/postbuild.bsh
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/postbuild.bsh
 Tue Dec 21 21:05:04 2010
@@ -0,0 +1,20 @@
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+import java.util.regex.*;
+
+try
+{
+    // create touch file so that the parent build can verify whether this 
script was called
+    File touchFile = new File( basedir, "target/created-by-postbuild.bsh" );
+    System.out.println( "Creating touch file: " + touchFile );
+    touchFile.getParentFile().mkdirs();
+    touchFile.createNewFile();
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;

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

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

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/prebuild.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/prebuild.bsh?rev=1051652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/prebuild.bsh
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/beanshell/prebuild.bsh
 Tue Dec 21 21:05:04 2010
@@ -0,0 +1,20 @@
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+import java.util.regex.*;
+
+try
+{
+    // create touch file so that the parent build can verify whether this 
script was called
+    File touchFile = new File( basedir, "target/created-by-prebuild.bsh" );
+    System.out.println( "Creating touch file: " + touchFile );
+    touchFile.getParentFile().mkdirs();
+    touchFile.createNewFile();
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;

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

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

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/pom.xml?rev=1051652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/pom.xml
 Tue Dec 21 21:05:04 2010
@@ -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-classpath-duplicates/src/it/groovy/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/postbuild.groovy
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/postbuild.groovy?rev=1051652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/postbuild.groovy
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/postbuild.groovy
 Tue Dec 21 21:05:04 2010
@@ -0,0 +1,20 @@
+import java.io.*
+import java.lang.reflect.*
+import java.util.*
+import java.util.regex.*
+
+try
+{
+    // create touch file so that the parent build can verify whether this 
script was called
+    File touchFile = new File( basedir, "target/created-by-postbuild.groovy" )
+    println "Creating touch file: " + touchFile
+    touchFile.getParentFile().mkdirs()
+    touchFile.createNewFile()
+}
+catch( Throwable t )
+{
+    t.printStackTrace()
+    return false
+}
+
+return true

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/postbuild.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/prebuild.groovy
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/prebuild.groovy?rev=1051652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/prebuild.groovy
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/prebuild.groovy
 Tue Dec 21 21:05:04 2010
@@ -0,0 +1,20 @@
+import java.io.*
+import java.lang.reflect.*
+import java.util.*
+import java.util.regex.*
+
+try
+{
+    // create touch file so that the parent build can verify whether this 
script was called
+    File touchFile = new File( basedir, "target/created-by-prebuild.groovy" )
+    println "Creating touch file: " + touchFile
+    touchFile.getParentFile().mkdirs()
+    touchFile.createNewFile()
+}
+catch( Throwable t )
+{
+    t.printStackTrace()
+    return false
+}
+
+return true

Propchange: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/src/it/groovy/prebuild.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/verify.bsh
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/verify.bsh?rev=1051652&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/verify.bsh
 (added)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/it/script-classpath-duplicates/verify.bsh
 Tue Dec 21 21:05:04 2010
@@ -0,0 +1,30 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+try
+{
+    String[] files = {
+            "target/it/beanshell/target/created-by-prebuild.bsh",
+            "target/it/beanshell/target/created-by-postbuild.bsh",
+            "target/it/groovy/target/created-by-prebuild.groovy",
+            "target/it/groovy/target/created-by-postbuild.groovy",
+      };
+    for ( String file : files )
+    {
+        File touchFile = new File( basedir, file );
+        System.out.println( "Checking for existence of: " + touchFile );
+        if ( !touchFile.isFile() )
+        {
+            System.out.println( "FAILED!" );
+            return false;
+        }
+    }
+}
+catch( Throwable t )
+{
+    t.printStackTrace();
+    return false;
+}
+
+return true;

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

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

Modified: 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java?rev=1051652&r1=1051651&r2=1051652&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
 Tue Dec 21 21:05:04 2010
@@ -24,6 +24,7 @@ import org.apache.maven.plugin.MojoExecu
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.invoker.model.BuildJob;
 import org.apache.maven.plugin.invoker.model.io.xpp3.BuildJobXpp3Writer;
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Profile;
 import org.apache.maven.shared.invoker.InvocationRequest;
@@ -535,7 +536,15 @@ public abstract class AbstractInvokerMoj
      * @since 1.6
      */
     private int parrallelThreads;
-    
+
+    /**
+     * @parameter expression="${plugin.artifacts}"
+     * @required
+     * @readonly
+     * @since 1.6
+     */
+    private List<Artifact> pluginArtifacts;
+
     /**
      * The scripter runner that is responsible to execute hook scripts.
      */
@@ -617,10 +626,21 @@ public abstract class AbstractInvokerMoj
                                + ", i.e. build is platform dependent!" );
         }
 
+        final List/*<String>*/ scriptClassPath;
+        if( addTestClassPath )
+        {
+            scriptClassPath = new ArrayList/*<String>*/( testClassPath );
+            for( Artifact pluginArtifact : pluginArtifacts )
+            {
+                scriptClassPath.remove( 
pluginArtifact.getFile().getAbsolutePath() );
+            }
+        } else {
+            scriptClassPath = null;
+        }
         scriptRunner = new ScriptRunner( getLog() );
         scriptRunner.setScriptEncoding( encoding );
         scriptRunner.setGlobalVariable( "localRepositoryPath", 
localRepositoryPath );
-        scriptRunner.setClassPath( addTestClassPath ? testClassPath : null );
+        scriptRunner.setClassPath( scriptClassPath );
 
         Collection collectedProjects = new LinkedHashSet();
         for ( int i = 0; i < buildJobs.length; i++ )


Reply via email to