View Javadoc

1   /*
2    *  Licensed under the Apache License, Version 2.0 (the "License");
3    *  you may not use this file except in compliance with the License.
4    *  You may obtain a copy of the License at
5    *
6    *      http://www.apache.org/licenses/LICENSE-2.0
7    *
8    *  Unless required by applicable law or agreed to in writing, software
9    *  distributed under the License is distributed on an "AS IS" BASIS,
10   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11   *  See the License for the specific language governing permissions and
12   *  limitations under the License.
13   */
14  /*
15   * This file has been modified by Chris Pheby in accordance with Section 4.2
16   * of the Apache Software License
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              // resolve as a regular dependency pom
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  }