maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1691645 - in /maven/plugins/trunk/maven-dependency-plugin/src: main/java/org/apache/maven/plugins/dependency/ main/java/org/apache/maven/plugins/dependency/resolvers/ test/java/org/apache/maven/plugins/dependency/
Date Fri, 17 Jul 2015 21:20:05 GMT
Author: rfscholte
Date: Fri Jul 17 21:20:05 2015
New Revision: 1691645

URL: http://svn.apache.org/r1691645
Log:
[MDEP-494] Remove/replace Maven2 specific code
introduce ArtifactCoordinate from maven-artifact-transfer

Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
    maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java?rev=1691645&r1=1691644&r2=1691645&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/GetMojo.java
Fri Jul 17 21:20:05 2015
@@ -21,13 +21,12 @@ package org.apache.maven.plugins.depende
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.MavenArtifactRepository;
@@ -41,6 +40,7 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.artifact.ArtifactCoordinate;
 import org.apache.maven.shared.artifact.resolve.ArtifactResolver;
 import org.apache.maven.shared.artifact.resolve.ArtifactResolverException;
 import org.codehaus.plexus.util.StringUtils;
@@ -63,12 +63,6 @@ public class GetMojo
      *
      */
     @Component
-    private ArtifactFactory artifactFactory;
-
-    /**
-     *
-     */
-    @Component
     private ArtifactResolver artifactResolver;
 
     /**
@@ -77,6 +71,8 @@ public class GetMojo
     @Component( role = ArtifactRepositoryLayout.class )
     private Map<String, ArtifactRepositoryLayout> repositoryLayouts;
 
+    private ArtifactCoordinate coordinate = new ArtifactCoordinate();
+    
     /**
      * The groupId of the artifact to download. Ignored if {@link #artifact} is used.
      */
@@ -152,7 +148,7 @@ public class GetMojo
             return;
         }
 
-        if ( artifactId == null && artifact == null )
+        if ( coordinate.getArtifactId() == null && artifact == null )
         {
             throw new MojoFailureException( "You must specify an artifact, "
                 + "e.g. -Dartifact=org.apache.maven.plugins:maven-downloader-plugin:1.0"
);
@@ -166,27 +162,19 @@ public class GetMojo
                     "Invalid artifact, you must specify groupId:artifactId:version[:packaging[:classifier]]
"
                         + artifact );
             }
-            groupId = tokens[0];
-            artifactId = tokens[1];
-            version = tokens[2];
+            coordinate.setGroupId( tokens[0] );
+            coordinate.setArtifactId( tokens[1] );
+            coordinate.setVersion( tokens[2] );
             if ( tokens.length >= 4 )
             {
-                packaging = tokens[3];
+                coordinate.setType( tokens[3] );
             }
             if ( tokens.length == 5 )
             {
-                classifier = tokens[4];
-            }
-            else
-            {
-                classifier = null;
+                coordinate.setClassifier( tokens[4] );
             }
         }
 
-        Artifact toDownload = classifier == null
-            ? artifactFactory.createBuildArtifact( groupId, artifactId, version, packaging
)
-            : artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
packaging, classifier );
-
         ArtifactRepositoryPolicy always =
             new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
                                           ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
@@ -217,13 +205,13 @@ public class GetMojo
             
             if ( transitive )
             {
-                getLog().info( "Resolving " + toDownload + " with transitive dependencies"
);
-                artifactResolver.resolveTransitively( buildingRequest, toDownload );
+                getLog().info( "Resolving " + coordinate + " with transitive dependencies"
);
+                artifactResolver.resolveDependencies( buildingRequest, Collections.singletonList(
coordinate ), null );
             }
             else
             {
-                getLog().info( "Resolving " + toDownload );
-                artifactResolver.resolveArtifact( buildingRequest, toDownload );
+                getLog().info( "Resolving " + coordinate );
+                artifactResolver.resolveArtifact( buildingRequest, coordinate );
             }
         }
         catch ( ArtifactResolverException e )
@@ -278,6 +266,34 @@ public class GetMojo
         return skip;
     }
 
-
+    // @Parameter( alias = "groupId" )
+    public void setGroupId( String groupId )
+    {
+      this.coordinate.setGroupId( groupId );
+    }
+    
+    // @Parameter( alias = "artifactId" )
+    public void setArtifactId( String artifactId )
+    {
+      this.coordinate.setArtifactId( artifactId );
+    }
+    
+    // @Parameter( alias = "version" )
+    public void setVersion( String version )
+    {
+      this.coordinate.setVersion( version );
+    }
+    
+    // @Parameter( alias = "classifier" )
+    public void setClassifier( String classifier )
+    {
+      this.coordinate.setClassifier( classifier );
+    }
+    
+    // @Parameter( alias = "packaging" )
+    public void setPackaging( String type )
+    {
+      this.coordinate.setType( type );
+    }
 
 }

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java?rev=1691645&r1=1691644&r2=1691645&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/PurgeLocalRepositoryMojo.java
Fri Jul 17 21:20:05 2015
@@ -30,7 +30,6 @@ import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactUtils;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -43,7 +42,7 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.shared.artifact.TransferUtils;
 import org.apache.maven.shared.artifact.filter.resolve.AbstractFilter;
 import org.apache.maven.shared.artifact.filter.resolve.AndFilter;
 import org.apache.maven.shared.artifact.filter.resolve.Node;
@@ -178,12 +177,6 @@ public class PurgeLocalRepositoryMojo
     private boolean actTransitively;
 
     /**
-     * Used to construct artifacts for deletion/resolution...
-     */
-    @Component
-    private ArtifactFactory factory;
-
-    /**
      * Whether this plugin should output verbose messages. Default is false.
      */
     @Parameter( property = "verbose", defaultValue = "false" )
@@ -310,16 +303,7 @@ public class PurgeLocalRepositoryMojo
             return;
         }
 
-        Set<Artifact> dependencyArtifacts;
-
-        try
-        {
-            dependencyArtifacts = project.createArtifacts( factory, null, null );
-        }
-        catch ( InvalidDependencyVersionException e )
-        {
-            throw new MojoFailureException( "Unable to purge dependencies due to invalid
dependency version ", e );
-        }
+        Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
 
         TransformableFilter dependencyFilter = createPurgeArtifactsFilter( dependencyArtifacts
);
 
@@ -496,8 +480,10 @@ public class PurgeLocalRepositoryMojo
     {
         try
         {
+            
             Iterable<ArtifactResult> results =
-                resolver.resolveTransitively( session.getProjectBuildingRequest(), project.getArtifact(),
filter );
+                resolver.resolveDependencies( session.getProjectBuildingRequest(),
+                                              TransferUtils.toArtifactCoordinate( project
), filter );
 
             Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();
             
@@ -584,10 +570,8 @@ public class PurgeLocalRepositoryMojo
         {
             try
             {
-                Artifact pomArtifact =
-                    factory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(),
-                                            null, "pom" );
-                resolver.resolveArtifact( session.getProjectBuildingRequest(), pomArtifact
);
+                resolver.resolveArtifact( session.getProjectBuildingRequest(),
+                                          TransferUtils.toArtifactCoordinate( artifact )
);
             }
             catch ( ArtifactResolverException e )
             {

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java?rev=1691645&r1=1691644&r2=1691645&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
Fri Jul 17 21:20:05 2015
@@ -24,14 +24,13 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo;
 import org.apache.maven.plugins.dependency.utils.DependencyUtil;
 import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.shared.artifact.ArtifactCoordinate;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
 import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter;
 import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
@@ -146,12 +145,6 @@ public abstract class AbstractResolveMoj
         return filter;
     }
 
-    protected Set<Artifact> resolveDependencyArtifacts( final MavenProject theProject
)
-        throws ArtifactResolverException, ArtifactNotFoundException, InvalidDependencyVersionException
-    {
-        return resolveArtifactDependencies( theProject.getArtifact() );
-    }
-
     /**
      * This method resolves all transitive dependencies of an artifact.
      *
@@ -159,15 +152,14 @@ public abstract class AbstractResolveMoj
      * @return resolved set of dependencies
      * @throws ArtifactResolverException
      */
-    protected Set<Artifact> resolveArtifactDependencies( final Artifact artifact )
+    protected Set<Artifact> resolveArtifactDependencies( final ArtifactCoordinate artifact
)
         throws ArtifactResolverException
     {
         ProjectBuildingRequest buildingRequest =
             new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
 
         Iterable<ArtifactResult> artifactResults =
-            getArtifactResolver().resolveTransitively( buildingRequest,
-                                                       artifact );
+            getArtifactResolver().resolveDependencies( buildingRequest, artifact, null );
 
         Set<Artifact> artifacts = new HashSet<Artifact>();
 

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java?rev=1691645&r1=1691644&r2=1691645&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
Fri Jul 17 21:20:05 2015
@@ -35,6 +35,8 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.plugins.dependency.utils.DependencyUtil;
 import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.artifact.ArtifactCoordinate;
+import org.apache.maven.shared.artifact.TransferUtils;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
 import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
 import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
@@ -105,7 +107,9 @@ public class ResolvePluginsMojo
 
                 if ( !excludeTransitive )
                 {
-                    for ( final Artifact artifact : resolveArtifactDependencies( plugin )
)
+                    ArtifactCoordinate coordinate = TransferUtils.toArtifactCoordinate( plugin
);
+                    
+                    for ( final Artifact artifact : resolveArtifactDependencies( coordinate
) )
                     {
                         logStr =
                             "    Plugin Dependency Resolved: " + DependencyUtil.getFormattedFileName(
artifact, false );
@@ -163,6 +167,7 @@ public class ResolvePluginsMojo
         final FilterArtifacts filter = getPluginArtifactsFilter();
         artifacts = filter.filter( artifacts );
 
+        Set<Artifact> resolvedArtifacts = new HashSet<Artifact>( artifacts.size()
);
         //        final ArtifactFilter filter = getPluginFilter();
         for ( final Artifact artifact : new HashSet<Artifact>( artifacts ) )
         {
@@ -186,7 +191,7 @@ public class ResolvePluginsMojo
             buildingRequest.setRemoteRepositories( this.remotePluginRepositories );
             
             // resolve the new artifact
-            getArtifactResolver().resolveArtifact( buildingRequest, artifact );
+            resolvedArtifacts.add( getArtifactResolver().resolveArtifact( buildingRequest,
artifact ) .getArtifact() );
         }
         return artifacts;
     }

Modified: maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java?rev=1691645&r1=1691644&r2=1691645&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java
(original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java
Fri Jul 17 21:20:05 2015
@@ -67,9 +67,9 @@ public class TestGetMojo
         // Set properties, transitive = default value = true
         setVariableValueToObject( mojo, "transitive", Boolean.FALSE );
         setVariableValueToObject( mojo, "remoteRepositories", "central::default::http://repo1.maven.apache.org/maven2"
);
-        setVariableValueToObject( mojo, "groupId", "org.apache.maven" );
-        setVariableValueToObject( mojo, "artifactId", "maven-model" );
-        setVariableValueToObject( mojo, "version", "2.0.9" );
+        mojo.setGroupId( "org.apache.maven" );
+        mojo.setArtifactId( "maven-model" );
+        mojo.setVersion( "2.0.9" );
 
         mojo.execute();
 
@@ -88,9 +88,9 @@ public class TestGetMojo
     {
         setVariableValueToObject( mojo, "remoteRepositories", "central::default::http://repo1.maven.apache.org/maven2,"
             + "central::::http://repo1.maven.apache.org/maven2," + "http://repo1.maven.apache.org/maven2"
);
-        setVariableValueToObject( mojo, "groupId", "org.apache.maven" );
-        setVariableValueToObject( mojo, "artifactId", "maven-model" );
-        setVariableValueToObject( mojo, "version", "2.0.9" );
+        mojo.setGroupId( "org.apache.maven" );
+        mojo.setArtifactId( "maven-model" );
+        mojo.setVersion( "2.0.9" );
 
         mojo.execute();
     }



Mime
View raw message