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 b2b2394f7a..9a0755bd1b 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 @@ -23,6 +23,12 @@ public class DefaultRepositoryMetadataManager // only resolve repository metadata once per session... private Map cachedMetadata = new HashMap(); + public void resolveLocally( RepositoryMetadata metadata, ArtifactRepository local ) + throws RepositoryMetadataManagementException + { + resolve( metadata, null, local ); + } + public void resolve( RepositoryMetadata metadata, ArtifactRepository remote, ArtifactRepository local ) throws RepositoryMetadataManagementException { @@ -30,29 +36,25 @@ public class DefaultRepositoryMetadataManager if ( metadataFile == null ) { - metadataFile = constructLocalRepositoryFile( metadata, local, remote.getId() ); + metadataFile = constructLocalRepositoryFile( metadata, local ); - if ( remote == null ) - { - throw new RepositoryMetadataManagementException( metadata, - "Cannot retrieve repository metadata from null repository." ); - } - else + if ( !metadataFile.exists() && remote != null ) { try { File tempMetadataFile = File.createTempFile( "plugins.xml", null ); - + try { wagonManager.getRepositoryMetadata( metadata, remote, tempMetadataFile ); - - if( !metadataFile.exists() || ( metadataFile.lastModified() <= tempMetadataFile.lastModified() ) ) + + if ( !metadataFile.exists() + || ( metadataFile.lastModified() <= tempMetadataFile.lastModified() ) ) { if ( !tempMetadataFile.renameTo( metadataFile ) ) { FileUtils.copyFile( tempMetadataFile, metadataFile ); - + tempMetadataFile.delete(); } } @@ -61,20 +63,18 @@ public class DefaultRepositoryMetadataManager { if ( !metadataFile.exists() ) { - throw new RepositoryMetadataManagementException( metadata, "Remote repository metadata not found.", - e ); + 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 ); } catch ( TransferFailedException e ) { @@ -83,9 +83,18 @@ public class DefaultRepositoryMetadataManager } catch ( IOException e ) { - throw new RepositoryMetadataManagementException( metadata, "Error constructing temporary metadata download file.", e ); + throw new RepositoryMetadataManagementException( + metadata, + "Error constructing temporary metadata download file.", + e ); } } + else + { + getLogger().info( "Using local copy of " + metadata + " from: " + metadataFile ); + } + + metadata.setFile( metadataFile ); } } @@ -110,18 +119,7 @@ public class DefaultRepositoryMetadataManager public void install( RepositoryMetadata metadata, ArtifactRepository local, String remoteRepositoryId ) throws RepositoryMetadataManagementException { - String realignedPath = local.formatAsFile( metadata.getRepositoryPath() ); - - realignedPath = realignedPath.replace( File.separatorChar, '/' ); - - if ( !realignedPath.startsWith( "/" ) ) - { - realignedPath = "/" + realignedPath; - } - - realignedPath = "/REPOSITORY-INF/" + remoteRepositoryId + realignedPath; - - File metadataFile = new File( local.getBasedir(), realignedPath ).getAbsoluteFile(); + File metadataFile = constructLocalRepositoryFile( metadata, local ); try { @@ -141,20 +139,27 @@ public class DefaultRepositoryMetadataManager } - private File constructLocalRepositoryFile( RepositoryMetadata metadata, ArtifactRepository local, String remoteId ) + public void purgeLocalCopy( RepositoryMetadata metadata, ArtifactRepository local ) + throws RepositoryMetadataManagementException + { + File metadataFile = constructLocalRepositoryFile( metadata, local ); + + if ( metadataFile.exists() ) + { + if ( !metadataFile.delete() ) + { + throw new RepositoryMetadataManagementException( metadata, "Failed to purge local copy from: " + metadataFile ); + } + } + } + + private File constructLocalRepositoryFile( RepositoryMetadata metadata, ArtifactRepository local ) { String metadataPath = local.formatAsFile( metadata.getRepositoryPath() ); - String realignedPath = metadataPath.replace( File.separatorChar, '/' ); + metadataPath = metadataPath.replace( File.separatorChar, '/' ); - if ( !realignedPath.startsWith( "/" ) ) - { - realignedPath = "/" + realignedPath; - } - - realignedPath = "/REPOSITORY-INF/" + remoteId + realignedPath; - - return new File( local.getBasedir(), realignedPath ); + return new File( local.getBasedir(), metadataPath ); } } 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 9a998cdb29..135498494b 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 @@ -5,6 +5,9 @@ import org.apache.maven.artifact.repository.ArtifactRepository; public interface RepositoryMetadataManager { + void resolveLocally( RepositoryMetadata repositoryMetadata, ArtifactRepository local ) + throws RepositoryMetadataManagementException; + void resolve( RepositoryMetadata repositoryMetadata, ArtifactRepository remote, ArtifactRepository local ) throws RepositoryMetadataManagementException; @@ -13,5 +16,8 @@ public interface RepositoryMetadataManager void install( RepositoryMetadata repositoryMetadata, ArtifactRepository local, String remoteRepositoryId ) throws RepositoryMetadataManagementException; + + void purgeLocalCopy( RepositoryMetadata repositoryMetadata, ArtifactRepository local ) + throws RepositoryMetadataManagementException; } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java index 759fe60d72..3aa951bfe1 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java @@ -18,9 +18,11 @@ package org.apache.maven.artifact.transform; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.VersionArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.wagon.ResourceDoesNotExistException; import org.codehaus.plexus.logging.AbstractLogEnabled; import java.io.IOException; @@ -101,8 +103,19 @@ public abstract class AbstractVersionTransformation getLogger().info( artifact.getArtifactId() + ": checking for updates from " + remoteRepository.getId() ); - VersionArtifactMetadata remoteMetadata = retrieveFromRemoteRepository( artifact, remoteRepository, localMetadata ); - + VersionArtifactMetadata remoteMetadata; + + try + { + remoteMetadata = retrieveFromRemoteRepository( artifact, remoteRepository, localMetadata ); + } + catch ( ResourceDoesNotExistException e ) + { + getLogger().debug( "Error resolving artifact version from metadata.", e ); + + continue; + } + int difference = remoteMetadata.compareTo( localMetadata ); if ( difference > 0 ) { @@ -124,13 +137,13 @@ public abstract class AbstractVersionTransformation } String version = localMetadata.constructVersion(); - + // TODO: if the POM and JAR are inconsistent, this might mean that different version of each are used if ( !artifact.getFile().exists() || localMetadata.newerThanFile( artifact.getFile() ) ) { if ( getLogger().isInfoEnabled() && !alreadyResolved ) { - if ( !version.equals( artifact.getBaseVersion() ) ) + if ( version != null && !version.equals( artifact.getBaseVersion() ) ) { String message = artifact.getArtifactId() + ": resolved to version " + version; if ( artifact.getRepository() != null ) @@ -158,14 +171,27 @@ public abstract class AbstractVersionTransformation } } - protected abstract VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact, - ArtifactRepository remoteRepository, - VersionArtifactMetadata localMetadata ) - throws ArtifactMetadataRetrievalException; + protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact, + ArtifactRepository remoteRepository, + VersionArtifactMetadata localMetadata ) + throws ArtifactMetadataRetrievalException, ResourceDoesNotExistException + { + AbstractVersionArtifactMetadata metadata = createMetadata( artifact ); + + metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager ); + + return metadata; + } + + protected abstract AbstractVersionArtifactMetadata createMetadata( Artifact artifact ); - protected abstract VersionArtifactMetadata readFromLocalRepository( Artifact artifact, - ArtifactRepository localRepository ) - throws IOException; + private VersionArtifactMetadata readFromLocalRepository( Artifact artifact, ArtifactRepository localRepository ) + throws IOException + { + AbstractVersionArtifactMetadata metadata = createMetadata( artifact ); + metadata.readFromLocalRepository( localRepository ); + return metadata; + } private Date getMidnightBoundary() { diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/LatestArtifactTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/LatestArtifactTransformation.java index 6d4ea81a0e..67abbfcffd 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/LatestArtifactTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/LatestArtifactTransformation.java @@ -4,11 +4,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.LatestArtifactMetadata; -import org.apache.maven.artifact.metadata.VersionArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import java.io.IOException; import java.util.List; public class LatestArtifactTransformation @@ -22,7 +19,7 @@ public class LatestArtifactTransformation if ( LATEST_VERSION.equals( artifact.getVersion() ) ) { String version = resolveVersion( artifact, localRepository, remoteRepositories ); - if ( !version.equals( artifact.getVersion() ) ) + if ( version != null && !version.equals( artifact.getVersion() ) ) { artifact.setBaseVersion( version ); artifact.updateVersion( version, localRepository ); @@ -42,32 +39,9 @@ public class LatestArtifactTransformation // metadata is added at deploy time } - protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact, - ArtifactRepository remoteRepository, - VersionArtifactMetadata localMetadata ) - throws ArtifactMetadataRetrievalException + protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact ) { - AbstractVersionArtifactMetadata metadata = new LatestArtifactMetadata( artifact ); - try - { - metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager ); - } - catch ( ResourceDoesNotExistException e ) - { - if ( localMetadata.constructVersion() == null ) - { - throw new ArtifactMetadataRetrievalException( "Unable to find latest version for plugin artifact " + artifact, e ); - } - // otherwise, ignore - use the local one - } - return metadata; + return new LatestArtifactMetadata( artifact ); } - protected VersionArtifactMetadata readFromLocalRepository( Artifact artifact, ArtifactRepository localRepository ) - throws IOException - { - AbstractVersionArtifactMetadata metadata = new LatestArtifactMetadata( artifact ); - metadata.readFromLocalRepository( localRepository ); - return metadata; - } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/ReleaseArtifactTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/ReleaseArtifactTransformation.java index 3e713bc608..3dc649b230 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/ReleaseArtifactTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/ReleaseArtifactTransformation.java @@ -20,11 +20,8 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ReleaseArtifactMetadata; -import org.apache.maven.artifact.metadata.VersionArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.wagon.ResourceDoesNotExistException; -import java.io.IOException; import java.util.List; /** @@ -44,7 +41,8 @@ public class ReleaseArtifactTransformation if ( RELEASE_VERSION.equals( artifact.getVersion() ) ) { String version = resolveVersion( artifact, localRepository, remoteRepositories ); - if ( !version.equals( artifact.getVersion() ) ) + + if ( version != null && !version.equals( artifact.getVersion() ) ) { artifact.setBaseVersion( version ); artifact.updateVersion( version, localRepository ); @@ -64,32 +62,9 @@ public class ReleaseArtifactTransformation // metadata is added at deploy time } - protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact, - ArtifactRepository remoteRepository, - VersionArtifactMetadata localMetadata ) - throws ArtifactMetadataRetrievalException + protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact ) { - AbstractVersionArtifactMetadata metadata = new ReleaseArtifactMetadata( artifact ); - try - { - metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager ); - } - catch ( ResourceDoesNotExistException e ) - { - if ( localMetadata.constructVersion() == null ) - { - throw new ArtifactMetadataRetrievalException( "Unable to find release for artifact " + artifact, e ); - } - // otherwise, ignore - use the local one - } - return metadata; + return new ReleaseArtifactMetadata( artifact ); } - protected VersionArtifactMetadata readFromLocalRepository( Artifact artifact, ArtifactRepository localRepository ) - throws IOException - { - AbstractVersionArtifactMetadata metadata = new ReleaseArtifactMetadata( artifact ); - metadata.readFromLocalRepository( localRepository ); - return metadata; - } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index 641ef5dbe4..29583443b9 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -17,13 +17,12 @@ package org.apache.maven.artifact.transform; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata; -import org.apache.maven.artifact.metadata.VersionArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.wagon.ResourceDoesNotExistException; -import java.io.IOException; import java.util.List; import java.util.regex.Matcher; @@ -81,7 +80,16 @@ public class SnapshotTransformation else if ( isSnapshot( artifact ) ) { SnapshotArtifactMetadata metadata = null; - metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null ); + + try + { + metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null ); + } + catch ( ResourceDoesNotExistException e ) + { + // ignore. We'll be creating this metadata if it doesn't exist... + } + metadata.update(); artifact.setVersion( metadata.constructVersion() ); @@ -95,29 +103,9 @@ public class SnapshotTransformation return artifact.getVersion().endsWith( SNAPSHOT_VERSION ); } - protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact, - ArtifactRepository remoteRepository, - VersionArtifactMetadata localMetadata ) - throws ArtifactMetadataRetrievalException + protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact ) { - SnapshotArtifactMetadata metadata = new SnapshotArtifactMetadata( artifact ); - try - { - metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager ); - } - catch ( ResourceDoesNotExistException e ) - { - // No problem... - // this just means that there is no snapshot version file, so we keep timestamp = null, build = 0 - } - return metadata; + return new SnapshotArtifactMetadata( artifact ); } - protected VersionArtifactMetadata readFromLocalRepository( Artifact artifact, ArtifactRepository localRepository ) - throws IOException - { - SnapshotArtifactMetadata metadata = new SnapshotArtifactMetadata( artifact ); - metadata.readFromLocalRepository( localRepository ); - return metadata; - } } \ No newline at end of file diff --git a/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java b/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java index 5d9b9f295a..6b7ca63804 100644 --- a/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java +++ b/maven-core-it-verifier/src/main/java/org/apache/maven/it/Verifier.java @@ -493,8 +493,8 @@ public class Verifier cli.setExecutable( executable ); -// cli.createArgument().setValue( "-e" ); - cli.createArgument().setValue( "-X" ); + cli.createArgument().setValue( "-e" ); +// cli.createArgument().setValue( "-X" ); cli.createArgument().setValue( "--no-plugin-registry" ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 04f61e7cfb..fe26a7d289 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -570,7 +570,26 @@ public class DefaultLifecycleExecutor // Steps for retrieving the plugin model instance: // 1. request directly from the plugin collector by prefix - pluginDescriptor = pluginManager.getPluginDescriptorForPrefix( prefix ); + try + { + pluginDescriptor = pluginManager.getPluginDescriptorForPrefix( prefix ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Cannot resolve plugin-prefix: \'" + prefix + "\' from plugin collector.", e ); + } + + if ( pluginDescriptor == null ) + { + try + { + plugin = pluginManager.getPluginDefinitionForPrefix( prefix, session, project ); + } + catch ( PluginManagerException e ) + { + throw new LifecycleExecutionException( "Cannot resolve plugin-prefix: \'" + prefix + "\' from plugin mappings metadata.", e ); + } + } if ( pluginDescriptor != null ) { @@ -581,15 +600,7 @@ public class DefaultLifecycleExecutor plugin.setVersion( pluginDescriptor.getVersion() ); } - // 2. use the plugin resolver to resolve the prefix in the search groups - if ( plugin == null ) - { - PluginMappingManager mappingManager = getPluginMappingManager( session, project ); - - plugin = mappingManager.getByPrefix( prefix ); - } - - // 3. default to o.a.m.plugins and maven--plugin + // 2. default to o.a.m.plugins and maven--plugin if ( plugin == null ) { plugin = new Plugin(); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index db3eca3e43..c26848eef9 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -21,6 +21,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManagementException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; @@ -40,6 +41,9 @@ import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugin.mapping.MavenPluginMappingBuilder; +import org.apache.maven.plugin.mapping.PluginMappingManagementException; +import org.apache.maven.plugin.mapping.PluginMappingManager; import org.apache.maven.plugin.version.PluginVersionManager; import org.apache.maven.plugin.version.PluginVersionResolutionException; import org.apache.maven.project.MavenProject; @@ -67,6 +71,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -74,7 +79,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.lang.reflect.Field; public class DefaultPluginManager extends AbstractLogEnabled @@ -100,6 +104,8 @@ public class DefaultPluginManager protected ArtifactResolver artifactResolver; protected MavenProjectBuilder mavenProjectBuilder; + + protected MavenPluginMappingBuilder pluginMappingBuilder; // END component requirements public DefaultPluginManager() @@ -112,9 +118,41 @@ public class DefaultPluginManager // ---------------------------------------------------------------------- public PluginDescriptor getPluginDescriptorForPrefix( String prefix ) + throws PluginManagerException { return pluginCollector.getPluginDescriptorForPrefix( prefix ); } + + public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ) throws PluginManagerException + { + PluginMappingManager mappingManager = getPluginMappingManager( session, project ); + + Plugin plugin = mappingManager.getByPrefix( prefix ); + + if ( plugin == null && !mappingManager.isRefreshed() ) + { + getLogger().info( "Refreshing plugin mapping metadata; looking for plugin with prefix: \'" + prefix + "\'." ); + + try + { + mappingManager = pluginMappingBuilder.refreshPluginMappingManager( session + .getPluginMappingManager(), project.getPluginArtifactRepositories(), session + .getLocalRepository() ); + } + catch ( RepositoryMetadataManagementException e ) + { + throw new PluginManagerException( "Error refreshing plugin mappings.", e ); + } + catch ( PluginMappingManagementException e ) + { + throw new PluginManagerException( "Error refreshing plugin mappings.", e ); + } + + plugin = mappingManager.getByPrefix( prefix ); + } + + return plugin; + } public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, ArtifactRepository localRepository ) @@ -929,4 +967,36 @@ public class DefaultPluginManager return pluginContainer.lookup( role, roleHint ); } + private PluginMappingManager getPluginMappingManager( MavenSession session, MavenProject project ) + throws PluginManagerException +{ + 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 PluginManagerException( "Cannot load plugin mappings.", e ); + } + catch ( PluginMappingManagementException e ) + { + throw new PluginManagerException( "Cannot load plugin mappings.", e ); + } + } + + return mappingManager; +} } diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java index dfbf0e1d98..c1c5172d0d 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginManager.java @@ -41,8 +41,12 @@ public interface PluginManager void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) throws MojoExecutionException, PluginManagerException, ArtifactResolutionException; - PluginDescriptor getPluginDescriptorForPrefix( String prefix ); + PluginDescriptor getPluginDescriptorForPrefix( String prefix ) + throws PluginManagerException; + Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ) + throws PluginManagerException; + PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, ArtifactRepository localRepository ) throws ArtifactResolutionException, PluginManagerException, PluginVersionResolutionException; 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 5f4bb21bc7..9c1516be31 100644 --- a/maven-core/src/main/resources/META-INF/plexus/components.xml +++ b/maven-core/src/main/resources/META-INF/plexus/components.xml @@ -22,6 +22,9 @@ org.apache.maven.project.MavenProjectBuilder + + org.apache.maven.plugin.mapping.MavenPluginMappingBuilder + diff --git a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/DefaultPluginMappingBuilder.java b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/DefaultPluginMappingBuilder.java index 53a2e27991..79477ec6f6 100644 --- a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/DefaultPluginMappingBuilder.java +++ b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/DefaultPluginMappingBuilder.java @@ -29,14 +29,50 @@ public class DefaultPluginMappingBuilder ArtifactRepository localRepository ) throws RepositoryMetadataManagementException, PluginMappingManagementException { - List pluginGroupIds = new ArrayList( groupIds ); + return loadPluginMappings( groupIds, pluginRepositories, localRepository, new PluginMappingManager() ); + } + + public PluginMappingManager refreshPluginMappingManager( PluginMappingManager mappingManager, List pluginRepositories, + ArtifactRepository localRepository ) + throws RepositoryMetadataManagementException, PluginMappingManagementException + { + // prevent performance drag from abuse of this method. + if ( mappingManager.isRefreshed() ) + { + throw new PluginMappingManagementException( "Plugin-mappings have already been refreshed. Cannot re-refresh." ); + } + getLogger().info( "Refreshing plugin-mapping metadata..." ); + + List groupIds = new ArrayList(); + + for ( Iterator it = mappingManager.getPluginMaps().iterator(); it.hasNext(); ) + { + PluginMap map = (PluginMap) it.next(); + + String groupId = map.getGroupId(); + + groupIds.add( groupId ); + + repositoryMetadataManager.purgeLocalCopy( new PluginMappingMetadata( groupId ), localRepository ); + } + + mappingManager.markRefreshed(); + + return loadPluginMappings(groupIds, pluginRepositories, localRepository, mappingManager); + } + + private PluginMappingManager loadPluginMappings( List groupIds, List pluginRepositories, + ArtifactRepository localRepository, + PluginMappingManager mappingManager ) + 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 ) { @@ -57,8 +93,9 @@ public class DefaultPluginMappingBuilder } catch ( RepositoryMetadataManagementException e ) { - getLogger().warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." ); - + getLogger() + .warn( "Cannot resolve plugin-mapping metadata for groupId: " + groupId + " - IGNORING." ); + getLogger().debug( "Error resolving plugin-mapping metadata for groupId: " + groupId + ".", e ); } } @@ -67,9 +104,10 @@ public class DefaultPluginMappingBuilder return mappingManager; } - private PluginMap readPluginMap( File mappingFile ) throws PluginMappingManagementException + private PluginMap readPluginMap( File mappingFile ) + throws PluginMappingManagementException { - if( mappingFile.exists() ) + if ( mappingFile.exists() ) { Reader fileReader = null; try @@ -77,8 +115,8 @@ public class DefaultPluginMappingBuilder fileReader = new FileReader( mappingFile ); PluginMappingXpp3Reader mappingReader = new PluginMappingXpp3Reader(); - - return mappingReader.read(fileReader); + + return mappingReader.read( fileReader ); } catch ( IOException e ) { @@ -113,7 +151,7 @@ public class DefaultPluginMappingBuilder try { repositoryMetadataManager.resolve( metadata, repository, localRepository ); - + // reset this to keep it from getting in the way when we succeed but not on first repo... repositoryException = null; diff --git a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/MavenPluginMappingBuilder.java b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/MavenPluginMappingBuilder.java index 6bb6f9c30b..b27a09e33f 100644 --- a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/MavenPluginMappingBuilder.java +++ b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/MavenPluginMappingBuilder.java @@ -12,4 +12,8 @@ public interface MavenPluginMappingBuilder ArtifactRepository localRepository ) throws RepositoryMetadataManagementException, PluginMappingManagementException; + PluginMappingManager refreshPluginMappingManager( PluginMappingManager mappingManager, List pluginRepositories, + ArtifactRepository localRepository ) + throws RepositoryMetadataManagementException, PluginMappingManagementException; + } diff --git a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/PluginMappingManager.java b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/PluginMappingManager.java index 054f1611c9..87cf30560a 100644 --- a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/PluginMappingManager.java +++ b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/PluginMappingManager.java @@ -12,6 +12,7 @@ public class PluginMappingManager { private List mappings = new ArrayList(); + private boolean refreshed = false; private Map pluginDefinitionsByPrefix = new HashMap(); private Map pluginDefinitionsByPackaging = new HashMap(); @@ -20,9 +21,34 @@ public class PluginMappingManager { mappings.add( pluginMap ); - // flush the cache. - pluginDefinitionsByPrefix = null; - pluginDefinitionsByPackaging = null; + clearCache(); + } + + public void markRefreshed() + { + this.refreshed = true; + } + + public boolean isRefreshed() + { + return refreshed; + } + + public List getPluginMaps() + { + return mappings; + } + + public void clear() + { + this.mappings = null; + clearCache(); + } + + private void clearCache() + { + this.pluginDefinitionsByPackaging = null; + this.pluginDefinitionsByPrefix = null; } public Plugin getByPrefix( String pluginPrefix ) diff --git a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/metadata/PluginMappingMetadata.java b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/metadata/PluginMappingMetadata.java index 831e9a23b0..2452900a64 100644 --- a/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/metadata/PluginMappingMetadata.java +++ b/maven-plugin-mapping/src/main/java/org/apache/maven/plugin/mapping/metadata/PluginMappingMetadata.java @@ -17,7 +17,7 @@ public class PluginMappingMetadata { this.groupId = groupId; } - + public String getRepositoryPath() { return groupId + "/" + PLUGIN_MAPPING_FILE; diff --git a/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java b/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java index 831f64b9ec..b1965cfcbf 100644 --- a/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java +++ b/maven-plugin-registry/src/main/java/org/apache/maven/plugin/registry/DefaultPluginRegistryBuilder.java @@ -58,8 +58,8 @@ public class DefaultPluginRegistryBuilder globalRegistryFile = getFile( globalRegistryPath, "maven.home", MavenPluginRegistryBuilder.ALT_GLOBAL_PLUGIN_REG_LOCATION ); - getLogger().debug( "Building Maven global-level settings from: '" + globalRegistryFile.getAbsolutePath() + "'" ); - getLogger().debug( "Building Maven user-level settings from: '" + userRegistryFile.getAbsolutePath() + "'" ); + getLogger().debug( "Building Maven global-level plugin registry from: '" + globalRegistryFile.getAbsolutePath() + "'" ); + getLogger().debug( "Building Maven user-level plugin registry from: '" + userRegistryFile.getAbsolutePath() + "'" ); } public PluginRegistry buildPluginRegistry()