1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.jadira.dependencynavigator.model;
19
20 import org.apache.maven.model.Dependency;
21 import org.jadira.dependencynavigator.assembler.AssembledModel;
22 import org.jadira.dependencynavigator.controller.ArtifactResolver;
23 import org.jadira.dependencynavigator.implementations.IProgressMeter;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Stack;
28
29 public class PomFile extends Artifact {
30
31 protected List<Artifact> dependencies;
32 protected AssembledModel model;
33
34 public PomFile(AssembledModel model, Artifact parent, String scope) throws ArtifactInitialisationException {
35
36 super(parent,
37 model.getAssembledModel().getGroupId() == null ? model.getAssembledModel().getParent().getGroupId() : model.getAssembledModel().getGroupId(),
38 model.getAssembledModel().getArtifactId(),
39 model.getAssembledModel().getVersion() == null ? model.getAssembledModel().getParent().getVersion() : model.getAssembledModel().getVersion(),
40 scope);
41
42 this.model = model;
43 }
44
45 public void resolveDependencies(ArtifactResolver resolver, IProgressMeter progress, Stack<LeafDependency> path) {
46 progress.resolving(this);
47 dependencies = new ArrayList<Artifact>();
48
49 for (Object o : model.getAssembledModel().getDependencies()) {
50 Dependency dependency = (Dependency) o;
51
52
53
54 try {
55 LeafDependency leafDependency = new LeafDependency(this, dependency, dependency.getScope());
56
57
58
59 if (!path.contains(leafDependency)) {
60 path.push(leafDependency);
61 Artifact artifact = resolver.resolveArtifact(this, dependency, progress, path);
62 if (artifact != null) {
63 dependencies.add(artifact);
64 }
65 }
66 } catch (ArtifactInitialisationException e) {
67 e.printStackTrace();
68 }
69 }
70 }
71
72 public AssembledModel getModel() {
73 return model;
74 }
75
76 @Override
77 public boolean isLeaf() {
78 return dependencies.size() == 0;
79 }
80
81 @Override
82 public List<Artifact> getDependencies() {
83 return dependencies;
84 }
85
86 @Override
87 public int dependencyCount() {
88 if (isLeaf()) {
89 return 1;
90 }
91 int dependencyCount = 0;
92 for (Artifact artifact : dependencies) {
93 dependencyCount += artifact.dependencyCount();
94 }
95 return dependencyCount;
96 }
97
98 }