001 /* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 /* 015 * This file has been modified by Chris Pheby in accordance with Section 4.2 016 * of the Apache Software License 017 */ 018 package org.jadira.dependencynavigator.model; 019 020 import java.util.ArrayList; 021 import java.util.List; 022 import java.util.Stack; 023 024 import org.apache.maven.project.interpolation.ModelInterpolationException; 025 import org.jadira.dependencynavigator.controller.ArtifactResolver; 026 import org.jadira.dependencynavigator.controller.DependencyResolutionException; 027 import org.jadira.dependencynavigator.implementations.IProgressMeter; 028 import org.jadira.dependencynavigator.implementations.Workspace; 029 030 public class RootPom extends PomFile { 031 private final Workspace workspace; 032 033 public RootPom(PomFile rootPom, Workspace workspace) throws ArtifactInitialisationException, ModelInterpolationException { 034 super(rootPom.getModel(), rootPom.getParent(), rootPom.getScope()); 035 this.workspace = workspace; 036 } 037 038 public void resolveDependencies(ArtifactResolver resolver, IProgressMeter progress) { 039 if (isModulePom()) { 040 progress.resolving(this); 041 dependencies = new ArrayList<Artifact>(); 042 for (Object o : getModel().getAssembledModel().getModules()) { 043 String moduleName = (String) o; 044 PomFile module = workspace.loadModulePom(moduleName); 045 if (module != null) { 046 dependencies.add(module); 047 resolver.addPomToDuplicatesList(module); 048 module.resolveDependencies(resolver, progress, new Stack<LeafDependency>()); 049 } else { 050 throw new DependencyResolutionException("Could not find module pom file: " + workspace.getPath(moduleName)); 051 } 052 } 053 } else { 054 // resolve as a regular dependency pom 055 super.resolveDependencies(resolver, progress, new Stack<LeafDependency>()); 056 } 057 } 058 059 private boolean isModulePom() { 060 List<String> modules = getModel().getAssembledModel().getModules(); 061 return modules != null && modules.size() != 0; 062 } 063 }