You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2015/05/30 13:01:40 UTC

svn commit: r1682597 - in /maven/plugins/branches/m-invoker-p-3.0: pom.xml src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java

Author: rfscholte
Date: Sat May 30 11:01:39 2015
New Revision: 1682597

URL: http://svn.apache.org/r1682597
Log:
Sync method signature change ArtifactResolver

Modified:
    maven/plugins/branches/m-invoker-p-3.0/pom.xml
    maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java

Modified: maven/plugins/branches/m-invoker-p-3.0/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-invoker-p-3.0/pom.xml?rev=1682597&r1=1682596&r2=1682597&view=diff
==============================================================================
--- maven/plugins/branches/m-invoker-p-3.0/pom.xml (original)
+++ maven/plugins/branches/m-invoker-p-3.0/pom.xml Sat May 30 11:01:39 2015
@@ -30,7 +30,7 @@ under the License.
   </parent>
 
   <artifactId>maven-invoker-plugin</artifactId>
-  <version>3.0.0-SNAPSHOT</version>
+  <version>3.0-SNAPSHOT</version>
   <packaging>maven-plugin</packaging>
 
   <name>Apache Maven Invoker Plugin</name>
@@ -60,7 +60,7 @@ under the License.
   </distributionManagement>
 
   <properties>
-    <mavenVersion>2.2.1</mavenVersion>
+    <mavenVersion>3.0</mavenVersion>
     <doxiaVersion>1.4</doxiaVersion>
     <doxia-sitetoolsVersion>1.1.4</doxia-sitetoolsVersion>
     <beanshell-groupId>org.beanshell</beanshell-groupId>
@@ -87,11 +87,6 @@ under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
-      <artifactId>maven-project</artifactId>
-      <version>${mavenVersion}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
       <artifactId>maven-model</artifactId>
       <version>${mavenVersion}</version>
     </dependency>
@@ -132,6 +127,12 @@ under the License.
       <artifactId>maven-script-interpreter</artifactId>
       <version>1.1</version>
     </dependency>
+    
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-artifact-transfer</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
 
     <!-- Doxia -->
     <dependency>

Modified: maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java?rev=1682597&r1=1682596&r2=1682597&view=diff
==============================================================================
--- maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java (original)
+++ maven/plugins/branches/m-invoker-p-3.0/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java Sat May 30 11:01:39 2015
@@ -28,16 +28,12 @@ import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 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.installer.ArtifactInstaller;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
 import org.apache.maven.plugin.AbstractMojo;
@@ -48,6 +44,12 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
+import org.apache.maven.shared.artifact.install.ArtifactInstaller;
+import org.apache.maven.shared.artifact.repository.RepositoryManager;
+import org.apache.maven.shared.artifact.resolve.ArtifactResolver;
 import org.codehaus.plexus.util.FileUtils;
 
 /**
@@ -73,22 +75,18 @@ public class InstallMojo
     @Component
     private ArtifactInstaller installer;
 
-    /**
-     * The component used to create artifacts.
-     */
     @Component
-    private ArtifactFactory artifactFactory;
-
+    private ArtifactResolver resolver; 
+    
+    @Component
+    private RepositoryManager repositoryManager;
+    
     /**
      * The component used to create artifacts.
      */
     @Component
-    private ArtifactRepositoryFactory repositoryFactory;
+    private ArtifactFactory artifactFactory;
 
-    /**
-     */
-    @Parameter( property = "localRepository", required = true, readonly = true )
-    private ArtifactRepository localRepository;
 
     /**
      * The path to the local repository into which the project artifacts should be installed for the integration tests.
@@ -155,11 +153,6 @@ public class InstallMojo
 
     /**
      */
-    @Component
-    private ArtifactResolver resolver;
-
-    /**
-     */
     @Parameter( defaultValue = "${project.remoteArtifactRepositories}", readonly = true )
     private List<ArtifactRepository> remoteArtifactRepositories;
 
@@ -168,10 +161,15 @@ public class InstallMojo
     @Parameter( defaultValue = "${project.pluginArtifactRepositories}", readonly = true )
     private List<ArtifactRepository> remotePluginRepositories;
 
+    @Parameter( defaultValue = "${session}", required = true, readonly = true )
+    private MavenSession session;
+    
     /**
      */
     @Component
     private ArtifactMetadataSource artifactMetadataSource;
+    
+    private ProjectBuildingRequest projectBuildingRequest;
 
     /**
      * Performs this mojo's tasks.
@@ -187,16 +185,16 @@ public class InstallMojo
             return;
         }
 
-        ArtifactRepository testRepository = createTestRepository();
+        createTestRepository();
 
         installedArtifacts = new HashSet<String>();
         copiedArtifacts = new HashSet<String>();
 
-        installProjectDependencies( project, reactorProjects, testRepository );
-        installProjectParents( project, testRepository );
-        installProjectArtifacts( project, testRepository );
+        installProjectDependencies( project, reactorProjects );
+        installProjectParents( project );
+        installProjectArtifacts( project );
 
-        installExtraArtifacts( testRepository, extraArtifacts );
+        installExtraArtifacts( extraArtifacts );
     }
 
     /**
@@ -205,14 +203,11 @@ public class InstallMojo
      * apart from the location, the custom repository will be indistinguishable from the real repository such that its
      * usage is transparent to the integration tests.
      *
-     * @return The local repository for the integration tests, never <code>null</code>.
      * @throws MojoExecutionException If the repository could not be created.
      */
-    private ArtifactRepository createTestRepository()
+    private void createTestRepository()
         throws MojoExecutionException
     {
-        ArtifactRepository testRepository = localRepository;
-
         if ( localRepositoryPath != null )
         {
             try
@@ -221,37 +216,35 @@ public class InstallMojo
                 {
                     throw new IOException( "Failed to create directory: " + localRepositoryPath );
                 }
-
-                testRepository =
-                    repositoryFactory.createArtifactRepository( localRepository.getId(),
-                                                                localRepositoryPath.toURL().toExternalForm(),
-                                                                localRepository.getLayout(),
-                                                                localRepository.getSnapshots(),
-                                                                localRepository.getReleases() );
+                
+                projectBuildingRequest =
+                    repositoryManager.setLocalRepositoryBasedir( session.getProjectBuildingRequest(),
+                                                                 localRepositoryPath );
             }
             catch ( Exception e )
             {
                 throw new MojoExecutionException( "Failed to create local repository: " + localRepositoryPath, e );
             }
         }
-
-        return testRepository;
+        else
+        {
+            projectBuildingRequest = session.getProjectBuildingRequest();
+        }
     }
 
     /**
      * Installs the specified artifact to the local repository. Note: This method should only be used for artifacts that
      * originate from the current (reactor) build. Artifacts that have been grabbed from the user's local repository
-     * should be installed to the test repository via {@link #copyArtifact(File, Artifact, ArtifactRepository)}.
+     * should be installed to the test repository via {@link #copyArtifact(File, Artifact)}.
      *
      * @param file The file associated with the artifact, must not be <code>null</code>. This is in most cases the value
      *            of <code>artifact.getFile()</code> with the exception of the main artifact from a project with
      *            packaging "pom". Projects with packaging "pom" have no main artifact file. They have however artifact
      *            metadata (e.g. site descriptors) which needs to be installed.
      * @param artifact The artifact to install, must not be <code>null</code>.
-     * @param testRepository The local repository to install the artifact to, must not be <code>null</code>.
      * @throws MojoExecutionException If the artifact could not be installed (e.g. has no associated file).
      */
-    private void installArtifact( File file, Artifact artifact, ArtifactRepository testRepository )
+    private void installArtifact( File file , Artifact artifact  )
         throws MojoExecutionException
     {
         try
@@ -267,7 +260,7 @@ public class InstallMojo
 
             if ( installedArtifacts.add( artifact.getId() ) )
             {
-                installer.install( file, artifact, testRepository );
+                installer.install( projectBuildingRequest, Collections.singletonList( artifact ) );
             }
             else
             {
@@ -282,17 +275,16 @@ public class InstallMojo
 
     /**
      * Installs the specified artifact to the local repository. This method serves basically the same purpose as
-     * {@link #installArtifact(File, Artifact, ArtifactRepository)} but is meant for artifacts that have been resolved
+     * {@link #installArtifact(File, Artifact)} but is meant for artifacts that have been resolved
      * from the user's local repository (and not the current build outputs). The subtle difference here is that
      * artifacts from the repository have already undergone transformations and these manipulations should not be redone
      * by the artifact installer. For this reason, this method performs plain copy operations to install the artifacts.
      *
      * @param file The file associated with the artifact, must not be <code>null</code>.
      * @param artifact The artifact to install, must not be <code>null</code>.
-     * @param testRepository The local repository to install the artifact to, must not be <code>null</code>.
      * @throws MojoExecutionException If the artifact could not be installed (e.g. has no associated file).
      */
-    private void copyArtifact( File file, Artifact artifact, ArtifactRepository testRepository )
+    private void copyArtifact( File file , Artifact artifact  )
         throws MojoExecutionException
     {
         try
@@ -308,9 +300,14 @@ public class InstallMojo
 
             if ( copiedArtifacts.add( artifact.getId() ) )
             {
-                File destination = new File( testRepository.getBasedir(), testRepository.pathOf( artifact ) );
+                File localRepositoryBasedir = repositoryManager.getLocalRepositoryBasedir( projectBuildingRequest );
+                
+                String pathOfArtifact =
+                    repositoryManager.getPathForLocalArtifact( projectBuildingRequest, artifact );
+                
+                File destination = new File( localRepositoryBasedir, pathOfArtifact );
 
-                getLog().debug( "Installing " + file + " to " + destination );
+                getLog().debug( "Copying " + file + " to " + destination );
 
                 copyFileIfDifferent( file, destination );
 
@@ -321,7 +318,7 @@ public class InstallMojo
                 getLog().debug( "Not re-installing " + artifact + ", " + file );
             }
         }
-        catch ( Exception e )
+        catch ( IOException e )
         {
             throw new MojoExecutionException( "Failed to stage artifact: " + artifact, e );
         }
@@ -341,29 +338,28 @@ public class InstallMojo
      * Installs the main artifact and any attached artifacts of the specified project to the local repository.
      *
      * @param mvnProject The project whose artifacts should be installed, must not be <code>null</code>.
-     * @param testRepository The local repository to install the artifacts to, must not be <code>null</code>.
      * @throws MojoExecutionException If any artifact could not be installed.
      */
-    private void installProjectArtifacts( MavenProject mvnProject, ArtifactRepository testRepository )
+    private void installProjectArtifacts( MavenProject mvnProject  )
         throws MojoExecutionException
     {
         try
         {
             // Install POM (usually attached as metadata but that happens only as a side effect of the Install Plugin)
-            installProjectPom( mvnProject, testRepository );
+            installProjectPom( mvnProject );
 
             // Install the main project artifact (if the project has one, e.g. has no "pom" packaging)
             Artifact mainArtifact = mvnProject.getArtifact();
             if ( mainArtifact.getFile() != null )
             {
-                installArtifact( mainArtifact.getFile(), mainArtifact, testRepository );
+                installArtifact( mainArtifact.getFile(), mainArtifact );
             }
 
             // Install any attached project artifacts
             Collection<Artifact> attachedArtifacts = (Collection<Artifact>) mvnProject.getAttachedArtifacts();
             for ( Artifact attachedArtifact : attachedArtifacts )
             {
-                installArtifact( attachedArtifact.getFile(), attachedArtifact, testRepository );
+                installArtifact( attachedArtifact.getFile(), attachedArtifact );
             }
         }
         catch ( Exception e )
@@ -377,10 +373,9 @@ public class InstallMojo
      * from the reactor must be installed or the forked IT builds will fail when using a clean repository.
      *
      * @param mvnProject The project whose parent POMs should be installed, must not be <code>null</code>.
-     * @param testRepository The local repository to install the POMs to, must not be <code>null</code>.
      * @throws MojoExecutionException If any POM could not be installed.
      */
-    private void installProjectParents( MavenProject mvnProject, ArtifactRepository testRepository )
+    private void installProjectParents( MavenProject mvnProject  )
         throws MojoExecutionException
     {
         try
@@ -389,10 +384,10 @@ public class InstallMojo
             {
                 if ( parent.getFile() == null )
                 {
-                    copyParentPoms( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), testRepository );
+                    copyParentPoms( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
                     break;
                 }
-                installProjectPom( parent, testRepository );
+                installProjectPom( parent );
             }
         }
         catch ( Exception e )
@@ -405,26 +400,27 @@ public class InstallMojo
      * Installs the POM of the specified project to the local repository.
      *
      * @param mvnProject The project whose POM should be installed, must not be <code>null</code>.
-     * @param testRepository The local repository to install the POM to, must not be <code>null</code>.
      * @throws MojoExecutionException If the POM could not be installed.
      */
-    private void installProjectPom( MavenProject mvnProject, ArtifactRepository testRepository )
+    private void installProjectPom( MavenProject mvnProject  )
         throws MojoExecutionException
     {
         try
         {
-            Artifact pomArtifact = null;
+            
+            Artifact artifact;
             if ( "pom".equals( mvnProject.getPackaging() ) )
             {
-                pomArtifact = mvnProject.getArtifact();
+                artifact = new ProjectArtifact( mvnProject );
             }
-            if ( pomArtifact == null )
+            else
             {
-                pomArtifact =
-                    artifactFactory.createProjectArtifact( mvnProject.getGroupId(), mvnProject.getArtifactId(),
-                                                           mvnProject.getVersion() );
+                artifact = mvnProject.getArtifact();
+                ProjectArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, mvnProject.getFile() );
+                artifact.addMetadata( metadata );
             }
-            installArtifact( mvnProject.getFile(), pomArtifact, testRepository );
+            
+            installArtifact( mvnProject.getFile(), artifact );
         }
         catch ( Exception e )
         {
@@ -438,11 +434,9 @@ public class InstallMojo
      *
      * @param mvnProject The project whose dependent projects should be installed, must not be <code>null</code>.
      * @param reactorProjects The set of projects in the reactor build, must not be <code>null</code>.
-     * @param testRepository The local repository to install the POMs to, must not be <code>null</code>.
      * @throws MojoExecutionException If any dependency could not be installed.
      */
-    private void installProjectDependencies( MavenProject mvnProject, Collection<MavenProject> reactorProjects,
-                                             ArtifactRepository testRepository )
+    private void installProjectDependencies( MavenProject mvnProject , Collection<MavenProject> reactorProjects  )
         throws MojoExecutionException
     {
         // keep track if we have passed mvnProject in reactorProjects
@@ -492,7 +486,7 @@ public class InstallMojo
             // copy dependencies that where resolved from the local repo
             for ( Artifact artifact : dependencyArtifacts )
             {
-                copyArtifact( artifact, testRepository );
+                copyArtifact( artifact );
             }
 
             // install dependencies that were resolved from the reactor
@@ -500,8 +494,8 @@ public class InstallMojo
             {
                 MavenProject dependencyProject = projects.get( projectId );
 
-                installProjectArtifacts( dependencyProject, testRepository );
-                installProjectParents( dependencyProject, testRepository );
+                installProjectArtifacts( dependencyProject );
+                installProjectParents( dependencyProject );
             }
         }
         catch ( Exception e )
@@ -510,10 +504,10 @@ public class InstallMojo
         }
     }
 
-    private void copyArtifact( Artifact artifact, ArtifactRepository testRepository )
+    private void copyArtifact( Artifact artifact  )
         throws MojoExecutionException
     {
-        copyPoms( artifact, testRepository );
+        copyPoms( artifact );
 
         Artifact depArtifact =
             artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
@@ -522,22 +516,27 @@ public class InstallMojo
 
         File artifactFile = artifact.getFile();
 
-        copyArtifact( artifactFile, depArtifact, testRepository );
+        copyArtifact( artifactFile, depArtifact );
     }
 
-    private void copyPoms( Artifact artifact, ArtifactRepository testRepository )
+    private void copyPoms( Artifact artifact  )
         throws MojoExecutionException
     {
         Artifact pomArtifact =
             artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
                                                    artifact.getBaseVersion() );
 
-        File pomFile = new File( localRepository.getBasedir(), localRepository.pathOf( pomArtifact ) );
+        File localRepoBasedir = repositoryManager.getLocalRepositoryBasedir( session.getProjectBuildingRequest() );
+
+        String pathOfArtifact =
+            repositoryManager.getPathForLocalArtifact( session.getProjectBuildingRequest(), pomArtifact );
+        
+        File pomFile = new File( localRepoBasedir, pathOfArtifact );
 
         if ( pomFile.isFile() )
         {
-            copyArtifact( pomFile, pomArtifact, testRepository );
-            copyParentPoms( pomFile, testRepository );
+            copyArtifact( pomFile, pomArtifact );
+            copyParentPoms( pomFile );
         }
     }
 
@@ -545,17 +544,16 @@ public class InstallMojo
      * Installs all parent POMs of the specified POM file that are available in the local repository.
      *
      * @param pomFile The path to the POM file whose parents should be installed, must not be <code>null</code>.
-     * @param testRepository The local repository to install the POMs to, must not be <code>null</code>.
      * @throws MojoExecutionException If any (existing) parent POM could not be installed.
      */
-    private void copyParentPoms( File pomFile, ArtifactRepository testRepository )
+    private void copyParentPoms( File pomFile  )
         throws MojoExecutionException
     {
         Model model = PomUtils.loadPom( pomFile );
         Parent parent = model.getParent();
         if ( parent != null )
         {
-            copyParentPoms( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), testRepository );
+            copyParentPoms( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
         }
     }
 
@@ -565,10 +563,9 @@ public class InstallMojo
      * @param groupId The group id of the POM which should be installed, must not be <code>null</code>.
      * @param artifactId The artifact id of the POM which should be installed, must not be <code>null</code>.
      * @param version The version of the POM which should be installed, must not be <code>null</code>.
-     * @param testRepository The local repository to install the POMs to, must not be <code>null</code>.
      * @throws MojoExecutionException If any (existing) parent POM could not be installed.
      */
-    private void copyParentPoms( String groupId, String artifactId, String version, ArtifactRepository testRepository )
+    private void copyParentPoms( String groupId, String artifactId, String version )
         throws MojoExecutionException
     {
         Artifact pomArtifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
@@ -579,15 +576,20 @@ public class InstallMojo
             return;
         }
 
-        File pomFile = new File( localRepository.getBasedir(), localRepository.pathOf( pomArtifact ) );
+        File localRepoBasedir = repositoryManager.getLocalRepositoryBasedir( session.getProjectBuildingRequest() );
+
+        String pathOfArtifact =
+                        repositoryManager.getPathForLocalArtifact( session.getProjectBuildingRequest(), pomArtifact );
+        
+        File pomFile = new File( localRepoBasedir, pathOfArtifact );
         if ( pomFile.isFile() )
         {
-            copyArtifact( pomFile, pomArtifact, testRepository );
-            copyParentPoms( pomFile, testRepository );
+            copyArtifact( pomFile, pomArtifact );
+            copyParentPoms( pomFile );
         }
     }
 
-    private void installExtraArtifacts( ArtifactRepository testRepository, String[] extraArtifacts )
+    private void installExtraArtifacts( String[] extraArtifacts  )
         throws MojoExecutionException
     {
         if ( extraArtifacts == null )
@@ -637,22 +639,17 @@ public class InstallMojo
                 artifact =
                     artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
 
-                ArtifactResolutionResult arr =
-                    resolver.resolveTransitively( Collections.singleton( artifact ), originatingArtifact,
-                                                  remoteRepositories, localRepository, artifactMetadataSource );
-
-                if ( !groupId.equals( artifact.getGroupId() ) || !artifactId.equals( artifact.getArtifactId() )
-                    || !version.equals( artifact.getVersion() ) )
-                {
-                    artifact =
-                        artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
-                    copyPoms( artifact, testRepository );
-                }
+                    resolver.resolveTransitively( projectBuildingRequest, artifact, remoteRepositories );
 
-                for ( Artifact arrArtifact : (Set<Artifact>) arr.getArtifacts() )
-                {
-                    copyArtifact( arrArtifact, testRepository );
-                }
+                // if ( !groupId.equals( artifact.getGroupId() ) || !artifactId.equals( artifact.getArtifactId() )
+                // || !version.equals( artifact.getVersion() ) )
+                // {
+                // artifact =
+                // artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
+                // copyPoms( artifact, testRepository );
+                // }
+                //
+                // copyArtifact( resolvedArtifact, testRepository );
             }
             catch ( Exception e )
             {