o adding PomMetadataSource for the changes to maven-artifact

o adding in all the artifact handlers here as they are Maven specific and don't belong in maven-artifact


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@593857 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-11-11 08:10:35 +00:00
parent 7946e31f40
commit 1a286e2325
5 changed files with 385 additions and 6 deletions

View File

@ -17,7 +17,7 @@
aspectj.version=1.5.3
classworlds.version=1.2-alpha-10
plexus.version=1.0-alpha-38
plexus.version=1.0-alpha-39
plexus-utils.version=1.4.5
maven-artifact.version=3.0-SNAPSHOT
commons-cli.version=1.0

View File

@ -19,6 +19,167 @@ under the License.
<component-set>
<components>
<!--
| These are the artifacts handlers that were previously in maven-artifact and they don't belong there as these
| are Maven specific artifact handlers. We need to put these into their respective plugins and make this fully dynamic. jvz.
-->
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ejb</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>ejb</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>jar</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>jar</type>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>test-jar</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<classifier>tests</classifier>
<extension>jar</extension>
<type>test-jar</type>
<packaging>jar</packaging>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>maven-plugin</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>maven-plugin</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>pom</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>pom</type>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>java-source</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<classifier>sources</classifier>
<type>java-source</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>false</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>javadoc</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<classifier>javadoc</classifier>
<type>javadoc</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>war</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>war</type>
<includesDependencies>true</includesDependencies>
<language>java</language>
<addedToClasspath>false</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ear</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>ear</type>
<includesDependencies>true</includesDependencies>
<language>java</language>
<addedToClasspath>false</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ejb-client</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>ejb-client</type>
<extension>jar</extension>
<packaging>ejb</packaging>
<classifier>client</classifier>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>rar</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>rar</type>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>par</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>par</type>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ejb3</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>ejb3</type>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.extension.BuildExtensionScanner</role>
<role-hint>default</role-hint>

View File

@ -0,0 +1,206 @@
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.
*/
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.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.resolver.metadata.ArtifactMetadata;
import org.apache.maven.artifact.resolver.metadata.MetadataResolution;
import org.apache.maven.artifact.resolver.metadata.MetadataRetrievalException;
import org.apache.maven.artifact.resolver.metadata.MetadataSource;
import org.apache.maven.context.BuildContextManager;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.InvalidProjectModelException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.build.ProjectBuildCache;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* @author Jason van Zyl
* @version $Id$
*/
public class PomMetadataSource
extends AbstractLogEnabled
implements MetadataSource, Contextualizable
{
public static final String ROLE_HINT = "default";
private MavenProjectBuilder mavenProjectBuilder;
private ArtifactFactory artifactFactory;
private BuildContextManager buildContextManager;
// lazily instantiated and cached.
private MavenProject superProject;
private PlexusContainer container;
/** Unfortunately we have projects that are still sending us JARs without the accompanying POMs. */
private boolean strictlyEnforceThePresenceOfAValidMavenPOM = true;
public MetadataResolution retrieve( ArtifactMetadata artifactMetadata,
ArtifactRepository localRepository,
List remoteRepositories )
throws MetadataRetrievalException
{
try
{
loadProjectBuilder();
}
catch ( ComponentLookupException e )
{
throw new MetadataRetrievalException(
"Cannot lookup MavenProjectBuilder component instance: " + e.getMessage(), e );
}
ProjectBuildCache cache = ProjectBuildCache.read( buildContextManager );
MavenProject project;
Artifact pomArtifact = artifactFactory.createProjectArtifact( artifactMetadata.getGroupId(), artifactMetadata.getArtifactId(),
artifactMetadata.getVersion(), artifactMetadata.getScope() );
project = cache.getCachedProject( artifactMetadata.getGroupId(), artifactMetadata.getArtifactId(), artifactMetadata.getVersion() );
if ( project == null )
{
try
{
project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
}
catch ( InvalidProjectModelException e )
{
// We want to capture this in the graph so that we can display the error to the user
}
catch ( ProjectBuildingException e )
{
if ( strictlyEnforceThePresenceOfAValidMavenPOM )
{
throw new MetadataRetrievalException(
"Unable to read the metadata file for artifactMetadata '" +
artifactMetadata.getDependencyConflictId() + "': " + e.getMessage(), e, artifactMetadata );
}
}
}
Set artifacts = new HashSet();
for ( Iterator i = project.getDependencies().iterator(); i.hasNext(); )
{
Dependency d = (Dependency) i.next();
artifacts.add( new ArtifactMetadata( d.getGroupId(), d.getArtifactId(), d.getVersion() ) );
}
// The remote repositories is intentially null here while working in the graph in the least invasive way
// and making sure repositories added for a POM are scope only for a particular POM. We don't want
// repositories lingering around or being aggregated after they are used. jvz
return new MetadataResolution( artifacts, null );
}
private void loadProjectBuilder()
throws ComponentLookupException
{
if ( mavenProjectBuilder == null )
{
mavenProjectBuilder = (MavenProjectBuilder) container.lookup( MavenProjectBuilder.class );
}
}
private List aggregateRepositoryLists( List remoteRepositories,
List remoteArtifactRepositories )
throws ArtifactMetadataRetrievalException
{
if ( superProject == null )
{
try
{
superProject = mavenProjectBuilder.buildStandaloneSuperProject();
}
catch ( ProjectBuildingException e )
{
throw new ArtifactMetadataRetrievalException(
"Unable to parse the Maven built-in model: " + e.getMessage(), e );
}
}
List repositories = new ArrayList();
repositories.addAll( remoteRepositories );
// ensure that these are defined
for ( Iterator it = superProject.getRemoteArtifactRepositories().iterator(); it.hasNext(); )
{
ArtifactRepository superRepo = (ArtifactRepository) it.next();
for ( Iterator aggregatedIterator = repositories.iterator(); aggregatedIterator.hasNext(); )
{
ArtifactRepository repo = (ArtifactRepository) aggregatedIterator.next();
// if the repository exists in the list and was introduced by another POM's super-pom,
// remove it...the repository definitions from the super-POM should only be at the end of
// the list.
// if the repository has been redefined, leave it.
if ( repo.getId().equals( superRepo.getId() ) && repo.getUrl().equals( superRepo.getUrl() ) )
{
aggregatedIterator.remove();
}
}
}
// this list should contain the super-POM repositories, so we don't have to explicitly add them back.
for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) it.next();
if ( !repositories.contains( repository ) )
{
repositories.add( repository );
}
}
return repositories;
}
public void contextualize( Context context )
throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
}

View File

@ -69,9 +69,6 @@ under the License.
</requirements>
</component>
<component>
<role>org.apache.maven.project.build.model.ModelLineageBuilder</role>
<role-hint>default</role-hint>
@ -346,6 +343,21 @@ under the License.
</requirements>
</component>
<component>
<role>org.apache.maven.artifact.resolver.metadata.MetadataSource</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.project.artifact.PomMetadataSource</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement>
<requirement>
<role>org.apache.maven.context.BuildContextManager</role>
<role-hint>default</role-hint>
</requirement>
</requirements>
</component>
<component>
<role>org.apache.maven.MavenTools</role>
<implementation>org.apache.maven.DefaultMavenTools</implementation>

View File

@ -153,7 +153,7 @@ under the License.
<module>maven-embedder</module>
</modules>
<properties>
<plexusVersion>1.0-alpha-38</plexusVersion>
<plexusVersion>1.0-alpha-39</plexusVersion>
<wagonVersion>1.0-beta-2</wagonVersion>
</properties>
<dependencies>
@ -294,4 +294,4 @@ under the License.
</modules>
</profile>
</profiles>
</project>
</project>