mirror of https://github.com/apache/maven.git
Working on: MNG-576
o Implemented plan from my comments on MNG-576 for looking up lifecycle mappings within plugins. o Fixed subtle bug in DefaultWagonManager for verifying checksums, where the destination file was being used to verify the checksum rather than the recently download temp destination. o Fixed the DefaultRepositoryMetadataManager.resolve(..) method to allow the locally-installed metadata to be used if it is newer than the one resolved from the repository. o Moved the lifecycle mappings for the EJB and WAR plugins out to META-INF/plexus/components.xml in the respective plugin's src/main/resources directory. it0016 and it0017 still pass. o Changed the distributionManagement repository for maven-plugins/pom.xml to have id of 'central-plugins' and then added a normal artifact repository definition for central-plugins to that pom, to allow locally-installed repository metadata for the plugins to be put in the right place (and these builds should have access to the central plugin repo anyway). o Changed the DefaultPluginMappingBuilder to only warn when plugins.xml for a particular plugin group is missing. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@216273 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1404266309
commit
0cc696a407
|
@ -337,7 +337,7 @@ public class DefaultWagonManager
|
|||
// try to verify the SHA-1 checksum for this file.
|
||||
try
|
||||
{
|
||||
verifyChecksum( sha1ChecksumObserver, destination, remotePath, ".sha1", wagon );
|
||||
verifyChecksum( sha1ChecksumObserver, temp, remotePath, ".sha1", wagon );
|
||||
}
|
||||
catch ( WagonException sha1TryException )
|
||||
{
|
||||
|
@ -364,7 +364,7 @@ public class DefaultWagonManager
|
|||
{
|
||||
try
|
||||
{
|
||||
verifyChecksum( md5ChecksumObserver, destination, remotePath, ".md5", wagon );
|
||||
verifyChecksum( md5ChecksumObserver, temp, remotePath, ".md5", wagon );
|
||||
}
|
||||
catch ( WagonException md5TryException )
|
||||
{
|
||||
|
@ -386,7 +386,7 @@ public class DefaultWagonManager
|
|||
// otherwise, this was a failed transfer, and we don't want to retry.
|
||||
else
|
||||
{
|
||||
handleChecksumFailure( repository, "Error retrieving checksum file for " + destination,
|
||||
handleChecksumFailure( repository, "Error retrieving checksum file for " + remotePath,
|
||||
md5TryException );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,12 +21,12 @@ public class DefaultRepositoryMetadataManager
|
|||
private WagonManager wagonManager;
|
||||
|
||||
// only resolve repository metadata once per session...
|
||||
private Map resolved = new HashMap();
|
||||
private Map cachedMetadata = new HashMap();
|
||||
|
||||
public void resolve( RepositoryMetadata metadata, ArtifactRepository remote, ArtifactRepository local )
|
||||
throws RepositoryMetadataManagementException
|
||||
{
|
||||
File metadataFile = (File) resolved.get( metadata.getRepositoryPath() );
|
||||
File metadataFile = (File) cachedMetadata.get( metadata.getRepositoryPath() );
|
||||
|
||||
if ( metadataFile == null )
|
||||
{
|
||||
|
@ -41,7 +41,38 @@ public class DefaultRepositoryMetadataManager
|
|||
{
|
||||
try
|
||||
{
|
||||
wagonManager.getRepositoryMetadata( metadata, remote, metadataFile );
|
||||
File tempMetadataFile = File.createTempFile( "plugins.xml", null );
|
||||
|
||||
try
|
||||
{
|
||||
wagonManager.getRepositoryMetadata( metadata, remote, tempMetadataFile );
|
||||
|
||||
if( !metadataFile.exists() || ( metadataFile.lastModified() <= tempMetadataFile.lastModified() ) )
|
||||
{
|
||||
if ( !tempMetadataFile.renameTo( metadataFile ) )
|
||||
{
|
||||
FileUtils.copyFile( tempMetadataFile, metadataFile );
|
||||
|
||||
tempMetadataFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
{
|
||||
if ( !metadataFile.exists() )
|
||||
{
|
||||
throw new RepositoryMetadataManagementException( metadata, "Remote repository metadata not found.",
|
||||
e );
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = "Cannot find " + metadata + " in remote repository - Using local copy.";
|
||||
|
||||
getLogger().info( message );
|
||||
|
||||
getLogger().debug( message, e );
|
||||
}
|
||||
}
|
||||
|
||||
metadata.setFile( metadataFile );
|
||||
}
|
||||
|
@ -50,10 +81,9 @@ public class DefaultRepositoryMetadataManager
|
|||
throw new RepositoryMetadataManagementException( metadata,
|
||||
"Failed to download repository metadata.", e );
|
||||
}
|
||||
catch ( ResourceDoesNotExistException e )
|
||||
catch ( IOException e )
|
||||
{
|
||||
throw new RepositoryMetadataManagementException( metadata, "Remote repository metadata not found.",
|
||||
e );
|
||||
throw new RepositoryMetadataManagementException( metadata, "Error constructing temporary metadata download file.", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -255,23 +255,11 @@ public class DefaultLifecycleExecutor
|
|||
private Map bindLifecycleForPackaging( MavenSession session, String selectedPhase, MavenProject project )
|
||||
throws ArtifactResolutionException, LifecycleExecutionException
|
||||
{
|
||||
Map mappings;
|
||||
String packaging = project.getPackaging();
|
||||
try
|
||||
{
|
||||
LifecycleMapping m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
|
||||
mappings = m.getPhases();
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
getLogger().error( "No lifecycle mapping for type '" + packaging + "': using defaults" );
|
||||
mappings = defaultPhases;
|
||||
}
|
||||
Map mappings = findMappingsForLifecycle( session, project );
|
||||
|
||||
Map lifecycleMappings = new HashMap();
|
||||
|
||||
boolean finished = false;
|
||||
for ( Iterator i = phases.iterator(); i.hasNext() && !finished; )
|
||||
for ( Iterator i = phases.iterator(); i.hasNext(); )
|
||||
{
|
||||
String phase = (String) i.next();
|
||||
|
||||
|
@ -291,13 +279,114 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( phase.equals( selectedPhase ) )
|
||||
{
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lifecycleMappings;
|
||||
}
|
||||
|
||||
private Map findMappingsForLifecycle( MavenSession session, MavenProject project )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
Map mappings;
|
||||
|
||||
String packaging = project.getPackaging();
|
||||
try
|
||||
{
|
||||
PluginMappingManager mappingManager = getPluginMappingManager( session, project );
|
||||
|
||||
Plugin pluginContainingLifecycleMapping = mappingManager.getByPackaging( packaging );
|
||||
|
||||
LifecycleMapping m = null;
|
||||
|
||||
if ( pluginContainingLifecycleMapping != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
pluginManager.verifyPlugin( pluginContainingLifecycleMapping, project, session.getSettings(), session.getLocalRepository() );
|
||||
|
||||
m = (LifecycleMapping) pluginManager.getPluginComponent( pluginContainingLifecycleMapping,
|
||||
LifecycleMapping.ROLE, packaging );
|
||||
|
||||
mappings = m.getPhases();
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Plugin: " + pluginContainingLifecycleMapping.getKey()
|
||||
+ " declares lifecycle mapping for: \'" + packaging
|
||||
+ "\', but does not appear to contain the actual mapping among its component descriptors.", e );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, packaging );
|
||||
|
||||
mappings = m.getPhases();
|
||||
}
|
||||
catch ( ComponentLookupException e )
|
||||
{
|
||||
getLogger().warn(
|
||||
"Lifecycle mappings not found for packaging: \'" + packaging
|
||||
+ "\'. Using defaults." );
|
||||
|
||||
getLogger().debug( "Lifecycle mappings not found for packaging: \'" + packaging + "\'.", e );
|
||||
|
||||
mappings = defaultPhases;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Cannot load plugin which defines lifecycle mappings for: \'" + packaging + "\'.", e );
|
||||
}
|
||||
catch ( PluginVersionResolutionException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Cannot load plugin which defines lifecycle mappings for: \'" + packaging + "\'.", e );
|
||||
}
|
||||
catch ( PluginManagerException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Cannot load lifecycle mappings.", e );
|
||||
}
|
||||
|
||||
return mappings;
|
||||
}
|
||||
|
||||
private PluginMappingManager getPluginMappingManager( MavenSession session, MavenProject project )
|
||||
throws LifecycleExecutionException
|
||||
{
|
||||
PluginMappingManager mappingManager = session.getPluginMappingManager();
|
||||
|
||||
// don't reassemble the plugin mappings if the session has already been configured with them.
|
||||
if ( mappingManager == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
List pluginGroupIds = session.getSettings().getPluginGroups();
|
||||
List pluginRepositories = project.getPluginArtifactRepositories();
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
|
||||
mappingManager = pluginMappingBuilder.loadPluginMappings( pluginGroupIds, pluginRepositories,
|
||||
localRepository );
|
||||
|
||||
// lazily configure this on the session.
|
||||
session.setPluginMappingManager( mappingManager );
|
||||
}
|
||||
catch ( RepositoryMetadataManagementException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Cannot load plugin mappings.", e );
|
||||
}
|
||||
catch ( PluginMappingManagementException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Cannot load plugin mappings.", e );
|
||||
}
|
||||
}
|
||||
|
||||
return mappingManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@ -495,32 +584,7 @@ public class DefaultLifecycleExecutor
|
|||
// 2. use the plugin resolver to resolve the prefix in the search groups
|
||||
if ( plugin == null )
|
||||
{
|
||||
PluginMappingManager mappingManager = session.getPluginMappingManager();
|
||||
|
||||
// don't reassemble the plugin mappings if the session has already been configured with them.
|
||||
if ( mappingManager == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
List pluginGroupIds = session.getSettings().getPluginGroups();
|
||||
List pluginRepositories = project.getPluginArtifactRepositories();
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
|
||||
mappingManager = pluginMappingBuilder.loadPluginMappings( pluginGroupIds, pluginRepositories,
|
||||
localRepository );
|
||||
|
||||
// lazily configure this on the session.
|
||||
session.setPluginMappingManager( mappingManager );
|
||||
}
|
||||
catch ( RepositoryMetadataManagementException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Cannot load plugin mappings.", e );
|
||||
}
|
||||
catch ( PluginMappingManagementException e )
|
||||
{
|
||||
throw new LifecycleExecutionException( "Cannot load plugin mappings.", e );
|
||||
}
|
||||
}
|
||||
PluginMappingManager mappingManager = getPluginMappingManager( session, project );
|
||||
|
||||
plugin = mappingManager.getByPrefix( prefix );
|
||||
}
|
||||
|
|
|
@ -914,4 +914,14 @@ public class DefaultPluginManager
|
|||
}
|
||||
}
|
||||
|
||||
public Object getPluginComponent( Plugin plugin, String role, String roleHint )
|
||||
throws ComponentLookupException, PluginManagerException
|
||||
{
|
||||
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( plugin );
|
||||
|
||||
PlexusContainer pluginContainer = getPluginContainer( pluginDescriptor );
|
||||
|
||||
return pluginContainer.lookup( role, roleHint );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.maven.settings.Settings;
|
|||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.ReportSet;
|
||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -50,4 +51,7 @@ public interface PluginManager
|
|||
ArtifactRepository localRepository )
|
||||
throws PluginManagerException, PluginVersionResolutionException, PluginConfigurationException,
|
||||
ArtifactResolutionException;
|
||||
|
||||
Object getPluginComponent( Plugin plugin, String role, String roleHint )
|
||||
throws ComponentLookupException, PluginManagerException;
|
||||
}
|
|
@ -201,46 +201,6 @@
|
|||
</configuration>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
|
||||
<role-hint>ejb</role-hint>
|
||||
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
|
||||
<configuration>
|
||||
<!-- START SNIPPET: ejb-lifecycle -->
|
||||
<phases>
|
||||
<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>ejb:ejb,source:jar</package>
|
||||
<install>install:install</install>
|
||||
<deploy>deploy:deploy</deploy>
|
||||
</phases>
|
||||
<!-- END SNIPPET: ejb-lifecycle -->
|
||||
</configuration>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
|
||||
<role-hint>war</role-hint>
|
||||
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
|
||||
<configuration>
|
||||
<!-- START SNIPPET: war-lifecycle -->
|
||||
<phases>
|
||||
<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>war:war</package>
|
||||
<install>install:install</install>
|
||||
<deploy>deploy:deploy</deploy>
|
||||
</phases>
|
||||
<!-- END SNIPPET: war-lifecycle -->
|
||||
</configuration>
|
||||
</component>
|
||||
|
||||
<!-- TODO: move to the plexus plugin -->
|
||||
<component>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagemen
|
|||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
|
||||
import org.apache.maven.plugin.mapping.io.xpp3.PluginMappingXpp3Reader;
|
||||
import org.apache.maven.plugin.mapping.metadata.PluginMappingMetadata;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
|
||||
|
@ -12,20 +13,29 @@ import java.io.File;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class DefaultPluginMappingBuilder
|
||||
extends AbstractLogEnabled
|
||||
implements MavenPluginMappingBuilder
|
||||
{
|
||||
|
||||
// component requirement
|
||||
private RepositoryMetadataManager repositoryMetadataManager;
|
||||
|
||||
public PluginMappingManager loadPluginMappings( List pluginGroupIds, List pluginRepositories,
|
||||
public PluginMappingManager loadPluginMappings( List groupIds, List pluginRepositories,
|
||||
ArtifactRepository localRepository )
|
||||
throws RepositoryMetadataManagementException, PluginMappingManagementException
|
||||
{
|
||||
List pluginGroupIds = new ArrayList( groupIds );
|
||||
|
||||
if ( !pluginGroupIds.contains( "org.apache.maven.plugins" ) )
|
||||
{
|
||||
pluginGroupIds.add( "org.apache.maven.plugins" );
|
||||
}
|
||||
|
||||
PluginMappingManager mappingManager = new PluginMappingManager();
|
||||
|
||||
if ( pluginGroupIds != null )
|
||||
|
@ -34,13 +44,22 @@ public class DefaultPluginMappingBuilder
|
|||
{
|
||||
String groupId = (String) it.next();
|
||||
|
||||
File mappingFile = resolveMappingMetadata( groupId, pluginRepositories, localRepository );
|
||||
|
||||
PluginMap pluginMap = readPluginMap( mappingFile );
|
||||
|
||||
if ( pluginMap != null )
|
||||
try
|
||||
{
|
||||
mappingManager.addPluginMap( pluginMap );
|
||||
File mappingFile = resolveMappingMetadata( groupId, pluginRepositories, localRepository );
|
||||
|
||||
PluginMap pluginMap = readPluginMap( mappingFile );
|
||||
|
||||
if ( pluginMap != null )
|
||||
{
|
||||
mappingManager.addPluginMap( pluginMap );
|
||||
}
|
||||
}
|
||||
catch ( RepositoryMetadataManagementException e )
|
||||
{
|
||||
getLogger().warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." );
|
||||
|
||||
getLogger().debug( "Error resolving plugin-mapping metadata for groupId: " + groupId + ".", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ public class PluginMappingManager
|
|||
private List mappings = new ArrayList();
|
||||
|
||||
private Map pluginDefinitionsByPrefix = new HashMap();
|
||||
private Map pluginDefinitionsByPackaging = new HashMap();
|
||||
|
||||
public void addPluginMap( PluginMap pluginMap )
|
||||
{
|
||||
|
@ -21,6 +22,7 @@ public class PluginMappingManager
|
|||
|
||||
// flush the cache.
|
||||
pluginDefinitionsByPrefix = null;
|
||||
pluginDefinitionsByPackaging = null;
|
||||
}
|
||||
|
||||
public Plugin getByPrefix( String pluginPrefix )
|
||||
|
@ -36,6 +38,51 @@ public class PluginMappingManager
|
|||
return (Plugin) pluginDefinitionsByPrefix.get( pluginPrefix );
|
||||
}
|
||||
|
||||
public Plugin getByPackaging( String packaging )
|
||||
{
|
||||
synchronized ( this )
|
||||
{
|
||||
if ( pluginDefinitionsByPackaging == null )
|
||||
{
|
||||
calculatePluginDefinitionsByPackaging();
|
||||
}
|
||||
}
|
||||
|
||||
return (Plugin) pluginDefinitionsByPackaging.get( packaging );
|
||||
}
|
||||
|
||||
private void calculatePluginDefinitionsByPackaging()
|
||||
{
|
||||
pluginDefinitionsByPackaging = new HashMap();
|
||||
|
||||
for ( Iterator it = mappings.iterator(); it.hasNext(); )
|
||||
{
|
||||
PluginMap pluginMap = (PluginMap) it.next();
|
||||
|
||||
String groupId = pluginMap.getGroupId();
|
||||
|
||||
for ( Iterator pluginIterator = pluginMap.getPlugins().iterator(); pluginIterator.hasNext(); )
|
||||
{
|
||||
MappedPlugin mapping = (MappedPlugin) pluginIterator.next();
|
||||
|
||||
String artifactId = mapping.getArtifactId();
|
||||
|
||||
Plugin plugin = new Plugin();
|
||||
|
||||
plugin.setGroupId( groupId );
|
||||
|
||||
plugin.setArtifactId( artifactId );
|
||||
|
||||
for ( Iterator packagingIterator = mapping.getPackagingHandlers().iterator(); packagingIterator.hasNext(); )
|
||||
{
|
||||
String packaging = (String) packagingIterator.next();
|
||||
|
||||
pluginDefinitionsByPackaging.put( packaging, plugin );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void calculatePluginDefinitionsByPrefix()
|
||||
{
|
||||
pluginDefinitionsByPrefix = new HashMap();
|
||||
|
|
|
@ -53,6 +53,15 @@
|
|||
<version>1.0.0</version>
|
||||
<description>The plugin artifactId</description>
|
||||
</field>
|
||||
<field>
|
||||
<name>packagingHandlers</name>
|
||||
<version>1.0.0</version>
|
||||
<description>A list of the packaging types supported by this plugin.</description>
|
||||
<association>
|
||||
<type>String</type>
|
||||
<multiplicity>*</multiplicity>
|
||||
</association>
|
||||
</field>
|
||||
</fields>
|
||||
</class>
|
||||
</classes>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
|
||||
<role-hint>ejb</role-hint>
|
||||
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
|
||||
<configuration>
|
||||
<!-- START SNIPPET: ejb-lifecycle -->
|
||||
<phases>
|
||||
<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>ejb:ejb,source:jar</package>
|
||||
<install>install:install</install>
|
||||
<deploy>deploy:deploy</deploy>
|
||||
</phases>
|
||||
<!-- END SNIPPET: ejb-lifecycle -->
|
||||
</configuration>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
|
@ -4,6 +4,7 @@ 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;
|
||||
|
@ -14,6 +15,20 @@ 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;
|
||||
|
||||
|
@ -23,6 +38,8 @@ 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;
|
||||
|
||||
|
@ -51,7 +68,14 @@ public class GenerateUpdatedMappingMojo
|
|||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private String outputDirectory;
|
||||
private String metadataDirectory;
|
||||
|
||||
/**
|
||||
* @parameter expression="${project.build.outputDirectory}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
private String classesDirectory;
|
||||
|
||||
/**
|
||||
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
|
||||
|
@ -67,7 +91,8 @@ public class GenerateUpdatedMappingMojo
|
|||
*/
|
||||
private ArtifactRepository localRepository;
|
||||
|
||||
public void execute() throws MojoExecutionException
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
|
||||
|
||||
|
@ -140,70 +165,132 @@ public class GenerateUpdatedMappingMojo
|
|||
}
|
||||
}
|
||||
|
||||
boolean prefixAlreadyMapped = false;
|
||||
|
||||
for ( Iterator it = pluginMap.getPlugins().iterator(); it.hasNext(); )
|
||||
{
|
||||
MappedPlugin preExisting = (MappedPlugin) it.next();
|
||||
|
||||
if ( preExisting.getPrefix().equals( getGoalPrefix() ) )
|
||||
if ( preExisting.getArtifactId().equals( project.getArtifactId() ) )
|
||||
{
|
||||
prefixAlreadyMapped = true;
|
||||
getLog().info( "Updating pre-existing plugin-mapping metadata." );
|
||||
|
||||
if ( !preExisting.getArtifactId().equals( project.getArtifactId() ) )
|
||||
{
|
||||
// TODO: In this case, should we rather just replace the existing plugin mapping??
|
||||
|
||||
throw new MojoExecutionException( "Cannot map plugin to it's prefix in plugins.xml metadata; the prefix: \'" + getGoalPrefix() + "\' is already mapped to: " + preExisting.getArtifactId() );
|
||||
}
|
||||
else
|
||||
{
|
||||
getLog().info( "NOT updating plugins.xml metadata; this plugin is already mapped." );
|
||||
}
|
||||
pluginMap.removePlugin( preExisting );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !prefixAlreadyMapped )
|
||||
MappedPlugin mappedPlugin = new MappedPlugin();
|
||||
|
||||
mappedPlugin.setArtifactId( project.getArtifactId() );
|
||||
|
||||
mappedPlugin.setPrefix( getGoalPrefix() );
|
||||
|
||||
mappedPlugin.setPackagingHandlers( extractPackagingHandlers() );
|
||||
|
||||
pluginMap.addPlugin( mappedPlugin );
|
||||
|
||||
Writer writer = null;
|
||||
try
|
||||
{
|
||||
MappedPlugin mappedPlugin = new MappedPlugin();
|
||||
File updatedMetadataFile = new File( metadataDirectory, metadata.getRepositoryPath() ).getAbsoluteFile();
|
||||
|
||||
mappedPlugin.setArtifactId( project.getArtifactId() );
|
||||
File dir = updatedMetadataFile.getParentFile();
|
||||
|
||||
mappedPlugin.setPrefix( getGoalPrefix() );
|
||||
|
||||
pluginMap.addPlugin( mappedPlugin );
|
||||
|
||||
Writer writer = null;
|
||||
try
|
||||
if ( !dir.exists() )
|
||||
{
|
||||
File updatedMetadataFile = new File( outputDirectory, metadata.getRepositoryPath() ).getAbsoluteFile();
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
File dir = updatedMetadataFile.getParentFile();
|
||||
writer = new FileWriter( updatedMetadataFile );
|
||||
|
||||
if ( !dir.exists() )
|
||||
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 )
|
||||
{
|
||||
dir.mkdirs();
|
||||
for ( Iterator componentIterator = components.iterator(); componentIterator.hasNext(); )
|
||||
{
|
||||
ComponentDescriptor descriptor = (ComponentDescriptor) componentIterator.next();
|
||||
|
||||
if ( LifecycleMapping.ROLE.equals( descriptor.getRole() ) )
|
||||
{
|
||||
packagingHandlers.add( descriptor.getRoleHint() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
return packagingHandlers;
|
||||
}
|
||||
|
||||
private String getGoalPrefix()
|
||||
|
@ -216,4 +303,38 @@ public class GenerateUpdatedMappingMojo
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<component-set>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
|
||||
<role-hint>war</role-hint>
|
||||
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
|
||||
<configuration>
|
||||
<!-- START SNIPPET: war-lifecycle -->
|
||||
<phases>
|
||||
<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>war:war</package>
|
||||
<install>install:install</install>
|
||||
<deploy>deploy:deploy</deploy>
|
||||
</phases>
|
||||
<!-- END SNIPPET: war-lifecycle -->
|
||||
</configuration>
|
||||
</component>
|
||||
</components>
|
||||
</component-set>
|
|
@ -71,8 +71,8 @@
|
|||
</organization>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>central</id>
|
||||
<name>Maven Central Repository</name>
|
||||
<id>central-plugins</id>
|
||||
<name>Maven Central Plugins Repository</name>
|
||||
<url>scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2/plugins</url>
|
||||
</repository>
|
||||
<site>
|
||||
|
@ -80,6 +80,13 @@
|
|||
<url>scp://minotaur.apache.org/www/maven.apache.org/maven2/plugins/</url>
|
||||
</site>
|
||||
</distributionManagement>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>central-plugins</id>
|
||||
<name>Maven Central Plugins Repository</name>
|
||||
<url>scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2/plugins</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<modules>
|
||||
<module>maven-ant-plugin</module>
|
||||
<module>maven-assembly-plugin</module>
|
||||
|
|
Loading…
Reference in New Issue