diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java index 9a0755bd1b..1aa006cd10 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java @@ -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 ); diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java index 135498494b..ad4669311d 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java @@ -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 ) diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml index 9c1516be31..b3bcec6b45 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -189,14 +189,13 @@ - plugin:validatePom plugin:descriptor resources:resources compiler:compile resources:testResources compiler:testCompile surefire:test - jar:jar,plugin:generateUpdatedMapping,plugin:addPluginArtifactMetadata + jar:jar,plugin:addPluginArtifactMetadata install:install,plugin:installMapping deploy:deploy,plugin:deployMapping diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/ValidatePluginPomMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/ValidatePluginPomMojo.java deleted file mode 100644 index 41b9203827..0000000000 --- a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/ValidatePluginPomMojo.java +++ /dev/null @@ -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 that matches " + - "the id of the repository specified in : \'" - + distributionRepositoryId + "\'." ); - - throw new MojoExecutionException( message.toString() ); - } - } - -} diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java index f8e238a67f..c82b2a3513 100644 --- a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java +++ b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/AddPluginArtifactMetadataMojo.java @@ -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() ); diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/GenerateUpdatedMappingMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/GenerateUpdatedMappingMojo.java deleted file mode 100644 index 36ddfd2f51..0000000000 --- a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/GenerateUpdatedMappingMojo.java +++ /dev/null @@ -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; - } - - } -} diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingDeployMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingDeployMojo.java index 5d2530af99..9b400a13c0 100644 --- a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingDeployMojo.java +++ b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingDeployMojo.java @@ -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 section with a valid 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 ); } } diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingInstallMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingInstallMojo.java index 87defdd5dc..b037cbf354 100644 --- a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingInstallMojo.java +++ b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingInstallMojo.java @@ -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 ) {