PR: MNG-598

allow type handlers to be specified by plugin extensions



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225477 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-27 08:03:33 +00:00
parent fc1cbaeb1e
commit 826413b74a
13 changed files with 126 additions and 26 deletions

View File

@ -39,6 +39,7 @@ public class DefaultArtifactDeployer
private List artifactTransformations;
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
public void deploy( String basedir, String finalName, Artifact artifact, ArtifactRepository deploymentRepository,
ArtifactRepository localRepository )
throws ArtifactDeploymentException

View File

@ -35,13 +35,12 @@ public class DefaultArtifactInstaller
{
private List artifactTransformations;
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
throws ArtifactInstallationException
{
File source = null;
String extension = artifact.getArtifactHandler().getExtension();
source = new File( basedir, finalName + "." + extension );
File source = new File( basedir, finalName + "." + extension );
install( source, artifact, localRepository );
}

View File

@ -18,6 +18,8 @@ package org.apache.maven.artifact.handler.manager;
import org.apache.maven.artifact.handler.ArtifactHandler;
import java.util.Map;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
@ -27,4 +29,6 @@ public interface ArtifactHandlerManager
String ROLE = ArtifactHandlerManager.class.getName();
ArtifactHandler getArtifactHandler( String type );
void addHandlers( Map handlers );
}

View File

@ -44,6 +44,11 @@ public class DefaultArtifactHandlerManager
return handler;
}
public void addHandlers( Map handlers )
{
artifactHandlers.putAll( handlers );
}
public Set getHandlerTypes()
{
return artifactHandlers.keySet();

View File

@ -247,6 +247,12 @@ public class Verifier
{
ext = "jar";
}
String classifier = null;
if ( "coreit-artifact".equals( a[3] ) )
{
ext = "jar";
classifier = "it";
}
String repositoryPath;
if ( "legacy".equals( localRepoLayout ) )
@ -260,7 +266,12 @@ public class Verifier
// {
repositoryPath = repositoryPath + "/" + a[1] + "/" + a[2];
// }
repositoryPath = repositoryPath + "/" + a[1] + "-" + a[2] + "." + ext;
repositoryPath = repositoryPath + "/" + a[1] + "-" + a[2];
if ( classifier != null )
{
repositoryPath = repositoryPath + "-" + classifier;
}
repositoryPath = repositoryPath + "." + ext;
}
else
{

View File

@ -1,4 +1,4 @@
#it0041
it0041
it0040
it0039
it0038

View File

@ -1 +1,2 @@
target/maven-core-it0036-1.0.jar
target/maven-core-it0041-1.0-SNAPSHOT.jar
${artifact:org.apache.maven:maven-core-it-support:1.2:coreit-artifact}

View File

@ -18,6 +18,8 @@ package org.apache.maven.lifecycle;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.extension.ExtensionManager;
@ -84,6 +86,8 @@ public class DefaultLifecycleExecutor
private Map defaultPhases;
private ArtifactHandlerManager artifactHandlerManager;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
@ -111,6 +115,9 @@ public class DefaultLifecycleExecutor
extensionManager.addExtension( extension, project, session.getLocalRepository() );
}
Map handlers = findArtifactTypeHandlers( project, session.getSettings(), session.getLocalRepository() );
artifactHandlerManager.addHandlers( handlers );
for ( Iterator i = tasks.iterator(); i.hasNext(); )
{
String task = (String) i.next();
@ -129,6 +136,14 @@ public class DefaultLifecycleExecutor
{
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
}
catch ( PluginManagerException e )
{
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
}
catch ( PluginVersionResolutionException e )
{
throw new LifecycleExecutionException( "Unable to initialise extensions", e );
}
finally
{
response.setFinish( new Date() );
@ -366,6 +381,37 @@ public class DefaultLifecycleExecutor
return null;
}
/**
* @todo Not particularly happy about this. Would like WagonManager and ArtifactTypeHandlerManager to be able to
* lookup directly, or have them passed in
*/
private Map findArtifactTypeHandlers( MavenProject project, Settings settings, ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException
{
Map map = new HashMap();
for ( Iterator i = project.getBuildPlugins().iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
if ( plugin.isExtensions() )
{
pluginManager.verifyPlugin( plugin, project, settings, localRepository );
// TODO: if moved to the plugin manager we already have the descriptor from above and so do can lookup the container directly
try
{
Map components = pluginManager.getPluginComponents( plugin, ArtifactHandler.ROLE );
map.putAll( components );
}
catch ( ComponentLookupException e )
{
getLogger().debug( "Unable to find the lifecycle component in the extension", e );
}
}
}
return map;
}
/**
* Take each mojo contained with a plugin, look to see whether it contributes to a
* phase in the lifecycle and if it does place it at the end of the list of goals

View File

@ -1049,6 +1049,14 @@ public class DefaultPluginManager
// TODO: we don't need to resolve over and over again, as long as we are sure that the parameters are the same
// check this with yourkit as a hot spot.
try
{
project.setDependencyArtifacts( MavenProject.createArtifacts( artifactFactory, project.getDependencies() ) );
}
catch ( InvalidVersionSpecificationException e )
{
throw new ArtifactResolutionException( "Error in dependency version", e );
}
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
artifact, context.getLocalRepository(),
project.getRemoteArtifactRepositories(),
@ -1085,6 +1093,16 @@ public class DefaultPluginManager
return pluginContainer.lookup( role, roleHint );
}
public Map getPluginComponents( Plugin plugin, String role )
throws ComponentLookupException, PluginManagerException
{
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
PlexusContainer pluginContainer = getPluginContainer( pluginDescriptor );
return pluginContainer.lookupMap( role );
}
private PluginMappingManager getPluginMappingManager( MavenSession session, MavenProject project )
throws PluginManagerException
{

View File

@ -29,6 +29,7 @@ import org.apache.maven.model.ReportSet;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.List;
import java.util.Map;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -44,11 +45,11 @@ public interface PluginManager
PluginDescriptor getPluginDescriptorForPrefix( String prefix )
throws PluginManagerException;
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project )
throws PluginManagerException;
PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings,
ArtifactRepository localRepository )
ArtifactRepository localRepository )
throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException;
List getReports( ReportPlugin reportPlugin, ReportSet reportSet, MavenProject project, MavenSession session )
@ -57,4 +58,7 @@ public interface PluginManager
Object getPluginComponent( Plugin plugin, String role, String roleHint )
throws ComponentLookupException, PluginManagerException;
Map getPluginComponents( Plugin plugin, String role )
throws ComponentLookupException, PluginManagerException;
}

View File

@ -139,6 +139,9 @@
<requirement>
<role>org.apache.maven.plugin.mapping.MavenPluginMappingBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.handler.manager.ArtifactHandlerManager</role>
</requirement>
</requirements>
<configuration>
<!-- START SNIPPET: lifecyle -->

View File

@ -38,7 +38,6 @@ 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.activation.ProfileActivationCalculator;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector;
import org.apache.maven.project.interpolation.ModelInterpolationException;
@ -149,7 +148,15 @@ public class DefaultMavenProjectBuilder
Map managedVersions = createManagedVersionMap( project.getDependencyManagement() );
ensureMetadataSourceIsInitialized();
try
{
project.setDependencyArtifacts( MavenProject.createArtifacts( artifactFactory, project.getDependencies() ) );
}
catch ( InvalidVersionSpecificationException e )
{
throw new ProjectBuildingException( "Error in dependency version", e );
}
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getDependencyArtifacts(),
projectArtifact, managedVersions,
localRepository,
@ -467,7 +474,6 @@ public class DefaultMavenProjectBuilder
}
project.setRemoteArtifactRepositories( remoteRepositories );
project.setDependencyArtifacts( createArtifacts( project.getDependencies() ) );
project.setPluginArtifacts( createPluginArtifacts( project.getBuildPlugins() ) );
return project;
@ -658,19 +664,6 @@ public class DefaultMavenProjectBuilder
return groupId + ":" + artifactId + ":" + version;
}
protected Set createArtifacts( List dependencies )
throws ProjectBuildingException
{
try
{
return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
}
catch ( InvalidVersionSpecificationException e )
{
throw new ProjectBuildingException( "Unable to parse dependency version", e );
}
}
protected Set createPluginArtifacts( List plugins )
throws ProjectBuildingException
{

View File

@ -19,6 +19,8 @@ package org.apache.maven.project;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
@ -42,6 +44,7 @@ import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Scm;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
@ -134,7 +137,10 @@ public class MavenProject
this.file = project.file;
// don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be sure!
this.dependencyArtifacts = Collections.unmodifiableSet( project.dependencyArtifacts );
if ( project.dependencyArtifacts != null )
{
this.dependencyArtifacts = Collections.unmodifiableSet( project.dependencyArtifacts );
}
if ( project.artifacts != null )
{
this.artifacts = Collections.unmodifiableSet( project.artifacts );
@ -1204,4 +1210,13 @@ public class MavenProject
return build.getExtensions();
}
}
/**
* @todo the lazy initialisation of this makes me uneasy.
*/
public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies )
throws InvalidVersionSpecificationException
{
return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, null, null );
}
}