Removing leftover lifecycle binding for ValidatePomMojo in the maven-plugin-plugin (removed that last night).

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219716 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-07-19 17:15:41 +00:00
parent 4e9bd7a8e9
commit 76d971b4ba
8 changed files with 27 additions and 499 deletions

View File

@ -116,7 +116,7 @@ public class DefaultRepositoryMetadataManager
}
public void install( RepositoryMetadata metadata, ArtifactRepository local, String remoteRepositoryId )
public void install( RepositoryMetadata metadata, ArtifactRepository local )
throws RepositoryMetadataManagementException
{
File metadataFile = constructLocalRepositoryFile( metadata, local );

View File

@ -14,7 +14,7 @@ public interface RepositoryMetadataManager
void deploy( RepositoryMetadata repositoryMetadata, ArtifactRepository remote )
throws RepositoryMetadataManagementException;
void install( RepositoryMetadata repositoryMetadata, ArtifactRepository local, String remoteRepositoryId )
void install( RepositoryMetadata repositoryMetadata, ArtifactRepository local )
throws RepositoryMetadataManagementException;
void purgeLocalCopy( RepositoryMetadata repositoryMetadata, ArtifactRepository local )

View File

@ -189,14 +189,13 @@
<configuration>
<!-- START SNIPPET: maven-plugin-lifecycle -->
<phases>
<validate>plugin:validatePom</validate>
<generate-resources>plugin:descriptor</generate-resources>
<process-resources>resources:resources</process-resources>
<compile>compiler:compile</compile>
<process-test-resources>resources:testResources</process-test-resources>
<test-compile>compiler:testCompile</test-compile>
<test>surefire:test</test>
<package>jar:jar,plugin:generateUpdatedMapping,plugin:addPluginArtifactMetadata</package>
<package>jar:jar,plugin:addPluginArtifactMetadata</package>
<install>install:install,plugin:installMapping</install>
<deploy>deploy:deploy,plugin:deployMapping</deploy>
</phases>

View File

@ -1,65 +0,0 @@
package org.apache.maven.plugin.plugin;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import java.util.Iterator;
import java.util.List;
/**
* @phase validate
* @goal validatePom
*/
public class ValidatePluginPomMojo
extends AbstractMojo
{
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
public void execute()
throws MojoExecutionException
{
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
if ( distributionRepository == null )
{
throw new MojoExecutionException(
"You must provide a distributionManagement section with a repository element in your POM." );
}
String distributionRepositoryId = distributionRepository.getId();
List remoteArtifactRepositories = project.getRemoteArtifactRepositories();
ArtifactRepository remote = null;
for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); )
{
ArtifactRepository remoteRepository = (ArtifactRepository) it.next();
if ( distributionRepositoryId.equals( remoteRepository.getId() ) )
{
remote = remoteRepository;
break;
}
}
if ( remote == null )
{
StringBuffer message = new StringBuffer();
message.append( "You must provide a artifact repository definition in <repositories/> that matches " +
"the id of the repository specified in <distributionManagement/>: \'"
+ distributionRepositoryId + "\'." );
throw new MojoExecutionException( message.toString() );
}
}
}

View File

@ -4,6 +4,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.LatestArtifactMetadata;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
/** Inject any plugin-specific artifact metadata to the project's artifact, for subsequent installation
* and deployment. The first use-case for this is to add the LATEST metadata (which is plugin-specific)
@ -18,15 +19,17 @@ public class AddPluginArtifactMetadataMojo
/** The project artifact, which should have the LATEST metadata added to it.
*
* @parameter expression="${project.artifact}"
* @parameter expression="${project}"
* @required
* @readonly
*/
private Artifact projectArtifact;
private MavenProject project;
public void execute()
throws MojoExecutionException
{
Artifact projectArtifact = project.getArtifact();
LatestArtifactMetadata metadata = new LatestArtifactMetadata( projectArtifact );
metadata.setVersion( projectArtifact.getVersion() );

View File

@ -1,340 +0,0 @@
package org.apache.maven.plugin.plugin.metadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.mapping.MappedPlugin;
import org.apache.maven.plugin.mapping.PluginMap;
import org.apache.maven.plugin.mapping.io.xpp3.PluginMappingXpp3Reader;
import org.apache.maven.plugin.mapping.io.xpp3.PluginMappingXpp3Writer;
import org.apache.maven.plugin.mapping.metadata.PluginMappingMetadata;
import org.apache.maven.project.MavenProject;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.classworlds.DuplicateRealmException;
import org.codehaus.plexus.component.discovery.ComponentDiscoverer;
import org.codehaus.plexus.component.discovery.ComponentDiscovererManager;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
import org.codehaus.plexus.component.discovery.DefaultComponentDiscoverer;
import org.codehaus.plexus.component.discovery.PlexusXmlComponentDiscoverer;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.DefaultContext;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @phase package
* @goal generateUpdatedMapping
*/
public class GenerateUpdatedMappingMojo
extends AbstractMojo
{
/**
* @parameter
*/
private String goalPrefix;
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter expression="${project.build.directory}/repository-metadata"
* @required
* @readonly
*/
private String metadataDirectory;
/**
* @parameter expression="${project.build.outputDirectory}"
* @required
* @readonly
*/
private String classesDirectory;
/**
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
* @required
* @readonly
*/
private RepositoryMetadataManager repositoryMetadataManager;
/**
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
private ArtifactRepository localRepository;
public void execute()
throws MojoExecutionException
{
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
String distributionRepositoryId = distributionRepository.getId();
List remoteArtifactRepositories = project.getRemoteArtifactRepositories();
ArtifactRepository readRemoteRepository = null;
for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); )
{
ArtifactRepository currentRepository = (ArtifactRepository) it.next();
if ( distributionRepositoryId.equals( currentRepository.getId() ) )
{
readRemoteRepository = currentRepository;
break;
}
}
PluginMappingXpp3Reader mappingReader = new PluginMappingXpp3Reader();
PluginMap pluginMap = null;
RepositoryMetadata metadata = new PluginMappingMetadata( project.getGroupId() );
try
{
repositoryMetadataManager.resolve( metadata, readRemoteRepository, localRepository );
Reader reader = null;
File metadataFile = metadata.getFile();
try
{
reader = new FileReader( metadataFile );
pluginMap = mappingReader.read( reader );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot read plugin-mapping metadata from file: " + metadataFile, e );
}
catch ( XmlPullParserException e )
{
throw new MojoExecutionException( "Cannot parse plugin-mapping metadata from file: " + metadataFile, e );
}
finally
{
IOUtil.close( reader );
}
}
catch ( RepositoryMetadataManagementException e )
{
Throwable cause = e.getCause();
if ( cause != null && ( cause instanceof ResourceDoesNotExistException ) )
{
getLog().info( "Cannot find " + metadata + " on remote repository. Creating a new one." );
getLog().debug( "Metadata " + metadata + " cannot be resolved.", e );
pluginMap = new PluginMap();
pluginMap.setGroupId( project.getGroupId() );
}
else
{
throw new MojoExecutionException( "Failed to resolve " + metadata, e );
}
}
for ( Iterator it = pluginMap.getPlugins().iterator(); it.hasNext(); )
{
MappedPlugin preExisting = (MappedPlugin) it.next();
if ( preExisting.getArtifactId().equals( project.getArtifactId() ) )
{
getLog().info( "Updating pre-existing plugin-mapping metadata." );
pluginMap.removePlugin( preExisting );
break;
}
}
MappedPlugin mappedPlugin = new MappedPlugin();
mappedPlugin.setArtifactId( project.getArtifactId() );
mappedPlugin.setPrefix( getGoalPrefix() );
mappedPlugin.setPackagingHandlers( extractPackagingHandlers() );
pluginMap.addPlugin( mappedPlugin );
Writer writer = null;
try
{
File updatedMetadataFile = new File( metadataDirectory, metadata.getRepositoryPath() ).getAbsoluteFile();
File dir = updatedMetadataFile.getParentFile();
if ( !dir.exists() )
{
dir.mkdirs();
}
writer = new FileWriter( updatedMetadataFile );
PluginMappingXpp3Writer mappingWriter = new PluginMappingXpp3Writer();
mappingWriter.write( writer, pluginMap );
metadata.setFile( updatedMetadataFile );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error writing repository metadata to build directory.", e );
}
finally
{
IOUtil.close( writer );
}
}
private List extractPackagingHandlers()
throws MojoExecutionException
{
List packagingHandlers = new ArrayList();
Context ctx = new DefaultContext();
ClassWorld discoveryWorld = new ClassWorld();
try
{
ClassRealm discoveryRealm = discoveryWorld.newRealm( "packageHandler-discovery" );
File classDir = new File( classesDirectory ).getAbsoluteFile();
discoveryRealm.addConstituent( classDir.toURL() );
packagingHandlers
.addAll( discoverLifecycleMappings( ctx, discoveryRealm, new DefaultComponentDiscoverer() ) );
packagingHandlers.addAll( discoverLifecycleMappings( ctx, discoveryRealm,
new PlexusXmlComponentDiscoverer() ) );
}
catch ( DuplicateRealmException e )
{
throw new MojoExecutionException( "Error constructing class-realm for lifecycle-mapping detection.", e );
}
catch ( MalformedURLException e )
{
throw new MojoExecutionException( "Error constructing class-realm for lifecycle-mapping detection.", e );
}
catch ( PlexusConfigurationException e )
{
throw new MojoExecutionException( "Error detecting lifecycle-mappings.", e );
}
return packagingHandlers;
}
private List discoverLifecycleMappings( Context ctx, ClassRealm discoveryRealm, ComponentDiscoverer discoverer )
throws PlexusConfigurationException
{
discoverer.setManager( new DummyComponentDiscovererManager() );
List packagingHandlers = new ArrayList();
List componentSetDescriptors = discoverer.findComponents( ctx, discoveryRealm );
if ( componentSetDescriptors != null )
{
for ( Iterator it = componentSetDescriptors.iterator(); it.hasNext(); )
{
ComponentSetDescriptor setDescriptor = (ComponentSetDescriptor) it.next();
List components = setDescriptor.getComponents();
if ( components != null )
{
for ( Iterator componentIterator = components.iterator(); componentIterator.hasNext(); )
{
ComponentDescriptor descriptor = (ComponentDescriptor) componentIterator.next();
if ( LifecycleMapping.ROLE.equals( descriptor.getRole() ) )
{
packagingHandlers.add( descriptor.getRoleHint() );
}
}
}
}
}
return packagingHandlers;
}
private String getGoalPrefix()
{
if ( goalPrefix == null )
{
goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
}
return goalPrefix;
}
public static class DummyComponentDiscovererManager implements ComponentDiscovererManager
{
DummyComponentDiscovererManager()
{
}
public List getComponentDiscoverers()
{
return null;
}
public void registerComponentDiscoveryListener( ComponentDiscoveryListener listener )
{
}
public void removeComponentDiscoveryListener( ComponentDiscoveryListener listener )
{
}
public void fireComponentDiscoveryEvent( ComponentDiscoveryEvent event )
{
}
public void initialize()
{
}
public List getListenerDescriptors()
{
return null;
}
}
}

View File

@ -19,66 +19,40 @@ package org.apache.maven.plugin.plugin.metadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.mapping.metadata.PluginMappingMetadata;
import org.apache.maven.project.MavenProject;
import java.io.File;
/**
* @goal deployMapping
* @phase deploy
*/
public class PluginMappingDeployMojo
extends AbstractMojo
extends AbstractPluginMappingMojo
{
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
* @required
* @readonly
*/
private RepositoryMetadataManager repositoryMetadataManager;
/**
* @parameter expression="${project.build.directory}/repository-metadata"
* @required
* @readonly
*/
private String outputDirectory;
public void execute()
throws MojoExecutionException
{
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
RepositoryMetadata metadata = new PluginMappingMetadata( getProject().getGroupId() );
RepositoryMetadata metadata = new PluginMappingMetadata( project.getGroupId() );
File updatedMetadataFile = new File( outputDirectory, metadata.getRepositoryPath() ).getAbsoluteFile();
ArtifactRepository distributionRepository = getProject().getDistributionManagementArtifactRepository();
if ( !updatedMetadataFile.exists() )
if ( distributionRepository == null )
{
throw new MojoExecutionException( "Cannot find updated " + metadata + " in file: \'" + updatedMetadataFile + "\'. This seems to indicate that the 'package' lifecycle phase didn't succeed." );
throw new MojoExecutionException( "No distribution repository specified. You must specify a <distributionManagement/> section with a valid <repository/> specified within." );
}
metadata.setFile( updatedMetadataFile );
try
{
repositoryMetadataManager.deploy( metadata, distributionRepository );
getRepositoryMetadataManager().resolve( metadata, distributionRepository, getLocalRepository() );
updatePluginMap( metadata );
getRepositoryMetadataManager().deploy( metadata, distributionRepository );
}
catch ( RepositoryMetadataManagementException e )
{
throw new MojoExecutionException( "Error updating plugin-mapping metadata.", e );
throw new MojoExecutionException( "Failed to install " + metadata, e );
}
}

View File

@ -1,73 +1,30 @@
package org.apache.maven.plugin.plugin.metadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.mapping.metadata.PluginMappingMetadata;
import org.apache.maven.project.MavenProject;
import java.io.File;
/**
* @goal installMapping
* @phase install
*/
public class PluginMappingInstallMojo
extends AbstractMojo
extends AbstractPluginMappingMojo
{
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
* @required
* @readonly
*/
private RepositoryMetadataManager repositoryMetadataManager;
/**
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
private ArtifactRepository localRepository;
/**
* @parameter expression="${project.build.directory}/repository-metadata"
* @required
* @readonly
*/
private String outputDirectory;
public void execute()
throws MojoExecutionException
{
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
String remoteRepositoryId = distributionRepository.getId();
RepositoryMetadata metadata = new PluginMappingMetadata( project.getGroupId() );
File updatedMetadataFile = new File( outputDirectory, metadata.getRepositoryPath() ).getAbsoluteFile();
if ( !updatedMetadataFile.exists() )
{
throw new MojoExecutionException( "Cannot find updated " + metadata + " in file: \'" + updatedMetadataFile + "\'. This seems to indicate that the 'package' lifecycle phase didn't succeed." );
}
metadata.setFile( updatedMetadataFile );
RepositoryMetadata metadata = new PluginMappingMetadata( getProject().getGroupId() );
try
{
repositoryMetadataManager.install( metadata, localRepository, remoteRepositoryId );
getRepositoryMetadataManager().resolveLocally( metadata, getLocalRepository() );
updatePluginMap( metadata );
getRepositoryMetadataManager().install( metadata, getLocalRepository() );
}
catch ( RepositoryMetadataManagementException e )
{