1 package org.eclipse.aether.collection;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.LinkedHashSet;
26 import java.util.List;
27
28 import org.eclipse.aether.RepositoryException;
29 import org.eclipse.aether.artifact.Artifact;
30 import org.eclipse.aether.graph.DependencyNode;
31 import org.eclipse.aether.version.VersionConstraint;
32
33
34
35
36 public class UnsolvableVersionConflictException
37 extends RepositoryException
38 {
39
40 private final transient Collection<String> versions;
41
42 private final transient Collection<? extends List<? extends DependencyNode>> paths;
43
44
45
46
47
48
49 public UnsolvableVersionConflictException( Collection<? extends List<? extends DependencyNode>> paths )
50 {
51 super( "Could not resolve version conflict among " + toPaths( paths ) );
52 if ( paths == null )
53 {
54 this.paths = Collections.emptyList();
55 this.versions = Collections.emptyList();
56 }
57 else
58 {
59 this.paths = paths;
60 this.versions = new LinkedHashSet<String>();
61 for ( List<? extends DependencyNode> path : paths )
62 {
63 VersionConstraint constraint = path.get( path.size() - 1 ).getVersionConstraint();
64 if ( constraint != null && constraint.getRange() != null )
65 {
66 versions.add( constraint.toString() );
67 }
68 }
69 }
70 }
71
72 private static String toPaths( Collection<? extends List<? extends DependencyNode>> paths )
73 {
74 String result = "";
75
76 if ( paths != null )
77 {
78 Collection<String> strings = new LinkedHashSet<String>();
79
80 for ( List<? extends DependencyNode> path : paths )
81 {
82 strings.add( toPath( path ) );
83 }
84
85 result = strings.toString();
86 }
87
88 return result;
89 }
90
91 private static String toPath( List<? extends DependencyNode> path )
92 {
93 StringBuilder buffer = new StringBuilder( 256 );
94
95 for ( Iterator<? extends DependencyNode> it = path.iterator(); it.hasNext(); )
96 {
97 DependencyNode node = it.next();
98 if ( node.getDependency() == null )
99 {
100 continue;
101 }
102
103 Artifact artifact = node.getDependency().getArtifact();
104 buffer.append( artifact.getGroupId() );
105 buffer.append( ':' ).append( artifact.getArtifactId() );
106 buffer.append( ':' ).append( artifact.getExtension() );
107 if ( artifact.getClassifier().length() > 0 )
108 {
109 buffer.append( ':' ).append( artifact.getClassifier() );
110 }
111 buffer.append( ':' ).append( node.getVersionConstraint() );
112
113 if ( it.hasNext() )
114 {
115 buffer.append( " -> " );
116 }
117 }
118
119 return buffer.toString();
120 }
121
122
123
124
125
126
127 public Collection<? extends List<? extends DependencyNode>> getPaths()
128 {
129 return paths;
130 }
131
132
133
134
135
136
137 public Collection<String> getVersions()
138 {
139 return versions;
140 }
141
142 }