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 java.util.ArrayList;
21 import java.util.List;
22 import java.util.Stack;
23
24 import org.apache.maven.project.interpolation.ModelInterpolationException;
25 import org.jadira.dependencynavigator.controller.ArtifactResolver;
26 import org.jadira.dependencynavigator.controller.DependencyResolutionException;
27 import org.jadira.dependencynavigator.implementations.IProgressMeter;
28 import org.jadira.dependencynavigator.implementations.Workspace;
29
30 public class RootPom extends PomFile {
31 private final Workspace workspace;
32
33 public RootPom(PomFile rootPom, Workspace workspace) throws ArtifactInitialisationException, ModelInterpolationException {
34 super(rootPom.getModel(), rootPom.getParent(), rootPom.getScope());
35 this.workspace = workspace;
36 }
37
38 public void resolveDependencies(ArtifactResolver resolver, IProgressMeter progress) {
39 if (isModulePom()) {
40 progress.resolving(this);
41 dependencies = new ArrayList<Artifact>();
42 for (Object o : getModel().getAssembledModel().getModules()) {
43 String moduleName = (String) o;
44 PomFile module = workspace.loadModulePom(moduleName);
45 if (module != null) {
46 dependencies.add(module);
47 resolver.addPomToDuplicatesList(module);
48 module.resolveDependencies(resolver, progress, new Stack<LeafDependency>());
49 } else {
50 throw new DependencyResolutionException("Could not find module pom file: " + workspace.getPath(moduleName));
51 }
52 }
53 } else {
54
55 super.resolveDependencies(resolver, progress, new Stack<LeafDependency>());
56 }
57 }
58
59 private boolean isModulePom() {
60 List<String> modules = getModel().getAssembledModel().getModules();
61 return modules != null && modules.size() != 0;
62 }
63 }