maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1687128 - in /maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal: Invoker.java Maven31DependencyGraphBuilder.java Maven3DependencyGraphBuilder.java
Date Tue, 23 Jun 2015 20:34:27 GMT
Author: rfscholte
Date: Tue Jun 23 20:34:26 2015
New Revision: 1687128

URL: http://svn.apache.org/r1687128
Log:
Replace deprecated ArtifactFactory with RepositoryUtils to translate an Aether artifact to
a Maven artifact

Modified:
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Invoker.java
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
    maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java

Modified: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Invoker.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Invoker.java?rev=1687128&r1=1687127&r2=1687128&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Invoker.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Invoker.java
Tue Jun 23 20:34:26 2015
@@ -19,10 +19,10 @@ package org.apache.maven.shared.dependen
  * under the License.
  */
 
-import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
-
 import java.lang.reflect.InvocationTargetException;
 
+import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
+
 /**
  * Invokes method on objects using reflection.
  */
@@ -70,6 +70,27 @@ final class Invoker
         }
         catch ( IllegalAccessException e )
         {
+            throw new DependencyGraphBuilderException( e.getMessage(), e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            throw new DependencyGraphBuilderException( e.getMessage(), e );
+        }
+        catch ( NoSuchMethodException e )
+        {
+            throw new DependencyGraphBuilderException( e.getMessage(), e );
+        }
+    }
+    
+    public static Object invoke( Class<?> objectClazz, String staticMethod, Class<?>
argClazz, Object arg )
+                    throws DependencyGraphBuilderException
+    {
+        try
+        {
+            return objectClazz.getMethod( staticMethod, argClazz ).invoke( null, arg );
+        }
+        catch ( IllegalAccessException e )
+        {
             throw new DependencyGraphBuilderException( e.getMessage(), e );
         }
         catch ( InvocationTargetException e )

Modified: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java?rev=1687128&r1=1687127&r2=1687128&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven31DependencyGraphBuilder.java
Tue Jun 23 20:34:26 2015
@@ -19,10 +19,16 @@ package org.apache.maven.shared.dependen
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.project.DefaultDependencyResolutionRequest;
 import org.apache.maven.project.DependencyResolutionException;
 import org.apache.maven.project.DependencyResolutionRequest;
@@ -40,13 +46,6 @@ import org.eclipse.aether.RepositorySyst
 import org.eclipse.aether.graph.Dependency;
 import org.eclipse.aether.version.VersionConstraint;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 /**
  * Wrapper around Eclipse Aether dependency resolver, used in Maven 3.1.
  *
@@ -62,9 +61,6 @@ public class Maven31DependencyGraphBuild
     @Requirement
     private ProjectDependenciesResolver resolver;
 
-    @Requirement
-    private ArtifactFactory factory;
-
     /**
      * Builds the dependency graph for Maven 3.1+.
      *
@@ -189,11 +185,16 @@ public class Maven31DependencyGraphBuild
     private Artifact getDependencyArtifact( Dependency dep )
     {
         org.eclipse.aether.artifact.Artifact artifact = dep.getArtifact();
-
-        return factory.createDependencyArtifact( artifact.getGroupId(), artifact.getArtifactId(),
-                                                 VersionRange.createFromVersion( artifact.getVersion()
),
-                                                 artifact.getProperty( "type", artifact.getExtension()
),
-                                                 artifact.getClassifier(), dep.getScope(),
dep.isOptional() );
+        
+        try
+        {
+            return (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", org.eclipse.aether.artifact.Artifact.class,
artifact );
+        }
+        catch ( DependencyGraphBuilderException e )
+        {
+            // ReflectionException should not happen
+            throw new RuntimeException( e.getMessage(), e );
+        }
     }
 
     private DependencyNode buildDependencyNode( DependencyNode parent, org.eclipse.aether.graph.DependencyNode
node,

Modified: maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java?rev=1687128&r1=1687127&r2=1687128&view=diff
==============================================================================
--- maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
(original)
+++ maven/shared/trunk/maven-dependency-tree/src/main/java/org/apache/maven/shared/dependency/graph/internal/Maven3DependencyGraphBuilder.java
Tue Jun 23 20:34:26 2015
@@ -19,10 +19,16 @@ package org.apache.maven.shared.dependen
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.project.DefaultDependencyResolutionRequest;
 import org.apache.maven.project.DependencyResolutionException;
 import org.apache.maven.project.DependencyResolutionRequest;
@@ -39,13 +45,6 @@ import org.codehaus.plexus.logging.Abstr
 import org.sonatype.aether.graph.Dependency;
 import org.sonatype.aether.version.VersionConstraint;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
 /**
  * Wrapper around Maven 3 dependency resolver.
  *
@@ -61,9 +60,6 @@ public class Maven3DependencyGraphBuilde
     @Requirement
     private ProjectDependenciesResolver resolver;
 
-    @Requirement
-    private ArtifactFactory factory;
-
     /**
      * Builds the dependency graph for Maven 3.
      *
@@ -175,12 +171,8 @@ public class Maven3DependencyGraphBuilde
 
     private Artifact getDependencyArtifact( Dependency dep )
     {
-        org.sonatype.aether.artifact.Artifact artifact = dep.getArtifact();
-
-        return factory.createDependencyArtifact( artifact.getGroupId(), artifact.getArtifactId(),
-                                                 VersionRange.createFromVersion( artifact.getVersion()
),
-                                                 artifact.getProperty( "type", artifact.getExtension()
),
-                                                 artifact.getClassifier(), dep.getScope(),
dep.isOptional() );
+        
+        return RepositoryUtils.toArtifact( dep.getArtifact() );
     }
 
     private DependencyNode buildDependencyNode( DependencyNode parent, org.sonatype.aether.graph.DependencyNode
node,



Mime
View raw message