PR: MNG-950

use active project artifacts for extensions and plugin dependencies

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@307245 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-08 03:06:54 +00:00
parent 9e9916da7a
commit cb259a7689
4 changed files with 42 additions and 58 deletions

View File

@ -70,6 +70,9 @@ public void addExtension( Extension extension, MavenProject project, ArtifactRep
for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
a = project.replaceWithActiveArtifact( a );
container.addJarResource( a.getFile() );
}
}

View File

@ -49,7 +49,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.artifact.ActiveProjectArtifact;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.reporting.MavenReport;
@ -259,30 +258,7 @@ protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject p
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, ArtifactNotFoundException
{
// TODO: share with MMS? Not sure if it belongs here
if ( project.getProjectReferences() != null && !project.getProjectReferences().isEmpty() )
{
// TODO: use MavenProject getProjectReferenceId
String refId = plugin.getGroupId() + ":" + plugin.getArtifactId();
MavenProject ref = (MavenProject) project.getProjectReferences().get( refId );
if ( ref != null && ref.getArtifact() != null )
{
// TODO: if not matching, we should get the correct artifact from that project (attached)
if ( ref.getArtifact().getDependencyConflictId().equals( pluginArtifact.getDependencyConflictId() ) )
{
// if the project artifact doesn't exist, don't use it. We haven't built that far.
if ( ref.getArtifact().getFile() != null && ref.getArtifact().getFile().exists() )
{
pluginArtifact = new ActiveProjectArtifact( ref, pluginArtifact );
}
else
{
getLogger().warn( "Plugin found in the reactor has not been built when it's use was attempted" +
" - resolving from the repository instead" );
}
}
}
}
pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
artifactResolver.resolve( pluginArtifact, project.getPluginArtifactRepositories(), localRepository );
@ -318,7 +294,7 @@ protected void addPlugin( Plugin plugin, Artifact pluginArtifact, MavenProject p
try
{
Set artifacts = MavenMetadataSource.createArtifacts( artifactFactory, plugin.getDependencies(), null, null,
project.getProjectReferences() );
project );
addedPlugin.setIntroducedDependencyArtifacts( artifacts );
}
catch ( InvalidVersionSpecificationException e )
@ -630,6 +606,8 @@ private void ensurePluginContainerIsComplete( PluginDescriptor pluginDescriptor,
if ( !artifact.equals( pluginArtifact ) )
{
artifact = project.replaceWithActiveArtifact( artifact );
pluginContainer.addJarResource( artifact.getFile() );
}
}

View File

@ -45,6 +45,7 @@
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.artifact.ActiveProjectArtifact;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.overlay.BuildOverlay;
import org.codehaus.plexus.util.xml.Xpp3Dom;
@ -1408,7 +1409,7 @@ public Set createArtifacts( ArtifactFactory artifactFactory, String inheritedSco
throws InvalidVersionSpecificationException
{
return MavenMetadataSource.createArtifacts( artifactFactory, getDependencies(), inheritedScope,
dependencyFilter, projectReferences );
dependencyFilter, this );
}
public void addProjectReference( MavenProject project )
@ -1454,4 +1455,34 @@ public String getDefaultGoal()
{
return getBuild() != null ? getBuild().getDefaultGoal() : null;
}
public Artifact replaceWithActiveArtifact( Artifact pluginArtifact )
{
if ( getProjectReferences() != null && !getProjectReferences().isEmpty() )
{
// TODO: use MavenProject getProjectReferenceId
String refId = pluginArtifact.getGroupId() + ":" + pluginArtifact.getArtifactId();
MavenProject ref = (MavenProject) getProjectReferences().get( refId );
if ( ref != null && ref.getArtifact() != null )
{
// TODO: if not matching, we should get the correct artifact from that project (attached)
if ( ref.getArtifact().getDependencyConflictId().equals( pluginArtifact.getDependencyConflictId() ) )
{
// if the project artifact doesn't exist, don't use it. We haven't built that far.
if ( ref.getArtifact().getFile() != null && ref.getArtifact().getFile().exists() )
{
pluginArtifact = new ActiveProjectArtifact( ref, pluginArtifact );
}
else
{
/* TODO...
logger.warn( "Artifact found in the reactor has not been built when it's use was " +
"attempted - resolving from the repository instead" );
*/
}
}
}
}
return pluginArtifact;
}
}

View File

@ -18,7 +18,6 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
@ -57,7 +56,6 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@ -259,7 +257,7 @@ private List aggregateRepositoryLists( List remoteRepositories, List remoteArtif
}
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,
ArtifactFilter dependencyFilter, Map projectReferences )
ArtifactFilter dependencyFilter, MavenProject project )
throws InvalidVersionSpecificationException
{
Set projectArtifacts = new HashSet( dependencies.size() );
@ -315,20 +313,9 @@ public static Set createArtifacts( ArtifactFactory artifactFactory, List depende
artifact.setDependencyFilter( dependencyFilter );
if ( projectReferences != null )
if ( project != null )
{
// TODO: use MavenProject getProjectReferenceId
String refId = d.getGroupId() + ":" + d.getArtifactId();
MavenProject project = (MavenProject) projectReferences.get( refId );
if ( project != null && project.getArtifact() != null )
{
// TODO: if not matching, we should get the correct artifact from that project (attached)
if ( project.getArtifact().getDependencyConflictId().equals(
artifact.getDependencyConflictId() ) )
{
artifact = new ActiveProjectArtifact( project, artifact );
}
}
artifact = project.replaceWithActiveArtifact( artifact );
}
projectArtifacts.add( artifact );
@ -365,21 +352,6 @@ public List retrieveAvailableVersions( Artifact artifact, ArtifactRepository loc
return versions;
}
private Metadata loadMetadata( ArtifactMetadata repoMetadata, ArtifactRepository remoteRepository,
ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
File metadataFile = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
Metadata metadata = null;
if ( metadataFile.exists() )
{
metadata = readMetadata( metadataFile );
}
return metadata;
}
/**
* @todo share with DefaultPluginMappingManager.
*/