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.eclipse.aether.graph.DependencyVisitor;
24 import org.modelmapper.ModelMapper;
25 import org.modelmapper.convention.MatchingStrategies;
26 import org.eclipse.aether.graph.DependencyNode;
27 import org.eclipse.aether.graph.DependencyVisitor;
28
29 import java.util.List;
30
31
32
33
34
35 public class TreeDependencyNodeVisitor
36 implements DependencyVisitor
37 {
38
39 final List<TreeEntry> treeEntries;
40
41 private TreeEntry currentEntry;
42
43 private org.eclipse.aether.graph.DependencyNode firstDependencyNode;
44
45 public TreeDependencyNodeVisitor( List<TreeEntry> treeEntries )
46 {
47 this.treeEntries = treeEntries;
48 }
49
50
51 @Override
52 public boolean visitEnter( DependencyNode dependencyNode )
53 {
54 TreeEntry entry =
55 new TreeEntry( getModelMapper().map( dependencyNode.getDependency().getArtifact(), Artifact.class ) );
56 entry.getArtifact().setFileExtension( dependencyNode.getDependency().getArtifact().getExtension() );
57 entry.getArtifact().setScope( dependencyNode.getDependency().getScope() );
58 entry.setParent( currentEntry );
59 currentEntry = entry;
60
61 if ( firstDependencyNode == null )
62 {
63 firstDependencyNode = dependencyNode;
64 treeEntries.add( currentEntry );
65 }
66 else
67 {
68 currentEntry.getParent().getChilds().add( currentEntry );
69 }
70 return true;
71 }
72
73 @Override
74 public boolean visitLeave( DependencyNode dependencyNode )
75 {
76 currentEntry = currentEntry.getParent();
77 return true;
78 }
79
80 private static class ModelMapperHolder
81 {
82 private static ModelMapper MODEL_MAPPER = new ModelMapper();
83
84 static
85 {
86 MODEL_MAPPER.getConfiguration().setMatchingStrategy( MatchingStrategies.STRICT );
87 }
88 }
89
90 protected ModelMapper getModelMapper()
91 {
92 return ModelMapperHolder.MODEL_MAPPER;
93 }
94 }