From 75ff0f8d73cc8a188414e4be7b8ea7f31672ca99 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 22 Jun 2005 13:39:45 +0000 Subject: [PATCH] print path to error for cyclical dependencies git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191839 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/ArtifactResolutionException.java | 50 +++++++++++++++---- .../resolver/CyclicDependencyException.java | 6 ++- .../resolver/DefaultArtifactCollector.java | 12 +++-- 3 files changed, 52 insertions(+), 16 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java index 4d7b97d138..8150432942 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionException.java @@ -42,9 +42,10 @@ public class ArtifactResolutionException private List remoteRepositories; public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, - List remoteRepositories, String downloadUrl, Throwable t ) + List remoteRepositories, String downloadUrl, List path, Throwable t ) { - super( constructMessage( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl ), t ); + super( constructMessage( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl, path ), + t ); this.groupId = groupId; this.artifactId = artifactId; @@ -55,9 +56,15 @@ public class ArtifactResolutionException } public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, - List remoteRepositories, String downloadUrl ) + List remoteRepositories, String downloadUrl, Throwable t ) { - super( constructMessage( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl ) ); + this( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl, null, t ); + } + + public ArtifactResolutionException( String message, String groupId, String artifactId, String version, String type, + List remoteRepositories, String downloadUrl, List path ) + { + super( constructMessage( message, groupId, artifactId, version, type, remoteRepositories, downloadUrl, path ) ); this.groupId = groupId; this.artifactId = artifactId; @@ -70,7 +77,7 @@ public class ArtifactResolutionException private static final String LS = System.getProperty( "line.separator" ); private static String constructMessage( String message, String groupId, String artifactId, String version, - String type, List remoteRepositories, String downloadUrl ) + String type, List remoteRepositories, String downloadUrl, List path ) { StringBuffer sb = new StringBuffer(); @@ -96,6 +103,23 @@ public class ArtifactResolutionException } } + if ( path != null ) + { + sb.append( LS ); + sb.append( "Path to dependency: " ); + sb.append( LS ); + int num = 1; + for ( Iterator i = path.iterator(); i.hasNext(); ) + { + sb.append( "\t" ); + sb.append( num++ ); + sb.append( ") " ); + sb.append( i.next() ); + sb.append( LS ); + } + sb.append( LS ); + } + if ( downloadUrl != null && !type.equals( "pom" ) ) { sb.append( LS ); @@ -120,16 +144,24 @@ public class ArtifactResolutionException return sb.toString(); } - public ArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, Throwable t ) + public ArtifactResolutionException( String message, Artifact artifact, List path, List remoteRepositories, + Throwable t ) { this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), - remoteRepositories, artifact.getDownloadUrl(), t ); + remoteRepositories, artifact.getDownloadUrl(), path, t ); } - public ArtifactResolutionException( String message, Artifact artifact ) + public ArtifactResolutionException( String message, Artifact artifact, List remoteRepositories, Throwable t ) + { + // TODO: path + this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), + remoteRepositories, artifact.getDownloadUrl(), null, t ); + } + + public ArtifactResolutionException( String message, Artifact artifact, List path ) { this( message, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), null, - artifact.getDownloadUrl() ); + artifact.getDownloadUrl(), path ); } public ArtifactResolutionException( String message, Throwable cause ) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java index 5b2807957d..54076ca56c 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/CyclicDependencyException.java @@ -18,6 +18,8 @@ package org.apache.maven.artifact.resolver; import org.apache.maven.artifact.Artifact; +import java.util.List; + /** * Indiciates a cycle in the dependency graph. * @@ -27,8 +29,8 @@ import org.apache.maven.artifact.Artifact; public class CyclicDependencyException extends ArtifactResolutionException { - public CyclicDependencyException( String message, Artifact artifact ) + public CyclicDependencyException( String message, Artifact artifact, List path ) { - super( message, artifact ); + super( message, artifact, path ); } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java index 6b6a7fb0fb..50db7fdea8 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java @@ -204,7 +204,7 @@ public class DefaultArtifactCollector private List children = null; - private final Set parents; + private final List parents; private final int depth; @@ -213,7 +213,7 @@ public class DefaultArtifactCollector this.artifact = artifact; this.parent = null; this.depth = 0; - this.parents = Collections.EMPTY_SET; + this.parents = Collections.EMPTY_LIST; } public ResolutionNode( Artifact artifact, ResolutionNode parent ) @@ -221,9 +221,9 @@ public class DefaultArtifactCollector this.artifact = artifact; this.parent = parent; this.depth = parent.depth + 1; - this.parents = new HashSet(); - this.parents.add( parent.getKey() ); + this.parents = new ArrayList(); this.parents.addAll( parent.parents ); + this.parents.add( parent.getKey() ); } public Artifact getArtifact() @@ -249,7 +249,9 @@ public class DefaultArtifactCollector { if ( parents.contains( a.getDependencyConflictId() ) ) { - throw new CyclicDependencyException( "The dependency is present in a cycle", a ); + List path = new ArrayList( parents ); + path.add( getKey() ); + throw new CyclicDependencyException( "The dependency is present in a cycle", a, path ); } children.add( new ResolutionNode( a, this ) );