This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 9efcc6e  [MINVOKER-249] InstallMojo extraArtifacts are always 
downloaded (optionally local repo must checked first) (#5)
9efcc6e is described below

commit 9efcc6e1d827f4c7cdc12f7123129e3f77721f80
Author: Olivier Lamy <[email protected]>
AuthorDate: Mon Sep 2 12:48:16 2019 +1000

    [MINVOKER-249] InstallMojo extraArtifacts are always downloaded (optionally 
local repo must checked first) (#5)
    
    Signed-off-by: olivier lamy <[email protected]>
---
 .../apache/maven/plugins/invoker/InstallMojo.java  | 68 ++++++++++++++++------
 1 file changed, 49 insertions(+), 19 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java 
b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
index 63543c9..bf9b721 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InstallMojo.java
@@ -19,16 +19,19 @@ package org.apache.maven.plugins.invoker;
  * under the License.
  */
 
+
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -46,6 +49,7 @@ import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter;
 import org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller;
+import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
 import 
org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate;
 import 
org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
 import 
org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;
@@ -161,6 +165,15 @@ public class InstallMojo
     @Component
     private DependencyResolver resolver;
 
+
+    /**
+     * if the local repository is not used as test repo, the parameter can 
force get artifacts from local repo
+     * if available instead of download the artifacts again.
+     * @since 3.2.1
+     */
+    @Parameter( property = "invoker.useLocalRepository", defaultValue = 
"false" )
+    private boolean useLocalRepository;
+
     private ProjectBuildingRequest projectBuildingRequest;
 
     /**
@@ -486,22 +499,6 @@ public class InstallMojo
         }
     }
 
-    protected boolean isInProjectReferences( Collection<MavenProject> 
references, MavenProject project )
-    {
-        if ( references == null || references.isEmpty() )
-        {
-            return false;
-        }
-        for ( MavenProject mavenProject : references )
-        {
-            if ( StringUtils.equals( mavenProject.getId(), project.getId() ) )
-            {
-                return true;
-            }
-        }
-        return false;
-    }
-
     private void copyArtifact( Artifact artifact )
         throws MojoExecutionException
     {
@@ -618,8 +615,30 @@ public class InstallMojo
                 coordinate.setType( type );
                 coordinate.setClassifier( classifier );
 
-                resolver.resolveDependencies( projectBuildingRequest, 
coordinate,
-                                              new PatternExclusionsFilter( 
Collections.<String>emptyList() ) );
+
+                if ( !localRepository.getBasedir().equals( 
localRepositoryPath.getPath() ) && useLocalRepository )
+                {
+                    String previousId = localRepository.getId();
+                    try
+                    {
+                        // using another request with the correct target repo
+                        ProjectBuildingRequest projectBuildingRequest = 
repositoryManager
+                                .setLocalRepositoryBasedir( 
session.getProjectBuildingRequest(),
+                                        localRepositoryPath );
+                        projectBuildingRequest.setRemoteRepositories( 
Arrays.asList( localRepository ) );
+                        resolver.resolveDependencies( projectBuildingRequest, 
coordinate,
+                                new PatternExclusionsFilter( 
Collections.<String>emptyList() ) );
+                    }
+                    finally
+                    {
+                        localRepository.setId( previousId );
+                    }
+                }
+                else
+                {
+                    resolver.resolveDependencies( projectBuildingRequest, 
coordinate,
+                            new PatternExclusionsFilter( 
Collections.<String>emptyList() ) );
+                }
             }
             catch ( DependencyResolverException e )
             {
@@ -628,4 +647,15 @@ public class InstallMojo
         }
     }
 
+    // FIXME could be simplify with using lambda... maybe in the next 
century... :P
+    private List<Artifact> toArtifactsList( Iterable<ArtifactResult> 
artifactResults )
+    {
+        List<Artifact> artifacts = new ArrayList<>( );
+        for ( ArtifactResult artifactResult : artifactResults )
+        {
+            artifacts.add( artifactResult.getArtifact() );
+        }
+        return artifacts;
+    }
+
 }

Reply via email to