maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1481407 - in /maven/plugins/trunk/maven-dependency-plugin/src: it/copy-dependencies/ main/java/org/apache/maven/plugin/dependency/
Date Sat, 11 May 2013 20:42:14 GMT
Author: hboutemy
Date: Sat May 11 20:42:13 2013
New Revision: 1481407

URL: http://svn.apache.org/r1481407
Log:
[MDEP-412] added addParentPoms property to copy-dependencies to include parent poms

Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/pom.xml
    maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/verify.bsh
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java

Modified: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/pom.xml?rev=1481407&r1=1481406&r2=1481407&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/pom.xml (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/pom.xml Sat May 11
20:42:13 2013
@@ -23,6 +23,12 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
+  <parent>
+    <groupId>org.apache</groupId>
+    <artifactId>apache</artifactId>
+    <version>5</version>
+  </parent>
+
   <groupId>org.apache.maven.its.dependency</groupId>
   <artifactId>test</artifactId>
   <version>1.0-SNAPSHOT</version>
@@ -109,6 +115,8 @@
               <outputDirectory>${project.build.directory}/it/repositoryLayout</outputDirectory>
               <useRepositoryLayout>true</useRepositoryLayout>
               <copyPom>true</copyPom>
+              <addParentPoms>true</addParentPoms>
+              <excludeArtifactIds>maven-parent</excludeArtifactIds>
             </configuration>
           </execution>
         </executions>

Modified: maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/verify.bsh?rev=1481407&r1=1481406&r2=1481407&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/verify.bsh (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/copy-dependencies/verify.bsh Sat May
11 20:42:13 2013
@@ -86,12 +86,17 @@ String [] expectedFiles4 = {
     "org/apache/maven/maven-model/2.0.6/maven-model-2.0.6-javadoc.jar",
     "org/codehaus/plexus/plexus-utils/maven-metadata-local.xml",
     "org/codehaus/plexus/plexus-utils/1.4.1/plexus-utils-1.4.1.jar",
-    "org/codehaus/plexus/plexus-utils/1.4.1/plexus-utils-1.4.1.pom"
+    "org/codehaus/plexus/plexus-utils/1.4.1/plexus-utils-1.4.1.pom",
+    "org/apache/apache/5/apache-5.pom", // parent pom
+    "org/apache/maven/maven/2.0.6/maven-2.0.6.jar", // parent of maven-model
+    "org/apache/apache/3/apache-3.pom", // parent of parent of maven
+    "org/codehaus/plexus/plexus/1.0.11/plexus-1.0.11.pom" // parent of plexus-utils
 };
 
 String [] unexpectedFiles4 = {
     "plexus-utils-1.4.1.pom",
-    "maven-model-2.0.6.pom"
+    "maven-model-2.0.6.pom",
+    "org/apache/maven/maven-parent/5/maven-parent-5.pom", // parent of maven, excluded by
artifactId
 };
 
 checkExpected( new File( baseOutput, "repositoryLayout" ), expectedFiles4, unexpectedFiles4
);

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java?rev=1481407&r1=1481406&r2=1481407&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/AbstractDependencyFilterMojo.java
Sat May 11 20:42:13 2013
@@ -20,6 +20,8 @@ package org.apache.maven.plugin.dependen
  */
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
 import org.apache.maven.plugin.dependency.utils.DependencyUtil;
@@ -27,7 +29,11 @@ import org.apache.maven.plugin.dependenc
 import org.apache.maven.plugin.dependency.utils.resolvers.DefaultArtifactsResolver;
 import org.apache.maven.plugin.dependency.utils.translators.ArtifactTranslator;
 import org.apache.maven.plugin.dependency.utils.translators.ClassifierTypeTranslator;
+import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
@@ -40,6 +46,7 @@ import org.apache.maven.shared.artifact.
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -204,6 +211,9 @@ public abstract class AbstractDependency
     @Parameter( property = "mdep.prependGroupId", defaultValue = "false" )
     protected boolean prependGroupId = false;
 
+    @Component
+    MavenProjectBuilder projectBuilder;
+
     /**
      * Return an {@link ArtifactsFilter} indicating which artifacts must be filtered out.
      * 
@@ -226,6 +236,12 @@ public abstract class AbstractDependency
         return status.getResolvedDependencies();
     }
 
+    protected DependencyStatusSets getDependencySets( boolean stopOnFailure )
+        throws MojoExecutionException
+    {
+        return getDependencySets( stopOnFailure, false );
+    }
+
     /**
      * Method creates filters and filters the projects dependencies. This method
      * also transforms the dependencies if classifier is set. The dependencies
@@ -236,7 +252,7 @@ public abstract class AbstractDependency
      *         on the projects dependencies
      * @throws MojoExecutionException
      */
-    protected DependencyStatusSets getDependencySets( boolean stopOnFailure )
+    protected DependencyStatusSets getDependencySets( boolean stopOnFailure, boolean includeParents
)
         throws MojoExecutionException
     {
         // add filters in well known order, least specific to most specific
@@ -262,6 +278,18 @@ public abstract class AbstractDependency
         // start with all artifacts.
         @SuppressWarnings( "unchecked" ) Set<Artifact> artifacts = project.getArtifacts();
 
+        if ( includeParents )
+        {
+            // add dependencies parents
+            for ( Artifact dep : new ArrayList<Artifact>( artifacts ) )
+            {
+                addParentArtifacts( buildProjectFromArtifact( dep ), artifacts );
+            }
+
+            // add current project parent
+            addParentArtifacts( project, artifacts );
+        }
+
         // perform filtering
         try
         {
@@ -286,6 +314,44 @@ public abstract class AbstractDependency
         return status;
     }
 
+    private MavenProject buildProjectFromArtifact( Artifact artifact )
+        throws MojoExecutionException
+    {
+        try
+        {
+            return projectBuilder.buildFromRepository( artifact, remoteRepos, getLocal()
);
+        }
+        catch ( ProjectBuildingException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+    }
+
+    private void addParentArtifacts( MavenProject project, Set<Artifact> artifacts
)
+        throws MojoExecutionException
+    {
+        while ( project.hasParent() )
+        {
+            project = project.getParent();
+            if ( !artifacts.add( project.getArtifact() ) )
+            {
+                // artifact already in the set
+                break;
+            }
+            try
+            {
+                resolver.resolve( project.getArtifact(), this.remoteRepos, this.getLocal()
);
+            }
+            catch ( ArtifactResolutionException e )
+            {
+                throw new MojoExecutionException( e.getMessage(), e );
+            }
+            catch ( ArtifactNotFoundException e )
+            {
+                throw new MojoExecutionException( e.getMessage(), e );
+            }
+        }
+    }
     /**
      * Transform artifacts
      *

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java?rev=1481407&r1=1481406&r2=1481407&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugin/dependency/CopyDependenciesMojo.java
Sat May 11 20:42:13 2013
@@ -90,6 +90,13 @@ public class CopyDependenciesMojo
     protected boolean useBaseVersion = true;
 
     /**
+     * Add parent poms to the list of copied dependencies (both current project pom parents
and dependencies parents).
+     * @since 2.8
+     */
+    @Parameter( defaultValue = "false" )
+    protected boolean addParentPoms;
+
+    /**
      * Main entry into mojo. Gets the list of dependencies and iterates through
      * calling copyArtifact.
      *
@@ -100,7 +107,7 @@ public class CopyDependenciesMojo
     protected void doExecute()
         throws MojoExecutionException
     {
-        DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact
);
+        DependencyStatusSets dss = getDependencySets( this.failOnMissingClassifierArtifact,
addParentPoms );
         Set<Artifact> artifacts = dss.getResolvedDependencies();
 
         if ( !useRepositoryLayout )
@@ -177,7 +184,7 @@ public class CopyDependenciesMojo
         }
         catch ( ArtifactInstallationException e )
         {
-            getLog().info( e.getMessage() );
+            getLog().warn( "unable to install " + artifact, e );
         }
     }
 



Mime
View raw message