1 | |
package org.apache.maven.archiva.dependency.graph.tasks; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.commons.collections.CollectionUtils; |
23 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraph; |
24 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder; |
25 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraphNode; |
26 | |
import org.apache.maven.archiva.dependency.graph.GraphTask; |
27 | |
import org.apache.maven.archiva.dependency.graph.PotentialCyclicEdgeProducer; |
28 | |
import org.apache.maven.archiva.dependency.graph.functors.UnresolvedGraphNodePredicate; |
29 | |
import org.apache.maven.archiva.model.VersionedReference; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class ResolveGraphTask |
38 | |
implements GraphTask, PotentialCyclicEdgeProducer |
39 | |
{ |
40 | |
private DependencyGraphBuilder builder; |
41 | |
|
42 | 0 | private int resolvedCount = 0; |
43 | |
|
44 | |
private VersionedReference toVersionedReference( DependencyGraphNode node ) |
45 | |
{ |
46 | 0 | VersionedReference ref = new VersionedReference(); |
47 | 0 | ref.setGroupId( node.getArtifact().getGroupId() ); |
48 | 0 | ref.setArtifactId( node.getArtifact().getArtifactId() ); |
49 | 0 | ref.setVersion( node.getArtifact().getVersion() ); |
50 | |
|
51 | 0 | return ref; |
52 | |
} |
53 | |
|
54 | |
public void executeTask( DependencyGraph graph ) |
55 | |
{ |
56 | 0 | resolvedCount = 0; |
57 | 0 | VersionedReference rootRef = toVersionedReference( graph.getRootNode() ); |
58 | |
|
59 | 0 | if ( !graph.getRootNode().isResolved() ) |
60 | |
{ |
61 | 0 | builder.resolveNode( graph, graph.getRootNode(), rootRef ); |
62 | 0 | resolvedCount++; |
63 | |
} |
64 | |
|
65 | 0 | boolean done = false; |
66 | |
|
67 | 0 | while ( !done ) |
68 | |
{ |
69 | 0 | DependencyGraphNode node = findUnresolvedNode( graph ); |
70 | 0 | if ( node == null ) |
71 | |
{ |
72 | 0 | done = true; |
73 | 0 | break; |
74 | |
} |
75 | |
|
76 | 0 | VersionedReference otherRef = toVersionedReference( node ); |
77 | |
|
78 | 0 | builder.resolveNode( graph, node, otherRef ); |
79 | 0 | resolvedCount++; |
80 | 0 | } |
81 | 0 | } |
82 | |
|
83 | |
private DependencyGraphNode findUnresolvedNode( DependencyGraph graph ) |
84 | |
{ |
85 | 0 | return (DependencyGraphNode) CollectionUtils |
86 | |
.find( graph.getNodes(), UnresolvedGraphNodePredicate.getInstance() ); |
87 | |
} |
88 | |
|
89 | |
public DependencyGraphBuilder getBuilder() |
90 | |
{ |
91 | 0 | return builder; |
92 | |
} |
93 | |
|
94 | |
public void setBuilder( DependencyGraphBuilder graphBuilder ) |
95 | |
{ |
96 | 0 | this.builder = graphBuilder; |
97 | 0 | } |
98 | |
|
99 | |
public String getTaskId() |
100 | |
{ |
101 | 0 | return "resolve-graph"; |
102 | |
} |
103 | |
|
104 | |
public int getResolvedCount() |
105 | |
{ |
106 | 0 | return resolvedCount; |
107 | |
} |
108 | |
} |