diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 6087dee3c3..d3a30376ca 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -18,7 +18,6 @@ import java.io.File; import java.io.IOException; import java.io.Reader; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -52,11 +51,9 @@ import org.apache.maven.profiles.ProfileActivationException; import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.ProfileManagerInfo; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidator; import org.apache.maven.repository.RepositorySystem; -import org.apache.maven.repository.VersionNotFoundException; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.Logger; @@ -140,10 +137,6 @@ public MavenProject build( File pomFile, ProjectBuilderConfiguration configurati catch ( ProfileActivationException e ) { throw new ProjectBuildingException( "", "Failed to activate pom profiles."); - } - catch(IOException e) - { - throw new ProjectBuildingException( "", "Failed to activate pom profiles."); } try @@ -158,9 +151,7 @@ public MavenProject build( File pomFile, ProjectBuilderConfiguration configurati } } - domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel ); - - + domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel ); } catch ( IOException e ) { @@ -257,16 +248,6 @@ public MavenProject build( File pomFile, ProjectBuilderConfiguration configurati return project; } - - private static void printPlugin(Plugin plugin, String tag) - { - System.out.println(tag + ":" + plugin); - System.out.println("CONFIG:" + plugin.getConfiguration()); - for(PluginExecution pe : plugin.getExecutions()) - { - System.out.println("PE:" + pe.getConfiguration()); - } - } private static PluginExecution contains(String goal, List plugins) { @@ -339,30 +320,24 @@ public MavenProject buildFromRepository( Artifact artifact, List projectProfiles; - Properties props = new Properties(); - props.putAll(configuration.getExecutionProperties()); - // props.putAll(configuration.getUserProperties()); - try { - projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration.getGlobalProfileManager(), props, domainModel.getModel() ); + domainModel = build( "unknown", artifact.getFile(), configuration ); + } + catch ( IOException e ) + { + throw new ProjectBuildingException( artifact.getId(), "Error reading project artifact.", e ); + } + + List projectProfiles; + Properties props = new Properties(); + props.putAll( configuration.getExecutionProperties() ); + // props.putAll(configuration.getUserProperties()); + + try + { + projectProfiles = DefaultProfileManager.getActiveProfilesFrom( configuration.getGlobalProfileManager(), props, domainModel.getModel() ); } catch ( ProfileActivationException e ) { - throw new ProjectBuildingException( "", "Failed to activate pom profiles."); - } - catch(IOException e) - { - throw new ProjectBuildingException( "", "Failed to activate pom profiles."); + throw new ProjectBuildingException( "", "Failed to activate pom profiles." ); } - + try { - for(Profile p : projectProfiles) - { - logger.debug("Merging profile into model (buildFromRepository): Model = " + domainModel.getId() + ", Profile = " + p.getId() ); - } - + for ( Profile p : projectProfiles ) + { + logger.debug( "Merging profile into model (buildFromRepository): Model = " + domainModel.getId() + ", Profile = " + p.getId() ); + } + domainModel = ProcessorContext.mergeProfilesIntoModel( projectProfiles, domainModel ); } catch ( IOException e ) { - throw new ProjectBuildingException("", ""); + throw new ProjectBuildingException( "", "" ); + } + + try + { + Model model = ProcessorContext.processManagementNodes( interpolateDomainModel( domainModel, configuration, artifact.getFile() ) ); + project = this.fromDomainModelToMavenProject( model, domainModel.getParentFile(), configuration, artifact.getFile() ); + } + catch ( IOException e ) + { + throw new ProjectBuildingException( "", "" ); } - - - try { - Model model = ProcessorContext.processManagementNodes(interpolateDomainModel( domainModel, configuration, artifact.getFile() )); - project = this.fromDomainModelToMavenProject(model, domainModel.getParentFile(), configuration, artifact.getFile()); - } catch (IOException e) { - throw new ProjectBuildingException("", ""); - } project.setActiveProfiles( projectProfiles ); artifact.setFile( artifact.getFile() ); @@ -427,7 +400,7 @@ public MavenProject buildFromRepository(Artifact artifact, ProjectBuilderConfigu hm.put( artifact.getId(), project ); - return project; + return project; } /** @@ -464,41 +437,23 @@ public MavenProjectBuildingResult buildProjectWithDependencies( File pomFile, Pr throws ProjectBuildingException { MavenProject project = build( pomFile, configuration ); - - try - { - project.setDependencyArtifacts( repositorySystem.createArtifacts( project.getDependencies(), null, null, project ) ); - } - catch ( VersionNotFoundException e ) - { - InvalidDependencyVersionException ee = new InvalidDependencyVersionException( e.getProjectId(), e.getDependency(), e.getPomFile(), e.getCauseException() ); - throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ), "Unable to build project due to an invalid dependency version: " + e.getMessage(), - pomFile, ee ); - } - Artifact pomArtifact = repositorySystem.createProjectArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion() ); pomArtifact.setFile( pomFile ); ArtifactResolutionRequest request = new ArtifactResolutionRequest() - .setArtifact( pomArtifact ).setArtifactDependencies( project.getDependencyArtifacts() ) + .setArtifact( pomArtifact ) + .setArtifactDependencies( project.getDependencyArtifacts() ) .setLocalRepository( configuration.getLocalRepository() ) .setRemoteRepostories( project.getRemoteArtifactRepositories() ) .setManagedVersionMap( project.getManagedVersionMap() ); - - - if(request.getRemoteRepostories() == null) - { - request.setRemoteRepostories( new ArrayList() ); - } - + ArtifactResolutionResult result = repositorySystem.resolve( request ); if ( result.hasExceptions() ) { Exception e = result.getExceptions().get( 0 ); - throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ), "Unable to build project due to an invalid dependency version: " + e.getMessage(), - pomFile, e ); + throw new ProjectBuildingException( safeVersionlessKey( project.getGroupId(), project.getArtifactId() ), "Unable to build project due to an invalid dependency version: " + e.getMessage(), pomFile, e ); } project.setArtifacts( result.getArtifacts() ); @@ -509,23 +464,13 @@ public MavenProjectBuildingResult buildProjectWithDependencies( File pomFile, Pr private Model interpolateDomainModel( DomainModel domainModel, ProjectBuilderConfiguration config, File projectDescriptor ) throws ProjectBuildingException { - Model model; - try - { - model = domainModel.getModel(); - } - catch ( IOException e ) - { - throw new ProjectBuildingException( "", e.getMessage() ); - } + Model model = domainModel.getModel(); String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); - Properties props = new Properties( config.getExecutionProperties() ); - try { - model = interpolator.interpolateModel( model, props, domainModel.getProjectDirectory() ); + model = interpolator.interpolateModel( model, config.getExecutionProperties(), domainModel.getProjectDirectory() ); } catch ( IOException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index fb04a1a743..0cf47e7077 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -35,7 +35,6 @@ import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.artifact.InvalidRepositoryException; -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; @@ -68,10 +67,8 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.artifact.ActiveProjectArtifact; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.repository.MavenRepositoryWrapper; import org.apache.maven.repository.RepositorySystem; -import org.apache.maven.repository.VersionNotFoundException; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; @@ -168,18 +165,6 @@ public class MavenProject private RepositorySystem repositorySystem; // - private File parentFile; - - public File getParentFile() - { - return parentFile; - } - - public void setParentFile( File parentFile ) - { - this.parentFile = parentFile; - } - public MavenProject() { Model model = new Model(); @@ -193,13 +178,37 @@ public MavenProject() public MavenProject( Model model ) { - if ( model == null ) - { - throw new IllegalArgumentException( "model: null" ); - } setModel( model ); } + /** + * @deprecated use {@link #clone()} so subclasses can provide a copy of the same class + */ + @Deprecated + public MavenProject( MavenProject project ) + { + deepCopy( project ); + } + + @Deprecated + public MavenProject( Model model, RepositorySystem repositorySystem ) + { + this.repositorySystem = repositorySystem; + setModel( model ); + } + + private File parentFile; + + public File getParentFile() + { + return parentFile; + } + + public void setParentFile( File parentFile ) + { + this.parentFile = parentFile; + } + /** * Constructor * @@ -229,17 +238,6 @@ public MavenProject( Model model, RepositorySystem repositorySystem, MavenProjec this.repositorySystem = repositorySystem; originalModel = model; - /* - DistributionManagement dm = model.getDistributionManagement(); - - if ( dm != null ) - { - ArtifactRepository repo = repositorySystem.buildArtifactRepository( dm.getRepository() ); - setReleaseArtifactRepository( repo ); - - } - */ - setRemoteArtifactRepositories( (projectBuilderConfiguration.getRemoteRepositories() != null) ? new ArrayList(projectBuilderConfiguration.getRemoteRepositories()) : new ArrayList()); for(Repository r: model.getPluginRepositories()) @@ -260,15 +258,6 @@ public MavenProject( Model model, RepositorySystem repositorySystem, MavenProjec } } - /** - * @deprecated use {@link #clone()} so subclasses can provide a copy of the same class - */ - @Deprecated - public MavenProject( MavenProject project ) - { - deepCopy( project ); - } - // TODO: Find a way to use here...it's tricky, because the moduleProject // usually doesn't have a file associated with it yet. public String getModulePathAdjustment( MavenProject moduleProject ) @@ -518,13 +507,15 @@ public List getCompileClasspathElements() list.add( getBuild().getOutputDirectory() ); for ( Artifact a : getArtifacts() ) - { + { + System.out.println( "++> " + a.getArtifactId() ); if ( a.getArtifactHandler().isAddedToClasspath() ) { // TODO: let the scope handler deal with this if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) { addArtifactPath( a, list ); + System.out.println( "--> " + a.getArtifactId() ); } } } @@ -1614,17 +1605,29 @@ public List getBuildExtensions() * @return {@link Set} < {@link Artifact} > * @todo the lazy initialisation of this makes me uneasy. */ - public Set createArtifacts( ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter dependencyFilter ) - throws InvalidDependencyVersionException + //TODO: this method doesn't belong here at all + @Deprecated + public Set createArtifacts( ArtifactFilter filter ) { - try + Set artifacts = new HashSet(); + + for( Dependency d : getDependencies() ) { - return repositorySystem.createArtifacts( getDependencies(), inheritedScope, dependencyFilter, this ); - } - catch ( VersionNotFoundException e ) - { - throw new InvalidDependencyVersionException( e.getProjectId(), e.getDependency(), e.getPomFile(), e.getCauseException() ); + //TODO: something is wrong here because the scope of compile is never set correctly. + if ( d.getScope() == null ) + { + d.setScope( Artifact.SCOPE_COMPILE ); + } + + Artifact artifact = repositorySystem.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getScope(), d.getType() ); + + if ( filter == null || filter.include( artifact ) ) + { + artifacts.add( artifact ); + } } + + return artifacts; } public void addProjectReference( MavenProject project ) diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 6695c401ed..e8f0912891 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -1,32 +1,26 @@ package org.apache.maven.project.artifact; /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Set; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ResolutionGroup; @@ -37,365 +31,76 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DistributionManagement; -import org.apache.maven.model.Relocation; import org.apache.maven.project.DefaultProjectBuilderConfiguration; -import org.apache.maven.project.InvalidProjectModelException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuilderConfiguration; import org.apache.maven.project.ProjectBuildingException; -import org.apache.maven.project.validation.ModelValidationResult; -import org.apache.maven.repository.LegacyRepositorySystem; -import org.apache.maven.repository.VersionNotFoundException; -import org.codehaus.plexus.PlexusContainer; +import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.logging.AbstractLogEnabled; /** * @author Jason van Zyl - * @author Brett Porter - * @version $Id$ */ -@Component(role = ArtifactMetadataSource.class ) +//TODO: we don't need the repository metadata thing really, we can retrieve files independendently and parse +@Component(role = ArtifactMetadataSource.class) public class MavenMetadataSource - extends AbstractLogEnabled implements ArtifactMetadataSource { - public static final String ROLE_HINT = "default"; - - @Requirement - private ArtifactFactory artifactFactory; - @Requirement private RepositoryMetadataManager repositoryMetadataManager; - - // lazily instantiated and cached. - private MavenProject superProject; @Requirement - private PlexusContainer container; + private RepositorySystem repositorySystem; - //!! not injected which is a problem - private MavenProjectBuilder mavenProjectBuilder; + @Requirement + private MavenProjectBuilder projectBuilder; - /** - * Unfortunately we have projects that are still sending us JARs without the accompanying POMs. - */ - private boolean strictlyEnforceThePresenceOfAValidMavenPOM = false; - - /** - * Resolve all relocations in the POM for this artifact, and return the new artifact coordinate. - */ - public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository, - List remoteRepositories ) + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { - if ( artifact instanceof ActiveProjectArtifact ) - { - return artifact; - } + Artifact pomArtifact = repositorySystem.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); - ProjectRelocation rel = retrieveRelocatedProject( artifact, localRepository, remoteRepositories ); + Set artifacts = Collections.emptySet(); - if ( rel == null ) - { - return artifact; - } + ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration(); + configuration.setLocalRepository( localRepository ); + configuration.setRemoteRepositories( remoteRepositories ); - MavenProject project = rel.project; - if ( project == null || getRelocationKey( artifact ).equals( getRelocationKey( project.getArtifact() ) ) ) - { - return artifact; - } - - // NOTE: Using artifact information here, since some POMs are deployed - // to central with one version in the filename, but another in the string! - // Case in point: org.apache.ws.commons:XmlSchema:1.1:pom. - // - // Since relocation triggers a reconfiguration of the artifact's information - // in retrieveRelocatedProject(..), this is safe to do. - Artifact result = null; - if ( artifact.getClassifier() != null ) - { - result = artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion(), artifact.getType(), - artifact.getClassifier() ); - } - else - { - result = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion(), artifact.getScope(), artifact.getType() ); - } - - result.setScope( artifact.getScope() ); - result.setArtifactHandler( artifact.getArtifactHandler() ); - result.setDependencyFilter( artifact.getDependencyFilter() ); - result.setDependencyTrail( artifact.getDependencyTrail() ); - result.setOptional( artifact.isOptional() ); - result.setRelease( artifact.isRelease() ); - - return result; - } - - private String getRelocationKey( Artifact artifact ) - { - return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); - } - - private ProjectRelocation retrieveRelocatedProject( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) - throws ArtifactMetadataRetrievalException - { - if ( remoteRepositories == null ) - { - remoteRepositories = Collections.emptyList(); - } + MavenProject project; try { - loadProjectBuilder(); - } - catch ( ComponentLookupException e ) - { - throw new ArtifactMetadataRetrievalException( - "Cannot lookup MavenProjectBuilder component instance: " + e.getMessage(), e ); - } + project = projectBuilder.buildFromRepository( pomArtifact, configuration ); - MavenProject project = null; - Artifact pomArtifact; - - boolean done = false; - do - { - // TODO: can we just modify the original? - pomArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() ); - - if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) ) - { - done = true; - } - else - { - try - { - project = mavenProjectBuilder.buildFromRepository( pomArtifact, new DefaultProjectBuilderConfiguration( localRepository, remoteRepositories ) ); - } - catch ( InvalidProjectModelException e ) - { - handleInvalidOrMissingMavenPOM( artifact, e ); - - if ( getLogger().isDebugEnabled() ) - { - getLogger().debug( "Reason: " + e.getMessage() ); - - ModelValidationResult validationResult = e.getValidationResult(); - - if ( validationResult != null ) - { - getLogger().debug( "\nValidation Errors:" ); - for ( Iterator i = validationResult.getMessages().iterator(); i.hasNext(); ) - { - getLogger().debug( i.next().toString() ); - } - getLogger().debug( "\n" ); - } - else - { - getLogger().debug( "", e ); - } - } - - throw new ArtifactMetadataRetrievalException( - "Cannot validate pom " + e.getMessage(), e ); - } - catch ( ProjectBuildingException e ) - { - handleInvalidOrMissingMavenPOM( artifact, e ); - - throw new ArtifactMetadataRetrievalException( - "Cannot build project: " + e.getMessage(), e ); - } - - - if ( project != null ) - { - Relocation relocation = null; - - DistributionManagement distMgmt = project.getDistributionManagement(); - if ( distMgmt != null ) - { - relocation = distMgmt.getRelocation(); - - artifact.setDownloadUrl( distMgmt.getDownloadUrl() ); - pomArtifact.setDownloadUrl( distMgmt.getDownloadUrl() ); - } - - if ( relocation != null ) - { - if ( relocation.getGroupId() != null ) - { - artifact.setGroupId( relocation.getGroupId() ); - project.setGroupId( relocation.getGroupId() ); - } - if ( relocation.getArtifactId() != null ) - { - artifact.setArtifactId( relocation.getArtifactId() ); - project.setArtifactId( relocation.getArtifactId() ); - } - if ( relocation.getVersion() != null ) - { - artifact.setVersionRange( VersionRange.createFromVersion( relocation.getVersion() ) ); - project.setVersion( relocation.getVersion() ); - } - - if ( ( artifact.getDependencyFilter() != null ) && - !artifact.getDependencyFilter().include( artifact ) ) - { - return null; - } - - //MNG-2861: the artifact data has changed. If the available versions where previously retrieved, - //we need to update it. TODO: shouldn't the versions be merged across relocations? - List available = artifact.getAvailableVersions(); - if ( available != null && !available.isEmpty() ) - { - artifact.setAvailableVersions( - retrieveAvailableVersions( artifact, localRepository, remoteRepositories ) ); - - } - - String message = "\n This artifact has been relocated to " + artifact.getGroupId() + ":" + - artifact.getArtifactId() + ":" + artifact.getVersion() + ".\n"; - - if ( relocation.getMessage() != null ) - { - message += " " + relocation.getMessage() + "\n"; - } - - if ( ( artifact.getDependencyTrail() != null ) && - ( artifact.getDependencyTrail().size() == 1 ) ) - { - getLogger().warn( "While downloading " + artifact.getGroupId() + ":" + - artifact.getArtifactId() + ":" + artifact.getVersion() + message + "\n" ); - } - else - { - getLogger().debug( "While downloading " + artifact.getGroupId() + ":" + - artifact.getArtifactId() + ":" + artifact.getVersion() + message + "\n" ); - } - } - else - { - done = true; - } - } - else - { - done = true; - } - } - } - while ( !done ); - - ProjectRelocation res = new ProjectRelocation(); - res.project = project; - res.pomArtifact = pomArtifact; - - return res; - } - - /** - * Retrieve the metadata for the project from the repository. - * Uses the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the - * associated artifacts. - */ - public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) - throws ArtifactMetadataRetrievalException - { - ProjectRelocation res = retrieveRelocatedProject( artifact, localRepository, remoteRepositories ); - MavenProject project = res.project; - Artifact pomArtifact = res.pomArtifact; - - // last ditch effort to try to get this set... - if ( artifact.getDownloadUrl() == null ) - { - // TODO: this could come straight from the project, negating the need to set it in the project itself? - artifact.setDownloadUrl( pomArtifact.getDownloadUrl() ); - } - - ResolutionGroup result; - - if ( project == null ) - { - // if the project is null, we encountered an invalid model (read: m1 POM) - // we'll just return an empty resolution group. - // or used the inherited scope (should that be passed to the buildFromRepository method above?) - result = new ResolutionGroup( pomArtifact, Collections.EMPTY_SET, Collections.EMPTY_LIST ); - } - else - { - Set artifacts = Collections.EMPTY_SET; if ( !artifact.getArtifactHandler().isIncludesDependencies() ) - { - // TODO: we could possibly use p.getDependencyArtifacts instead of this call, but they haven't been filtered - // or used the inherited scope (should that be passed to the buildFromRepository method above?) - try - { - artifacts = - project.createArtifacts( artifactFactory, artifact.getScope(), artifact.getDependencyFilter() ); - } - catch ( InvalidDependencyVersionException e ) - { - throw new ArtifactMetadataRetrievalException( "Error in metadata for artifact '" + - artifact.getDependencyConflictId() + "': " + e.getMessage(), e ); - } + { + ArtifactFilter filter = new ScopeArtifactFilter( artifact.getScope() ); + + artifacts = project.createArtifacts( filter ); + + project.setArtifacts( artifacts ); } - - //List repositories = aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() ); - - result = new ResolutionGroup( pomArtifact, artifacts, remoteRepositories ); + } + catch ( ProjectBuildingException e ) + { + // When this happens we have a Maven 1.x POM, or some invalid POM. There is still a pile of + // shit in the Maven 2.x repository that should have never found its way into the repository + // but it did. } - return result; + return new ResolutionGroup( pomArtifact, artifacts, remoteRepositories ); } - private void handleInvalidOrMissingMavenPOM( Artifact artifact, ProjectBuildingException e ) - throws ArtifactMetadataRetrievalException - { - if ( strictlyEnforceThePresenceOfAValidMavenPOM ) - { - throw new ArtifactMetadataRetrievalException( - "Invalid POM file for artifact: '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e, - artifact ); - } - else - { - getLogger().debug( "\n\tDEPRECATION: The POM for the artifact '" + artifact.getDependencyConflictId() + - "' was invalid or not found on any repositories.\n" + - "\tThis may not be supported by future versions of Maven and should be corrected as soon as possible.\n" + - "\tError given: " + e.getMessage() + "\n" ); - } - } - - private void loadProjectBuilder() - throws ComponentLookupException - { - if ( mavenProjectBuilder == null ) - { - mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.class ); - } - } - - public List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, - List remoteRepositories ) + public List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); + try { repositoryMetadataManager.resolve( metadata, remoteRepositories, localRepository ); @@ -408,9 +113,7 @@ public List retrieveAvailableVersions( Artifact artifact, Artif return retrieveAvailableVersionsFromMetadata( metadata.getMetadata() ); } - public List retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, - ArtifactRepository localRepository, - ArtifactRepository deploymentRepository ) + public List retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository deploymentRepository ) throws ArtifactMetadataRetrievalException { RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact ); @@ -440,36 +143,9 @@ private List retrieveAvailableVersionsFromMetadata( Metadata re } else { - versions = Collections.emptyList(); + versions = Collections. emptyList(); } return versions; } - - private static final class ProjectRelocation - { - private MavenProject project; - - private Artifact pomArtifact; - } - - // USED BY MAVEN ASSEMBLY PLUGIN - @Deprecated - public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, - String inheritedScope, ArtifactFilter dependencyFilter, - MavenProject project ) - throws InvalidDependencyVersionException - { - try - { - return LegacyRepositorySystem.createArtifacts( artifactFactory, dependencies, inheritedScope, - dependencyFilter, project ); - } - catch ( VersionNotFoundException e ) - { - throw new InvalidDependencyVersionException( e.getProjectId(), e.getDependency(), e.getPomFile(), - e.getCauseException() ); - } - } - }