This project has retired. For details please refer to its
Attic page.
TreeDependencyNodeVisitor xref
1 package org.apache.archiva.dependency.tree.maven2;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import org.apache.archiva.maven2.model.Artifact;
22 import org.apache.archiva.maven2.model.TreeEntry;
23 import org.modelmapper.ModelMapper;
24 import org.modelmapper.convention.MatchingStrategies;
25 import org.sonatype.aether.graph.DependencyNode;
26 import org.sonatype.aether.graph.DependencyVisitor;
27
28 import java.util.List;
29
30
31
32
33
34 public class TreeDependencyNodeVisitor
35 implements DependencyVisitor
36 {
37
38 final List<TreeEntry> treeEntries;
39
40 private TreeEntry currentEntry;
41
42 private org.sonatype.aether.graph.DependencyNode firstDependencyNode;
43
44 public TreeDependencyNodeVisitor( List<TreeEntry> treeEntries )
45 {
46 this.treeEntries = treeEntries;
47 }
48
49
50 @Override
51 public boolean visitEnter( DependencyNode dependencyNode )
52 {
53 TreeEntry entry =
54 new TreeEntry( getModelMapper().map( dependencyNode.getDependency().getArtifact(), Artifact.class ) );
55 entry.getArtifact().setFileExtension( dependencyNode.getDependency().getArtifact().getExtension() );
56 entry.getArtifact().setScope( dependencyNode.getDependency().getScope() );
57 entry.setParent( currentEntry );
58 currentEntry = entry;
59
60 if ( firstDependencyNode == null )
61 {
62 firstDependencyNode = dependencyNode;
63 treeEntries.add( currentEntry );
64 }
65 else
66 {
67 currentEntry.getParent().getChilds().add( currentEntry );
68 }
69 return true;
70 }
71
72 @Override
73 public boolean visitLeave( DependencyNode dependencyNode )
74 {
75 currentEntry = currentEntry.getParent();
76 return true;
77 }
78
79 private static class ModelMapperHolder
80 {
81 private static ModelMapper MODEL_MAPPER = new ModelMapper();
82
83 static
84 {
85 MODEL_MAPPER.getConfiguration().setMatchingStrategy( MatchingStrategies.STRICT );
86 }
87 }
88
89 protected ModelMapper getModelMapper()
90 {
91 return ModelMapperHolder.MODEL_MAPPER;
92 }
93 }