Author: sisbell Date: Thu Aug 14 19:18:38 2008 New Revision: 686112 URL: http://svn.apache.org/viewvc?rev=686112&view=rev Log: Refactored out repository contruction methods from DefaultMavenProjectBuilder to RepositoryHelper to get the methods out of the way. The helper class will be deleted when we integrate with Mercury.
Added: maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java Modified: maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/resources/META-INF/plexus/components.xml maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml Modified: maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java URL: http://svn.apache.org/viewvc/maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=686112&r1=686111&r2=686112&view=diff ============================================================================== --- maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original) +++ maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Thu Aug 14 19:18:38 2008 @@ -21,30 +21,23 @@ import org.apache.maven.MavenTools; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.ArtifactStatus; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Build; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.DistributionManagement; import org.apache.maven.model.Extension; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.PluginManagement; import org.apache.maven.model.ReportPlugin; -import org.apache.maven.model.Repository; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.profiles.MavenProfilesBuilder; import org.apache.maven.profiles.ProfileManager; @@ -151,6 +144,8 @@ private ProjectBuilder projectBuilder; + private RepositoryHelper repositoryHelper; + //DO NOT USE, it is here only for backward compatibility reasons. The existing // maven-assembly-plugin (2.2-beta-1) is accessing it via reflection. @@ -213,7 +208,7 @@ if ( project == null ) { - Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); + Model model = repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ); @@ -279,7 +274,7 @@ try { - processProjectLogic( project, null, config, null, true, true ); + processProjectLogic( project, null, config); project.setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); @@ -390,10 +385,10 @@ if ( project == null ) { Model model = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver(config.getLocalRepository(), - buildArtifactRepositories( getSuperModel() ), artifactResolver) ); + repositoryHelper.buildArtifactRepositories( getSuperModel() ), artifactResolver) ); project = buildInternal(model, config, - buildArtifactRepositories( getSuperModel() ), + repositoryHelper.buildArtifactRepositories( getSuperModel() ), projectDescriptor, STRICT_MODEL_PARSING, true, @@ -402,167 +397,6 @@ return project; } - private Model findModelFromRepository( Artifact artifact, - List remoteArtifactRepositories, - ArtifactRepository localRepository ) - throws ProjectBuildingException - { - - String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); - remoteArtifactRepositories = normalizeToArtifactRepositories( remoteArtifactRepositories, projectId ); - - Artifact projectArtifact; - - // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given. - if ( "pom".equals( artifact.getType() ) ) - { - projectArtifact = artifact; - } - else - { - getLogger().warn( "Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":" - + artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: " - + artifact.getType() + "; constructing POM artifact instead." ); - - projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), - artifact.getArtifactId(), - artifact.getVersion(), - artifact.getScope() ); - } - - Model legacy_model; - try - { - artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository ); - - File file = projectArtifact.getFile(); - - legacy_model = readModelLegacy( projectId, file, STRICT_MODEL_PARSING ); - - String downloadUrl = null; - - ArtifactStatus status = ArtifactStatus.NONE; - - DistributionManagement distributionManagement = legacy_model.getDistributionManagement(); - - if ( distributionManagement != null ) - { - downloadUrl = distributionManagement.getDownloadUrl(); - - status = ArtifactStatus.valueOf( distributionManagement.getStatus() ); - } - - checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories, localRepository ); - - // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that - // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions? - if ( downloadUrl != null ) - { - projectArtifact.setDownloadUrl( downloadUrl ); - } - else - { - projectArtifact.setDownloadUrl( legacy_model.getUrl() ); - } - } - catch ( ArtifactResolutionException e ) - { - throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + "' from the repository: " + e.getMessage(), e ); - } - catch ( ArtifactNotFoundException e ) - { - throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " + e.getMessage(), e ); - } - - return legacy_model; - } - - private List normalizeToArtifactRepositories( List remoteArtifactRepositories, - String projectId ) - throws ProjectBuildingException - { - List normalized = new ArrayList( remoteArtifactRepositories.size() ); - - boolean normalizationNeeded = false; - for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); ) - { - Object item = it.next(); - - if ( item instanceof ArtifactRepository ) - { - normalized.add( item ); - } - else if ( item instanceof Repository ) - { - Repository repo = (Repository) item; - try - { - item = mavenTools.buildArtifactRepository( repo ); - - normalized.add( item ); - normalizationNeeded = true; - } - catch ( InvalidRepositoryException e ) - { - throw new ProjectBuildingException( projectId, "Error building artifact repository for id: " + repo.getId(), e ); - } - } - else - { - throw new ProjectBuildingException( projectId, "Error building artifact repository from non-repository information item: " + item ); - } - } - - if ( normalizationNeeded ) - { - return normalized; - } - else - { - return remoteArtifactRepositories; - } - } - - private void checkStatusAndUpdate( Artifact projectArtifact, - ArtifactStatus status, - File file, - List remoteArtifactRepositories, - ArtifactRepository localRepository ) - throws ArtifactNotFoundException - { - // TODO: configurable actions dependant on status - if ( !projectArtifact.isSnapshot() && ( status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) ) - { - // use default policy (enabled, daily update, warn on bad checksum) - ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(); - // TODO: re-enable [MNG-798/865] - policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); - - if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) ) - { - getLogger().info( - projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" ); - try - { - projectArtifact.setResolved( false ); - artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository ); - } - catch ( ArtifactResolutionException e ) - { - getLogger().warn( "Error updating POM - using existing version" ); - getLogger().debug( "Cause", e ); - } - catch ( ArtifactNotFoundException e ) - { - getLogger().warn( "Error updating POM - not found. Removing local copy." ); - getLogger().debug( "Cause", e ); - file.delete(); - throw e; - } - } - } - } - // jvz:note // We've got a mixture of things going in the USD and from the repository, sometimes the descriptor // is a real file and sometimes null which makes things confusing. @@ -575,9 +409,8 @@ boolean fromSourceTree ) throws ProjectBuildingException { - Model superModel = getSuperModel(); - MavenProject superProject = new MavenProject( superModel, artifactFactory ); + MavenProject superProject = new MavenProject( getSuperModel(), artifactFactory ); String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); @@ -605,13 +438,13 @@ } LinkedHashSet activeInSuperPom = new LinkedHashSet(); - List activated = profileAdvisor.applyActivatedProfiles( superModel, projectDescriptor, isReactorProject, profileActivationContext ); + List activated = profileAdvisor.applyActivatedProfiles( getSuperModel(), projectDescriptor, isReactorProject, profileActivationContext ); if ( !activated.isEmpty() ) { activeInSuperPom.addAll( activated ); } - activated = profileAdvisor.applyActivatedExternalProfiles( superModel, projectDescriptor, externalProfileManager ); + activated = profileAdvisor.applyActivatedExternalProfiles( getSuperModel(), projectDescriptor, externalProfileManager ); if ( !activated.isEmpty() ) { activeInSuperPom.addAll( activated ); @@ -622,7 +455,7 @@ //noinspection CollectionDeclaredAsConcreteClass LinkedList lineage = new LinkedList(); - LinkedHashSet aggregatedRemoteWagonRepositories = collectInitialRepositories( model, superModel, + LinkedHashSet aggregatedRemoteWagonRepositories = repositoryHelper.collectInitialRepositories( model, getSuperModel(), parentSearchRepositories, projectDescriptor, isReactorProject, @@ -676,7 +509,7 @@ // only add the super repository if it wasn't overridden by a profile or project List repositories = new ArrayList( aggregatedRemoteWagonRepositories ); - List superRepositories = buildArtifactRepositories( superModel ); + List superRepositories = repositoryHelper.buildArtifactRepositories( getSuperModel() ); for ( Iterator i = superRepositories.iterator(); i.hasNext(); ) { @@ -693,7 +526,7 @@ try { - project = processProjectLogic( project, projectDescriptor, config, repositories, strict, false ); + project = processProjectLogic( project, projectDescriptor, config); } catch ( ModelInterpolationException e ) { @@ -726,67 +559,6 @@ return project; } - /* - * Order is: - * - * 1. model profile repositories - * 2. model repositories - * 3. superModel profile repositories - * 4. superModel repositories - * 5. parentSearchRepositories - */ - private LinkedHashSet collectInitialRepositories( Model model, - Model superModel, - List parentSearchRepositories, - File pomFile, - boolean validProfilesXmlLocation, - ProfileActivationContext profileActivationContext ) - throws ProjectBuildingException - { - LinkedHashSet collected = new LinkedHashSet(); - - collectInitialRepositoriesFromModel( collected, model, pomFile, validProfilesXmlLocation, profileActivationContext ); - - collectInitialRepositoriesFromModel( collected, superModel, null, validProfilesXmlLocation, profileActivationContext ); - - if ( ( parentSearchRepositories != null ) && !parentSearchRepositories.isEmpty() ) - { - collected.addAll( parentSearchRepositories ); - } - - return collected; - } - - private void collectInitialRepositoriesFromModel( LinkedHashSet collected, - Model model, - File pomFile, - boolean validProfilesXmlLocation, - ProfileActivationContext profileActivationContext ) - throws ProjectBuildingException - { - Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, pomFile, validProfilesXmlLocation, profileActivationContext ); - - if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() ) - { - collected.addAll( reposFromProfiles ); - } - - List modelRepos = model.getRepositories(); - - if ( ( modelRepos != null ) && !modelRepos.isEmpty() ) - { - try - { - collected.addAll( mavenTools.buildArtifactRepositories( modelRepos ) ); - } - catch ( InvalidRepositoryException e ) - { - throw new ProjectBuildingException( safeVersionlessKey( model.getGroupId(), model.getArtifactId() ), - "Failed to construct ArtifactRepository instances for repositories declared in: " + - model.getId(), e ); - } - } - } private String safeVersionlessKey( String groupId, String artifactId ) @@ -808,21 +580,6 @@ return ArtifactUtils.versionlessKey( gid, aid ); } - private List buildArtifactRepositories( Model model ) - throws ProjectBuildingException - { - try - { - return mavenTools.buildArtifactRepositories( model.getRepositories() ); - } - catch ( InvalidRepositoryException e ) - { - String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); - - throw new ProjectBuildingException( projectId, e.getMessage(), e ); - } - } - /** * @todo can this take in a model instead of a project and still be successful? * @todo In fact, does project REALLY need a MavenProject as a parent? Couldn't it have just a wrapper around a @@ -830,12 +587,10 @@ * the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently * and projects are not cached or reused */ - private MavenProject processProjectLogic( MavenProject project, - File pomFile, - ProjectBuilderConfiguration config, - List remoteRepositories, - boolean strict, - boolean isSuperPom ) + private MavenProject processProjectLogic(MavenProject project, + File pomFile, + ProjectBuilderConfiguration config + ) throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException { Model model = project.getModel(); @@ -879,8 +634,6 @@ project.getVersion(), project.getPackaging() ); project.setArtifact( projectArtifact ); -// project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( model.getPluginRepositories() ) ); - DistributionManagement dm = model.getDistributionManagement(); if ( dm != null ) @@ -1082,48 +835,6 @@ } - private Model readModelLegacy( String projectId, - File file, - boolean strict ) - throws ProjectBuildingException - { - Reader reader = null; - try - { - reader = ReaderFactory.newXmlReader( file ); - - String modelSource = IOUtil.toString( reader ); - - checkModelVersion( modelSource, projectId, file ); - - StringReader sReader = new StringReader( modelSource ); - - try - { - return modelReader.read( sReader, strict ); - } - catch ( XmlPullParserException e ) - { - throw new InvalidProjectModelException( projectId, "Parse error reading POM. Reason: " + e.getMessage(), - file, e ); - } - } - catch ( FileNotFoundException e ) - { - throw new ProjectBuildingException( projectId, - "Could not find the model file '" + file.getAbsolutePath() + "'.", file, e ); - } - catch ( IOException e ) - { - throw new ProjectBuildingException( projectId, "Failed to build model from file '" + - file.getAbsolutePath() + "'.\nError: \'" + e.getLocalizedMessage() + "\'", file, e ); - } - finally - { - IOUtil.close( reader ); - } - } - private void checkModelVersion( String modelSource, String projectId, File file ) @@ -1135,22 +846,6 @@ } } - /** - * @deprecated use [EMAIL PROTECTED] #createReportArtifacts(String, List, File)} - * @param projectId - * @param reports - * @param pomLocation absolute path of pom file - * @return - * @throws ProjectBuildingException - */ - @Deprecated - protected Set createReportArtifacts( String projectId, - List reports, String pomLocation ) - throws ProjectBuildingException - { - return createReportArtifacts( projectId, reports, new File( pomLocation ) ); - } - // TODO: share with createPluginArtifacts? protected Set createReportArtifacts( String projectId, List reports, File pomLocation ) @@ -1195,22 +890,6 @@ return pluginArtifacts; } - /** - * @deprecated use [EMAIL PROTECTED] #createExtensionArtifacts(String, List, File)} - * @param projectId - * @param extensions - * @param pomLocation absolute path of pom file - * @return - * @throws ProjectBuildingException - */ - @Deprecated - protected Set createExtensionArtifacts( String projectId, - List extensions, String pomLocation ) - throws ProjectBuildingException - { - return createExtensionArtifacts( projectId, extensions, new File( pomLocation ) ); - } - // TODO: share with createPluginArtifacts? protected Set createExtensionArtifacts( String projectId, List extensions, File pomFile ) @@ -1286,7 +965,8 @@ StringReader sReader = new StringReader( modelSource ); - return modelReader.read( sReader, STRICT_MODEL_PARSING ); + superModel = modelReader.read( sReader, STRICT_MODEL_PARSING ); + return superModel; } catch ( XmlPullParserException e ) { Added: maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java URL: http://svn.apache.org/viewvc/maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java?rev=686112&view=auto ============================================================================== --- maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java (added) +++ maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java Thu Aug 14 19:18:38 2008 @@ -0,0 +1,330 @@ +package org.apache.maven.project; + +import org.apache.maven.model.Model; +import org.apache.maven.model.Repository; +import org.apache.maven.model.DistributionManagement; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.profiles.activation.ProfileActivationContext; +import org.apache.maven.profiles.build.ProfileAdvisor; +import org.apache.maven.artifact.InvalidRepositoryException; +import org.apache.maven.artifact.ArtifactUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.ArtifactStatus; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.MavenTools; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.ReaderFactory; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.logging.LogEnabled; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; + +import java.util.*; +import java.io.*; + +/** + * This is a temporary class. These methods are originally from the DefaultMavenProjectHelper. This class will be + * eliminated when Mercury is integrated. + */ +public class DefaultRepositoryHelper implements RepositoryHelper, Initializable, LogEnabled { + + private Logger logger; + + public static final String MAVEN_MODEL_VERSION = "4.0.0"; + + private ArtifactFactory artifactFactory; + + private ArtifactResolver artifactResolver; + + private MavenTools mavenTools; + + private ProfileAdvisor profileAdvisor; + + private MavenXpp3Reader modelReader; + + private Logger getLogger() { + return logger; + } + + public Model findModelFromRepository(Artifact artifact, + List remoteArtifactRepositories, + ArtifactRepository localRepository) + throws ProjectBuildingException { + + String projectId = safeVersionlessKey(artifact.getGroupId(), artifact.getArtifactId()); + remoteArtifactRepositories = normalizeToArtifactRepositories(remoteArtifactRepositories, projectId); + + Artifact projectArtifact; + + // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given. + if ("pom".equals(artifact.getType())) { + projectArtifact = artifact; + } else { + getLogger().warn("Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":" + + artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: " + + artifact.getType() + "; constructing POM artifact instead."); + + projectArtifact = artifactFactory.createProjectArtifact(artifact.getGroupId(), + artifact.getArtifactId(), + artifact.getVersion(), + artifact.getScope()); + } + + Model legacy_model; + try { + artifactResolver.resolve(projectArtifact, remoteArtifactRepositories, localRepository); + + File file = projectArtifact.getFile(); + + legacy_model = readModelLegacy(projectId, file, true); + + String downloadUrl = null; + + ArtifactStatus status = ArtifactStatus.NONE; + + DistributionManagement distributionManagement = legacy_model.getDistributionManagement(); + + if (distributionManagement != null) { + downloadUrl = distributionManagement.getDownloadUrl(); + + status = ArtifactStatus.valueOf(distributionManagement.getStatus()); + } + + checkStatusAndUpdate(projectArtifact, status, file, remoteArtifactRepositories, localRepository); + + // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that + // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions? + if (downloadUrl != null) { + projectArtifact.setDownloadUrl(downloadUrl); + } else { + projectArtifact.setDownloadUrl(legacy_model.getUrl()); + } + } + catch (ArtifactResolutionException e) { + throw new ProjectBuildingException(projectId, "Error getting POM for '" + projectId + "' from the repository: " + e.getMessage(), e); + } + catch (ArtifactNotFoundException e) { + throw new ProjectBuildingException(projectId, "POM '" + projectId + "' not found in repository: " + e.getMessage(), e); + } + + return legacy_model; + } + + public List buildArtifactRepositories(Model model) + throws ProjectBuildingException { + try { + return mavenTools.buildArtifactRepositories(model.getRepositories()); + } + catch (InvalidRepositoryException e) { + String projectId = safeVersionlessKey(model.getGroupId(), model.getArtifactId()); + + throw new ProjectBuildingException(projectId, e.getMessage(), e); + } + } + + /* + * Order is: + * + * 1. model profile repositories + * 2. model repositories + * 3. superModel profile repositories + * 4. superModel repositories + * 5. parentSearchRepositories + */ + public LinkedHashSet collectInitialRepositories(Model model, + Model superModel, + List parentSearchRepositories, + File pomFile, + boolean validProfilesXmlLocation, + ProfileActivationContext profileActivationContext) + throws ProjectBuildingException { + LinkedHashSet collected = new LinkedHashSet(); + + collectInitialRepositoriesFromModel(collected, model, pomFile, validProfilesXmlLocation, profileActivationContext); + + collectInitialRepositoriesFromModel(collected, superModel, null, validProfilesXmlLocation, profileActivationContext); + + if ((parentSearchRepositories != null) && !parentSearchRepositories.isEmpty()) { + collected.addAll(parentSearchRepositories); + } + + return collected; + } + + private List normalizeToArtifactRepositories(List remoteArtifactRepositories, + String projectId) + throws ProjectBuildingException { + List normalized = new ArrayList(remoteArtifactRepositories.size()); + + boolean normalizationNeeded = false; + for (Iterator it = remoteArtifactRepositories.iterator(); it.hasNext();) { + Object item = it.next(); + + if (item instanceof ArtifactRepository) { + normalized.add(item); + } else if (item instanceof Repository) { + Repository repo = (Repository) item; + try { + item = mavenTools.buildArtifactRepository(repo); + + normalized.add(item); + normalizationNeeded = true; + } + catch (InvalidRepositoryException e) { + throw new ProjectBuildingException(projectId, "Error building artifact repository for id: " + repo.getId(), e); + } + } else { + throw new ProjectBuildingException(projectId, "Error building artifact repository from non-repository information item: " + item); + } + } + + if (normalizationNeeded) { + return normalized; + } else { + return remoteArtifactRepositories; + } + } + + private String safeVersionlessKey(String groupId, + String artifactId) { + String gid = groupId; + + if (StringUtils.isEmpty(gid)) { + gid = "unknown"; + } + + String aid = artifactId; + + if (StringUtils.isEmpty(aid)) { + aid = "unknown"; + } + + return ArtifactUtils.versionlessKey(gid, aid); + } + + private void checkModelVersion(String modelSource, + String projectId, + File file) + throws InvalidProjectModelException { + if (modelSource.indexOf("<modelVersion>4.0.0") < 0) { + throw new InvalidProjectModelException(projectId, "Not a v" + MAVEN_MODEL_VERSION + " POM.", file); + } + } + + private Model readModelLegacy(String projectId, + File file, + boolean strict) + throws ProjectBuildingException { + Reader reader = null; + try { + reader = ReaderFactory.newXmlReader(file); + + String modelSource = IOUtil.toString(reader); + + checkModelVersion(modelSource, projectId, file); + + StringReader sReader = new StringReader(modelSource); + + try { + return new MavenXpp3Reader().read(sReader, strict); + } + catch (XmlPullParserException e) { + throw new InvalidProjectModelException(projectId, "Parse error reading POM. Reason: " + e.getMessage(), + file, e); + } + } + catch (FileNotFoundException e) { + throw new ProjectBuildingException(projectId, + "Could not find the model file '" + file.getAbsolutePath() + "'.", file, e); + } + catch (IOException e) { + throw new ProjectBuildingException(projectId, "Failed to build model from file '" + + file.getAbsolutePath() + "'.\nError: \'" + e.getLocalizedMessage() + "\'", file, e); + } + finally { + IOUtil.close(reader); + } + } + + private void collectInitialRepositoriesFromModel(LinkedHashSet collected, + Model model, + File pomFile, + boolean validProfilesXmlLocation, + ProfileActivationContext profileActivationContext) + throws ProjectBuildingException { + + Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles(model, pomFile, validProfilesXmlLocation, profileActivationContext); + + if ((reposFromProfiles != null) && !reposFromProfiles.isEmpty()) { + collected.addAll(reposFromProfiles); + } + + List modelRepos = model.getRepositories(); + + if ((modelRepos != null) && !modelRepos.isEmpty()) { + try { + collected.addAll(mavenTools.buildArtifactRepositories(modelRepos)); + } + catch (InvalidRepositoryException e) { + throw new ProjectBuildingException(safeVersionlessKey(model.getGroupId(), model.getArtifactId()), + "Failed to construct ArtifactRepository instances for repositories declared in: " + + model.getId(), e); + } + } + } + private void checkStatusAndUpdate( Artifact projectArtifact, + ArtifactStatus status, + File file, + List remoteArtifactRepositories, + ArtifactRepository localRepository ) + throws ArtifactNotFoundException + { + // TODO: configurable actions dependant on status + if ( !projectArtifact.isSnapshot() && ( status.compareTo( ArtifactStatus.DEPLOYED ) < 0 ) ) + { + // use default policy (enabled, daily update, warn on bad checksum) + ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(); + // TODO: re-enable [MNG-798/865] + policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); + + if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) ) + { + getLogger().info( + projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" ); + try + { + projectArtifact.setResolved( false ); + artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories, localRepository ); + } + catch ( ArtifactResolutionException e ) + { + getLogger().warn( "Error updating POM - using existing version" ); + getLogger().debug( "Cause", e ); + } + catch ( ArtifactNotFoundException e ) + { + getLogger().warn( "Error updating POM - not found. Removing local copy." ); + getLogger().debug( "Cause", e ); + file.delete(); + throw e; + } + } + } + } + + + public void initialize() throws InitializationException { + modelReader = new MavenXpp3Reader(); + } + + public void enableLogging(Logger logger) { + this.logger = logger; + } +} \ No newline at end of file Added: maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java URL: http://svn.apache.org/viewvc/maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java?rev=686112&view=auto ============================================================================== --- maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java (added) +++ maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java Thu Aug 14 19:18:38 2008 @@ -0,0 +1,35 @@ +package org.apache.maven.project; + +import org.apache.maven.model.Model; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.profiles.activation.ProfileActivationContext; + +import java.util.List; +import java.util.LinkedHashSet; +import java.io.File; + +/** + * This is a temporary class. These methods are originally from the DefaultMavenProjectHelper. This class will be + * eliminated when Mercury is integrated. + */ +public interface RepositoryHelper { + + String ROLE = RepositoryHelper.class.getName(); + + Model findModelFromRepository(Artifact artifact, + List remoteArtifactRepositories, + ArtifactRepository localRepository) + throws ProjectBuildingException; + + List buildArtifactRepositories(Model model) + throws ProjectBuildingException; + + LinkedHashSet collectInitialRepositories(Model model, + Model superModel, + List parentSearchRepositories, + File pomFile, + boolean validProfilesXmlLocation, + ProfileActivationContext profileActivationContext) + throws ProjectBuildingException; +} Modified: maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/resources/META-INF/plexus/components.xml URL: http://svn.apache.org/viewvc/maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/resources/META-INF/plexus/components.xml?rev=686112&r1=686111&r2=686112&view=diff ============================================================================== --- maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/resources/META-INF/plexus/components.xml (original) +++ maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/main/resources/META-INF/plexus/components.xml Thu Aug 14 19:18:38 2008 @@ -126,6 +126,9 @@ <implementation>org.apache.maven.project.DefaultMavenProjectBuilder</implementation> <requirements> <requirement> + <role>org.apache.maven.project.RepositoryHelper</role> + </requirement> + <requirement> <role>org.apache.maven.project.builder.ProjectBuilder</role> </requirement> <requirement> @@ -170,6 +173,27 @@ </requirement> </requirements> </component> + +<!--Eliminate this component after Mercury Integration--> + <component> + <role>org.apache.maven.project.RepositoryHelper</role> + <implementation>org.apache.maven.project.DefaultRepositoryHelper</implementation> + <requirements> + <requirement> + <role>org.apache.maven.profiles.build.ProfileAdvisor</role> + </requirement> + <requirement> + <role>org.apache.maven.artifact.factory.ArtifactFactory</role> + </requirement> + <requirement> + <role>org.apache.maven.artifact.resolver.ArtifactResolver</role> + <role-hint>default</role-hint> + </requirement> + <requirement> + <role>org.apache.maven.MavenTools</role> + </requirement> + </requirements> + </component> <!-- | | Modified: maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml URL: http://svn.apache.org/viewvc/maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml?rev=686112&r1=686111&r2=686112&view=diff ============================================================================== --- maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml (original) +++ maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml Thu Aug 14 19:18:38 2008 @@ -19,6 +19,27 @@ <plexus> <components> +<!--Eliminate this component after Mercury Integration--> + <component> + <role>org.apache.maven.project.RepositoryHelper</role> + <implementation>org.apache.maven.project.DefaultRepositoryHelper</implementation> + <requirements> + <requirement> + <role>org.apache.maven.profiles.build.ProfileAdvisor</role> + <role-hint>default</role-hint> + </requirement> + <requirement> + <role>org.apache.maven.artifact.factory.ArtifactFactory</role> + </requirement> + <requirement> + <role>org.apache.maven.artifact.resolver.ArtifactResolver</role> + <role-hint>default</role-hint> + </requirement> + <requirement> + <role>org.apache.maven.MavenTools</role> + </requirement> + </requirements> + </component> <!-- Due to PLX-108, have to work around it... <component> <role>org.apache.maven.artifact.ArtifactResolver</role> @@ -91,9 +112,12 @@ <implementation>org.apache.maven.project.TestProjectBuilder</implementation> <requirements> <requirement> - <role>org.apache.maven.project.builder.ProjectBuilder</role> + <role>org.apache.maven.project.RepositoryHelper</role> </requirement> <requirement> + <role>org.apache.maven.project.builder.ProjectBuilder</role> + </requirement> + <requirement> <role>org.apache.maven.project.workspace.ProjectWorkspace</role> </requirement> <requirement> Modified: maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml URL: http://svn.apache.org/viewvc/maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml?rev=686112&r1=686111&r2=686112&view=diff ============================================================================== --- maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml (original) +++ maven/components/branches/sisbell-maven-2.1-profile/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml Thu Aug 14 19:18:38 2008 @@ -18,7 +18,27 @@ --> <plexus> - <components> + <components><!--Eliminate this component after Mercury Integration--> + <component> + <role>org.apache.maven.project.RepositoryHelper</role> + <implementation>org.apache.maven.project.DefaultRepositoryHelper</implementation> + <requirements> + <requirement> + <role>org.apache.maven.profiles.build.ProfileAdvisor</role> + </requirement> + <requirement> + <role>org.apache.maven.artifact.factory.ArtifactFactory</role> + </requirement> + <requirement> + <role>org.apache.maven.artifact.resolver.ArtifactResolver</role> + <role-hint>default</role-hint> + </requirement> + <requirement> + <role>org.apache.maven.MavenTools</role> + </requirement> + </requirements> + </component> + <!-- Due to PLX-108, have to work around it... <component> <role>org.apache.maven.artifact.ArtifactResolver</role> @@ -89,6 +109,9 @@ <implementation>org.apache.maven.project.TestProjectBuilder</implementation> <requirements> <requirement> + <role>org.apache.maven.project.RepositoryHelper</role> + </requirement> + <requirement> <role>org.apache.maven.project.builder.ProjectBuilder</role> </requirement> <requirement>