You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2009/05/07 19:58:16 UTC
svn commit: r772728 - in
/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project:
DefaultMavenProjectBuilder.java MavenProject.java
artifact/MavenMetadataSource.java
Author: jvanzyl
Date: Thu May 7 17:58:15 2009
New Revision: 772728
URL: http://svn.apache.org/viewvc?rev=772728&view=rev
Log:
o starting to collapse the methods in the project builder
o rebuilder the maven metadata source
Modified:
maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=772728&r1=772727&r2=772728&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Thu May 7 17:58:15 2009
@@ -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 @@
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 @@
}
}
- domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel );
-
-
+ domainModel = ProcessorContext.mergeProfilesIntoModel( externalProfiles, domainModel );
}
catch ( IOException e )
{
@@ -257,16 +248,6 @@
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<PluginExecution> plugins)
{
@@ -339,30 +320,24 @@
return buildFromRepository( artifact, new DefaultProjectBuilderConfiguration( localRepository, remoteRepositories ) );
}
- public MavenProject buildFromRepository(Artifact artifact, ProjectBuilderConfiguration configuration )
- throws ProjectBuildingException
+ public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration )
+ throws ProjectBuildingException
{
-
MavenProject project = hm.get( artifact.getId() );
if ( project != null )
{
return project;
}
-
- if(configuration.getRemoteRepositories() == null)
- {
- throw new IllegalArgumentException("configuration.getRemoteRepositories(): null");
- }
-
+
if ( !artifact.getType().equals( "pom" ) )
{
artifact = repositorySystem.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() );
}
-
+
ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifact, configuration.getLocalRepository(), configuration.getRemoteRepositories() );
ArtifactResolutionResult result = repositorySystem.resolve( request );
-
+
try
{
resolutionErrorHandler.throwErrors( request, result );
@@ -372,54 +347,52 @@
throw new ProjectBuildingException( artifact.getId(), "Error resolving project artifact.", e );
}
DomainModel domainModel;
- try
+ try
{
- domainModel = build( "unknown", artifact.getFile(), configuration );
- }
- catch (IOException e)
+ domainModel = build( "unknown", artifact.getFile(), configuration );
+ }
+ catch ( IOException e )
{
- throw new ProjectBuildingException(artifact.getId(), "Error reading project artifact.", e);
- }
-
+ throw new ProjectBuildingException( artifact.getId(), "Error reading project artifact.", e );
+ }
+
List<Profile> projectProfiles;
- Properties props = new Properties();
- props.putAll(configuration.getExecutionProperties());
- // props.putAll(configuration.getUserProperties());
-
+ Properties props = new Properties();
+ props.putAll( configuration.getExecutionProperties() );
+ // props.putAll(configuration.getUserProperties());
+
try
{
- projectProfiles = DefaultProfileManager.getActiveProfilesFrom(configuration.getGlobalProfileManager(), props, domainModel.getModel() );
+ 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 @@
hm.put( artifact.getId(), project );
- return project;
+ return project;
}
/**
@@ -464,41 +437,23 @@
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<ArtifactRepository>() );
- }
-
+
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 @@
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 )
{
Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/MavenProject.java?rev=772728&r1=772727&r2=772728&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/MavenProject.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/MavenProject.java Thu May 7 17:58:15 2009
@@ -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 @@
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,14 +178,38 @@
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
*
* @param model - may not be null
@@ -229,17 +238,6 @@
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<ArtifactRepository>(projectBuilderConfiguration.getRemoteRepositories()) : new ArrayList<ArtifactRepository>());
for(Repository r: model.getPluginRepositories())
@@ -260,15 +258,6 @@
}
}
- /**
- * @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 <relativePath/> 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 @@
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 @@
* @return {@link Set} < {@link Artifact} >
* @todo the lazy initialisation of this makes me uneasy.
*/
- public Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, String inheritedScope, ArtifactFilter dependencyFilter )
- throws InvalidDependencyVersionException
+ //TODO: this method doesn't belong here at all
+ @Deprecated
+ public Set<Artifact> createArtifacts( ArtifactFilter filter )
{
- try
- {
- return repositorySystem.createArtifacts( getDependencies(), inheritedScope, dependencyFilter, this );
- }
- catch ( VersionNotFoundException e )
+ Set<Artifact> artifacts = new HashSet<Artifact>();
+
+ for( Dependency d : getDependencies() )
{
- 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 )
Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=772728&r1=772727&r2=772728&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java Thu May 7 17:58:15 2009
@@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
- * @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<ArtifactRepository> remoteRepositories )
+ public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> 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<Artifact> 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 <version> 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<ArtifactRepository> 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 );
- }
-
- 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;
- }
+ project = projectBuilder.buildFromRepository( pomArtifact, configuration );
- /**
- * 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 );
- }
-
- return result;
- }
-
- 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
+ catch ( ProjectBuildingException e )
{
- 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" );
+ // 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.
}
- }
- private void loadProjectBuilder()
- throws ComponentLookupException
- {
- if ( mavenProjectBuilder == null )
- {
- mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.class );
- }
+ return new ResolutionGroup( pomArtifact, artifacts, remoteRepositories );
}
- public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository,
- List<ArtifactRepository> remoteRepositories )
+ public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
+
try
{
repositoryMetadataManager.resolve( metadata, remoteRepositories, localRepository );
@@ -408,9 +113,7 @@
return retrieveAvailableVersionsFromMetadata( metadata.getMetadata() );
}
- public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact,
- ArtifactRepository localRepository,
- ArtifactRepository deploymentRepository )
+ public List<ArtifactVersion> retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository deploymentRepository )
throws ArtifactMetadataRetrievalException
{
RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact );
@@ -440,36 +143,9 @@
}
else
{
- versions = Collections.<ArtifactVersion>emptyList();
+ versions = Collections.<ArtifactVersion> emptyList();
}
return versions;
}
-
- private static final class ProjectRelocation
- {
- private MavenProject project;
-
- private Artifact pomArtifact;
- }
-
- // USED BY MAVEN ASSEMBLY PLUGIN
- @Deprecated
- public static Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, List<Dependency> 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() );
- }
- }
-
}