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
This commit is contained in:
Brett Leslie Porter 2005-06-22 13:39:45 +00:00
parent 5c1fb112b9
commit 75ff0f8d73
3 changed files with 52 additions and 16 deletions

View File

@ -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 )

View File

@ -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 );
}
}

View File

@ -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 ) );