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.MavenTools;
0023: import org.apache.maven.artifact.Artifact;
0024: import org.apache.maven.artifact.ArtifactStatus;
0025: import org.apache.maven.artifact.ArtifactUtils;
0026: import org.apache.maven.artifact.InvalidRepositoryException;
0027: import org.apache.maven.artifact.factory.ArtifactFactory;
0028: import org.apache.maven.artifact.manager.WagonManager;
0029: import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
0030: import org.apache.maven.artifact.repository.ArtifactRepository;
0031: import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
0032: import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
0033: import org.apache.maven.artifact.resolver.ArtifactResolutionException;
0034: import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
0035: import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
0036: import org.apache.maven.artifact.resolver.ArtifactResolver;
0037: import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
0038: import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
0039: import org.apache.maven.artifact.versioning.ManagedVersionMap;
0040: import org.apache.maven.artifact.versioning.VersionRange;
0041: import org.apache.maven.context.BuildContextManager;
0042: import org.apache.maven.model.Build;
0043: import org.apache.maven.model.Dependency;
0044: import org.apache.maven.model.DependencyManagement;
0045: import org.apache.maven.model.DistributionManagement;
0046: import org.apache.maven.model.Exclusion;
0047: import org.apache.maven.model.Extension;
0048: import org.apache.maven.model.Model;
0049: import org.apache.maven.model.Plugin;
0050: import org.apache.maven.model.ReportPlugin;
0051: import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
0052: import org.apache.maven.profiles.MavenProfilesBuilder;
0053: import org.apache.maven.profiles.ProfileManager;
0054: import org.apache.maven.profiles.activation.ProfileActivationException;
0055: import org.apache.maven.project.artifact.InvalidDependencyVersionException;
0056: import org.apache.maven.project.build.ProjectBuildCache;
0057: import org.apache.maven.project.build.ProjectBuildContext;
0058: import org.apache.maven.project.build.model.DefaultModelLineage;
0059: import org.apache.maven.project.build.model.ModelLineage;
0060: import org.apache.maven.project.build.model.ModelLineageBuilder;
0061: import org.apache.maven.project.build.model.ModelLineageIterator;
0062: import org.apache.maven.profiles.build.ProfileAdvisor;
0063: import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
0064: import org.apache.maven.project.injection.ModelDefaultsInjector;
0065: import org.apache.maven.project.interpolation.ModelInterpolationException;
0066: import org.apache.maven.project.interpolation.ModelInterpolator;
0067: import org.apache.maven.project.path.PathTranslator;
0068: import org.apache.maven.project.validation.ModelValidationResult;
0069: import org.apache.maven.project.validation.ModelValidator;
0070: import org.apache.maven.wagon.events.TransferListener;
0071: import org.codehaus.plexus.PlexusConstants;
0072: import org.codehaus.plexus.PlexusContainer;
0073: import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
0074: import org.codehaus.plexus.context.Context;
0075: import org.codehaus.plexus.context.ContextException;
0076: import org.codehaus.plexus.logging.AbstractLogEnabled;
0077: import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
0078: import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
0079: import org.codehaus.plexus.util.IOUtil;
0080: import org.codehaus.plexus.util.StringUtils;
0081: import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
0082:
0083: import java.io.File;
0084: import java.io.FileNotFoundException;
0085: import java.io.FileReader;
0086: import java.io.IOException;
0087: import java.io.InputStreamReader;
0088: import java.io.Reader;
0089: import java.io.StringReader;
0090: import java.io.StringWriter;
0091: import java.net.URL;
0092: import java.util.ArrayList;
0093: import java.util.Collections;
0094: import java.util.Date;
0095: import java.util.HashMap;
0096: import java.util.HashSet;
0097: import java.util.Iterator;
0098: import java.util.LinkedHashSet;
0099: import java.util.LinkedList;
0100: import java.util.List;
0101: import java.util.Map;
0102: import java.util.Set;
0103: import java.util.TreeMap;
0104:
0105: /*:apt
0106:
0107: -----
0108: POM lifecycle
0109: -----
0110:
0111: POM Lifecycle
0112:
0113: Order of operations when building a POM
0114:
0115: * inheritance
0116: * path translation
0117: * interpolation
0118: * defaults injection
0119:
0120: Current processing is:
0121:
0122: * inheritance
0123: * interpolation
0124: * defaults injection
0125: * path translation
0126:
0127: I'm not sure how this is working at all ... i think i have a case where this is failing but i need to
0128: encapsulate as a test so i can fix it. Also need to think of the in working build directory versus looking
0129: things up from the repository i.e buildFromSource vs buildFromRepository.
0130:
0131: Notes
0132:
0133: * when the model is read it may not have a groupId, as it must be inherited
0134:
0135: * the inheritance assembler must use models that are unadulterated!
0136:
0137: */
0138:
0139: /**
0140: * @version $Id: DefaultMavenProjectBuilder.java,v 1.37 2005/03/08 01:55:22
0141: * trygvis Exp $
0142: */
0143: public class DefaultMavenProjectBuilder extends AbstractLogEnabled
0144: implements MavenProjectBuilder, Initializable, Contextualizable {
0145: protected PlexusContainer container;
0146:
0147: protected MavenProfilesBuilder profilesBuilder;
0148:
0149: protected ArtifactResolver artifactResolver;
0150:
0151: protected ArtifactMetadataSource artifactMetadataSource;
0152:
0153: private ArtifactFactory artifactFactory;
0154:
0155: private ModelInheritanceAssembler modelInheritanceAssembler;
0156:
0157: private ModelValidator validator;
0158:
0159: // TODO: make it a component
0160: private MavenXpp3Reader modelReader;
0161:
0162: private PathTranslator pathTranslator;
0163:
0164: private ModelDefaultsInjector modelDefaultsInjector;
0165:
0166: private ModelInterpolator modelInterpolator;
0167:
0168: private ModelLineageBuilder modelLineageBuilder;
0169:
0170: private ProfileAdvisor profileAdvisor;
0171:
0172: private BuildContextManager buildContextManager;
0173:
0174: private MavenTools mavenTools;
0175:
0176: // ----------------------------------------------------------------------
0177: // I am making this available for use with a new method that takes a
0178: // a monitor wagon monitor as a parameter so that tools can use the
0179: // methods here and receive callbacks. MNG-1015
0180: //
0181: // Probably no longer relevant with wagonManager/wagonManager change - joakime
0182: // ----------------------------------------------------------------------
0183:
0184: private WagonManager wagonManager;
0185:
0186: public static final String MAVEN_MODEL_VERSION = "4.0.0";
0187:
0188: public void initialize() {
0189: modelReader = new MavenXpp3Reader();
0190: }
0191:
0192: // ----------------------------------------------------------------------
0193: // MavenProjectBuilder Implementation
0194: // ----------------------------------------------------------------------
0195:
0196: public MavenProject build(File projectDescriptor,
0197: ArtifactRepository localRepository,
0198: ProfileManager profileManager)
0199: throws ProjectBuildingException {
0200: return buildFromSourceFileInternal(projectDescriptor,
0201: localRepository, profileManager, true);
0202: }
0203:
0204: public MavenProject build(File projectDescriptor,
0205: ArtifactRepository localRepository,
0206: ProfileManager profileManager,
0207: boolean checkDistributionManagementStatus)
0208: throws ProjectBuildingException {
0209: return buildFromSourceFileInternal(projectDescriptor,
0210: localRepository, profileManager,
0211: checkDistributionManagementStatus);
0212: }
0213:
0214: // jvz:note
0215: // When asked for something from the repository are we getting it from the reactor? Yes, when using this call
0216: // we are assuming that the reactor has been run and we have collected the projects required to satisfy it0042
0217: // which means the projects in the reactor are required for finding classes in <project>/target/classes. Not
0218: // sure this is ideal. I remove all caching from the builder and all reactor related ITs which assume
0219: // access to simbling project resources failed.
0220: public MavenProject buildFromRepository(Artifact artifact,
0221: List remoteArtifactRepositories,
0222: ArtifactRepository localRepository, boolean allowStubModel)
0223: throws ProjectBuildingException {
0224: ProjectBuildCache projectBuildCache = ProjectBuildCache
0225: .read(buildContextManager);
0226:
0227: MavenProject project = projectBuildCache
0228: .getCachedProject(artifact);
0229:
0230: if (project != null) {
0231: return project;
0232: }
0233:
0234: Model model = findModelFromRepository(artifact,
0235: remoteArtifactRepositories, localRepository,
0236: allowStubModel);
0237:
0238: return buildInternal("Artifact [" + artifact + "]", model,
0239: localRepository, remoteArtifactRepositories, null,
0240: null, false);
0241: }
0242:
0243: public MavenProject buildFromRepository(Artifact artifact,
0244: List remoteArtifactRepositories,
0245: ArtifactRepository localRepository)
0246: throws ProjectBuildingException {
0247: return buildFromRepository(artifact,
0248: remoteArtifactRepositories, localRepository, true);
0249: }
0250:
0251: private MavenProject super Project;
0252:
0253: public MavenProject buildStandaloneSuperProject()
0254: throws ProjectBuildingException {
0255: if (this .super Project != null) {
0256: return this .super Project;
0257: }
0258:
0259: Model super Model = getSuperModel();
0260:
0261: super Model.setGroupId(STANDALONE_SUPERPOM_GROUPID);
0262:
0263: super Model.setArtifactId(STANDALONE_SUPERPOM_ARTIFACTID);
0264:
0265: super Model.setVersion(STANDALONE_SUPERPOM_VERSION);
0266:
0267: super Project = new MavenProject(super Model);
0268:
0269: try {
0270: super Project.setRemoteArtifactRepositories(mavenTools
0271: .buildArtifactRepositories(super Model
0272: .getRepositories()));
0273:
0274: super Project.setPluginArtifactRepositories(mavenTools
0275: .buildArtifactRepositories(super Model
0276: .getRepositories()));
0277: } catch (InvalidRepositoryException e) {
0278: // This will never happen with the repositories in the SuperPOM
0279: }
0280:
0281: super Project.setOriginalModel(super Model);
0282:
0283: super Project.setExecutionRoot(true);
0284:
0285: return super Project;
0286: }
0287:
0288: public MavenProjectBuildingResult buildWithDependencies(
0289: File projectDescriptor, ArtifactRepository localRepository,
0290: ProfileManager profileManager)
0291: throws ProjectBuildingException {
0292: return buildWithDependencies(projectDescriptor,
0293: localRepository, profileManager, null);
0294: }
0295:
0296: // note:jvz This was added for the embedder.
0297:
0298: /** @todo move to metadatasource itself? */
0299: public MavenProjectBuildingResult buildWithDependencies(
0300: File projectDescriptor, ArtifactRepository localRepository,
0301: ProfileManager profileManager,
0302: TransferListener transferListener)
0303: throws ProjectBuildingException {
0304: MavenProject project = build(projectDescriptor,
0305: localRepository, profileManager, false);
0306:
0307: // ----------------------------------------------------------------------
0308: // Typically when the project builder is being used from maven proper
0309: // the transitive dependencies will not be resolved here because this
0310: // requires a lot of work when we may only be interested in running
0311: // something simple like 'm2 clean'. So the artifact collector is used
0312: // in the dependency resolution phase if it is required by any of the
0313: // goals being executed. But when used as a component in another piece
0314: // of code people may just want to build maven projects and have the
0315: // dependencies resolved for whatever reason: this is why we keep
0316: // this snippet of code here.
0317: // ----------------------------------------------------------------------
0318:
0319: // TODO: such a call in MavenMetadataSource too - packaging not really the intention of type
0320: Artifact projectArtifact = project.getArtifact();
0321:
0322: String projectId = safeVersionlessKey(project.getGroupId(),
0323: project.getArtifactId());
0324:
0325: Map managedVersions = project.getManagedVersionMap();
0326:
0327: ensureMetadataSourceIsInitialized();
0328:
0329: try {
0330: project.setDependencyArtifacts(project.createArtifacts(
0331: artifactFactory, null, null));
0332: } catch (InvalidDependencyVersionException e) {
0333: throw new ProjectBuildingException(projectId,
0334: "Unable to build project due to an invalid dependency version: "
0335: + e.getMessage(), e);
0336: }
0337:
0338: if (transferListener != null) {
0339: wagonManager.setDownloadMonitor(transferListener);
0340: }
0341:
0342: ArtifactResolutionRequest request = new ArtifactResolutionRequest()
0343: .setArtifact(projectArtifact).setArtifactDependencies(
0344: project.getDependencyArtifacts())
0345: .setLocalRepository(localRepository)
0346: .setRemoteRepostories(
0347: project.getRemoteArtifactRepositories())
0348: .setManagedVersionMap(managedVersions)
0349: .setMetadataSource(artifactMetadataSource);
0350:
0351: ArtifactResolutionResult result = artifactResolver
0352: .resolve(request);
0353:
0354: project.setArtifacts(result.getArtifacts());
0355:
0356: return new MavenProjectBuildingResult(project, result);
0357: }
0358:
0359: // ----------------------------------------------------------------------
0360: //
0361: // ----------------------------------------------------------------------
0362:
0363: private void ensureMetadataSourceIsInitialized()
0364: throws ProjectBuildingException {
0365: if (artifactMetadataSource == null) {
0366: try {
0367: artifactMetadataSource = (ArtifactMetadataSource) container
0368: .lookup(ArtifactMetadataSource.ROLE);
0369: } catch (ComponentLookupException e) {
0370: throw new ProjectBuildingException(
0371: "all",
0372: "Cannot lookup metadata source for building the project.",
0373: e);
0374: }
0375: }
0376: }
0377:
0378: private Map createManagedVersionMap(String projectId,
0379: DependencyManagement dependencyManagement,
0380: MavenProject parent) throws ProjectBuildingException {
0381: Map map = null;
0382: List deps;
0383: if ((dependencyManagement != null)
0384: && ((deps = dependencyManagement.getDependencies()) != null)
0385: && (deps.size() > 0)) {
0386: map = new ManagedVersionMap(map);
0387:
0388: if (getLogger().isDebugEnabled()) {
0389: getLogger().debug(
0390: "Adding managed dependencies for " + projectId);
0391: }
0392:
0393: for (Iterator i = dependencyManagement.getDependencies()
0394: .iterator(); i.hasNext();) {
0395: Dependency d = (Dependency) i.next();
0396:
0397: try {
0398: VersionRange versionRange = VersionRange
0399: .createFromVersionSpec(d.getVersion());
0400: Artifact artifact = artifactFactory
0401: .createDependencyArtifact(d.getGroupId(), d
0402: .getArtifactId(), versionRange, d
0403: .getType(), d.getClassifier(), d
0404: .getScope(), d.isOptional());
0405: if (getLogger().isDebugEnabled()) {
0406: getLogger().debug(" " + artifact);
0407: }
0408:
0409: // If the dependencyManagement section listed exclusions,
0410: // add them to the managed artifacts here so that transitive
0411: // dependencies will be excluded if necessary.
0412: if ((null != d.getExclusions())
0413: && !d.getExclusions().isEmpty()) {
0414: List exclusions = new ArrayList();
0415: Iterator exclItr = d.getExclusions().iterator();
0416: while (exclItr.hasNext()) {
0417: Exclusion e = (Exclusion) exclItr.next();
0418: exclusions.add(e.getGroupId() + ":"
0419: + e.getArtifactId());
0420: }
0421: ExcludesArtifactFilter eaf = new ExcludesArtifactFilter(
0422: exclusions);
0423: artifact.setDependencyFilter(eaf);
0424: } else {
0425: artifact.setDependencyFilter(null);
0426: }
0427: map.put(d.getManagementKey(), artifact);
0428: } catch (InvalidVersionSpecificationException e) {
0429: throw new ProjectBuildingException(projectId,
0430: "Unable to parse version '"
0431: + d.getVersion()
0432: + "' for dependency '"
0433: + d.getManagementKey() + "': "
0434: + e.getMessage(), e);
0435: }
0436: }
0437: } else if (map == null) {
0438: map = Collections.EMPTY_MAP;
0439: }
0440: return map;
0441: }
0442:
0443: private MavenProject buildFromSourceFileInternal(
0444: File projectDescriptor, ArtifactRepository localRepository,
0445: ProfileManager profileManager,
0446: boolean checkDistributionManagementStatus)
0447: throws ProjectBuildingException {
0448: // TODO: Remove this once we have build-context stuff working...
0449: if (!container.getContext().contains("SystemProperties")) {
0450: container.addContextValue("SystemProperties", System
0451: .getProperties());
0452: }
0453:
0454: Model model = readModel("unknown", projectDescriptor,
0455: STRICT_MODEL_PARSING);
0456:
0457: MavenProject project = buildInternal(projectDescriptor
0458: .getAbsolutePath(), model, localRepository,
0459: buildArtifactRepositories(getSuperModel()),
0460: projectDescriptor, profileManager, STRICT_MODEL_PARSING);
0461:
0462: /*
0463:
0464: MNG-3178: What is this actually for as we're not deploying this anymore.
0465:
0466: if ( checkDistributionManagementStatus )
0467: {
0468: if ( ( project.getDistributionManagement() != null ) && ( project.getDistributionManagement().getStatus() != null ) )
0469: {
0470: String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() );
0471:
0472: throw new ProjectBuildingException( projectId,
0473: "Invalid project file: distribution status must not be specified for a project outside of the repository" );
0474: }
0475: }
0476: */
0477:
0478: return project;
0479: }
0480:
0481: private Model findModelFromRepository(Artifact artifact,
0482: List remoteArtifactRepositories,
0483: ArtifactRepository localRepository, boolean allowStubModel)
0484: throws ProjectBuildingException {
0485: Artifact projectArtifact;
0486:
0487: // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given.
0488: if ("pom".equals(artifact.getType())) {
0489: projectArtifact = artifact;
0490: } else {
0491: getLogger().warn(
0492: "Attempting to build MavenProject instance for Artifact ("
0493: + artifact.getGroupId() + ":"
0494: + artifact.getArtifactId() + ":"
0495: + artifact.getVersion() + ") of type: "
0496: + artifact.getType()
0497: + "; constructing POM artifact instead.");
0498:
0499: projectArtifact = artifactFactory.createProjectArtifact(
0500: artifact.getGroupId(), artifact.getArtifactId(),
0501: artifact.getVersion(), artifact.getScope());
0502: }
0503:
0504: Model model;
0505:
0506: String projectId = ArtifactUtils
0507: .versionlessKey(projectArtifact);
0508:
0509: try {
0510: artifactResolver.resolve(projectArtifact,
0511: remoteArtifactRepositories, localRepository);
0512:
0513: File file = projectArtifact.getFile();
0514:
0515: model = readModel(projectId, file, STRICT_MODEL_PARSING);
0516:
0517: String downloadUrl = null;
0518:
0519: ArtifactStatus status = ArtifactStatus.NONE;
0520:
0521: DistributionManagement distributionManagement = model
0522: .getDistributionManagement();
0523:
0524: if (distributionManagement != null) {
0525: downloadUrl = distributionManagement.getDownloadUrl();
0526:
0527: status = ArtifactStatus.valueOf(distributionManagement
0528: .getStatus());
0529: }
0530:
0531: checkStatusAndUpdate(projectArtifact, status, file,
0532: remoteArtifactRepositories, localRepository);
0533:
0534: // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
0535: // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
0536: if (downloadUrl != null) {
0537: projectArtifact.setDownloadUrl(downloadUrl);
0538: } else {
0539: projectArtifact.setDownloadUrl(model.getUrl());
0540: }
0541: } catch (ArtifactResolutionException e) {
0542: throw new ProjectBuildingException(projectId,
0543: "Error getting POM for '" + projectId
0544: + "' from the repository: "
0545: + e.getMessage(), e);
0546: } catch (ArtifactNotFoundException e) {
0547: if (allowStubModel) {
0548: getLogger().debug(
0549: "Artifact not found - using stub model: "
0550: + e.getMessage());
0551:
0552: model = createStubModel(projectArtifact);
0553: } else {
0554: throw new ProjectBuildingException(projectId, "POM '"
0555: + projectId + "' not found in repository: "
0556: + e.getMessage(), e);
0557: }
0558: }
0559:
0560: return model;
0561: }
0562:
0563: private void checkStatusAndUpdate(Artifact projectArtifact,
0564: ArtifactStatus status, File file,
0565: List remoteArtifactRepositories,
0566: ArtifactRepository localRepository)
0567: throws ArtifactNotFoundException {
0568: // TODO: configurable actions dependant on status
0569: if (!projectArtifact.isSnapshot()
0570: && (status.compareTo(ArtifactStatus.DEPLOYED) < 0)) {
0571: // use default policy (enabled, daily update, warn on bad checksum)
0572: ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
0573: // TODO: re-enable [MNG-798/865]
0574: policy
0575: .setUpdatePolicy(ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER);
0576:
0577: if (policy.checkOutOfDate(new Date(file.lastModified()))) {
0578: getLogger()
0579: .info(
0580: projectArtifact.getArtifactId()
0581: + ": updating metadata due to status of '"
0582: + status + "'");
0583: try {
0584: projectArtifact.setResolved(false);
0585: artifactResolver
0586: .resolveAlways(projectArtifact,
0587: remoteArtifactRepositories,
0588: localRepository);
0589: } catch (ArtifactResolutionException e) {
0590: getLogger()
0591: .warn(
0592: "Error updating POM - using existing version");
0593: getLogger().debug("Cause", e);
0594: } catch (ArtifactNotFoundException e) {
0595: getLogger()
0596: .warn(
0597: "Error updating POM - not found. Removing local copy.");
0598: getLogger().debug("Cause", e);
0599: file.delete();
0600: throw e;
0601: }
0602: }
0603: }
0604: }
0605:
0606: // jvz:note
0607: // This is used when requested artifacts do not have an associated POM. This is for the case where we are
0608: // using an m1 repo where the only thing required to be present are the JAR files.
0609: private Model createStubModel(Artifact projectArtifact) {
0610: getLogger().debug(
0611: "Using defaults for missing POM " + projectArtifact);
0612:
0613: Model model = new Model();
0614:
0615: model.setModelVersion("4.0.0");
0616:
0617: model.setArtifactId(projectArtifact.getArtifactId());
0618:
0619: model.setGroupId(projectArtifact.getGroupId());
0620:
0621: model.setVersion(projectArtifact.getVersion());
0622:
0623: // TODO: not correct in some instances
0624: model.setPackaging(projectArtifact.getType());
0625:
0626: model.setDistributionManagement(new DistributionManagement());
0627:
0628: model.getDistributionManagement().setStatus(
0629: ArtifactStatus.GENERATED.toString());
0630:
0631: return model;
0632: }
0633:
0634: // jvz:note
0635: // We've got a mixture of things going in the USD and from the repository, sometimes the descriptor
0636: // is a real file and sometimes null which makes things confusing.
0637: private MavenProject buildInternal(String pomLocation, Model model,
0638: ArtifactRepository localRepository,
0639: List parentSearchRepositories, File projectDescriptor,
0640: ProfileManager externalProfileManager, boolean strict)
0641: throws ProjectBuildingException {
0642: File projectDir = null;
0643:
0644: if (projectDescriptor != null) {
0645: projectDir = projectDescriptor.getAbsoluteFile()
0646: .getParentFile();
0647: }
0648:
0649: Model super Model = getSuperModel();
0650:
0651: MavenProject super Project = new MavenProject(super Model);
0652:
0653: String projectId = safeVersionlessKey(model.getGroupId(), model
0654: .getArtifactId());
0655:
0656: List explicitlyActive;
0657: List explicitlyInactive;
0658:
0659: if (externalProfileManager != null) {
0660: // used to trigger the caching of SystemProperties in the container context...
0661: try {
0662: externalProfileManager.getActiveProfiles();
0663: } catch (ProfileActivationException e) {
0664: throw new ProjectBuildingException(projectId,
0665: "Failed to activate external profiles.", e);
0666: }
0667:
0668: explicitlyActive = externalProfileManager
0669: .getExplicitlyActivatedIds();
0670: explicitlyInactive = externalProfileManager
0671: .getExplicitlyDeactivatedIds();
0672: } else {
0673: explicitlyActive = Collections.EMPTY_LIST;
0674: explicitlyInactive = Collections.EMPTY_LIST;
0675: }
0676:
0677: super Project.setActiveProfiles(profileAdvisor
0678: .applyActivatedProfiles(super Model, null,
0679: explicitlyActive, explicitlyInactive));
0680:
0681: //noinspection CollectionDeclaredAsConcreteClass
0682: LinkedList lineage = new LinkedList();
0683:
0684: LinkedHashSet aggregatedRemoteWagonRepositories = collectInitialRepositories(
0685: model, super Model, parentSearchRepositories,
0686: projectDir, explicitlyActive, explicitlyInactive);
0687:
0688: Model originalModel = ModelUtils.cloneModel(model);
0689:
0690: MavenProject project = null;
0691: try {
0692: project = assembleLineage(model, lineage, localRepository,
0693: projectDir, parentSearchRepositories,
0694: aggregatedRemoteWagonRepositories,
0695: externalProfileManager, strict);
0696: } catch (InvalidRepositoryException e) {
0697: throw new ProjectBuildingException(projectId, e
0698: .getMessage(), e);
0699: }
0700:
0701: project.setOriginalModel(originalModel);
0702:
0703: // we don't have to force the collision exception for superModel here, it's already been done in getSuperModel()
0704: MavenProject previousProject = super Project;
0705:
0706: Model previous = super Project.getModel();
0707:
0708: for (Iterator i = lineage.iterator(); i.hasNext();) {
0709: MavenProject currentProject = (MavenProject) i.next();
0710:
0711: Model current = currentProject.getModel();
0712:
0713: String pathAdjustment = null;
0714:
0715: try {
0716: pathAdjustment = previousProject
0717: .getModulePathAdjustment(currentProject);
0718: } catch (IOException e) {
0719: getLogger().debug(
0720: "Cannot determine whether "
0721: + currentProject.getId()
0722: + " is a module of "
0723: + previousProject.getId()
0724: + ". Reason: " + e.getMessage(), e);
0725: }
0726:
0727: modelInheritanceAssembler.assembleModelInheritance(current,
0728: previous, pathAdjustment);
0729:
0730: previous = current;
0731: previousProject = currentProject;
0732: }
0733:
0734: // only add the super repository if it wasn't overridden by a profile or project
0735: List repositories = new ArrayList(
0736: aggregatedRemoteWagonRepositories);
0737:
0738: List super Repositories = buildArtifactRepositories(super Model);
0739:
0740: for (Iterator i = super Repositories.iterator(); i.hasNext();) {
0741: ArtifactRepository repository = (ArtifactRepository) i
0742: .next();
0743:
0744: if (!repositories.contains(repository)) {
0745: repositories.add(repository);
0746: }
0747: }
0748:
0749: mergeManagedDependencies(project.getModel(), localRepository,
0750: parentSearchRepositories);
0751:
0752: try {
0753: project = processProjectLogic(pomLocation, project,
0754: externalProfileManager, projectDir, strict);
0755: } catch (ModelInterpolationException e) {
0756: throw new InvalidProjectModelException(projectId,
0757: pomLocation, e.getMessage(), e);
0758: } catch (InvalidRepositoryException e) {
0759: throw new InvalidProjectModelException(projectId,
0760: pomLocation, e.getMessage(), e);
0761: }
0762:
0763: ProjectBuildCache projectBuildCache = ProjectBuildCache
0764: .read(buildContextManager);
0765: projectBuildCache.cacheProject(project);
0766: projectBuildCache.store(buildContextManager);
0767:
0768: // jvz:note
0769: // this only happens if we are building from a source file
0770: if (projectDescriptor != null) {
0771: // Only translate the base directory for files in the source tree
0772: pathTranslator.alignToBaseDirectory(project.getModel(),
0773: projectDescriptor.getParentFile());
0774:
0775: Build build = project.getBuild();
0776:
0777: project.addCompileSourceRoot(build.getSourceDirectory());
0778:
0779: project.addScriptSourceRoot(build
0780: .getScriptSourceDirectory());
0781:
0782: project.addTestCompileSourceRoot(build
0783: .getTestSourceDirectory());
0784:
0785: // Only track the file of a POM in the source tree
0786: project.setFile(projectDescriptor);
0787: }
0788:
0789: MavenProject rawParent = project.getParent();
0790:
0791: if (rawParent != null) {
0792: MavenProject processedParent = projectBuildCache
0793: .getCachedProject(rawParent);
0794:
0795: // yeah, this null check might be a bit paranoid, but better safe than sorry...
0796: if (processedParent != null) {
0797: project.setParent(processedParent);
0798: }
0799: }
0800:
0801: project
0802: .setManagedVersionMap(createManagedVersionMap(
0803: projectId, project.getDependencyManagement(),
0804: project.getParent()));
0805:
0806: return project;
0807: }
0808:
0809: /*
0810: * Order is:
0811: *
0812: * 1. model profile repositories
0813: * 2. model repositories
0814: * 3. superModel profile repositories
0815: * 4. superModel repositories
0816: * 5. parentSearchRepositories
0817: */
0818: private LinkedHashSet collectInitialRepositories(Model model,
0819: Model super Model, List parentSearchRepositories,
0820: File projectDir, List explicitlyActive,
0821: List explicitlyInactive) throws ProjectBuildingException {
0822: LinkedHashSet collected = new LinkedHashSet();
0823:
0824: collectInitialRepositoriesFromModel(collected, model,
0825: projectDir, explicitlyActive, explicitlyInactive);
0826:
0827: collectInitialRepositoriesFromModel(collected, super Model,
0828: projectDir, explicitlyActive, explicitlyInactive);
0829:
0830: if ((parentSearchRepositories != null)
0831: && !parentSearchRepositories.isEmpty()) {
0832: collected.addAll(parentSearchRepositories);
0833: }
0834:
0835: return collected;
0836: }
0837:
0838: private void collectInitialRepositoriesFromModel(
0839: LinkedHashSet collected, Model model, File projectDir,
0840: List explicitlyActive, List explicitlyInactive)
0841: throws ProjectBuildingException {
0842: Set reposFromProfiles = profileAdvisor
0843: .getArtifactRepositoriesFromActiveProfiles(model,
0844: projectDir, explicitlyActive,
0845: explicitlyInactive);
0846:
0847: if ((reposFromProfiles != null) && !reposFromProfiles.isEmpty()) {
0848: collected.addAll(reposFromProfiles);
0849: }
0850:
0851: List modelRepos = model.getRepositories();
0852: if ((modelRepos != null) && !modelRepos.isEmpty()) {
0853: try {
0854: collected.addAll(mavenTools
0855: .buildArtifactRepositories(modelRepos));
0856: } catch (InvalidRepositoryException e) {
0857: throw new ProjectBuildingException(
0858: safeVersionlessKey(model.getGroupId(), model
0859: .getArtifactId()),
0860: "Failed to construct ArtifactRepository instances for repositories declared in: "
0861: + model.getId(), e);
0862: }
0863: }
0864: }
0865:
0866: private String safeVersionlessKey(String groupId, String artifactId) {
0867: String gid = groupId;
0868:
0869: if (StringUtils.isEmpty(gid)) {
0870: gid = "unknown";
0871: }
0872:
0873: String aid = artifactId;
0874:
0875: if (StringUtils.isEmpty(aid)) {
0876: aid = "unknown";
0877: }
0878:
0879: return ArtifactUtils.versionlessKey(gid, aid);
0880: }
0881:
0882: private List buildArtifactRepositories(Model model)
0883: throws ProjectBuildingException {
0884: try {
0885: return mavenTools.buildArtifactRepositories(model
0886: .getRepositories());
0887: } catch (InvalidRepositoryException e) {
0888: String projectId = safeVersionlessKey(model.getGroupId(),
0889: model.getArtifactId());
0890:
0891: throw new ProjectBuildingException(projectId, e
0892: .getMessage(), e);
0893: }
0894: }
0895:
0896: /**
0897: * @todo can this take in a model instead of a project and still be successful?
0898: * @todo In fact, does project REALLY need a MavenProject as a parent? Couldn't it have just a wrapper around a
0899: * model that supported parents which were also the wrapper so that inheritence was assembled. We don't really need
0900: * the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently
0901: * and projects are not cached or reused
0902: */
0903: private MavenProject processProjectLogic(String pomLocation,
0904: MavenProject project, ProfileManager profileMgr,
0905: File projectDir, boolean strict)
0906: throws ProjectBuildingException,
0907: ModelInterpolationException, InvalidRepositoryException {
0908: Model model = project.getModel();
0909:
0910: List activeProfiles = project.getActiveProfiles();
0911:
0912: // TODO: Clean this up...we're using this to 'jump' the interpolation step for model properties not expressed in XML.
0913: // [BP] - Can this above comment be explained?
0914: // We don't need all the project methods that are added over those in the model, but we do need basedir
0915: // mkleint - using System.getProperties() is almost definitely bad for embedding.
0916: Map context = new HashMap(System.getProperties());
0917:
0918: if (projectDir != null) {
0919: context.put("basedir", projectDir.getAbsolutePath());
0920: }
0921:
0922: // TODO: this is a hack to ensure MNG-2124 can be satisfied without triggering MNG-1927
0923: // MNG-1927 relies on the false assumption that ${project.build.*} evaluates to null, which occurs before
0924: // MNG-2124 is fixed. The null value would leave it uninterpolated, to be handled after path translation.
0925: // Until these steps are correctly sequenced, we guarantee these fields remain uninterpolated.
0926: context.put("build.directory", null);
0927: context.put("build.outputDirectory", null);
0928: context.put("build.testOutputDirectory", null);
0929: context.put("build.sourceDirectory", null);
0930: context.put("build.testSourceDirectory", null);
0931:
0932: model = modelInterpolator.interpolate(model, context, strict);
0933:
0934: // interpolation is before injection, because interpolation is off-limits in the injected variables
0935: modelDefaultsInjector.injectDefaults(model);
0936:
0937: MavenProject parentProject = project.getParent();
0938:
0939: Model originalModel = project.getOriginalModel();
0940:
0941: Artifact parentArtifact = project.getParentArtifact();
0942:
0943: // We will return a different project object using the new model (hence the need to return a project, not just modify the parameter)
0944: project = new MavenProject(model);
0945:
0946: project.setOriginalModel(originalModel);
0947:
0948: project.setActiveProfiles(activeProfiles);
0949:
0950: // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
0951: Artifact projectArtifact = artifactFactory.createBuildArtifact(
0952: project.getGroupId(), project.getArtifactId(), project
0953: .getVersion(), project.getPackaging());
0954: project.setArtifact(projectArtifact);
0955:
0956: project.setPluginArtifactRepositories(mavenTools
0957: .buildArtifactRepositories(model
0958: .getPluginRepositories()));
0959:
0960: DistributionManagement dm = model.getDistributionManagement();
0961:
0962: if (dm != null) {
0963: ArtifactRepository repo = mavenTools
0964: .buildDeploymentArtifactRepository(dm
0965: .getRepository());
0966: project.setReleaseArtifactRepository(repo);
0967:
0968: if (dm.getSnapshotRepository() != null) {
0969: repo = mavenTools.buildDeploymentArtifactRepository(dm
0970: .getSnapshotRepository());
0971: project.setSnapshotArtifactRepository(repo);
0972: }
0973: }
0974:
0975: project.setParent(parentProject);
0976:
0977: if (parentProject != null) {
0978: project.setParentArtifact(parentArtifact);
0979: }
0980:
0981: // Must validate before artifact construction to make sure dependencies are good
0982: ModelValidationResult validationResult = validator
0983: .validate(model);
0984:
0985: String projectId = safeVersionlessKey(model.getGroupId(), model
0986: .getArtifactId());
0987:
0988: if (validationResult.getMessageCount() > 0) {
0989: throw new InvalidProjectModelException(projectId,
0990: pomLocation, "Failed to validate POM",
0991: validationResult);
0992: }
0993:
0994: project.setRemoteArtifactRepositories(mavenTools
0995: .buildArtifactRepositories(model.getRepositories()));
0996:
0997: // TODO: these aren't taking active project artifacts into consideration in the reactor
0998: project.setPluginArtifacts(createPluginArtifacts(projectId,
0999: project.getBuildPlugins()));
1000:
1001: project.setReportArtifacts(createReportArtifacts(projectId,
1002: project.getReportPlugins()));
1003:
1004: project.setExtensionArtifacts(createExtensionArtifacts(
1005: projectId, project.getBuildExtensions()));
1006:
1007: return project;
1008: }
1009:
1010: /**
1011: * @noinspection CollectionDeclaredAsConcreteClass
1012: * @todo We need to find an effective way to unit test parts of this method!
1013: * @todo Refactor this into smaller methods with discrete purposes.
1014: */
1015: private MavenProject assembleLineage(Model model,
1016: LinkedList lineage, ArtifactRepository localRepository,
1017: File projectDir, List parentSearchRepositories,
1018: Set aggregatedRemoteWagonRepositories,
1019: ProfileManager externalProfileManager, boolean strict)
1020: throws ProjectBuildingException, InvalidRepositoryException {
1021: ModelLineage modelLineage = new DefaultModelLineage();
1022: modelLineage.setOrigin(model, new File(projectDir, "pom.xml"),
1023: new ArrayList(aggregatedRemoteWagonRepositories));
1024:
1025: // strict means "no stubs", so we invert it here for the allowStubs parameter.
1026: modelLineageBuilder.resumeBuildingModelLineage(modelLineage,
1027: localRepository, externalProfileManager, !strict);
1028:
1029: ProjectBuildContext projectContext = ProjectBuildContext
1030: .getProjectBuildContext(buildContextManager, true);
1031:
1032: projectContext.setModelLineage(modelLineage);
1033: projectContext.store(buildContextManager);
1034:
1035: List explicitlyActive;
1036: List explicitlyInactive;
1037:
1038: if (externalProfileManager != null) {
1039: explicitlyActive = externalProfileManager
1040: .getExplicitlyActivatedIds();
1041: explicitlyInactive = externalProfileManager
1042: .getExplicitlyDeactivatedIds();
1043: } else {
1044: explicitlyActive = Collections.EMPTY_LIST;
1045: explicitlyInactive = Collections.EMPTY_LIST;
1046: }
1047:
1048: MavenProject lastProject = null;
1049: for (ModelLineageIterator it = modelLineage.lineageIterator(); it
1050: .hasNext();) {
1051: Model currentModel = (Model) it.next();
1052:
1053: File currentPom = it.getPOMFile();
1054:
1055: MavenProject project = new MavenProject(currentModel);
1056: project.setFile(currentPom);
1057:
1058: projectContext.setCurrentProject(project);
1059: projectContext.store(buildContextManager);
1060:
1061: project.setActiveProfiles(profileAdvisor
1062: .applyActivatedProfiles(currentModel, projectDir,
1063: explicitlyActive, explicitlyInactive));
1064:
1065: if (lastProject != null) {
1066: lastProject.setParent(project);
1067:
1068: lastProject.setParentArtifact(artifactFactory
1069: .createParentArtifact(project.getGroupId(),
1070: project.getArtifactId(), project
1071: .getVersion()));
1072: }
1073:
1074: lineage.addFirst(project);
1075:
1076: lastProject = project;
1077: }
1078:
1079: MavenProject result = (MavenProject) lineage.getLast();
1080:
1081: if (externalProfileManager != null) {
1082: LinkedHashSet active = new LinkedHashSet();
1083:
1084: List existingActiveProfiles = result.getActiveProfiles();
1085: if ((existingActiveProfiles != null)
1086: && !existingActiveProfiles.isEmpty()) {
1087: active.addAll(existingActiveProfiles);
1088: }
1089:
1090: profileAdvisor.applyActivatedExternalProfiles(result
1091: .getModel(), projectDir, externalProfileManager);
1092: }
1093:
1094: return result;
1095: }
1096:
1097: private void mergeManagedDependencies(Model model,
1098: ArtifactRepository localRepository,
1099: List parentSearchRepositories)
1100: throws ProjectBuildingException {
1101: DependencyManagement modelDepMgmt = model
1102: .getDependencyManagement();
1103:
1104: if (modelDepMgmt != null) {
1105: Map depsMap = new TreeMap();
1106: Iterator iter = modelDepMgmt.getDependencies().iterator();
1107: boolean doInclude = false;
1108: while (iter.hasNext()) {
1109: Dependency dep = (Dependency) iter.next();
1110: depsMap.put(dep.getManagementKey(), dep);
1111: if (dep.getType().equals("pom")
1112: && Artifact.SCOPE_IMPORT.equals(dep.getScope())) {
1113: doInclude = true;
1114: }
1115: }
1116: Map newDeps = new TreeMap(depsMap);
1117: iter = modelDepMgmt.getDependencies().iterator();
1118: if (doInclude) {
1119: while (iter.hasNext()) {
1120: Dependency dep = (Dependency) iter.next();
1121: if (dep.getType().equals("pom")
1122: && Artifact.SCOPE_IMPORT.equals(dep
1123: .getScope())) {
1124: Artifact artifact = artifactFactory
1125: .createProjectArtifact(
1126: dep.getGroupId(), dep
1127: .getArtifactId(), dep
1128: .getVersion(), dep
1129: .getScope());
1130: MavenProject project = buildFromRepository(
1131: artifact, parentSearchRepositories,
1132: localRepository, false);
1133:
1134: DependencyManagement depMgmt = project
1135: .getDependencyManagement();
1136:
1137: if (depMgmt != null) {
1138: if (getLogger().isDebugEnabled()) {
1139: getLogger().debug(
1140: "Importing managed dependencies for "
1141: + dep.toString());
1142: }
1143:
1144: for (Iterator it = depMgmt
1145: .getDependencies().iterator(); it
1146: .hasNext();) {
1147: Dependency includedDep = (Dependency) it
1148: .next();
1149: String key = includedDep
1150: .getManagementKey();
1151: if (!newDeps.containsKey(key)) {
1152: newDeps.put(includedDep
1153: .getManagementKey(),
1154: includedDep);
1155: }
1156: }
1157: newDeps.remove(dep.getManagementKey());
1158: }
1159: }
1160: }
1161: List deps = new ArrayList(newDeps.values());
1162: modelDepMgmt.setDependencies(deps);
1163: }
1164: }
1165: }
1166:
1167: private Model readModel(String projectId, File file, boolean strict)
1168: throws ProjectBuildingException {
1169: Reader reader = null;
1170: try {
1171: reader = new FileReader(file);
1172: return readModel(projectId, file.getAbsolutePath(), reader,
1173: strict);
1174: } catch (FileNotFoundException e) {
1175: throw new ProjectBuildingException(projectId,
1176: "Could not find the model file '"
1177: + file.getAbsolutePath() + "'.", e);
1178: } catch (IOException e) {
1179: throw new ProjectBuildingException(projectId,
1180: "Failed to build model from file '"
1181: + file.getAbsolutePath() + "'.\nError: \'"
1182: + e.getLocalizedMessage() + "\'", e);
1183: } finally {
1184: IOUtil.close(reader);
1185: }
1186: }
1187:
1188: private Model readModel(String projectId, String pomLocation,
1189: Reader reader, boolean strict) throws IOException,
1190: InvalidProjectModelException {
1191: StringWriter sw = new StringWriter();
1192:
1193: IOUtil.copy(reader, sw);
1194:
1195: String modelSource = sw.toString();
1196:
1197: if (modelSource.indexOf("<modelVersion>4.0.0") < 0) {
1198: throw new InvalidProjectModelException(projectId,
1199: pomLocation, "Not a v4.0.0 POM.");
1200: }
1201:
1202: StringReader sReader = new StringReader(modelSource);
1203:
1204: try {
1205: return modelReader.read(sReader, strict);
1206: } catch (XmlPullParserException e) {
1207: throw new InvalidProjectModelException(projectId,
1208: pomLocation, "Parse error reading POM. Reason: "
1209: + e.getMessage(), e);
1210: }
1211: }
1212:
1213: private Model readModel(String projectId, URL url, boolean strict)
1214: throws ProjectBuildingException {
1215: InputStreamReader reader = null;
1216: try {
1217: reader = new InputStreamReader(url.openStream());
1218: return readModel(projectId, url.toExternalForm(), reader,
1219: strict);
1220: } catch (IOException e) {
1221: throw new ProjectBuildingException(projectId,
1222: "Failed build model from URL \'"
1223: + url.toExternalForm() + "\'\nError: \'"
1224: + e.getLocalizedMessage() + "\'", e);
1225: } finally {
1226: IOUtil.close(reader);
1227: }
1228: }
1229:
1230: private static String createCacheKey(String groupId,
1231: String artifactId, String version) {
1232: return groupId + ":" + artifactId + ":" + version;
1233: }
1234:
1235: protected Set createPluginArtifacts(String projectId, List plugins)
1236: throws ProjectBuildingException {
1237: Set pluginArtifacts = new HashSet();
1238:
1239: for (Iterator i = plugins.iterator(); i.hasNext();) {
1240: Plugin p = (Plugin) i.next();
1241:
1242: String version;
1243: if (StringUtils.isEmpty(p.getVersion())) {
1244: version = "RELEASE";
1245: } else {
1246: version = p.getVersion();
1247: }
1248:
1249: Artifact artifact;
1250: try {
1251: artifact = artifactFactory.createPluginArtifact(p
1252: .getGroupId(), p.getArtifactId(), VersionRange
1253: .createFromVersionSpec(version));
1254: } catch (InvalidVersionSpecificationException e) {
1255: throw new ProjectBuildingException(projectId,
1256: "Unable to parse version '"
1257: + version
1258: + "' for plugin '"
1259: + ArtifactUtils.versionlessKey(p
1260: .getGroupId(), p
1261: .getArtifactId()) + "': "
1262: + e.getMessage(), e);
1263: }
1264:
1265: if (artifact != null) {
1266: pluginArtifacts.add(artifact);
1267: }
1268: }
1269:
1270: return pluginArtifacts;
1271: }
1272:
1273: // TODO: share with createPluginArtifacts?
1274: protected Set createReportArtifacts(String projectId, List reports)
1275: throws ProjectBuildingException {
1276: Set pluginArtifacts = new HashSet();
1277:
1278: if (reports != null) {
1279: for (Iterator i = reports.iterator(); i.hasNext();) {
1280: ReportPlugin p = (ReportPlugin) i.next();
1281:
1282: String version;
1283: if (StringUtils.isEmpty(p.getVersion())) {
1284: version = "RELEASE";
1285: } else {
1286: version = p.getVersion();
1287: }
1288:
1289: Artifact artifact;
1290: try {
1291: artifact = artifactFactory
1292: .createPluginArtifact(p.getGroupId(), p
1293: .getArtifactId(), VersionRange
1294: .createFromVersionSpec(version));
1295: } catch (InvalidVersionSpecificationException e) {
1296: throw new ProjectBuildingException(projectId,
1297: "Unable to parse version '"
1298: + version
1299: + "' for report '"
1300: + ArtifactUtils.versionlessKey(p
1301: .getGroupId(), p
1302: .getArtifactId()) + "': "
1303: + e.getMessage(), e);
1304: }
1305:
1306: if (artifact != null) {
1307: pluginArtifacts.add(artifact);
1308: }
1309: }
1310: }
1311:
1312: return pluginArtifacts;
1313: }
1314:
1315: // TODO: share with createPluginArtifacts?
1316: protected Set createExtensionArtifacts(String projectId,
1317: List extensions) throws ProjectBuildingException {
1318: Set extensionArtifacts = new HashSet();
1319:
1320: if (extensions != null) {
1321: for (Iterator i = extensions.iterator(); i.hasNext();) {
1322: Extension ext = (Extension) i.next();
1323:
1324: String version;
1325: if (StringUtils.isEmpty(ext.getVersion())) {
1326: version = "RELEASE";
1327: } else {
1328: version = ext.getVersion();
1329: }
1330:
1331: Artifact artifact;
1332: try {
1333: VersionRange versionRange = VersionRange
1334: .createFromVersionSpec(version);
1335: artifact = artifactFactory.createExtensionArtifact(
1336: ext.getGroupId(), ext.getArtifactId(),
1337: versionRange);
1338: } catch (InvalidVersionSpecificationException e) {
1339: throw new ProjectBuildingException(projectId,
1340: "Unable to parse version '"
1341: + version
1342: + "' for extension '"
1343: + ArtifactUtils.versionlessKey(ext
1344: .getGroupId(), ext
1345: .getArtifactId()) + "': "
1346: + e.getMessage(), e);
1347: }
1348:
1349: if (artifact != null) {
1350: extensionArtifacts.add(artifact);
1351: }
1352: }
1353: }
1354:
1355: return extensionArtifacts;
1356: }
1357:
1358: // ----------------------------------------------------------------------
1359: //
1360: // ----------------------------------------------------------------------
1361:
1362: private Model getSuperModel() throws ProjectBuildingException {
1363: URL url = DefaultMavenProjectBuilder.class.getResource("pom-"
1364: + MAVEN_MODEL_VERSION + ".xml");
1365:
1366: String projectId = safeVersionlessKey(
1367: STANDALONE_SUPERPOM_GROUPID,
1368: STANDALONE_SUPERPOM_ARTIFACTID);
1369:
1370: return readModel(projectId, url, STRICT_MODEL_PARSING);
1371: }
1372:
1373: public void contextualize(Context context) throws ContextException {
1374: container = (PlexusContainer) context
1375: .get(PlexusConstants.PLEXUS_KEY);
1376: }
1377: }
|