Skip to content

Commit

Permalink
[MDEP-563] Print dependency:resolve-plugins output just like other go…
Browse files Browse the repository at this point in the history
…al output

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1791633 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
michael-o committed Apr 16, 2017
1 parent 9ffcd3f commit 5147267
Showing 1 changed file with 61 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
* 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;
Expand All @@ -41,7 +39,6 @@
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.
Expand All @@ -61,12 +58,6 @@ public class ResolvePluginsMojo
@Parameter( defaultValue = "${project.pluginArtifactRepositories}", readonly = true, required = true )
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.
Expand All @@ -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 );
}

}

/**
Expand Down

0 comments on commit 5147267

Please sign in to comment.