1 |
|
package org.apache.maven.report.projectinfo.dependencies; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
import org.apache.maven.artifact.Artifact; |
20 |
|
import org.apache.maven.artifact.resolver.ResolutionListener; |
21 |
|
import org.apache.maven.artifact.versioning.VersionRange; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Collection; |
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
import java.util.Stack; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
5 |
public class ReportResolutionListener |
34 |
|
implements ResolutionListener |
35 |
|
{ |
36 |
3 |
private Stack parents = new Stack(); |
37 |
|
|
38 |
3 |
private Map artifacts = new HashMap(); |
39 |
|
|
40 |
|
private Node rootNode; |
41 |
|
|
42 |
3 |
private int currentDepth = 0; |
43 |
|
|
44 |
|
public void testArtifact( Artifact artifact ) |
45 |
|
{ |
46 |
|
|
47 |
0 |
} |
48 |
|
|
49 |
|
public void startProcessChildren( Artifact artifact ) |
50 |
|
{ |
51 |
7 |
Node node = (Node) artifacts.get( artifact.getDependencyConflictId() ); |
52 |
|
|
53 |
7 |
node.depth = currentDepth++; |
54 |
7 |
if ( parents.isEmpty() ) |
55 |
|
{ |
56 |
3 |
rootNode = node; |
57 |
|
} |
58 |
|
|
59 |
7 |
parents.push( node ); |
60 |
7 |
} |
61 |
|
|
62 |
|
public void endProcessChildren( Artifact artifact ) |
63 |
|
{ |
64 |
7 |
Node check = (Node) parents.pop(); |
65 |
7 |
assert artifact.equals( check.artifact ); |
66 |
7 |
currentDepth--; |
67 |
7 |
} |
68 |
|
|
69 |
|
public void omitForNearer( Artifact omitted, Artifact kept ) |
70 |
|
{ |
71 |
1 |
assert omitted.getDependencyConflictId().equals( kept.getDependencyConflictId() ); |
72 |
|
|
73 |
1 |
Node prev = (Node) artifacts.get( omitted.getDependencyConflictId() ); |
74 |
1 |
if ( prev != null ) |
75 |
|
{ |
76 |
1 |
if ( prev.parent != null ) |
77 |
|
{ |
78 |
1 |
prev.parent.children.remove( prev ); |
79 |
|
} |
80 |
1 |
artifacts.remove( omitted.getDependencyConflictId() ); |
81 |
|
} |
82 |
|
|
83 |
1 |
includeArtifact( kept ); |
84 |
1 |
} |
85 |
|
|
86 |
|
public void omitForCycle( Artifact artifact ) |
87 |
|
{ |
88 |
|
|
89 |
0 |
} |
90 |
|
|
91 |
|
public void includeArtifact( Artifact artifact ) |
92 |
|
{ |
93 |
19 |
if ( artifacts.containsKey( artifact.getDependencyConflictId() ) ) |
94 |
|
{ |
95 |
1 |
Node prev = (Node) artifacts.get( artifact.getDependencyConflictId() ); |
96 |
1 |
if ( prev.parent != null ) |
97 |
|
{ |
98 |
1 |
prev.parent.children.remove( prev ); |
99 |
|
} |
100 |
1 |
artifacts.remove( artifact.getDependencyConflictId() ); |
101 |
|
} |
102 |
|
|
103 |
19 |
Node node = new Node(); |
104 |
19 |
node.artifact = artifact; |
105 |
19 |
if ( !parents.isEmpty() ) |
106 |
|
{ |
107 |
16 |
node.parent = (Node) parents.peek(); |
108 |
16 |
node.parent.children.add( node ); |
109 |
16 |
node.depth = currentDepth; |
110 |
|
} |
111 |
19 |
artifacts.put( artifact.getDependencyConflictId(), node ); |
112 |
19 |
} |
113 |
|
|
114 |
|
public void updateScope( Artifact artifact, String scope ) |
115 |
|
{ |
116 |
0 |
Node node = (Node) artifacts.get( artifact.getDependencyConflictId() ); |
117 |
|
|
118 |
0 |
node.artifact.setScope( scope ); |
119 |
0 |
} |
120 |
|
|
121 |
|
public void manageArtifact( Artifact artifact, Artifact replacement ) |
122 |
|
{ |
123 |
0 |
Node node = (Node) artifacts.get( artifact.getDependencyConflictId() ); |
124 |
|
|
125 |
0 |
if ( node != null ) |
126 |
|
{ |
127 |
0 |
if ( replacement.getVersion() != null ) |
128 |
|
{ |
129 |
0 |
node.artifact.setVersion( replacement.getVersion() ); |
130 |
|
} |
131 |
0 |
if ( replacement.getScope() != null ) |
132 |
|
{ |
133 |
0 |
node.artifact.setScope( replacement.getScope() ); |
134 |
|
} |
135 |
|
} |
136 |
0 |
} |
137 |
|
|
138 |
|
public void updateScopeCurrentPom( Artifact artifact, String key ) |
139 |
|
{ |
140 |
|
|
141 |
0 |
} |
142 |
|
|
143 |
|
public void selectVersionFromRange( Artifact artifact ) |
144 |
|
{ |
145 |
|
|
146 |
0 |
} |
147 |
|
|
148 |
|
public void restrictRange( Artifact artifact, Artifact artifact1, VersionRange versionRange ) |
149 |
|
{ |
150 |
|
|
151 |
0 |
} |
152 |
|
|
153 |
|
public Collection getArtifacts() |
154 |
|
{ |
155 |
3 |
return artifacts.values(); |
156 |
|
} |
157 |
|
|
158 |
3 |
public static class Node |
159 |
|
{ |
160 |
|
private Node parent; |
161 |
|
|
162 |
19 |
private List children = new ArrayList(); |
163 |
|
|
164 |
|
private Artifact artifact; |
165 |
|
|
166 |
|
private int depth; |
167 |
|
|
168 |
|
public List getChildren() |
169 |
|
{ |
170 |
11 |
return children; |
171 |
|
} |
172 |
|
|
173 |
|
public Artifact getArtifact() |
174 |
|
{ |
175 |
40 |
return artifact; |
176 |
|
} |
177 |
|
|
178 |
|
public int getDepth() |
179 |
|
{ |
180 |
0 |
return depth; |
181 |
|
} |
182 |
|
} |
183 |
|
|
184 |
|
public Node getRootNode() |
185 |
|
{ |
186 |
9 |
return rootNode; |
187 |
|
} |
188 |
|
} |