From 20047d63c9b1949c4cc68e8bdc22c0c69d0e5ff4 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 12 Jul 2005 20:08:21 +0000 Subject: [PATCH] Fixing problem with using distributionManagement repository definition for download of plugins.xml metadata. Now, in order to build a maven plugin, you need two things: 1. a repository defined in distributionManagment 2. a repository defined in which has the same id as the one in distributionManagement. This is necessary, since in most cases SSH will be used in the distributionManagement definition for uploading the plugin...which means that the download of the existing plugins.xml file might not be available for users trying to run an install. SSH requires authentication information, and users (particularly those running the bootstrap) might not have this auth info. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@216013 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultRepositoryMetadataManager.java | 35 ---------------- maven-core-it/it0013/pom.xml | 2 +- maven-core-it/it0015/pom.xml | 2 +- maven-core-it/it0020/pom.xml | 2 +- maven-core-it/it0021/pom.xml | 2 +- .../plugin/plugin/ValidatePluginPomMojo.java | 40 +++++++++++++++++-- .../metadata/GenerateUpdatedMappingMojo.java | 27 +++++++++++-- maven-plugins/pom.xml | 2 +- 8 files changed, 64 insertions(+), 48 deletions(-) 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 64879432c1..aa54fe0e43 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 @@ -6,12 +6,9 @@ import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.IOUtil; import java.io.File; -import java.io.FileReader; import java.io.IOException; -import java.io.Reader; import java.util.HashMap; import java.util.Map; @@ -46,8 +43,6 @@ public class DefaultRepositoryMetadataManager { wagonManager.getRepositoryMetadata( metadata, remote, metadataFile ); - verifyLocalRepositoryFile( metadataFile ); - metadata.setFile( metadataFile ); } catch ( TransferFailedException e ) @@ -60,13 +55,6 @@ public class DefaultRepositoryMetadataManager throw new RepositoryMetadataManagementException( metadata, "Remote repository metadata not found.", e ); } - catch ( IOException e ) - { - throw new RepositoryMetadataManagementException( - metadata, - "Download of repository metadata resulted in an invalid file.", - e ); - } } } } @@ -139,27 +127,4 @@ public class DefaultRepositoryMetadataManager return new File( local.getBasedir(), realignedPath ); } - private void verifyLocalRepositoryFile( File metadataFile ) - throws IOException - { - Reader metadataReader = null; - - try - { - metadataReader = new FileReader( metadataFile ); - - char[] cbuf = new char[16]; - - while ( metadataReader.read( cbuf ) > -1 ) - { - // do nothing...just verify that it can be read. - } - } - finally - { - IOUtil.close( metadataReader ); - } - - } - } diff --git a/maven-core-it/it0013/pom.xml b/maven-core-it/it0013/pom.xml index 83d06834a9..3f0b63649a 100644 --- a/maven-core-it/it0013/pom.xml +++ b/maven-core-it/it0013/pom.xml @@ -22,7 +22,7 @@ - test-repo + central Test Repository file:/tmp/testRepo diff --git a/maven-core-it/it0015/pom.xml b/maven-core-it/it0015/pom.xml index ce7dd71e9b..98bcde094e 100644 --- a/maven-core-it/it0015/pom.xml +++ b/maven-core-it/it0015/pom.xml @@ -31,7 +31,7 @@ - test-repo + central Test Repository file:/tmp/testRepo diff --git a/maven-core-it/it0020/pom.xml b/maven-core-it/it0020/pom.xml index ca6f314824..0e3e2321fa 100644 --- a/maven-core-it/it0020/pom.xml +++ b/maven-core-it/it0020/pom.xml @@ -23,7 +23,7 @@ - test-repo + central Test Repository file:/tmp/testRepo diff --git a/maven-core-it/it0021/pom.xml b/maven-core-it/it0021/pom.xml index b75e1ae50c..22dca26f2a 100644 --- a/maven-core-it/it0021/pom.xml +++ b/maven-core-it/it0021/pom.xml @@ -27,7 +27,7 @@ - test-repo + central Test Repository file:/tmp/testRepo 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 index db0039af00..41b9203827 100644 --- 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 @@ -5,6 +5,9 @@ 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 @@ -22,12 +25,41 @@ public class ValidatePluginPomMojo public void execute() throws MojoExecutionException { - ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository(); - - if ( distributionRepository == null ) + 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() ) ) { - throw new MojoExecutionException( "You must provide a distributionManagement section with a repository element in your POM." ); + 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/GenerateUpdatedMappingMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/GenerateUpdatedMappingMojo.java index 286842c8b0..85e7b6995c 100644 --- 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.util.Iterator; +import java.util.List; /** * @phase package @@ -70,6 +71,24 @@ public class GenerateUpdatedMappingMojo { 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; @@ -78,7 +97,7 @@ public class GenerateUpdatedMappingMojo try { - repositoryMetadataManager.resolve( metadata, distributionRepository, localRepository ); + repositoryMetadataManager.resolve( metadata, readRemoteRepository, localRepository ); Reader reader = null; @@ -109,15 +128,15 @@ public class GenerateUpdatedMappingMojo if ( cause != null && ( cause instanceof ResourceDoesNotExistException ) ) { - getLog().info( "Cannot find " + metadata + " on remote repository. We'll create a new one." ); - getLog().debug( "Metadata " + metadata + " not found.", e ); + 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( "Cannot resolve plugin-mapping metadata: " + metadata, e ); + throw new MojoExecutionException( "Failed to resolve " + metadata, e ); } } diff --git a/maven-plugins/pom.xml b/maven-plugins/pom.xml index 60a55cab83..0f1c64a901 100644 --- a/maven-plugins/pom.xml +++ b/maven-plugins/pom.xml @@ -71,7 +71,7 @@ - repo1 + central Maven Central Repository scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2/plugins