Skip to content

Commit

Permalink
[MNG-8045] Use DependencyGraphDumper instead of own implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Feb 8, 2024
1 parent c88afd4 commit c2ec76c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import javax.inject.Named;
import javax.inject.Singleton;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.api.DependencyScope;
Expand All @@ -43,7 +41,6 @@
import org.eclipse.aether.collection.DependencyCollectionException;
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.graph.DependencyVisitor;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactDescriptorException;
import org.eclipse.aether.resolution.ArtifactDescriptorRequest;
Expand All @@ -55,7 +52,7 @@
import org.eclipse.aether.resolution.DependencyResult;
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.visitor.DependencyGraphDumper;
import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -225,7 +222,7 @@ private DependencyResult resolveInternal(
node = repoSystem.collectDependencies(pluginSession, request).getRoot();

if (logger.isDebugEnabled()) {
node.accept(new GraphLogger());
node.accept(new DependencyGraphDumper(logger::debug));
}

depRequest.setRoot(node);
Expand All @@ -236,79 +233,4 @@ private DependencyResult resolveInternal(
throw new PluginResolutionException(plugin, e.getCause());
}
}

// Keep this class in sync with org.apache.maven.project.DefaultProjectDependenciesResolver.GraphLogger
class GraphLogger implements DependencyVisitor {

private String indent = "";

public boolean visitEnter(DependencyNode node) {
StringBuilder buffer = new StringBuilder(128);
buffer.append(indent);
org.eclipse.aether.graph.Dependency dep = node.getDependency();
if (dep != null) {
org.eclipse.aether.artifact.Artifact art = dep.getArtifact();

buffer.append(art);
if (dep.getScope() != null && !dep.getScope().isEmpty()) {
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(Objects.toString(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(Objects.toString(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(Objects.toString(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(Objects.toString(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(Objects.toString(premanagedProperties, "default"));
buffer.append(')');
}
}

logger.debug(buffer.toString());
indent += " ";
return true;
}

public boolean visitLeave(DependencyNode node) {
indent = indent.substring(0, indent.length() - 3);
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.maven.RepositoryUtils;
import org.apache.maven.api.DependencyScope;
Expand All @@ -44,11 +43,11 @@
import org.eclipse.aether.collection.DependencyCollectionException;
import org.eclipse.aether.graph.DependencyFilter;
import org.eclipse.aether.graph.DependencyNode;
import org.eclipse.aether.graph.DependencyVisitor;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.aether.resolution.DependencyRequest;
import org.eclipse.aether.util.artifact.ArtifactIdUtils;
import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
import org.eclipse.aether.util.graph.visitor.DependencyGraphDumper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -181,7 +180,7 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
}

if (logger.isDebugEnabled()) {
node.accept(new GraphLogger(project));
node.accept(new DependencyGraphDumper(logger::debug));
}

try {
Expand All @@ -206,90 +205,4 @@ private void process(DefaultDependencyResolutionResult result, Collection<Artifa
}
}
}

// Keep this class in sync with org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver.GraphLogger
class GraphLogger implements DependencyVisitor {

private final MavenProject project;

private String indent = "";

GraphLogger(MavenProject project) {
this.project = project;
}

public boolean visitEnter(DependencyNode node) {
StringBuilder buffer = new StringBuilder(128);
buffer.append(indent);
org.eclipse.aether.graph.Dependency dep = node.getDependency();
if (dep != null) {
org.eclipse.aether.artifact.Artifact art = dep.getArtifact();

buffer.append(art);
if (dep.getScope() != null && !dep.getScope().isEmpty()) {
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(Objects.toString(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(Objects.toString(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(Objects.toString(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(Objects.toString(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(Objects.toString(premanagedProperties, "default"));
buffer.append(')');
}
} else {
buffer.append(project.getGroupId());
buffer.append(':').append(project.getArtifactId());
buffer.append(':').append(project.getPackaging());
buffer.append(':').append(project.getVersion());
}

logger.debug(buffer.toString());
indent += " ";
return true;
}

public boolean visitLeave(DependencyNode node) {
indent = indent.substring(0, indent.length() - 3);
return true;
}
}
}

0 comments on commit c2ec76c

Please sign in to comment.