You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/05/06 12:15:54 UTC

[GitHub] [maven-dependency-plugin] pmoerenhout opened a new pull request #50: MDEP-648: Add location of listed repository.

pmoerenhout opened a new pull request #50:
URL: https://github.com/apache/maven-dependency-plugin/pull/50


   After maven-artifact-transfer 0.13.0 has been released, the PR will use the new functions from the maven-artifact-transfer to resolve the used repositories, and in verbose mode, also show the (local) location where this repository is defined.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-dependency-plugin] mthmulders commented on a change in pull request #50: MDEP-648: Add location of listed repository.

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #50:
URL: https://github.com/apache/maven-dependency-plugin/pull/50#discussion_r421266798



##########
File path: src/site/apt/usage.apt.vm
##########
@@ -687,6 +687,17 @@ mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
   This goal is used to list all the repositories that this build depends upon. It will show repositories defined in your settings, 
   poms and declared in transitive dependency poms.
 
+  This goal can be executed from the command line:

Review comment:
       Good to see you updated the documentation as well!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-dependency-plugin] mthmulders commented on a change in pull request #50: MDEP-648: Add location of listed repository.

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #50:
URL: https://github.com/apache/maven-dependency-plugin/pull/50#discussion_r421269765



##########
File path: src/main/java/org/apache/maven/plugins/dependency/resolvers/ListRepositoriesMojo.java
##########
@@ -55,22 +110,276 @@
     protected void doExecute()
         throws MojoExecutionException
     {
+
+        for ( ArtifactRepository artifactRepository : remoteRepositories )
+        {
+            verbose( "Maven remote repositories: " + repositoryAsString( artifactRepository ) );
+        }
+
+        final Set<ArtifactRepository> repositories = new HashSet<>();
+        final Set<Artifact> artifacts = new HashSet<>();
+
+        DependencyVisitor visitor = new DependencyVisitor()
+        {
+            @Override
+            public boolean visitEnter( DependencyNode dependencyNode )
+            {
+                repositories.addAll( dependencyNode.getRemoteRepositories() );
+                artifacts.add( dependencyNode.getArtifact() );
+                return true;
+            }
+
+            @Override
+            public boolean visitLeave( DependencyNode dependencyNode )
+            {
+                return true;
+            }
+        };
+
         try
         {
-            CollectorResult collectResult =
-                dependencyCollector.collectDependencies( session.getProjectBuildingRequest(), getProject().getModel() );
+            ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest();
+
+            CollectResult collectResult =
+                dependencyCollector.collectDependencies( projectBuildingRequest, getProject().getModel() );
+
+            for ( Exception e : collectResult.getExceptions() )
+            {
+                throw new MojoExecutionException( "Collect dependencies failed", e );
+            }
+
+            collectResult.getRoot().accept( visitor );
+
+            verbose( "Artifacts used by the build of " + collectResult.getRoot().getArtifact() + ":" );
+            for ( Artifact artifact : artifacts )
+            {
+                verbose( " " + artifact.toString() );
+            }
 
             this.getLog().info( "Repositories used by this build:" );
+            for ( ArtifactRepository repo : repositories )
+            {
+                if ( isVerbose() )
+                {
+                    Set<String> locations = new HashSet<String>();
+                    for ( Mirror mirror : settings.getMirrors() )
+                    {
+                        if ( mirror.getId().equals( repo.getId() )
+                            && ( mirror.getUrl().equals( repo.getUrl() ) ) )
+                        {
+                            locations.add( "Maven settings (user/global)" );
+                        }
+                    }
+
+                    Artifact projectArtifact = getProject().getArtifact();
+                    MavenProject project = getMavenProject( ArtifactUtils.key( projectArtifact ) );
+                    traversePom( repo, projectArtifact, project, locations );
+
+                    for ( Artifact artifact : artifacts )
+                    {
+                        MavenProject artifactProject = getMavenProject( ArtifactUtils.key( artifact ) );
+                        traversePom( repo, artifact, artifactProject, locations );
+                    }
+                    writeRepository( repo, locations );
+                }
+                else
+                {
+                    this.getLog().info( repo.toString() );
+                }
+            }
+        }
+        catch ( DependencyCollectionException e )
+        {
+            throw new MojoExecutionException( "Unable to collect", e );
+        }
+    }
+
+    private void writeRepository( ArtifactRepository artifactRepository, Set<String> locations )
+    {
+        StringBuilder sb = new StringBuilder( 256 );
+        sb.append( artifactRepository.toString() );
+        for ( String location : locations )
+        {
+            sb.append( " location: " ).append( location ).append( System.lineSeparator() );
+        }
+        this.getLog().info( sb.toString() );
+    }
+
+    /**
+     * Parses the given String into GAV artifact coordinate information, adding the given type.
+     *
+     * @param artifactString should respect the format <code>groupId:artifactId[:version]</code>
+     * @param type The extension for the artifact, must not be <code>null</code>.
+     * @return the <code>Artifact</code> object for the <code>artifactString</code> parameter.
+     * @throws MojoExecutionException if the <code>artifactString</code> doesn't respect the format.
+     */
+    private ArtifactCoordinate getArtifactCoordinate( String artifactString, String type )
+        throws MojoExecutionException
+    {
+        if ( org.codehaus.plexus.util.StringUtils.isEmpty( artifactString ) )
+        {
+            throw new IllegalArgumentException( "artifact parameter could not be empty" );
+        }
+
+        String groupId; // required
+        String artifactId; // required
+        String version; // optional
+
+        String[] artifactParts = artifactString.split( ":" );
+        switch ( artifactParts.length )
+        {
+            case 2:
+                groupId = artifactParts[0];
+                artifactId = artifactParts[1];
+                version = Artifact.LATEST_VERSION;
+                break;
+            case 3:
+                groupId = artifactParts[0];
+                artifactId = artifactParts[1];
+                version = artifactParts[2];
+                break;
+            default:
+                throw new MojoExecutionException( "The artifact parameter '" + artifactString
+                    + "' should be conform to: " + "'groupId:artifactId[:version]'." );
+        }
+        return getArtifactCoordinate( groupId, artifactId, version, type );
+    }
+
+    private ArtifactCoordinate getArtifactCoordinate( String groupId, String artifactId, String version, String type )
+    {
+        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
+        coordinate.setGroupId( groupId );
+        coordinate.setArtifactId( artifactId );
+        coordinate.setVersion( version );
+        coordinate.setExtension( type );
+        return coordinate;
+    }
+
+    /**
+     * Retrieves the Maven Project associated with the given artifact String, in the form of
+     * <code>groupId:artifactId[:version]</code>. This resolves the POM artifact at those coordinates and then builds
+     * the Maven project from it.
+     *
+     * @param artifactString Coordinates of the Maven project to get.
+     * @return New Maven project.
+     * @throws MojoExecutionException If there was an error while getting the Maven project.
+     */
+    private MavenProject getMavenProject( String artifactString )
+        throws MojoExecutionException
+    {
+        ArtifactCoordinate coordinate = getArtifactCoordinate( artifactString, "pom" );
+        try
+        {
+            ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
+            pbr.setRemoteRepositories( remoteRepositories );
+            pbr.setProject( null );
+            pbr.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
+            pbr.setResolveDependencies( false );
+            Artifact artifact = artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact();
+            return projectBuilder.build( artifact.getFile(), pbr ).getProject();
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Unable to get the POM for the artifact '" + artifactString
+                + "'. Verify the artifact parameter.", e );
+        }
+    }
+
+    private void traversePom( ArtifactRepository artifactRepository,
+                              Artifact artifact, MavenProject mavenProject, Set<String> locations )
+        throws MojoExecutionException
+    {
+        getLog().debug( "Looking for locations of repository " + repositoryAsString( artifactRepository )
+            + " for " + artifact );
+        if ( mavenProject != null )
+        {
+            for ( Repository repository : mavenProject.getOriginalModel().getRepositories() )
+            {
+                getLog().debug( "Found repository: " + repositoryAsString( repository )
+                    + " @ " + artifact + ":" + mavenProject.getOriginalModel().getPomFile() );
+                if ( isRepositoryEqual( repository, artifactRepository ) )
+                {
+                    locations.add( mavenProject.getModel().getPomFile().toString() );
+                }
+            }
+
+            traverseParentPom( artifactRepository, mavenProject, locations );
+        }
+        else
+        {
+            throw new MojoExecutionException( "No POM for the artifact '" + artifact + "'" );
+        }
+        return;
+    }
 
-            for ( ArtifactRepository repo : collectResult.getRemoteRepositories() )
+    private void traverseParentPom( ArtifactRepository artifactRepository,
+                                    MavenProject mavenProject, Set<String> locations )
+        throws MojoExecutionException
+    {
+        MavenProject parent = mavenProject.getParent();
+        if ( parent != null )
+        {
+            Model originalModel = parent.getOriginalModel();
+            if ( originalModel.getRepositories().size() != 0
+                || originalModel.getPluginRepositories().size() != 0 )
             {
-                this.getLog().info( repo.toString() );
+                String artifactKey =
+                    ArtifactUtils.key( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
+                MavenProject parentPom = getMavenProject( artifactKey );

Review comment:
       It seems to me as if you first concatenate _groupId_, _artifactId_ and _version_ into an _artifactKey_ (line 326), only to pass it to `getMavenProject(String)` which then uses `getArtifactCoordinate` to disassemble then into their original values. Why is that??

##########
File path: src/main/java/org/apache/maven/plugins/dependency/resolvers/ListRepositoriesMojo.java
##########
@@ -55,22 +110,276 @@
     protected void doExecute()
         throws MojoExecutionException
     {
+
+        for ( ArtifactRepository artifactRepository : remoteRepositories )
+        {
+            verbose( "Maven remote repositories: " + repositoryAsString( artifactRepository ) );
+        }
+
+        final Set<ArtifactRepository> repositories = new HashSet<>();
+        final Set<Artifact> artifacts = new HashSet<>();
+
+        DependencyVisitor visitor = new DependencyVisitor()
+        {
+            @Override
+            public boolean visitEnter( DependencyNode dependencyNode )
+            {
+                repositories.addAll( dependencyNode.getRemoteRepositories() );
+                artifacts.add( dependencyNode.getArtifact() );
+                return true;
+            }
+
+            @Override
+            public boolean visitLeave( DependencyNode dependencyNode )
+            {
+                return true;
+            }
+        };
+
         try
         {
-            CollectorResult collectResult =
-                dependencyCollector.collectDependencies( session.getProjectBuildingRequest(), getProject().getModel() );
+            ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest();
+
+            CollectResult collectResult =
+                dependencyCollector.collectDependencies( projectBuildingRequest, getProject().getModel() );
+
+            for ( Exception e : collectResult.getExceptions() )
+            {
+                throw new MojoExecutionException( "Collect dependencies failed", e );
+            }
+
+            collectResult.getRoot().accept( visitor );
+
+            verbose( "Artifacts used by the build of " + collectResult.getRoot().getArtifact() + ":" );
+            for ( Artifact artifact : artifacts )
+            {
+                verbose( " " + artifact.toString() );
+            }
 
             this.getLog().info( "Repositories used by this build:" );
+            for ( ArtifactRepository repo : repositories )
+            {
+                if ( isVerbose() )
+                {
+                    Set<String> locations = new HashSet<String>();
+                    for ( Mirror mirror : settings.getMirrors() )
+                    {
+                        if ( mirror.getId().equals( repo.getId() )
+                            && ( mirror.getUrl().equals( repo.getUrl() ) ) )
+                        {
+                            locations.add( "Maven settings (user/global)" );
+                        }
+                    }
+
+                    Artifact projectArtifact = getProject().getArtifact();
+                    MavenProject project = getMavenProject( ArtifactUtils.key( projectArtifact ) );
+                    traversePom( repo, projectArtifact, project, locations );
+
+                    for ( Artifact artifact : artifacts )
+                    {
+                        MavenProject artifactProject = getMavenProject( ArtifactUtils.key( artifact ) );
+                        traversePom( repo, artifact, artifactProject, locations );
+                    }
+                    writeRepository( repo, locations );
+                }
+                else
+                {
+                    this.getLog().info( repo.toString() );
+                }
+            }
+        }
+        catch ( DependencyCollectionException e )
+        {
+            throw new MojoExecutionException( "Unable to collect", e );
+        }
+    }
+
+    private void writeRepository( ArtifactRepository artifactRepository, Set<String> locations )
+    {
+        StringBuilder sb = new StringBuilder( 256 );
+        sb.append( artifactRepository.toString() );
+        for ( String location : locations )
+        {
+            sb.append( " location: " ).append( location ).append( System.lineSeparator() );
+        }
+        this.getLog().info( sb.toString() );
+    }
+
+    /**
+     * Parses the given String into GAV artifact coordinate information, adding the given type.
+     *
+     * @param artifactString should respect the format <code>groupId:artifactId[:version]</code>
+     * @param type The extension for the artifact, must not be <code>null</code>.
+     * @return the <code>Artifact</code> object for the <code>artifactString</code> parameter.
+     * @throws MojoExecutionException if the <code>artifactString</code> doesn't respect the format.
+     */
+    private ArtifactCoordinate getArtifactCoordinate( String artifactString, String type )
+        throws MojoExecutionException
+    {
+        if ( org.codehaus.plexus.util.StringUtils.isEmpty( artifactString ) )
+        {
+            throw new IllegalArgumentException( "artifact parameter could not be empty" );
+        }
+
+        String groupId; // required
+        String artifactId; // required
+        String version; // optional
+
+        String[] artifactParts = artifactString.split( ":" );
+        switch ( artifactParts.length )
+        {
+            case 2:
+                groupId = artifactParts[0];
+                artifactId = artifactParts[1];
+                version = Artifact.LATEST_VERSION;
+                break;
+            case 3:
+                groupId = artifactParts[0];
+                artifactId = artifactParts[1];
+                version = artifactParts[2];
+                break;
+            default:
+                throw new MojoExecutionException( "The artifact parameter '" + artifactString
+                    + "' should be conform to: " + "'groupId:artifactId[:version]'." );
+        }
+        return getArtifactCoordinate( groupId, artifactId, version, type );
+    }
+
+    private ArtifactCoordinate getArtifactCoordinate( String groupId, String artifactId, String version, String type )
+    {
+        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
+        coordinate.setGroupId( groupId );
+        coordinate.setArtifactId( artifactId );
+        coordinate.setVersion( version );
+        coordinate.setExtension( type );
+        return coordinate;
+    }
+
+    /**
+     * Retrieves the Maven Project associated with the given artifact String, in the form of
+     * <code>groupId:artifactId[:version]</code>. This resolves the POM artifact at those coordinates and then builds
+     * the Maven project from it.
+     *
+     * @param artifactString Coordinates of the Maven project to get.
+     * @return New Maven project.
+     * @throws MojoExecutionException If there was an error while getting the Maven project.
+     */
+    private MavenProject getMavenProject( String artifactString )
+        throws MojoExecutionException
+    {
+        ArtifactCoordinate coordinate = getArtifactCoordinate( artifactString, "pom" );
+        try
+        {
+            ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
+            pbr.setRemoteRepositories( remoteRepositories );
+            pbr.setProject( null );
+            pbr.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
+            pbr.setResolveDependencies( false );
+            Artifact artifact = artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact();
+            return projectBuilder.build( artifact.getFile(), pbr ).getProject();
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Unable to get the POM for the artifact '" + artifactString
+                + "'. Verify the artifact parameter.", e );
+        }
+    }
+
+    private void traversePom( ArtifactRepository artifactRepository,
+                              Artifact artifact, MavenProject mavenProject, Set<String> locations )
+        throws MojoExecutionException
+    {
+        getLog().debug( "Looking for locations of repository " + repositoryAsString( artifactRepository )
+            + " for " + artifact );
+        if ( mavenProject != null )
+        {
+            for ( Repository repository : mavenProject.getOriginalModel().getRepositories() )
+            {
+                getLog().debug( "Found repository: " + repositoryAsString( repository )
+                    + " @ " + artifact + ":" + mavenProject.getOriginalModel().getPomFile() );
+                if ( isRepositoryEqual( repository, artifactRepository ) )
+                {
+                    locations.add( mavenProject.getModel().getPomFile().toString() );
+                }
+            }
+
+            traverseParentPom( artifactRepository, mavenProject, locations );
+        }
+        else
+        {
+            throw new MojoExecutionException( "No POM for the artifact '" + artifact + "'" );
+        }
+        return;
+    }
 
-            for ( ArtifactRepository repo : collectResult.getRemoteRepositories() )
+    private void traverseParentPom( ArtifactRepository artifactRepository,
+                                    MavenProject mavenProject, Set<String> locations )
+        throws MojoExecutionException
+    {
+        MavenProject parent = mavenProject.getParent();
+        if ( parent != null )
+        {
+            Model originalModel = parent.getOriginalModel();
+            if ( originalModel.getRepositories().size() != 0
+                || originalModel.getPluginRepositories().size() != 0 )
             {
-                this.getLog().info( repo.toString() );
+                String artifactKey =
+                    ArtifactUtils.key( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
+                MavenProject parentPom = getMavenProject( artifactKey );

Review comment:
       It seems to me as if you first concatenate _groupId_, _artifactId_ and _version_ into an _artifactKey_ (line 326), only to pass it to `getMavenProject(String)` which then uses `getArtifactCoordinate` to disassemble then into their original values. Why is that?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-dependency-plugin] mthmulders commented on a change in pull request #50: MDEP-648: Add location of listed repository.

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #50:
URL: https://github.com/apache/maven-dependency-plugin/pull/50#discussion_r421266319



##########
File path: src/main/java/org/apache/maven/plugins/dependency/resolvers/ListRepositoriesMojo.java
##########
@@ -40,12 +61,46 @@
 public class ListRepositoriesMojo
     extends AbstractDependencyMojo
 {
+    /**
+     * Maven Project Builder component.
+     */
+    @Component
+    private ProjectBuilder projectBuilder;
+
     /**
      * Dependency collector, needed to resolve dependencies.
      */
     @Component( role = DependencyCollector.class )
     private DependencyCollector dependencyCollector;
 
+    /**
+     * Component used to resolve artifacts and download their files from remote repositories.
+     */
+    @Component
+    private ArtifactResolver artifactResolver;
+
+    /**
+     * The system settings for Maven. This is the instance resulting from
+     * merging global and user-level settings files.
+     */
+    @Parameter( defaultValue = "${settings}", readonly = true, required = true )
+    private Settings settings;
+
+    /**
+     * Remote repositories used for the project.
+     */
+    @Parameter( defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true )
+    private List<ArtifactRepository> remoteRepositories;
+
+    /**
+     * Sets whether the plugin runs in verbose mode. As of plugin version 2.3, the default value is derived from Maven's
+     * global debug flag (compare command line switch <code>-X</code>). <br/>
+     *
+     * @since 3.1.2

Review comment:
       The `@since` contradicts the first line of the Javadoc.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-dependency-plugin] mthmulders commented on a change in pull request #50: MDEP-648: Add location of listed repository.

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #50:
URL: https://github.com/apache/maven-dependency-plugin/pull/50#discussion_r421265856



##########
File path: pom.xml
##########
@@ -254,7 +257,7 @@ under the License.
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
-      <version>3.6</version>

Review comment:
       Is this related to the functionality that you've implemented?

##########
File path: pom.xml
##########
@@ -317,7 +320,7 @@ under the License.
     <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-http-lightweight</artifactId>
-      <version>3.3.4</version>

Review comment:
       Is this related to the functionality that you've implemented?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-dependency-plugin] mthmulders commented on a change in pull request #50: MDEP-648: Add location of listed repository.

Posted by GitBox <gi...@apache.org>.
mthmulders commented on a change in pull request #50:
URL: https://github.com/apache/maven-dependency-plugin/pull/50#discussion_r421267390



##########
File path: src/main/java/org/apache/maven/plugins/dependency/resolvers/ListRepositoriesMojo.java
##########
@@ -55,22 +110,276 @@
     protected void doExecute()
         throws MojoExecutionException
     {
+
+        for ( ArtifactRepository artifactRepository : remoteRepositories )
+        {
+            verbose( "Maven remote repositories: " + repositoryAsString( artifactRepository ) );
+        }
+
+        final Set<ArtifactRepository> repositories = new HashSet<>();
+        final Set<Artifact> artifacts = new HashSet<>();
+
+        DependencyVisitor visitor = new DependencyVisitor()
+        {
+            @Override
+            public boolean visitEnter( DependencyNode dependencyNode )
+            {
+                repositories.addAll( dependencyNode.getRemoteRepositories() );
+                artifacts.add( dependencyNode.getArtifact() );
+                return true;
+            }
+
+            @Override
+            public boolean visitLeave( DependencyNode dependencyNode )
+            {
+                return true;
+            }
+        };
+
         try
         {
-            CollectorResult collectResult =
-                dependencyCollector.collectDependencies( session.getProjectBuildingRequest(), getProject().getModel() );
+            ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest();
+
+            CollectResult collectResult =
+                dependencyCollector.collectDependencies( projectBuildingRequest, getProject().getModel() );
+
+            for ( Exception e : collectResult.getExceptions() )
+            {
+                throw new MojoExecutionException( "Collect dependencies failed", e );
+            }
+
+            collectResult.getRoot().accept( visitor );
+
+            verbose( "Artifacts used by the build of " + collectResult.getRoot().getArtifact() + ":" );
+            for ( Artifact artifact : artifacts )
+            {
+                verbose( " " + artifact.toString() );
+            }
 
             this.getLog().info( "Repositories used by this build:" );
+            for ( ArtifactRepository repo : repositories )
+            {
+                if ( isVerbose() )
+                {
+                    Set<String> locations = new HashSet<String>();
+                    for ( Mirror mirror : settings.getMirrors() )
+                    {
+                        if ( mirror.getId().equals( repo.getId() )
+                            && ( mirror.getUrl().equals( repo.getUrl() ) ) )
+                        {
+                            locations.add( "Maven settings (user/global)" );
+                        }
+                    }
+
+                    Artifact projectArtifact = getProject().getArtifact();
+                    MavenProject project = getMavenProject( ArtifactUtils.key( projectArtifact ) );
+                    traversePom( repo, projectArtifact, project, locations );
+
+                    for ( Artifact artifact : artifacts )
+                    {
+                        MavenProject artifactProject = getMavenProject( ArtifactUtils.key( artifact ) );
+                        traversePom( repo, artifact, artifactProject, locations );
+                    }
+                    writeRepository( repo, locations );
+                }
+                else
+                {
+                    this.getLog().info( repo.toString() );
+                }
+            }
+        }
+        catch ( DependencyCollectionException e )
+        {
+            throw new MojoExecutionException( "Unable to collect", e );
+        }
+    }
+
+    private void writeRepository( ArtifactRepository artifactRepository, Set<String> locations )
+    {
+        StringBuilder sb = new StringBuilder( 256 );
+        sb.append( artifactRepository.toString() );
+        for ( String location : locations )
+        {
+            sb.append( " location: " ).append( location ).append( System.lineSeparator() );
+        }
+        this.getLog().info( sb.toString() );
+    }
+
+    /**
+     * Parses the given String into GAV artifact coordinate information, adding the given type.
+     *
+     * @param artifactString should respect the format <code>groupId:artifactId[:version]</code>
+     * @param type The extension for the artifact, must not be <code>null</code>.
+     * @return the <code>Artifact</code> object for the <code>artifactString</code> parameter.
+     * @throws MojoExecutionException if the <code>artifactString</code> doesn't respect the format.
+     */
+    private ArtifactCoordinate getArtifactCoordinate( String artifactString, String type )
+        throws MojoExecutionException
+    {
+        if ( org.codehaus.plexus.util.StringUtils.isEmpty( artifactString ) )
+        {
+            throw new IllegalArgumentException( "artifact parameter could not be empty" );
+        }
+
+        String groupId; // required
+        String artifactId; // required
+        String version; // optional
+
+        String[] artifactParts = artifactString.split( ":" );
+        switch ( artifactParts.length )
+        {
+            case 2:
+                groupId = artifactParts[0];
+                artifactId = artifactParts[1];
+                version = Artifact.LATEST_VERSION;
+                break;
+            case 3:
+                groupId = artifactParts[0];
+                artifactId = artifactParts[1];
+                version = artifactParts[2];
+                break;
+            default:
+                throw new MojoExecutionException( "The artifact parameter '" + artifactString
+                    + "' should be conform to: " + "'groupId:artifactId[:version]'." );
+        }
+        return getArtifactCoordinate( groupId, artifactId, version, type );
+    }
+
+    private ArtifactCoordinate getArtifactCoordinate( String groupId, String artifactId, String version, String type )
+    {
+        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
+        coordinate.setGroupId( groupId );
+        coordinate.setArtifactId( artifactId );
+        coordinate.setVersion( version );
+        coordinate.setExtension( type );
+        return coordinate;
+    }
+
+    /**
+     * Retrieves the Maven Project associated with the given artifact String, in the form of
+     * <code>groupId:artifactId[:version]</code>. This resolves the POM artifact at those coordinates and then builds
+     * the Maven project from it.
+     *
+     * @param artifactString Coordinates of the Maven project to get.
+     * @return New Maven project.
+     * @throws MojoExecutionException If there was an error while getting the Maven project.
+     */
+    private MavenProject getMavenProject( String artifactString )
+        throws MojoExecutionException
+    {
+        ArtifactCoordinate coordinate = getArtifactCoordinate( artifactString, "pom" );
+        try
+        {
+            ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
+            pbr.setRemoteRepositories( remoteRepositories );
+            pbr.setProject( null );
+            pbr.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
+            pbr.setResolveDependencies( false );
+            Artifact artifact = artifactResolver.resolveArtifact( pbr, coordinate ).getArtifact();
+            return projectBuilder.build( artifact.getFile(), pbr ).getProject();
+        }
+        catch ( Exception e )
+        {
+            throw new MojoExecutionException( "Unable to get the POM for the artifact '" + artifactString
+                + "'. Verify the artifact parameter.", e );
+        }
+    }
+
+    private void traversePom( ArtifactRepository artifactRepository,
+                              Artifact artifact, MavenProject mavenProject, Set<String> locations )
+        throws MojoExecutionException
+    {
+        getLog().debug( "Looking for locations of repository " + repositoryAsString( artifactRepository )
+            + " for " + artifact );
+        if ( mavenProject != null )
+        {
+            for ( Repository repository : mavenProject.getOriginalModel().getRepositories() )
+            {
+                getLog().debug( "Found repository: " + repositoryAsString( repository )
+                    + " @ " + artifact + ":" + mavenProject.getOriginalModel().getPomFile() );
+                if ( isRepositoryEqual( repository, artifactRepository ) )
+                {
+                    locations.add( mavenProject.getModel().getPomFile().toString() );
+                }
+            }
+
+            traverseParentPom( artifactRepository, mavenProject, locations );
+        }
+        else
+        {
+            throw new MojoExecutionException( "No POM for the artifact '" + artifact + "'" );
+        }
+        return;
+    }
 
-            for ( ArtifactRepository repo : collectResult.getRemoteRepositories() )
+    private void traverseParentPom( ArtifactRepository artifactRepository,
+                                    MavenProject mavenProject, Set<String> locations )
+        throws MojoExecutionException
+    {
+        MavenProject parent = mavenProject.getParent();
+        if ( parent != null )
+        {
+            Model originalModel = parent.getOriginalModel();
+            if ( originalModel.getRepositories().size() != 0
+                || originalModel.getPluginRepositories().size() != 0 )
             {
-                this.getLog().info( repo.toString() );
+                String artifactKey =
+                    ArtifactUtils.key( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
+                MavenProject parentPom = getMavenProject( artifactKey );
+
+                for ( Repository repository : originalModel.getRepositories() )
+                {
+                    getLog().debug( "Found parent repository " + repositoryAsString( repository )
+                        + " @ " + parentPom.getArtifact() + ":" + parentPom.getFile() );
+                    if ( isRepositoryEqual( repository, artifactRepository ) )
+                    {
+                        locations.add( parentPom.getFile().toString() );
+                    }
+                }
             }
+            traverseParentPom( artifactRepository, parent, locations );
         }
-        catch ( DependencyCollectorException e )
+        return;
+    }
+
+    private String repositoryAsString( Repository repository )
+    {
+        StringBuilder sb = new StringBuilder( 32 );
+        sb.append( repository.getId() );
+        sb.append( " (" );
+        sb.append( repository.getUrl() );
+        sb.append( ")" );
+        return sb.toString();
+    }
+
+    private String repositoryAsString( ArtifactRepository repository )
+    {
+        StringBuilder sb = new StringBuilder( 32 );
+        sb.append( repository.getId() );
+        sb.append( " (" );
+        sb.append( repository.getUrl() );
+        sb.append( ")" );
+        return sb.toString();
+    }
+
+    private boolean isVerbose()
+    {
+        return ( verbose || getLog().isDebugEnabled() );

Review comment:
       It's a bit strange that `isVerbose` checks for `log.isDebugEnabled()`, while there is a `verbose` flag already which is triggered (according to its Javadoc) by the `-X` flag in the CLI.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org