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 <repositories/> 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
This commit is contained in:
John Dennis Casey 2005-07-12 20:08:21 +00:00
parent d210bf33df
commit 20047d63c9
8 changed files with 64 additions and 48 deletions

View File

@ -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 );
}
}
}

View File

@ -22,7 +22,7 @@
</dependencies>
<distributionManagement>
<repository>
<id>test-repo</id>
<id>central</id>
<name>Test Repository</name>
<url>file:/tmp/testRepo</url>
</repository>

View File

@ -31,7 +31,7 @@
</build>
<distributionManagement>
<repository>
<id>test-repo</id>
<id>central</id>
<name>Test Repository</name>
<url>file:/tmp/testRepo</url>
</repository>

View File

@ -23,7 +23,7 @@
</build>
<distributionManagement>
<repository>
<id>test-repo</id>
<id>central</id>
<name>Test Repository</name>
<url>file:/tmp/testRepo</url>
</repository>

View File

@ -27,7 +27,7 @@
<distributionManagement>
<repository>
<id>test-repo</id>
<id>central</id>
<name>Test Repository</name>
<url>file:/tmp/testRepo</url>
</repository>

View File

@ -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 <repositories/> that matches " +
"the id of the repository specified in <distributionManagement/>: \'"
+ distributionRepositoryId + "\'." );
throw new MojoExecutionException( message.toString() );
}
}
}

View File

@ -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 );
}
}

View File

@ -71,7 +71,7 @@
</organization>
<distributionManagement>
<repository>
<id>repo1</id>
<id>central</id>
<name>Maven Central Repository</name>
<url>scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2/plugins</url>
</repository>