mirror of https://github.com/apache/maven.git
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:
parent
d210bf33df
commit
20047d63c9
|
@ -6,12 +6,9 @@ import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||||
import org.apache.maven.wagon.TransferFailedException;
|
import org.apache.maven.wagon.TransferFailedException;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
import org.codehaus.plexus.util.IOUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -46,8 +43,6 @@ public class DefaultRepositoryMetadataManager
|
||||||
{
|
{
|
||||||
wagonManager.getRepositoryMetadata( metadata, remote, metadataFile );
|
wagonManager.getRepositoryMetadata( metadata, remote, metadataFile );
|
||||||
|
|
||||||
verifyLocalRepositoryFile( metadataFile );
|
|
||||||
|
|
||||||
metadata.setFile( metadataFile );
|
metadata.setFile( metadataFile );
|
||||||
}
|
}
|
||||||
catch ( TransferFailedException e )
|
catch ( TransferFailedException e )
|
||||||
|
@ -60,13 +55,6 @@ public class DefaultRepositoryMetadataManager
|
||||||
throw new RepositoryMetadataManagementException( metadata, "Remote repository metadata not found.",
|
throw new RepositoryMetadataManagementException( metadata, "Remote repository metadata not found.",
|
||||||
e );
|
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 );
|
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>test-repo</id>
|
<id>central</id>
|
||||||
<name>Test Repository</name>
|
<name>Test Repository</name>
|
||||||
<url>file:/tmp/testRepo</url>
|
<url>file:/tmp/testRepo</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
</build>
|
</build>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>test-repo</id>
|
<id>central</id>
|
||||||
<name>Test Repository</name>
|
<name>Test Repository</name>
|
||||||
<url>file:/tmp/testRepo</url>
|
<url>file:/tmp/testRepo</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
</build>
|
</build>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>test-repo</id>
|
<id>central</id>
|
||||||
<name>Test Repository</name>
|
<name>Test Repository</name>
|
||||||
<url>file:/tmp/testRepo</url>
|
<url>file:/tmp/testRepo</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>test-repo</id>
|
<id>central</id>
|
||||||
<name>Test Repository</name>
|
<name>Test Repository</name>
|
||||||
<url>file:/tmp/testRepo</url>
|
<url>file:/tmp/testRepo</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
|
@ -5,6 +5,9 @@ import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @phase validate
|
* @phase validate
|
||||||
* @goal validatePom
|
* @goal validatePom
|
||||||
|
@ -26,7 +29,36 @@ public class ValidatePluginPomMojo
|
||||||
|
|
||||||
if ( distributionRepository == null )
|
if ( distributionRepository == null )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "You must provide a distributionManagement section with a repository element in your POM." );
|
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 <repositories/> that matches " +
|
||||||
|
"the id of the repository specified in <distributionManagement/>: \'"
|
||||||
|
+ distributionRepositoryId + "\'." );
|
||||||
|
|
||||||
|
throw new MojoExecutionException( message.toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @phase package
|
* @phase package
|
||||||
|
@ -70,6 +71,24 @@ public class GenerateUpdatedMappingMojo
|
||||||
{
|
{
|
||||||
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
|
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();
|
PluginMappingXpp3Reader mappingReader = new PluginMappingXpp3Reader();
|
||||||
|
|
||||||
PluginMap pluginMap = null;
|
PluginMap pluginMap = null;
|
||||||
|
@ -78,7 +97,7 @@ public class GenerateUpdatedMappingMojo
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
repositoryMetadataManager.resolve( metadata, distributionRepository, localRepository );
|
repositoryMetadataManager.resolve( metadata, readRemoteRepository, localRepository );
|
||||||
|
|
||||||
Reader reader = null;
|
Reader reader = null;
|
||||||
|
|
||||||
|
@ -109,15 +128,15 @@ public class GenerateUpdatedMappingMojo
|
||||||
|
|
||||||
if ( cause != null && ( cause instanceof ResourceDoesNotExistException ) )
|
if ( cause != null && ( cause instanceof ResourceDoesNotExistException ) )
|
||||||
{
|
{
|
||||||
getLog().info( "Cannot find " + metadata + " on remote repository. We'll create a new one." );
|
getLog().info( "Cannot find " + metadata + " on remote repository. Creating a new one." );
|
||||||
getLog().debug( "Metadata " + metadata + " not found.", e );
|
getLog().debug( "Metadata " + metadata + " cannot be resolved.", e );
|
||||||
|
|
||||||
pluginMap = new PluginMap();
|
pluginMap = new PluginMap();
|
||||||
pluginMap.setGroupId( project.getGroupId() );
|
pluginMap.setGroupId( project.getGroupId() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "Cannot resolve plugin-mapping metadata: " + metadata, e );
|
throw new MojoExecutionException( "Failed to resolve " + metadata, e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
</organization>
|
</organization>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<repository>
|
<repository>
|
||||||
<id>repo1</id>
|
<id>central</id>
|
||||||
<name>Maven Central Repository</name>
|
<name>Maven Central Repository</name>
|
||||||
<url>scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2/plugins</url>
|
<url>scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2/plugins</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
Loading…
Reference in New Issue