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/09/19 00:03:34 UTC

svn commit: r816799 - in /maven/core-integration-testing/trunk: core-it-suite/src/test/java/org/apache/maven/it/ core-it-suite/src/test/resources/mng-4363/ core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/m...

Author: bentmann
Date: Fri Sep 18 22:03:33 2009
New Revision: 816799

URL: http://svn.apache.org/viewvc?rev=816799&view=rev
Log:
[MNG-4363] [regression] Dependency artifacts injected by plugins aren't included in class paths

o Added IT

Added:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4363DynamicAdditionOfDependencyArtifactTest.java   (with props)
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4363/
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4363/pom.xml   (with props)
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/InjectMojo.java   (with props)
Modified:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java?rev=816799&r1=816798&r2=816799&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java (original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java Fri Sep 18 22:03:33 2009
@@ -85,6 +85,7 @@
         // suite.addTestSuite( MavenIT0109ReleaseUpdateTest.class );
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
 
+        suite.addTestSuite( MavenITmng4363DynamicAdditionOfDependencyArtifactTest.class );
         suite.addTestSuite( MavenITmng4361ForceSnapshotUpdateTest.class );
         suite.addTestSuite( MavenITmng4360WebDavSupportTest.class );
         suite.addTestSuite( MavenITmng4359LocallyReachableParentOutsideOfReactorTest.class );

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4363DynamicAdditionOfDependencyArtifactTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4363DynamicAdditionOfDependencyArtifactTest.java?rev=816799&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4363DynamicAdditionOfDependencyArtifactTest.java (added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4363DynamicAdditionOfDependencyArtifactTest.java Fri Sep 18 22:03:33 2009
@@ -0,0 +1,62 @@
+package org.apache.maven.it;
+
+/*
+ * 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 org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4363">MNG-4363</a>.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class MavenITmng4363DynamicAdditionOfDependencyArtifactTest
+    extends AbstractMavenIntegrationTestCase
+{
+
+    public MavenITmng4363DynamicAdditionOfDependencyArtifactTest()
+    {
+        super( ALL_MAVEN_VERSIONS );
+    }
+
+    /**
+     * Verify that plugins can dynamically add dependency artifacts to the project. Those added artifacts need to
+     * be resolved and added to the affected class paths for later goal executions.
+     */
+    public void testit()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4363" );
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.executeGoal( "initialize" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        List classpath = verifier.loadLines( "target/classpath.txt", "UTF-8" );
+        assertTrue( classpath.toString(), classpath.contains( "maven-core-it-support-1.0.jar" ) );
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4363DynamicAdditionOfDependencyArtifactTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4363DynamicAdditionOfDependencyArtifactTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4363/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4363/pom.xml?rev=816799&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4363/pom.xml (added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4363/pom.xml Fri Sep 18 22:03:33 2009
@@ -0,0 +1,76 @@
+<?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>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng4363</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+
+  <name>Maven Integration Test :: MNG-4363</name>
+  <description>
+    Verify that plugins can dynamically add dependency artifacts to the project. Those added artifacts need to
+    be resolved and added to the affected class paths for later goal executions.
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.its.plugins</groupId>
+        <artifactId>maven-it-plugin-dependency-resolution</artifactId>
+        <version>2.1-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <id>cobertura</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>inject</goal>
+            </goals>
+            <configuration>
+              <artifacts>
+                <artifact>org.apache.maven.its:maven-core-it-support</artifact>
+              </artifacts>
+            </configuration>
+          </execution>
+          <execution>
+            <id>surefire</id>
+            <phase>initialize</phase>
+            <goals>
+              <goal>compile</goal>
+            </goals>
+            <configuration>
+              <compileClassPath>target/classpath.txt</compileClassPath>
+              <significantPathLevels>1</significantPathLevels>
+            </configuration>
+          </execution>
+        </executions>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.maven.its</groupId>
+            <artifactId>maven-core-it-support</artifactId>
+            <version>1.0</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4363/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4363/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/InjectMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/InjectMojo.java?rev=816799&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/InjectMojo.java (added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/InjectMojo.java Fri Sep 18 22:03:33 2009
@@ -0,0 +1,118 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * 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.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Injects artifacts from the plugin into the dependency artifacts of the project.
+ * 
+ * @goal inject
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class InjectMojo
+    extends AbstractMojo
+{
+
+    /**
+     * The version-less keys in the form <code>groupId:artifactId</code> of the plugin artifacts to inject into
+     * dependency artifacts of the project.
+     * 
+     * @parameter
+     */
+    private String[] artifacts;
+
+    /**
+     * @parameter default-value="${plugin.artifacts}"
+     * @readonly
+     */
+    private Collection pluginArtifacts;
+
+    /**
+     * The current Maven project.
+     * 
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+
+    /**
+     * Runs this mojo.
+     * 
+     * @throws MojoExecutionException If an error occured.
+     */
+    public void execute()
+        throws MojoExecutionException
+    {
+        Set artifactKeys = new LinkedHashSet();
+
+        if ( artifacts != null )
+        {
+            artifactKeys.addAll( Arrays.asList( artifacts ) );
+        }
+
+        Set dependencyArtifacts = project.getDependencyArtifacts();
+
+        if ( dependencyArtifacts != null )
+        {
+            dependencyArtifacts = new LinkedHashSet( dependencyArtifacts );
+        }
+        else
+        {
+            dependencyArtifacts = new LinkedHashSet();
+        }
+
+        for ( Iterator it = pluginArtifacts.iterator(); it.hasNext(); )
+        {
+            Artifact artifact = (Artifact) it.next();
+
+            String artifactKey = artifact.getGroupId() + ':' + artifact.getArtifactId();
+
+            if ( artifactKeys.remove( artifactKey ) )
+            {
+                getLog().info( "[MAVEN-CORE-IT-LOG] Injecting dependency artifact " + artifact );
+
+                dependencyArtifacts.add( artifact );
+            }
+        }
+
+        project.setDependencyArtifacts( dependencyArtifacts );
+
+        getLog().info( "[MAVEN-CORE-IT-LOG] Set dependency artifacts to " + dependencyArtifacts );
+
+        if ( !artifactKeys.isEmpty() )
+        {
+            getLog().warn( "[MAVEN-CORE-IT-LOG] These artifacts were not found " + artifactKeys );
+        }
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/InjectMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/InjectMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision