maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rfscho...@apache.org
Subject svn commit: r1779258 - in /maven/plugins/trunk/maven-shade-plugin: pom.xml src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java
Date Tue, 17 Jan 2017 20:43:28 GMT
Author: rfscholte
Date: Tue Jan 17 20:43:28 2017
New Revision: 1779258

URL: http://svn.apache.org/viewvc?rev=1779258&view=rev
Log:
[MSHADE-246] Switch to maven-artifact-transfer to support both Aether implementations

Modified:
    maven/plugins/trunk/maven-shade-plugin/pom.xml
    maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
    maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java

Modified: maven/plugins/trunk/maven-shade-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/pom.xml?rev=1779258&r1=1779257&r2=1779258&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-shade-plugin/pom.xml Tue Jan 17 20:43:28 2017
@@ -25,7 +25,7 @@
   <parent>
     <artifactId>maven-plugins</artifactId>
     <groupId>org.apache.maven.plugins</groupId>
-    <version>28</version>
+    <version>30</version>
     <relativePath>../../pom/maven/maven-plugins/pom.xml</relativePath>
   </parent>
 
@@ -93,11 +93,6 @@
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
-      <artifactId>maven-compat</artifactId>
-      <version>${mavenVersion}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
       <artifactId>maven-artifact</artifactId>
       <version>${mavenVersion}</version>
     </dependency>
@@ -114,6 +109,11 @@
       <version>3.0.24</version>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-artifact-transfer</artifactId>
+      <version>0.9.0</version>
+    </dependency>
     <!-- Others -->
     <dependency>
       <groupId>org.ow2.asm</groupId>

Modified: maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java?rev=1779258&r1=1779257&r2=1779258&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java
Tue Jan 17 20:43:28 2017
@@ -37,12 +37,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Exclusion;
@@ -70,6 +65,9 @@ import org.apache.maven.project.ProjectB
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.project.ProjectBuildingResult;
+import org.apache.maven.shared.artifact.DefaultArtifactCoordinate;
+import org.apache.maven.shared.artifact.resolve.ArtifactResolver;
+import org.apache.maven.shared.artifact.resolve.ArtifactResolverException;
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
 import org.apache.maven.shared.dependency.graph.DependencyNode;
@@ -128,12 +126,6 @@ public class ShadeMojo
     private ProjectBuilder projectBuilder;
 
     /**
-     * The artifact metadata source to use.
-     */
-    @Component
-    private ArtifactMetadataSource artifactMetadataSource;
-
-    /**
      * Remote repositories which will be searched for source attachments.
      */
     @Parameter( readonly = true, required = true, defaultValue = "${project.remoteArtifactRepositories}"
)
@@ -146,12 +138,6 @@ public class ShadeMojo
     protected ArtifactRepository localRepository;
 
     /**
-     * Artifact factory, needed to download source jars for inclusion in classpath.
-     */
-    @Component
-    protected ArtifactFactory artifactFactory;
-
-    /**
      * Artifact resolver, needed to download source jars for inclusion in classpath.
      */
     @Component
@@ -705,20 +691,20 @@ public class ShadeMojo
 
     private File resolveArtifactSources( Artifact artifact )
     {
-
-        Artifact resolvedArtifact =
-            artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
-                                                          artifact.getVersion(), "java-source",
"sources" );
-
+        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
+        coordinate.setGroupId( artifact.getGroupId() );
+        coordinate.setArtifactId( artifact.getArtifactId() );
+        coordinate.setVersion( artifact.getVersion() );
+        coordinate.setExtension( "jar" );
+        coordinate.setClassifier( "sources" );
+        
+        Artifact resolvedArtifact = null;
         try
         {
-            artifactResolver.resolve( resolvedArtifact, remoteArtifactRepositories, localRepository
);
-        }
-        catch ( ArtifactNotFoundException e )
-        {
-            // ignore, the jar has not been found
+            resolvedArtifact =
+                artifactResolver.resolveArtifact( session.getProjectBuildingRequest(), coordinate
).getArtifact();
         }
-        catch ( ArtifactResolutionException e )
+        catch ( ArtifactResolverException e )
         {
             getLog().warn( "Could not get sources for " + artifact );
         }

Modified: maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java?rev=1779258&r1=1779257&r2=1779258&view=diff
==============================================================================
--- maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java
(original)
+++ maven/plugins/trunk/maven-shade-plugin/src/test/java/org/apache/maven/plugins/shade/mojo/ShadeMojoTest.java
Tue Jan 17 20:43:28 2017
@@ -18,17 +18,25 @@ package org.apache.maven.plugins.shade.m
  * specific language governing permissions and limitations
  * under the License.
  */
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.artifact.resolver.DefaultArtifactResolver;
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugins.shade.ShadeRequest;
 import org.apache.maven.plugins.shade.Shader;
 import org.apache.maven.plugins.shade.filter.Filter;
@@ -37,19 +45,13 @@ import org.apache.maven.plugins.shade.re
 import org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer;
 import org.apache.maven.plugins.shade.resource.ResourceTransformer;
 import org.apache.maven.project.MavenProject;
+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.apache.maven.shared.artifact.resolve.ArtifactResult;
 import org.codehaus.plexus.PlexusTestCase;
 
-import java.io.File;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
 /**
  * @author Jason van Zyl
  * @author Mauro Talevi
@@ -121,28 +123,51 @@ public class ShadeMojoTest
         createSourcesJar.setAccessible( true );
         createSourcesJar.set( mojo, Boolean.TRUE );
 
-        // configure artifactFactory for mojo
-        ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE
);
-        Field artifactFactoryField = ShadeMojo.class.getDeclaredField( "artifactFactory"
);
-        artifactFactoryField.setAccessible( true );
-        artifactFactoryField.set( mojo, artifactFactory );
-
         // configure artifactResolver (mocked) for mojo
-        ArtifactResolver mockArtifactResolver = new DefaultArtifactResolver()
+        ArtifactResolver mockArtifactResolver = new ArtifactResolver()
         {
-
-            public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepos,
ArtifactRepository repo )
-                throws ArtifactResolutionException, ArtifactNotFoundException
+            @Override
+            public ArtifactResult resolveArtifact( ProjectBuildingRequest req, final Artifact
art )
+                throws ArtifactResolverException
             {
-                // artifact is resolved
-                artifact.setResolved( true );
+                return new ArtifactResult()
+                {
 
-                // set file
-                artifact.setFile( new File(
-                    artifact.getArtifactId() + "-" + artifact.getVersion() + ( artifact.getClassifier()
!= null ? "-"
-                        + artifact.getClassifier() : "" ) + ".jar" ) );
+                    @Override
+                    public Artifact getArtifact()
+                    {
+                        art.setResolved( true );
+                        String fileName = art.getArtifactId() + "-" + art.getVersion()
+                            + ( art.getClassifier() != null ? "-" + art.getClassifier() :
"" ) + ".jar";
+                        art.setFile( new File( fileName ) );
+                        return art;
+                    }
+                };
             }
 
+            @Override
+            public ArtifactResult resolveArtifact( ProjectBuildingRequest req, final ArtifactCoordinate
coordinate )
+                throws ArtifactResolverException
+            {
+                return new ArtifactResult()
+                {
+
+                    @Override
+                    public Artifact getArtifact()
+                    {
+                        Artifact art = mock( Artifact.class );
+                        when( art.getGroupId() ).thenReturn( coordinate.getGroupId() );
+                        when( art.getArtifactId() ).thenReturn( coordinate.getArtifactId()
);
+                        when( art.getType() ).thenReturn( coordinate.getExtension() );
+                        when( art.getClassifier() ).thenReturn( coordinate.getClassifier()
);
+                        when( art.isResolved() ).thenReturn( true );
+                        String fileName = coordinate.getArtifactId() + "-" + coordinate.getVersion()
+                            + ( coordinate.getClassifier() != null ? "-" + coordinate.getClassifier()
: "" ) + ".jar";
+                        when( art.getFile() ).thenReturn( new File( fileName ) );
+                        return art;
+                    }
+                };
+            }
         };
         Field artifactResolverField = ShadeMojo.class.getDeclaredField( "artifactResolver"
);
         artifactResolverField.setAccessible( true );
@@ -154,7 +179,7 @@ public class ShadeMojoTest
         Artifact artifact = new DefaultArtifact( "org.apache.myfaces.core", "myfaces-impl",
                                                  VersionRange.createFromVersion( "2.0.1-SNAPSHOT"
), "compile", "jar",
                                                  null, artifactHandler );
-        mockArtifactResolver.resolve( artifact, null, null ); // setFile and setResolved
+        artifact = mockArtifactResolver.resolveArtifact( null, artifact ).getArtifact();
// setFile and setResolved
         project.setArtifact( artifact );
         Field projectField = ShadeMojo.class.getDeclaredField( "project" );
         projectField.setAccessible( true );
@@ -171,6 +196,10 @@ public class ShadeMojoTest
         filtersField.setAccessible( true );
         filtersField.set( mojo, new ArchiveFilter[]{ archiveFilter } );
 
+        Field sessionField = ShadeMojo.class.getDeclaredField( "session" );
+        sessionField.setAccessible( true );
+        sessionField.set( mojo, mock( MavenSession.class ) );
+
         // invoke getFilters()
         Method getFilters = ShadeMojo.class.getDeclaredMethod( "getFilters", new Class[0]
);
         getFilters.setAccessible( true );



Mime
View raw message