0001: package org.apache.maven.project;
0002:
0003: /*
0004: * Licensed to the Apache Software Foundation (ASF) under one
0005: * or more contributor license agreements. See the NOTICE file
0006: * distributed with this work for additional information
0007: * regarding copyright ownership. The ASF licenses this file
0008: * to you under the Apache License, Version 2.0 (the
0009: * "License"); you may not use this file except in compliance
0010: * with the License. You may obtain a copy of the License at
0011: *
0012: * http://www.apache.org/licenses/LICENSE-2.0
0013: *
0014: * Unless required by applicable law or agreed to in writing,
0015: * software distributed under the License is distributed on an
0016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0017: * KIND, either express or implied. See the License for the
0018: * specific language governing permissions and limitations
0019: * under the License.
0020: */
0021:
0022: import org.apache.maven.artifact.Artifact;
0023: import org.apache.maven.artifact.ArtifactUtils;
0024: import org.apache.maven.artifact.DependencyResolutionRequiredException;
0025: import org.apache.maven.artifact.versioning.ManagedVersionMap;
0026: import org.apache.maven.artifact.factory.ArtifactFactory;
0027: import org.apache.maven.artifact.repository.ArtifactRepository;
0028: import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
0029: import org.apache.maven.model.Build;
0030: import org.apache.maven.model.CiManagement;
0031: import org.apache.maven.model.Contributor;
0032: import org.apache.maven.model.Dependency;
0033: import org.apache.maven.model.DependencyManagement;
0034: import org.apache.maven.model.Developer;
0035: import org.apache.maven.model.DistributionManagement;
0036: import org.apache.maven.model.IssueManagement;
0037: import org.apache.maven.model.License;
0038: import org.apache.maven.model.MailingList;
0039: import org.apache.maven.model.Model;
0040: import org.apache.maven.model.Organization;
0041: import org.apache.maven.model.Plugin;
0042: import org.apache.maven.model.PluginExecution;
0043: import org.apache.maven.model.PluginManagement;
0044: import org.apache.maven.model.Prerequisites;
0045: import org.apache.maven.model.ReportPlugin;
0046: import org.apache.maven.model.ReportSet;
0047: import org.apache.maven.model.Reporting;
0048: import org.apache.maven.model.Resource;
0049: import org.apache.maven.model.Scm;
0050: import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
0051: import org.apache.maven.project.artifact.ActiveProjectArtifact;
0052: import org.apache.maven.project.artifact.InvalidDependencyVersionException;
0053: import org.apache.maven.project.artifact.MavenMetadataSource;
0054: import org.apache.maven.project.overlay.BuildOverlay;
0055: import org.codehaus.plexus.util.xml.Xpp3Dom;
0056:
0057: import java.io.File;
0058: import java.io.IOException;
0059: import java.io.Writer;
0060: import java.util.ArrayList;
0061: import java.util.Collections;
0062: import java.util.HashMap;
0063: import java.util.Iterator;
0064: import java.util.List;
0065: import java.util.Map;
0066: import java.util.Properties;
0067: import java.util.Set;
0068: import java.util.Stack;
0069:
0070: /**
0071: * The concern of the project is provide runtime values based on the model. <p/>
0072: * The values in the model remain untouched but during the process of building a
0073: * project notions like inheritance and interpolation can be added. This allows
0074: * to have an entity which is useful in a runtime while preserving the model so
0075: * that it can be marshalled and unmarshalled without being tainted by runtime
0076: * requirements. <p/>We need to leave the model intact because we don't want
0077: * the following:
0078: * <ol>
0079: * <li>We don't want interpolated values being written back into the model.
0080: * <li>We don't want inherited values being written back into the model.
0081: * </ol>
0082: */
0083: public class MavenProject {
0084: public static final String EMPTY_PROJECT_GROUP_ID = "unknown";
0085:
0086: public static final String EMPTY_PROJECT_ARTIFACT_ID = "empty-project";
0087:
0088: public static final String EMPTY_PROJECT_VERSION = "0";
0089:
0090: private Model model;
0091:
0092: private MavenProject parent;
0093:
0094: private File file;
0095:
0096: private Set artifacts;
0097:
0098: private Artifact parentArtifact;
0099:
0100: private Set pluginArtifacts;
0101:
0102: private List remoteArtifactRepositories;
0103:
0104: private List collectedProjects = Collections.EMPTY_LIST;
0105:
0106: private List attachedArtifacts;
0107:
0108: private MavenProject executionProject;
0109:
0110: private List compileSourceRoots = new ArrayList();
0111:
0112: private List testCompileSourceRoots = new ArrayList();
0113:
0114: private List scriptSourceRoots = new ArrayList();
0115:
0116: private List pluginArtifactRepositories;
0117:
0118: private ArtifactRepository releaseArtifactRepository;
0119:
0120: private ArtifactRepository snapshotArtifactRepository;
0121:
0122: private List activeProfiles = new ArrayList();
0123:
0124: private Set dependencyArtifacts;
0125:
0126: private Artifact artifact;
0127:
0128: // calculated.
0129: private Map artifactMap;
0130:
0131: private Model originalModel;
0132:
0133: private Map pluginArtifactMap;
0134:
0135: private Set reportArtifacts;
0136:
0137: private Map reportArtifactMap;
0138:
0139: private Set extensionArtifacts;
0140:
0141: private Map extensionArtifactMap;
0142:
0143: private Map managedVersionMap;
0144:
0145: private Map projectReferences = new HashMap();
0146:
0147: private Build buildOverlay;
0148:
0149: private boolean executionRoot;
0150:
0151: private Map moduleAdjustments;
0152:
0153: private Stack previousExecutionProjects = new Stack();
0154:
0155: public MavenProject() {
0156: Model model = new Model();
0157:
0158: model.setGroupId(EMPTY_PROJECT_GROUP_ID);
0159: model.setArtifactId(EMPTY_PROJECT_ARTIFACT_ID);
0160: model.setVersion(EMPTY_PROJECT_VERSION);
0161:
0162: this .model = model;
0163: }
0164:
0165: public MavenProject(Model model) {
0166: this .model = model;
0167: }
0168:
0169: public MavenProject(MavenProject project) {
0170: // disown the parent
0171:
0172: // copy fields
0173: this .file = project.file;
0174:
0175: // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be sure!
0176: if (project.dependencyArtifacts != null) {
0177: this .dependencyArtifacts = Collections
0178: .unmodifiableSet(project.dependencyArtifacts);
0179: }
0180:
0181: if (project.artifacts != null) {
0182: this .artifacts = Collections
0183: .unmodifiableSet(project.artifacts);
0184: }
0185:
0186: if (project.pluginArtifacts != null) {
0187: this .pluginArtifacts = Collections
0188: .unmodifiableSet(project.pluginArtifacts);
0189: }
0190:
0191: if (project.reportArtifacts != null) {
0192: this .reportArtifacts = Collections
0193: .unmodifiableSet(project.reportArtifacts);
0194: }
0195:
0196: if (project.extensionArtifacts != null) {
0197: this .extensionArtifacts = Collections
0198: .unmodifiableSet(project.extensionArtifacts);
0199: }
0200:
0201: this .parentArtifact = project.parentArtifact;
0202:
0203: if (project.remoteArtifactRepositories != null) {
0204: this .remoteArtifactRepositories = Collections
0205: .unmodifiableList(project.remoteArtifactRepositories);
0206: }
0207:
0208: if (project.pluginArtifactRepositories != null) {
0209: this .pluginArtifactRepositories = Collections
0210: .unmodifiableList(project.pluginArtifactRepositories);
0211: }
0212:
0213: if (project.collectedProjects != null) {
0214: this .collectedProjects = Collections
0215: .unmodifiableList(project.collectedProjects);
0216: }
0217:
0218: if (project.activeProfiles != null) {
0219: this .activeProfiles = Collections
0220: .unmodifiableList(project.activeProfiles);
0221: }
0222:
0223: if (project.getAttachedArtifacts() != null) {
0224: // clone properties modifyable by plugins in a forked lifecycle
0225: this .attachedArtifacts = new ArrayList(project
0226: .getAttachedArtifacts());
0227: }
0228:
0229: if (project.compileSourceRoots != null) {
0230: // clone source roots
0231: this .compileSourceRoots = new ArrayList(
0232: project.compileSourceRoots);
0233: }
0234:
0235: if (project.testCompileSourceRoots != null) {
0236: this .testCompileSourceRoots = new ArrayList(
0237: project.testCompileSourceRoots);
0238: }
0239:
0240: if (project.scriptSourceRoots != null) {
0241: this .scriptSourceRoots = new ArrayList(
0242: project.scriptSourceRoots);
0243: }
0244:
0245: this .model = ModelUtils.cloneModel(project.model);
0246:
0247: if (project.originalModel != null) {
0248: this .originalModel = ModelUtils
0249: .cloneModel(project.originalModel);
0250: }
0251:
0252: this .executionRoot = project.executionRoot;
0253:
0254: if (project.artifact != null) {
0255: this .artifact = ArtifactUtils
0256: .copyArtifact(project.artifact);
0257: }
0258:
0259: if (project.getManagedVersionMap() != null) {
0260: setManagedVersionMap(new ManagedVersionMap(project
0261: .getManagedVersionMap()));
0262: }
0263:
0264: if (project.releaseArtifactRepository != null) {
0265: releaseArtifactRepository = project.releaseArtifactRepository;
0266: }
0267:
0268: if (project.snapshotArtifactRepository != null) {
0269: snapshotArtifactRepository = project.snapshotArtifactRepository;
0270: }
0271: }
0272:
0273: // TODO: Find a way to use <relativePath/> here...it's tricky, because the moduleProject
0274: // usually doesn't have a file associated with it yet.
0275: public String getModulePathAdjustment(MavenProject moduleProject)
0276: throws IOException {
0277: // FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
0278: // is coming from the repository??
0279: String module = moduleProject.getArtifactId();
0280:
0281: File moduleFile = moduleProject.getFile();
0282:
0283: if (moduleFile != null) {
0284: File moduleDir = moduleFile.getCanonicalFile()
0285: .getParentFile();
0286:
0287: module = moduleDir.getName();
0288: }
0289:
0290: if (moduleAdjustments == null) {
0291: moduleAdjustments = new HashMap();
0292:
0293: List modules = getModules();
0294: if (modules != null) {
0295: for (Iterator it = modules.iterator(); it.hasNext();) {
0296: String modulePath = (String) it.next();
0297: String moduleName = modulePath;
0298:
0299: if (moduleName.endsWith("/")
0300: || moduleName.endsWith("\\")) {
0301: moduleName = moduleName.substring(0, moduleName
0302: .length() - 1);
0303: }
0304:
0305: int lastSlash = moduleName.lastIndexOf('/');
0306:
0307: if (lastSlash < 0) {
0308: lastSlash = moduleName.lastIndexOf('\\');
0309: }
0310:
0311: String adjustment = null;
0312:
0313: if (lastSlash > -1) {
0314: moduleName = moduleName
0315: .substring(lastSlash + 1);
0316: adjustment = modulePath.substring(0, lastSlash);
0317: }
0318:
0319: moduleAdjustments.put(moduleName, adjustment);
0320: }
0321: }
0322: }
0323:
0324: return (String) moduleAdjustments.get(module);
0325: }
0326:
0327: // ----------------------------------------------------------------------
0328: // Accessors
0329: // ----------------------------------------------------------------------
0330:
0331: public Artifact getArtifact() {
0332: return artifact;
0333: }
0334:
0335: public void setArtifact(Artifact artifact) {
0336: this .artifact = artifact;
0337: }
0338:
0339: //@todo I would like to get rid of this. jvz.
0340: public Model getModel() {
0341: return model;
0342: }
0343:
0344: public MavenProject getParent() {
0345: return parent;
0346: }
0347:
0348: public void setParent(MavenProject parent) {
0349: this .parent = parent;
0350: }
0351:
0352: public void setRemoteArtifactRepositories(
0353: List remoteArtifactRepositories) {
0354: this .remoteArtifactRepositories = remoteArtifactRepositories;
0355: }
0356:
0357: public List getRemoteArtifactRepositories() {
0358: return remoteArtifactRepositories;
0359: }
0360:
0361: public boolean hasParent() {
0362: return getParent() != null;
0363: }
0364:
0365: public File getFile() {
0366: return file;
0367: }
0368:
0369: public void setFile(File file) {
0370: this .file = file;
0371: }
0372:
0373: public File getBasedir() {
0374: if (getFile() != null) {
0375: return getFile().getParentFile();
0376: } else {
0377: // repository based POM
0378: return null;
0379: }
0380: }
0381:
0382: public void setDependencies(List dependencies) {
0383: model.setDependencies(dependencies);
0384: }
0385:
0386: public List getDependencies() {
0387: return model.getDependencies();
0388: }
0389:
0390: public DependencyManagement getDependencyManagement() {
0391: return model.getDependencyManagement();
0392: }
0393:
0394: // ----------------------------------------------------------------------
0395: // Test and compile sourceroots.
0396: // ----------------------------------------------------------------------
0397:
0398: public void addCompileSourceRoot(String path) {
0399: if (path != null) {
0400: path = path.trim();
0401: if (path.length() != 0) {
0402: if (!compileSourceRoots.contains(path)) {
0403: compileSourceRoots.add(path);
0404: }
0405: }
0406: }
0407: }
0408:
0409: public void addScriptSourceRoot(String path) {
0410: if (path != null) {
0411: path = path.trim();
0412: if (path.length() != 0) {
0413: if (!scriptSourceRoots.contains(path)) {
0414: scriptSourceRoots.add(path);
0415: }
0416: }
0417: }
0418: }
0419:
0420: public void addTestCompileSourceRoot(String path) {
0421: if (path != null) {
0422: path = path.trim();
0423: if (path.length() != 0) {
0424: if (!testCompileSourceRoots.contains(path)) {
0425: testCompileSourceRoots.add(path);
0426: }
0427: }
0428: }
0429: }
0430:
0431: public List getCompileSourceRoots() {
0432: return compileSourceRoots;
0433: }
0434:
0435: public List getScriptSourceRoots() {
0436: return scriptSourceRoots;
0437: }
0438:
0439: public List getTestCompileSourceRoots() {
0440: return testCompileSourceRoots;
0441: }
0442:
0443: public List getCompileClasspathElements()
0444: throws DependencyResolutionRequiredException {
0445: List list = new ArrayList(getArtifacts().size());
0446:
0447: list.add(getBuild().getOutputDirectory());
0448:
0449: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0450: Artifact a = (Artifact) i.next();
0451:
0452: if (a.getArtifactHandler().isAddedToClasspath()) {
0453: // TODO: let the scope handler deal with this
0454: if (Artifact.SCOPE_COMPILE.equals(a.getScope())
0455: || Artifact.SCOPE_PROVIDED.equals(a.getScope())
0456: || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
0457: addArtifactPath(a, list);
0458: }
0459: }
0460: }
0461: return list;
0462: }
0463:
0464: public List getCompileArtifacts() {
0465: List list = new ArrayList(getArtifacts().size());
0466:
0467: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0468: Artifact a = (Artifact) i.next();
0469:
0470: // TODO: classpath check doesn't belong here - that's the other method
0471: if (a.getArtifactHandler().isAddedToClasspath()) {
0472: // TODO: let the scope handler deal with this
0473: if (Artifact.SCOPE_COMPILE.equals(a.getScope())
0474: || Artifact.SCOPE_PROVIDED.equals(a.getScope())
0475: || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
0476: list.add(a);
0477: }
0478: }
0479: }
0480: return list;
0481: }
0482:
0483: public List getCompileDependencies() {
0484: Set artifacts = getArtifacts();
0485:
0486: if (artifacts == null || artifacts.isEmpty()) {
0487: return Collections.EMPTY_LIST;
0488: }
0489:
0490: List list = new ArrayList(artifacts.size());
0491:
0492: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0493: Artifact a = (Artifact) i.next();
0494:
0495: // TODO: let the scope handler deal with this
0496: if (Artifact.SCOPE_COMPILE.equals(a.getScope())
0497: || Artifact.SCOPE_PROVIDED.equals(a.getScope())
0498: || Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
0499: Dependency dependency = new Dependency();
0500:
0501: dependency.setArtifactId(a.getArtifactId());
0502: dependency.setGroupId(a.getGroupId());
0503: dependency.setVersion(a.getVersion());
0504: dependency.setScope(a.getScope());
0505: dependency.setType(a.getType());
0506: dependency.setClassifier(a.getClassifier());
0507:
0508: list.add(dependency);
0509: }
0510: }
0511: return list;
0512: }
0513:
0514: public List getTestClasspathElements()
0515: throws DependencyResolutionRequiredException {
0516: List list = new ArrayList(getArtifacts().size() + 2);
0517:
0518: list.add(getBuild().getTestOutputDirectory());
0519:
0520: list.add(getBuild().getOutputDirectory());
0521:
0522: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0523: Artifact a = (Artifact) i.next();
0524:
0525: if (a.getArtifactHandler().isAddedToClasspath()) {
0526: // TODO: let the scope handler deal with this
0527: // NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform
0528: // this check...
0529: // if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
0530: // Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
0531: // {
0532: // }
0533: File file = a.getFile();
0534: if (file == null) {
0535: throw new DependencyResolutionRequiredException(a);
0536: }
0537: list.add(file.getPath());
0538: }
0539: }
0540: return list;
0541: }
0542:
0543: public List getTestArtifacts() {
0544: List list = new ArrayList(getArtifacts().size());
0545:
0546: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0547: Artifact a = (Artifact) i.next();
0548:
0549: // TODO: classpath check doesn't belong here - that's the other method
0550: if (a.getArtifactHandler().isAddedToClasspath()) {
0551: // TODO: let the scope handler deal with this
0552: // NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform
0553: // this check...
0554: // if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
0555: // Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
0556: // {
0557: // list.add( a );
0558: // }
0559:
0560: list.add(a);
0561: }
0562: }
0563: return list;
0564: }
0565:
0566: public List getTestDependencies() {
0567: Set artifacts = getArtifacts();
0568:
0569: if (artifacts == null || artifacts.isEmpty()) {
0570: return Collections.EMPTY_LIST;
0571: }
0572:
0573: List list = new ArrayList(artifacts.size());
0574:
0575: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0576: Artifact a = (Artifact) i.next();
0577:
0578: // TODO: let the scope handler deal with this
0579: // NOTE: [jc] scope == 'test' is the widest possible scope, so we don't really need to perform
0580: // this check...
0581: // if ( Artifact.SCOPE_TEST.equals( a.getScope() ) || Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
0582: // Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
0583: // {
0584: // }
0585:
0586: Dependency dependency = new Dependency();
0587:
0588: dependency.setArtifactId(a.getArtifactId());
0589: dependency.setGroupId(a.getGroupId());
0590: dependency.setVersion(a.getVersion());
0591: dependency.setScope(a.getScope());
0592: dependency.setType(a.getType());
0593: dependency.setClassifier(a.getClassifier());
0594:
0595: list.add(dependency);
0596: }
0597: return list;
0598: }
0599:
0600: public List getRuntimeClasspathElements()
0601: throws DependencyResolutionRequiredException {
0602: List list = new ArrayList(getArtifacts().size() + 1);
0603:
0604: list.add(getBuild().getOutputDirectory());
0605:
0606: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0607: Artifact a = (Artifact) i.next();
0608:
0609: if (a.getArtifactHandler().isAddedToClasspath()) {
0610: // TODO: let the scope handler deal with this
0611: if (Artifact.SCOPE_COMPILE.equals(a.getScope())
0612: || Artifact.SCOPE_RUNTIME.equals(a.getScope())) {
0613: File file = a.getFile();
0614: if (file == null) {
0615: throw new DependencyResolutionRequiredException(
0616: a);
0617: }
0618: list.add(file.getPath());
0619: }
0620: }
0621: }
0622: return list;
0623: }
0624:
0625: public List getRuntimeArtifacts() {
0626: List list = new ArrayList(getArtifacts().size());
0627:
0628: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0629: Artifact a = (Artifact) i.next();
0630:
0631: // TODO: classpath check doesn't belong here - that's the other method
0632: if (a.getArtifactHandler().isAddedToClasspath()) {
0633: // TODO: let the scope handler deal with this
0634: if (Artifact.SCOPE_COMPILE.equals(a.getScope())
0635: || Artifact.SCOPE_RUNTIME.equals(a.getScope())) {
0636: list.add(a);
0637: }
0638: }
0639: }
0640: return list;
0641: }
0642:
0643: public List getRuntimeDependencies() {
0644: Set artifacts = getArtifacts();
0645:
0646: if (artifacts == null || artifacts.isEmpty()) {
0647: return Collections.EMPTY_LIST;
0648: }
0649:
0650: List list = new ArrayList(artifacts.size());
0651:
0652: for (Iterator i = artifacts.iterator(); i.hasNext();) {
0653: Artifact a = (Artifact) i.next();
0654:
0655: // TODO: let the scope handler deal with this
0656: if (Artifact.SCOPE_COMPILE.equals(a.getScope())
0657: || Artifact.SCOPE_RUNTIME.equals(a.getScope())) {
0658: Dependency dependency = new Dependency();
0659:
0660: dependency.setArtifactId(a.getArtifactId());
0661: dependency.setGroupId(a.getGroupId());
0662: dependency.setVersion(a.getVersion());
0663: dependency.setScope(a.getScope());
0664: dependency.setType(a.getType());
0665: dependency.setClassifier(a.getClassifier());
0666:
0667: list.add(dependency);
0668: }
0669: }
0670: return list;
0671: }
0672:
0673: public List getSystemClasspathElements()
0674: throws DependencyResolutionRequiredException {
0675: List list = new ArrayList(getArtifacts().size());
0676:
0677: list.add(getBuild().getOutputDirectory());
0678:
0679: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0680: Artifact a = (Artifact) i.next();
0681:
0682: if (a.getArtifactHandler().isAddedToClasspath()) {
0683: // TODO: let the scope handler deal with this
0684: if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
0685: addArtifactPath(a, list);
0686: }
0687: }
0688: }
0689: return list;
0690: }
0691:
0692: public List getSystemArtifacts() {
0693: List list = new ArrayList(getArtifacts().size());
0694:
0695: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0696: Artifact a = (Artifact) i.next();
0697:
0698: // TODO: classpath check doesn't belong here - that's the other method
0699: if (a.getArtifactHandler().isAddedToClasspath()) {
0700: // TODO: let the scope handler deal with this
0701: if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
0702: list.add(a);
0703: }
0704: }
0705: }
0706: return list;
0707: }
0708:
0709: public List getSystemDependencies() {
0710: Set artifacts = getArtifacts();
0711:
0712: if (artifacts == null || artifacts.isEmpty()) {
0713: return Collections.EMPTY_LIST;
0714: }
0715:
0716: List list = new ArrayList(artifacts.size());
0717:
0718: for (Iterator i = getArtifacts().iterator(); i.hasNext();) {
0719: Artifact a = (Artifact) i.next();
0720:
0721: // TODO: let the scope handler deal with this
0722: if (Artifact.SCOPE_SYSTEM.equals(a.getScope())) {
0723: Dependency dependency = new Dependency();
0724:
0725: dependency.setArtifactId(a.getArtifactId());
0726: dependency.setGroupId(a.getGroupId());
0727: dependency.setVersion(a.getVersion());
0728: dependency.setScope(a.getScope());
0729: dependency.setType(a.getType());
0730: dependency.setClassifier(a.getClassifier());
0731:
0732: list.add(dependency);
0733: }
0734: }
0735: return list;
0736: }
0737:
0738: // ----------------------------------------------------------------------
0739: // Delegate to the model
0740: // ----------------------------------------------------------------------
0741:
0742: public void setModelVersion(String pomVersion) {
0743: model.setModelVersion(pomVersion);
0744: }
0745:
0746: public String getModelVersion() {
0747: return model.getModelVersion();
0748: }
0749:
0750: public String getId() {
0751: return model.getId();
0752: }
0753:
0754: public void setGroupId(String groupId) {
0755: model.setGroupId(groupId);
0756: }
0757:
0758: public String getGroupId() {
0759: String groupId = model.getGroupId();
0760:
0761: if (groupId == null && model.getParent() != null) {
0762: groupId = model.getParent().getGroupId();
0763: }
0764:
0765: return groupId;
0766: }
0767:
0768: public void setArtifactId(String artifactId) {
0769: model.setArtifactId(artifactId);
0770: }
0771:
0772: public String getArtifactId() {
0773: return model.getArtifactId();
0774: }
0775:
0776: public void setName(String name) {
0777: model.setName(name);
0778: }
0779:
0780: public String getName() {
0781: // TODO: this should not be allowed to be null.
0782: if (model.getName() != null) {
0783: return model.getName();
0784: } else {
0785: return "Unnamed - " + getId();
0786: }
0787: }
0788:
0789: public void setVersion(String version) {
0790: model.setVersion(version);
0791: }
0792:
0793: public String getVersion() {
0794: String version = model.getVersion();
0795:
0796: if (version == null && model.getParent() != null) {
0797: version = model.getParent().getVersion();
0798: }
0799:
0800: return version;
0801: }
0802:
0803: public String getPackaging() {
0804: return model.getPackaging();
0805: }
0806:
0807: public void setPackaging(String packaging) {
0808: model.setPackaging(packaging);
0809: }
0810:
0811: public void setInceptionYear(String inceptionYear) {
0812: model.setInceptionYear(inceptionYear);
0813: }
0814:
0815: public String getInceptionYear() {
0816: return model.getInceptionYear();
0817: }
0818:
0819: public void setUrl(String url) {
0820: model.setUrl(url);
0821: }
0822:
0823: public String getUrl() {
0824: return model.getUrl();
0825: }
0826:
0827: public Prerequisites getPrerequisites() {
0828: return model.getPrerequisites();
0829: }
0830:
0831: public void setIssueManagement(IssueManagement issueManagement) {
0832: model.setIssueManagement(issueManagement);
0833: }
0834:
0835: public CiManagement getCiManagement() {
0836: return model.getCiManagement();
0837: }
0838:
0839: public void setCiManagement(CiManagement ciManagement) {
0840: model.setCiManagement(ciManagement);
0841: }
0842:
0843: public IssueManagement getIssueManagement() {
0844: return model.getIssueManagement();
0845: }
0846:
0847: public void setDistributionManagement(
0848: DistributionManagement distributionManagement) {
0849: model.setDistributionManagement(distributionManagement);
0850: }
0851:
0852: public DistributionManagement getDistributionManagement() {
0853: return model.getDistributionManagement();
0854: }
0855:
0856: public void setDescription(String description) {
0857: model.setDescription(description);
0858: }
0859:
0860: public String getDescription() {
0861: return model.getDescription();
0862: }
0863:
0864: public void setOrganization(Organization organization) {
0865: model.setOrganization(organization);
0866: }
0867:
0868: public Organization getOrganization() {
0869: return model.getOrganization();
0870: }
0871:
0872: public void setScm(Scm scm) {
0873: model.setScm(scm);
0874: }
0875:
0876: public Scm getScm() {
0877: return model.getScm();
0878: }
0879:
0880: public void setMailingLists(List mailingLists) {
0881: model.setMailingLists(mailingLists);
0882: }
0883:
0884: public List getMailingLists() {
0885: return model.getMailingLists();
0886: }
0887:
0888: public void addMailingList(MailingList mailingList) {
0889: model.addMailingList(mailingList);
0890: }
0891:
0892: public void setDevelopers(List developers) {
0893: model.setDevelopers(developers);
0894: }
0895:
0896: public List getDevelopers() {
0897: return model.getDevelopers();
0898: }
0899:
0900: public void addDeveloper(Developer developer) {
0901: model.addDeveloper(developer);
0902: }
0903:
0904: public void setContributors(List contributors) {
0905: model.setContributors(contributors);
0906: }
0907:
0908: public List getContributors() {
0909: return model.getContributors();
0910: }
0911:
0912: public void addContributor(Contributor contributor) {
0913: model.addContributor(contributor);
0914: }
0915:
0916: public void setBuild(Build build) {
0917: this .buildOverlay = new BuildOverlay(build);
0918:
0919: model.setBuild(build);
0920: }
0921:
0922: public Build getBuild() {
0923: if (buildOverlay == null) {
0924: buildOverlay = new BuildOverlay(getModelBuild());
0925: }
0926:
0927: return buildOverlay;
0928: }
0929:
0930: public List getResources() {
0931: return getBuild().getResources();
0932: }
0933:
0934: public List getTestResources() {
0935: return getBuild().getTestResources();
0936: }
0937:
0938: public void addResource(Resource resource) {
0939: getBuild().addResource(resource);
0940: }
0941:
0942: public void addTestResource(Resource testResource) {
0943: getBuild().addTestResource(testResource);
0944: }
0945:
0946: public void setReporting(Reporting reporting) {
0947: model.setReporting(reporting);
0948: }
0949:
0950: public Reporting getReporting() {
0951: return model.getReporting();
0952: }
0953:
0954: public void setLicenses(List licenses) {
0955: model.setLicenses(licenses);
0956: }
0957:
0958: public List getLicenses() {
0959: return model.getLicenses();
0960: }
0961:
0962: public void addLicense(License license) {
0963: model.addLicense(license);
0964: }
0965:
0966: public void setArtifacts(Set artifacts) {
0967: this .artifacts = artifacts;
0968:
0969: // flush the calculated artifactMap
0970: this .artifactMap = null;
0971: }
0972:
0973: /**
0974: * All dependencies that this project has, including transitive ones.
0975: * Contents are lazily populated, so depending on what phases have run dependencies in some scopes won't be included.
0976: * eg. if only compile phase has run, dependencies with scope test won't be included.
0977: * @return {@link Set} < {@link Artifact} >
0978: * @see #getDependencyArtifacts() to get only direct dependencies
0979: */
0980: public Set getArtifacts() {
0981: return artifacts == null ? Collections.EMPTY_SET : artifacts;
0982: }
0983:
0984: public Map getArtifactMap() {
0985: if (artifactMap == null) {
0986: artifactMap = ArtifactUtils
0987: .artifactMapByVersionlessId(getArtifacts());
0988: }
0989:
0990: return artifactMap;
0991: }
0992:
0993: public void setPluginArtifacts(Set pluginArtifacts) {
0994: this .pluginArtifacts = pluginArtifacts;
0995:
0996: this .pluginArtifactMap = null;
0997: }
0998:
0999: public Set getPluginArtifacts() {
1000: return pluginArtifacts;
1001: }
1002:
1003: public Map getPluginArtifactMap() {
1004: if (pluginArtifactMap == null) {
1005: pluginArtifactMap = ArtifactUtils
1006: .artifactMapByVersionlessId(getPluginArtifacts());
1007: }
1008:
1009: return pluginArtifactMap;
1010: }
1011:
1012: public void setReportArtifacts(Set reportArtifacts) {
1013: this .reportArtifacts = reportArtifacts;
1014:
1015: this .reportArtifactMap = null;
1016: }
1017:
1018: public Set getReportArtifacts() {
1019: return reportArtifacts;
1020: }
1021:
1022: public Map getReportArtifactMap() {
1023: if (reportArtifactMap == null) {
1024: reportArtifactMap = ArtifactUtils
1025: .artifactMapByVersionlessId(getReportArtifacts());
1026: }
1027:
1028: return reportArtifactMap;
1029: }
1030:
1031: public void setExtensionArtifacts(Set extensionArtifacts) {
1032: this .extensionArtifacts = extensionArtifacts;
1033:
1034: this .extensionArtifactMap = null;
1035: }
1036:
1037: public Set getExtensionArtifacts() {
1038: return this .extensionArtifacts;
1039: }
1040:
1041: public Map getExtensionArtifactMap() {
1042: if (extensionArtifactMap == null) {
1043: extensionArtifactMap = ArtifactUtils
1044: .artifactMapByVersionlessId(getExtensionArtifacts());
1045: }
1046:
1047: return extensionArtifactMap;
1048: }
1049:
1050: public void setParentArtifact(Artifact parentArtifact) {
1051: this .parentArtifact = parentArtifact;
1052: }
1053:
1054: public Artifact getParentArtifact() {
1055: return parentArtifact;
1056: }
1057:
1058: public List getRepositories() {
1059: return model.getRepositories();
1060: }
1061:
1062: // ----------------------------------------------------------------------
1063: // Plugins
1064: // ----------------------------------------------------------------------
1065:
1066: public List getReportPlugins() {
1067: if (model.getReporting() == null) {
1068: return null;
1069: }
1070: return model.getReporting().getPlugins();
1071:
1072: }
1073:
1074: public List getBuildPlugins() {
1075: if (model.getBuild() == null) {
1076: return null;
1077: }
1078: return model.getBuild().getPlugins();
1079: }
1080:
1081: public List getModules() {
1082: return model.getModules();
1083: }
1084:
1085: public PluginManagement getPluginManagement() {
1086: PluginManagement pluginMgmt = null;
1087:
1088: Build build = model.getBuild();
1089: if (build != null) {
1090: pluginMgmt = build.getPluginManagement();
1091: }
1092:
1093: return pluginMgmt;
1094: }
1095:
1096: private Build getModelBuild() {
1097: Build build = model.getBuild();
1098:
1099: if (build == null) {
1100: build = new Build();
1101:
1102: model.setBuild(build);
1103: }
1104:
1105: return build;
1106: }
1107:
1108: public void addPlugin(Plugin plugin) {
1109: Build build = getModelBuild();
1110:
1111: if (!build.getPluginsAsMap().containsKey(plugin.getKey())) {
1112: injectPluginManagementInfo(plugin);
1113:
1114: build.addPlugin(plugin);
1115:
1116: build.flushPluginMap();
1117: }
1118: }
1119:
1120: public void injectPluginManagementInfo(Plugin plugin) {
1121: PluginManagement pm = getModelBuild().getPluginManagement();
1122:
1123: if (pm != null) {
1124: Map pmByKey = pm.getPluginsAsMap();
1125:
1126: String pluginKey = plugin.getKey();
1127:
1128: if (pmByKey != null && pmByKey.containsKey(pluginKey)) {
1129: Plugin pmPlugin = (Plugin) pmByKey.get(pluginKey);
1130:
1131: ModelUtils.mergePluginDefinitions(plugin, pmPlugin,
1132: false);
1133: }
1134: }
1135: }
1136:
1137: public List getCollectedProjects() {
1138: return collectedProjects;
1139: }
1140:
1141: public void setCollectedProjects(List collectedProjects) {
1142: this .collectedProjects = collectedProjects;
1143: }
1144:
1145: public void setPluginArtifactRepositories(
1146: List pluginArtifactRepositories) {
1147: this .pluginArtifactRepositories = pluginArtifactRepositories;
1148: }
1149:
1150: /**
1151: * @return a list of ArtifactRepository objects constructed
1152: * from the Repository objects returned by getPluginRepositories.
1153: */
1154: public List getPluginArtifactRepositories() {
1155: return pluginArtifactRepositories;
1156: }
1157:
1158: public ArtifactRepository getDistributionManagementArtifactRepository() {
1159: return getArtifact().isSnapshot()
1160: && snapshotArtifactRepository != null ? snapshotArtifactRepository
1161: : releaseArtifactRepository;
1162: }
1163:
1164: public List getPluginRepositories() {
1165: return model.getPluginRepositories();
1166: }
1167:
1168: public void setActiveProfiles(List activeProfiles) {
1169: this .activeProfiles.addAll(activeProfiles);
1170: }
1171:
1172: public List getActiveProfiles() {
1173: return activeProfiles;
1174: }
1175:
1176: public void addAttachedArtifact(Artifact artifact) {
1177: getAttachedArtifacts().add(artifact);
1178: }
1179:
1180: public List getAttachedArtifacts() {
1181: if (attachedArtifacts == null) {
1182: attachedArtifacts = new ArrayList();
1183: }
1184: return attachedArtifacts;
1185: }
1186:
1187: public Xpp3Dom getGoalConfiguration(String pluginGroupId,
1188: String pluginArtifactId, String executionId, String goalId) {
1189: Xpp3Dom dom = null;
1190:
1191: // ----------------------------------------------------------------------
1192: // I would like to be able to lookup the Mojo object using a key but
1193: // we have a limitation in modello that will be remedied shortly. So
1194: // for now I have to iterate through and see what we have.
1195: // ----------------------------------------------------------------------
1196:
1197: if (getBuildPlugins() != null) {
1198: for (Iterator iterator = getBuildPlugins().iterator(); iterator
1199: .hasNext();) {
1200: Plugin plugin = (Plugin) iterator.next();
1201:
1202: if (pluginGroupId.equals(plugin.getGroupId())
1203: && pluginArtifactId.equals(plugin
1204: .getArtifactId())) {
1205: dom = (Xpp3Dom) plugin.getConfiguration();
1206:
1207: if (executionId != null) {
1208: PluginExecution execution = (PluginExecution) plugin
1209: .getExecutionsAsMap().get(executionId);
1210: if (execution != null) {
1211: Xpp3Dom executionConfiguration = (Xpp3Dom) execution
1212: .getConfiguration();
1213: if (executionConfiguration != null) {
1214: Xpp3Dom newDom = new Xpp3Dom(
1215: executionConfiguration);
1216: dom = Xpp3Dom.mergeXpp3Dom(newDom, dom);
1217: }
1218: }
1219: }
1220: break;
1221: }
1222: }
1223: }
1224:
1225: if (dom != null) {
1226: // make a copy so the original in the POM doesn't get messed with
1227: dom = new Xpp3Dom(dom);
1228: }
1229:
1230: return dom;
1231: }
1232:
1233: public Xpp3Dom getReportConfiguration(String pluginGroupId,
1234: String pluginArtifactId, String reportSetId) {
1235: Xpp3Dom dom = null;
1236:
1237: // ----------------------------------------------------------------------
1238: // I would like to be able to lookup the Mojo object using a key but
1239: // we have a limitation in modello that will be remedied shortly. So
1240: // for now I have to iterate through and see what we have.
1241: // ----------------------------------------------------------------------
1242:
1243: if (getReportPlugins() != null) {
1244: for (Iterator iterator = getReportPlugins().iterator(); iterator
1245: .hasNext();) {
1246: ReportPlugin plugin = (ReportPlugin) iterator.next();
1247:
1248: if (pluginGroupId.equals(plugin.getGroupId())
1249: && pluginArtifactId.equals(plugin
1250: .getArtifactId())) {
1251: dom = (Xpp3Dom) plugin.getConfiguration();
1252:
1253: if (reportSetId != null) {
1254: ReportSet reportSet = (ReportSet) plugin
1255: .getReportSetsAsMap().get(reportSetId);
1256: if (reportSet != null) {
1257: Xpp3Dom executionConfiguration = (Xpp3Dom) reportSet
1258: .getConfiguration();
1259: if (executionConfiguration != null) {
1260: Xpp3Dom newDom = new Xpp3Dom(
1261: executionConfiguration);
1262: dom = Xpp3Dom.mergeXpp3Dom(newDom, dom);
1263: }
1264: }
1265: }
1266: break;
1267: }
1268: }
1269: }
1270:
1271: if (dom != null) {
1272: // make a copy so the original in the POM doesn't get messed with
1273: dom = new Xpp3Dom(dom);
1274: }
1275:
1276: return dom;
1277: }
1278:
1279: public MavenProject getExecutionProject() {
1280: return (executionProject == null ? this : executionProject);
1281: }
1282:
1283: public void setExecutionProject(MavenProject executionProject) {
1284: if (this .executionProject != null) {
1285: previousExecutionProjects.push(this .executionProject);
1286: }
1287:
1288: this .executionProject = executionProject;
1289: }
1290:
1291: public void writeModel(Writer writer) throws IOException {
1292: MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1293:
1294: pomWriter.write(writer, getModel());
1295: }
1296:
1297: public void writeOriginalModel(Writer writer) throws IOException {
1298: MavenXpp3Writer pomWriter = new MavenXpp3Writer();
1299:
1300: pomWriter.write(writer, getOriginalModel());
1301: }
1302:
1303: /**
1304: * Direct dependencies that this project has.
1305: * @return {@link Set} < {@link Artifact} >
1306: * @see #getArtifacts() to get all transitive dependencies
1307: */
1308: public Set getDependencyArtifacts() {
1309: return dependencyArtifacts;
1310: }
1311:
1312: public void setDependencyArtifacts(Set dependencyArtifacts) {
1313: this .dependencyArtifacts = dependencyArtifacts;
1314: }
1315:
1316: public void setReleaseArtifactRepository(
1317: ArtifactRepository releaseArtifactRepository) {
1318: this .releaseArtifactRepository = releaseArtifactRepository;
1319: }
1320:
1321: public void setSnapshotArtifactRepository(
1322: ArtifactRepository snapshotArtifactRepository) {
1323: this .snapshotArtifactRepository = snapshotArtifactRepository;
1324: }
1325:
1326: public void setOriginalModel(Model originalModel) {
1327: this .originalModel = originalModel;
1328: }
1329:
1330: public Model getOriginalModel() {
1331: return originalModel;
1332: }
1333:
1334: public void setManagedVersionMap(Map map) {
1335: this .managedVersionMap = map;
1336: }
1337:
1338: public Map getManagedVersionMap() {
1339: return this .managedVersionMap;
1340: }
1341:
1342: public boolean equals(Object other) {
1343: if (other == this ) {
1344: return true;
1345: } else if (!(other instanceof MavenProject)) {
1346: return false;
1347: } else {
1348: MavenProject otherProject = (MavenProject) other;
1349:
1350: return getId().equals(otherProject.getId());
1351: }
1352: }
1353:
1354: public int hashCode() {
1355: return getId().hashCode();
1356: }
1357:
1358: public List getBuildExtensions() {
1359: Build build = getBuild();
1360: if (build == null || build.getExtensions() == null) {
1361: return Collections.EMPTY_LIST;
1362: } else {
1363: return build.getExtensions();
1364: }
1365: }
1366:
1367: /**
1368: * @todo the lazy initialisation of this makes me uneasy.
1369: * @return {@link Set} < {@link Artifact} >
1370: */
1371: public Set createArtifacts(ArtifactFactory artifactFactory,
1372: String inheritedScope, ArtifactFilter dependencyFilter)
1373: throws InvalidDependencyVersionException {
1374: return MavenMetadataSource.createArtifacts(artifactFactory,
1375: getDependencies(), inheritedScope, dependencyFilter,
1376: this );
1377: }
1378:
1379: public void addProjectReference(MavenProject project) {
1380: projectReferences.put(getProjectReferenceId(project
1381: .getGroupId(), project.getArtifactId(), project
1382: .getVersion()), project);
1383: }
1384:
1385: private static String getProjectReferenceId(String groupId,
1386: String artifactId, String version) {
1387: return groupId + ":" + artifactId + ":" + version;
1388: }
1389:
1390: /**
1391: * @deprecated Use MavenProjectHelper.attachArtifact(..) instead.
1392: */
1393: public void attachArtifact(String type, String classifier, File file) {
1394: }
1395:
1396: public Properties getProperties() {
1397: return getModel().getProperties();
1398: }
1399:
1400: public List getFilters() {
1401: return getBuild().getFilters();
1402: }
1403:
1404: public Map getProjectReferences() {
1405: return projectReferences;
1406: }
1407:
1408: public boolean isExecutionRoot() {
1409: return executionRoot;
1410: }
1411:
1412: public void setExecutionRoot(boolean executionRoot) {
1413: this .executionRoot = executionRoot;
1414: }
1415:
1416: public String getDefaultGoal() {
1417: return getBuild() != null ? getBuild().getDefaultGoal() : null;
1418: }
1419:
1420: public Artifact replaceWithActiveArtifact(Artifact pluginArtifact) {
1421: if (getProjectReferences() != null
1422: && !getProjectReferences().isEmpty()) {
1423: String refId = getProjectReferenceId(pluginArtifact
1424: .getGroupId(), pluginArtifact.getArtifactId(),
1425: pluginArtifact.getVersion());
1426: MavenProject ref = (MavenProject) getProjectReferences()
1427: .get(refId);
1428: if (ref != null && ref.getArtifact() != null) {
1429: // TODO: if not matching, we should get the correct artifact from that project (attached)
1430: if (ref.getArtifact().getDependencyConflictId().equals(
1431: pluginArtifact.getDependencyConflictId())) {
1432: // if the project artifact doesn't exist, don't use it. We haven't built that far.
1433: if (ref.getArtifact().getFile() != null
1434: && ref.getArtifact().getFile().exists()) {
1435: pluginArtifact = new ActiveProjectArtifact(ref,
1436: pluginArtifact);
1437: return pluginArtifact;
1438: } else {
1439: /* TODO...
1440: logger.warn( "Artifact found in the reactor has not been built when it's use was " +
1441: "attempted - resolving from the repository instead" );
1442: */
1443: }
1444: }
1445:
1446: Iterator itr = ref.getAttachedArtifacts().iterator();
1447: while (itr.hasNext()) {
1448: Artifact attached = (Artifact) itr.next();
1449: if (attached.getDependencyConflictId().equals(
1450: pluginArtifact.getDependencyConflictId())) {
1451: /* TODO: if I use the original, I get an exception below:
1452: java.lang.UnsupportedOperationException: Cannot change the download information for an attached artifact. It is derived from the main artifact.
1453: at org.apache.maven.project.artifact.AttachedArtifact.setDownloadUrl(AttachedArtifact.java:89)
1454: at org.apache.maven.project.artifact.MavenMetadataSource.retrieve(MavenMetadataSource.java:205)
1455: at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:275)
1456: at org.apache.maven.artifact.resolver.DefaultArtifactCollector.collect(DefaultArtifactCollector.java:67)
1457: at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:223)
1458: at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:211)
1459: at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:182)
1460: at org.apache.maven.plugin.DefaultPluginManager.resolveTransitiveDependencies(DefaultPluginManager.java:1117)
1461: at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:366)
1462: at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
1463: at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475)
1464: at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
1465: at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306)
1466: at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
1467: at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
1468: at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
1469: at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
1470: at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
1471: */
1472: Artifact resultArtifact = ArtifactUtils
1473: .copyArtifact(attached);
1474: resultArtifact.setScope(pluginArtifact
1475: .getScope());
1476: return resultArtifact;
1477: }
1478: }
1479:
1480: /**
1481: * Patch/workaround for: MNG-2871
1482: *
1483: * We want to use orginal artifact (packaging:ejb) when we are
1484: * resolving ejb-client package and we didn't manage to find
1485: * attached to project one.
1486: *
1487: * The scenario is such that somebody run "mvn test" in composity project,
1488: * and ejb-client.jar will not be attached to ejb.jar (because it is done in package phase)
1489: *
1490: * We prefer in such a case use orginal sources (of ejb.jar) instead of failure
1491: */
1492: if ((ref.getArtifactId().equals(pluginArtifact
1493: .getArtifactId()))
1494: && (ref.getGroupId().equals(pluginArtifact
1495: .getGroupId()))
1496: && (ref.getArtifact().getType().equals("ejb"))
1497: && (pluginArtifact.getType()
1498: .equals("ejb-client"))
1499: && (ref.getArtifact().getFile() != null && ref
1500: .getArtifact().getFile().exists())) {
1501: pluginArtifact = new ActiveProjectArtifact(ref,
1502: pluginArtifact);
1503: return pluginArtifact;
1504: }
1505: }
1506: }
1507: return pluginArtifact;
1508: }
1509:
1510: private void addArtifactPath(Artifact a, List list)
1511: throws DependencyResolutionRequiredException {
1512: String refId = getProjectReferenceId(a.getGroupId(), a
1513: .getArtifactId(), a.getVersion());
1514: MavenProject project = (MavenProject) projectReferences
1515: .get(refId);
1516: if (project != null) {
1517: list.add(project.getBuild().getOutputDirectory());
1518: } else {
1519: File file = a.getFile();
1520: if (file == null) {
1521: throw new DependencyResolutionRequiredException(a);
1522: }
1523: list.add(file.getPath());
1524: }
1525: }
1526:
1527: public void clearExecutionProject() {
1528: if (!previousExecutionProjects.isEmpty()) {
1529: executionProject = (MavenProject) previousExecutionProjects
1530: .pop();
1531: } else {
1532: executionProject = null;
1533: }
1534: }
1535: }
|