You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2017/04/16 20:49:54 UTC

svn commit: r1791633 - /maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java

Author: michaelo
Date: Sun Apr 16 20:49:54 2017
New Revision: 1791633

URL: http://svn.apache.org/viewvc?rev=1791633&view=rev
Log:
[MDEP-563] Print dependency:resolve-plugins output just like other goal output

Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java?rev=1791633&r1=1791632&r2=1791633&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java Sun Apr 16 20:49:54 2017
@@ -19,9 +19,7 @@ package org.apache.maven.plugins.depende
  * under the License.
  */
 
-import java.io.FileWriter;
 import java.io.IOException;
-import java.io.Writer;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -41,7 +39,6 @@ import org.apache.maven.shared.artifact.
 import org.apache.maven.shared.artifact.resolve.ArtifactResolverException;
 import org.apache.maven.shared.dependencies.DefaultDependableCoordinate;
 import org.apache.maven.shared.dependencies.resolve.DependencyResolverException;
-import org.codehaus.plexus.util.IOUtil;
 
 /**
  * Goal that resolves all project plugins and reports and their dependencies.
@@ -62,12 +59,6 @@ public class ResolvePluginsMojo
     private List<ArtifactRepository> remotePluginRepositories;
 
     /**
-     * If we should exclude transitive dependencies
-     */
-    @Parameter( property = "excludeTransitive", defaultValue = "false" )
-    private boolean excludeTransitive;
-
-    /**
      * Main entry into mojo. Gets the list of dependencies and iterates through
      * displaying the resolved version.
      *
@@ -77,88 +68,99 @@ public class ResolvePluginsMojo
     protected void doExecute()
         throws MojoExecutionException
     {
-        Writer outputWriter = null;
-
         try
         {
             // ideally this should either be DependencyCoordinates or DependencyNode
             final Set<Artifact> plugins = resolvePluginArtifacts();
 
-            if ( this.outputFile != null )
+            StringBuilder sb = new StringBuilder();
+            sb.append( "\n" );
+            sb.append( "The following plugins have been resolved:\n" );
+            if ( plugins == null || plugins.isEmpty() )
             {
-                outputFile.getParentFile()
-                          .mkdirs();
-
-                outputWriter = new FileWriter( outputFile );
+                sb.append( "   none\n" );
             }
-
-            for ( final Artifact plugin : plugins )
+            else
             {
-                String logStr = "Plugin resolved: " + DependencyUtil.getFormattedFileName( plugin, false );
-                if ( !isSilent() )
+                for ( Artifact plugin : plugins )
                 {
-                    this.getLog().info( logStr );
-                }
-
-                if ( outputWriter != null )
-                {
-                    outputWriter.write( logStr );
-                    outputWriter.write( "\n" );
-                }
-
-                if ( !excludeTransitive )
-                {
-                    DefaultDependableCoordinate pluginCoordinate = new DefaultDependableCoordinate();
-                    pluginCoordinate.setGroupId( plugin.getGroupId() );
-                    pluginCoordinate.setArtifactId( plugin.getArtifactId() );
-                    pluginCoordinate.setVersion( plugin.getVersion() );
-
-                    for ( final Artifact artifact : resolveArtifactDependencies( pluginCoordinate ) )
+                    String artifactFilename = null;
+                    if ( outputAbsoluteArtifactFilename )
                     {
-                        logStr =
-                            "    Plugin dependency resolved: " + DependencyUtil.getFormattedFileName( artifact, false );
-
-                        if ( !isSilent() )
+                        try
                         {
-                            this.getLog().info( logStr );
+                            // we want to print the absolute file name here
+                            artifactFilename = plugin.getFile().getAbsoluteFile().getPath();
                         }
+                        catch ( NullPointerException e )
+                        {
+                            // ignore the null pointer, we'll output a null string
+                            artifactFilename = null;
+                        }
+                    }
 
-                        if ( outputWriter != null )
+                    String id = plugin.toString();
+                    sb.append( "   " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" ) + "\n" );
+
+                    if ( !excludeTransitive )
+                    {
+                        DefaultDependableCoordinate pluginCoordinate = new DefaultDependableCoordinate();
+                        pluginCoordinate.setGroupId( plugin.getGroupId() );
+                        pluginCoordinate.setArtifactId( plugin.getArtifactId() );
+                        pluginCoordinate.setVersion( plugin.getVersion() );
+
+                        for ( final Artifact artifact : resolveArtifactDependencies( pluginCoordinate ) )
                         {
-                            outputWriter.write( logStr );
-                            outputWriter.write( "\n" );
+                            artifactFilename = null;
+                            if ( outputAbsoluteArtifactFilename )
+                            {
+                                try
+                                {
+                                    // we want to print the absolute file name here
+                                    artifactFilename = artifact.getFile().getAbsoluteFile().getPath();
+                                }
+                                catch ( NullPointerException e )
+                                {
+                                    // ignore the null pointer, we'll output a null string
+                                    artifactFilename = null;
+                                }
+                            }
+
+                            id = artifact.toString();
+                            sb.append( "      " + id + ( outputAbsoluteArtifactFilename ? ":" + artifactFilename : "" )
+                                       + "\n" );
                         }
                     }
                 }
-            }
+                sb.append( "\n" );
 
-            if ( outputWriter != null )
-            {
-                outputWriter.close();
-                outputWriter = null;
+                String output = sb.toString();
+                if ( outputFile == null )
+                {
+                    DependencyUtil.log( output, getLog() );
+                }
+                else
+                {
+                    DependencyUtil.write( output, outputFile, appendOutput, getLog() );
+                }
             }
         }
         catch ( final IOException e )
         {
-            throw new MojoExecutionException( "Nested:", e );
+            throw new MojoExecutionException( e.getMessage(), e );
         }
         catch ( final ArtifactFilterException e )
         {
-            throw new MojoExecutionException( "Nested:", e );
+            throw new MojoExecutionException( e.getMessage(), e );
         }
         catch ( ArtifactResolverException e )
         {
-            throw new MojoExecutionException( "Nested:", e );
+            throw new MojoExecutionException( e.getMessage(), e );
         }
         catch ( DependencyResolverException e )
         {
-            throw new MojoExecutionException( "Nested:", e );
+            throw new MojoExecutionException( e.getMessage(), e );
         }
-        finally
-        {
-            IOUtil.close( outputWriter );
-        }
-
     }
 
     /**