Skip to content

Commit

Permalink
[MNG-6675] Make Resolver debug log messages for projects and plugins …
Browse files Browse the repository at this point in the history
…consistent

This closes #124 and closes #253
  • Loading branch information
ChristianSchulte authored and michael-o committed Jun 15, 2019
1 parent 3d76fae commit c2f13f7
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* under the License.
*/

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -30,6 +31,7 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
Expand All @@ -54,6 +56,7 @@
import org.eclipse.aether.util.artifact.JavaScopes;
import org.eclipse.aether.util.filter.AndDependencyFilter;
import org.eclipse.aether.util.filter.ScopeDependencyFilter;
import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
import org.eclipse.aether.util.graph.selector.AndDependencySelector;
import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
Expand Down Expand Up @@ -221,6 +224,7 @@ private DependencyNode resolveInternal( Plugin plugin, Artifact pluginArtifact,
return node;
}

// Keep this class in sync with org.apache.maven.project.DefaultProjectDependenciesResolver.GraphLogger
class GraphLogger
implements DependencyVisitor
{
Expand All @@ -234,10 +238,67 @@ public boolean visitEnter( DependencyNode node )
org.eclipse.aether.graph.Dependency dep = node.getDependency();
if ( dep != null )
{
Artifact art = dep.getArtifact();
org.eclipse.aether.artifact.Artifact art = dep.getArtifact();

buffer.append( art );
buffer.append( ':' ).append( dep.getScope() );
if ( StringUtils.isNotEmpty( dep.getScope() ) )
{
buffer.append( ':' ).append( dep.getScope() );
}

if ( dep.isOptional() )
{
buffer.append( " (optional)" );
}

// TODO We currently cannot tell which <dependencyManagement> section contained the management
// information. When the resolver provides this information, these log messages should be updated
// to contain it.
if ( ( node.getManagedBits() & DependencyNode.MANAGED_SCOPE ) == DependencyNode.MANAGED_SCOPE )
{
final String premanagedScope = DependencyManagerUtils.getPremanagedScope( node );
buffer.append( " (scope managed from " );
buffer.append( StringUtils.defaultString( premanagedScope, "default" ) );
buffer.append( ')' );
}

if ( ( node.getManagedBits() & DependencyNode.MANAGED_VERSION ) == DependencyNode.MANAGED_VERSION )
{
final String premanagedVersion = DependencyManagerUtils.getPremanagedVersion( node );
buffer.append( " (version managed from " );
buffer.append( StringUtils.defaultString( premanagedVersion, "default" ) );
buffer.append( ')' );
}

if ( ( node.getManagedBits() & DependencyNode.MANAGED_OPTIONAL ) == DependencyNode.MANAGED_OPTIONAL )
{
final Boolean premanagedOptional = DependencyManagerUtils.getPremanagedOptional( node );
buffer.append( " (optionality managed from " );
buffer.append( StringUtils.defaultString( premanagedOptional, "default" ) );
buffer.append( ')' );
}

if ( ( node.getManagedBits() & DependencyNode.MANAGED_EXCLUSIONS )
== DependencyNode.MANAGED_EXCLUSIONS )
{
final Collection<org.eclipse.aether.graph.Exclusion> premanagedExclusions =
DependencyManagerUtils.getPremanagedExclusions( node );

buffer.append( " (exclusions managed from " );
buffer.append( StringUtils.defaultString( premanagedExclusions, "default" ) );
buffer.append( ')' );
}

if ( ( node.getManagedBits() & DependencyNode.MANAGED_PROPERTIES )
== DependencyNode.MANAGED_PROPERTIES )
{
final Map<String, String> premanagedProperties =
DependencyManagerUtils.getPremanagedProperties( node );

buffer.append( " (properties managed from " );
buffer.append( StringUtils.defaultString( premanagedProperties, "default" ) );
buffer.append( ')' );
}
}

logger.debug( buffer.toString() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ private void process( DefaultDependencyResolutionResult result, Collection<Artif
}
}

// Keep this class in sync with org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.GraphLogger
class GraphLogger
implements DependencyVisitor
{
Expand All @@ -251,10 +252,18 @@ public boolean visitEnter( DependencyNode node )
org.eclipse.aether.artifact.Artifact art = dep.getArtifact();

buffer.append( art );
buffer.append( ':' ).append( dep.getScope() );
if ( StringUtils.isNotEmpty( dep.getScope() ) )
{
buffer.append( ':' ).append( dep.getScope() );
}

if ( dep.isOptional() )
{
buffer.append( " (optional)" );
}

// TODO We currently cannot tell which <dependencyManagement> section contained the management
// information. When resolver 1.1 provides this information, these log messages should be updated
// information. When the resolver provides this information, these log messages should be updated
// to contain it.
if ( ( node.getManagedBits() & DependencyNode.MANAGED_SCOPE ) == DependencyNode.MANAGED_SCOPE )
{
Expand All @@ -281,24 +290,25 @@ public boolean visitEnter( DependencyNode node )
}

if ( ( node.getManagedBits() & DependencyNode.MANAGED_EXCLUSIONS )
== DependencyNode.MANAGED_EXCLUSIONS )
== DependencyNode.MANAGED_EXCLUSIONS )
{
// TODO As of resolver 1.1, use DependencyManagerUtils.getPremanagedExclusions( node ).
// The resolver 1.0.x releases do not record premanaged state of exclusions.
buffer.append( " (exclusions managed)" );
final Collection<org.eclipse.aether.graph.Exclusion> premanagedExclusions =
DependencyManagerUtils.getPremanagedExclusions( node );

buffer.append( " (exclusions managed from " );
buffer.append( StringUtils.defaultString( premanagedExclusions, "default" ) );
buffer.append( ')' );
}

if ( ( node.getManagedBits() & DependencyNode.MANAGED_PROPERTIES )
== DependencyNode.MANAGED_PROPERTIES )
== DependencyNode.MANAGED_PROPERTIES )
{
// TODO As of resolver 1.1, use DependencyManagerUtils.getPremanagedProperties( node ).
// The resolver 1.0.x releases do not record premanaged state of properties.
buffer.append( " (properties managed)" );
}
final Map<String, String> premanagedProperties =
DependencyManagerUtils.getPremanagedProperties( node );

if ( dep.isOptional() )
{
buffer.append( " (optional)" );
buffer.append( " (properties managed from " );
buffer.append( StringUtils.defaultString( premanagedProperties, "default" ) );
buffer.append( ')' );
}
}
else
Expand Down

0 comments on commit c2f13f7

Please sign in to comment.