Fixing issues related to MNG-377, where the plugins.xml metadata was being mishandled. Separated updating of this metadata into a separate mojo, bound to the 'package' phase, and put in a validator for the POM (POM has to have distributionRepository now for maven-plugin's) which is bound to the 'validate' phase. Put together an integration test that uses modello:java as a case where the pluginGroups must be consulted. Also had to change the Verifier to check a verifier.properties for failOnErrorOutput, which will suppress IT failures based on [ERROR] log output (modello outputs one of these, and kills the IT unnecessarily).

MNG-377 should be resolved at this point.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@215890 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-07-11 22:08:58 +00:00
parent b90c2d1e24
commit 4b53aba3bb
25 changed files with 561 additions and 361 deletions

View File

@ -6,9 +6,14 @@ 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;
public class DefaultRepositoryMetadataManager
extends AbstractLogEnabled
@ -18,61 +23,49 @@ public class DefaultRepositoryMetadataManager
// component requirement
private WagonManager wagonManager;
public void resolve( RepositoryMetadata metadata, ArtifactRepository remote, ArtifactRepository local, String remoteId )
// only resolve repository metadata once per session...
private Map resolved = new HashMap();
public void resolve( RepositoryMetadata metadata, ArtifactRepository remote, ArtifactRepository local )
throws RepositoryMetadataManagementException
{
String metadataPath = local.formatAsFile( metadata.getRepositoryPath() );
File metadataFile = (File) resolved.get( metadata.getRepositoryPath() );
String realignedPath = metadataPath.replace( File.separatorChar, '/' );
if ( !realignedPath.startsWith( "/" ) )
if ( metadataFile == null )
{
realignedPath = "/" + realignedPath;
}
metadataFile = constructLocalRepositoryFile( metadata, local, remote.getId() );
realignedPath = "/REPOSITORY-INF/" + remoteId + realignedPath;
File metadataFile = new File( local.getBasedir(), realignedPath );
if ( remote == null )
{
if ( metadataFile.exists() )
if ( remote == null )
{
getLogger().warn( "Cannot retrieve repository metadata for: " + metadataPath + ". Using locally cached version instead." );
getLogger().debug( "Error retrieving repository metadata: " + metadataPath + ". Reason: repository is null." );
metadata.setFile( metadataFile );
throw new RepositoryMetadataManagementException( metadata,
"Cannot retrieve repository metadata from null repository." );
}
else
{
throw new RepositoryMetadataManagementException( metadata, "Cannot retrieve repository metadata from null repository." );
}
}
else
{
try
{
wagonManager.getRepositoryMetadata( metadata, remote, metadataFile );
metadata.setFile( metadataFile );
}
catch ( TransferFailedException e )
{
throw new RepositoryMetadataManagementException( metadata, "Failed to download repository metadata.", e );
}
catch ( ResourceDoesNotExistException e )
{
if ( metadataFile.exists() )
try
{
getLogger().warn( "Cannot find repository metadata for: " + metadataPath + ". Using locally cached version instead." );
getLogger().debug( "Error retrieving repository metadata: " + metadataPath, e );
wagonManager.getRepositoryMetadata( metadata, remote, metadataFile );
verifyLocalRepositoryFile( metadataFile );
metadata.setFile( metadataFile );
}
else
catch ( TransferFailedException e )
{
throw new RepositoryMetadataManagementException( metadata, "Remote repository metadata not found.", e );
throw new RepositoryMetadataManagementException( metadata,
"Failed to download repository metadata.", e );
}
catch ( ResourceDoesNotExistException e )
{
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 );
}
}
}
@ -97,7 +90,7 @@ public class DefaultRepositoryMetadataManager
}
public void install( RepositoryMetadata metadata, ArtifactRepository local, String remoteRepositoryId )
throws RepositoryMetadataManagementException
throws RepositoryMetadataManagementException
{
String realignedPath = local.formatAsFile( metadata.getRepositoryPath() );
@ -115,19 +108,58 @@ public class DefaultRepositoryMetadataManager
try
{
File dir = metadataFile.getParentFile();
if ( !dir.exists() )
{
dir.mkdirs();
}
FileUtils.copyFile( metadata.getFile(), metadataFile );
}
catch ( IOException e )
{
throw new RepositoryMetadataManagementException( metadata, "Failed to install repository metadata.", e );
}
}
private File constructLocalRepositoryFile( RepositoryMetadata metadata, ArtifactRepository local, String remoteId )
{
String metadataPath = local.formatAsFile( metadata.getRepositoryPath() );
String realignedPath = metadataPath.replace( File.separatorChar, '/' );
if ( !realignedPath.startsWith( "/" ) )
{
realignedPath = "/" + realignedPath;
}
realignedPath = "/REPOSITORY-INF/" + remoteId + 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 );
}
}
}

View File

@ -4,8 +4,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
public interface RepositoryMetadataManager
{
void resolve( RepositoryMetadata repositoryMetadata, ArtifactRepository remote, ArtifactRepository local, String remoteRepositoryId )
void resolve( RepositoryMetadata repositoryMetadata, ArtifactRepository remote, ArtifactRepository local )
throws RepositoryMetadataManagementException;
void deploy( RepositoryMetadata repositoryMetadata, ArtifactRepository remote )

View File

@ -98,7 +98,7 @@ public class Verifier
//
// ----------------------------------------------------------------------
public void verify()
public void verify( boolean chokeOnErrorOutput )
throws VerificationException
{
List lines = loadFile( basedir, "expected-results.txt" );
@ -110,15 +110,18 @@ public class Verifier
verifyExpectedResult( line );
}
lines = loadFile( basedir, LOG_FILENAME );
for ( Iterator i = lines.iterator(); i.hasNext(); )
if ( chokeOnErrorOutput )
{
String line = (String) i.next();
lines = loadFile( basedir, LOG_FILENAME );
if ( line.indexOf( "[ERROR]" ) >= 0 )
for ( Iterator i = lines.iterator(); i.hasNext(); )
{
throw new VerificationException( "Error in execution." );
String line = (String) i.next();
if ( line.indexOf( "[ERROR]" ) >= 0 )
{
throw new VerificationException( "Error in execution." );
}
}
}
}
@ -563,7 +566,7 @@ public class Verifier
public static void main( String args[] )
{
String basedir = System.getProperty( "user.dir" );
localRepo = retrieveLocalRepo();
List tests = null;
@ -602,11 +605,17 @@ public class Verifier
Properties properties = verifier.loadProperties( "system.properties" );
Properties controlProperties = verifier.loadProperties( "verifier.properties" );
boolean chokeOnErrorOutput = Boolean.valueOf( controlProperties.getProperty( "failOnErrorOutput", "true" ) ).booleanValue();
verifier.executeGoals( properties, "goals.txt" );
verifier.executeHook( "postbuild-hook.txt" );
verifier.verify();
System.out.println("*** Verifying: fail when [ERROR] detected? " + chokeOnErrorOutput + " ***");
verifier.verify( chokeOnErrorOutput );
verifier.resetStreams();

View File

@ -93,6 +93,10 @@ it0029: Test for pluginManagement injection of plugin configuration.
it0030: Test for injection of dependencyManagement through parents of
dependency poms.
it0031: Test usage of plugins.xml mapping file on the repository to resolve
plugin artifactId from it's prefix using the pluginGroups in
the provided settings.xml.
-------------------------------------------------------------------------------
- generated sources

View File

@ -1,3 +1,4 @@
it0031
#it0030
#it0029
it0028

View File

@ -1,4 +1,4 @@
<model>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-it0013-plugin</artifactId>
@ -20,4 +20,11 @@
<scope>test</scope>
</dependency>
</dependencies>
</model>
<distributionManagement>
<repository>
<id>test-repo</id>
<name>Test Repository</name>
<url>file:/tmp/testRepo</url>
</repository>
</distributionManagement>
</project>

View File

@ -1,4 +1,4 @@
<model>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-it0015-plugin</artifactId>
@ -29,4 +29,11 @@
</resource>
</resources>
</build>
</model>
<distributionManagement>
<repository>
<id>test-repo</id>
<name>Test Repository</name>
<url>file:/tmp/testRepo</url>
</repository>
</distributionManagement>
</project>

View File

@ -1,4 +1,4 @@
<model>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-it0020-plugin</artifactId>
@ -21,4 +21,11 @@
</resource>
</resources>
</build>
</model>
<distributionManagement>
<repository>
<id>test-repo</id>
<name>Test Repository</name>
<url>file:/tmp/testRepo</url>
</repository>
</distributionManagement>
</project>

View File

@ -1,4 +1,4 @@
<model>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-it0021-plugin</artifactId>
@ -25,4 +25,11 @@
</profile>
</profiles>
</model>
<distributionManagement>
<repository>
<id>test-repo</id>
<name>Test Repository</name>
<url>file:/tmp/testRepo</url>
</repository>
</distributionManagement>
</project>

View File

@ -0,0 +1 @@
target/generated-sources/org/apache/maven/it/it0031/Root.java

View File

@ -0,0 +1 @@
modello:java

View File

@ -0,0 +1,24 @@
<model>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-it0031</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-core-it-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<pluginItem>${test}</pluginItem>
</configuration>
</plugin>
<!-- plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-projecthelp-plugin</artifactId>
<version>2.0-alpha-3-SNAPSHOT</version>
</plugin -->
</plugins>
</build>
</model>

View File

@ -0,0 +1,19 @@
<settings>
<pluginGroups>
<pluginGroup>org.codehaus.modello</pluginGroup>
</pluginGroups>
<mirrors>
<mirror>
<id>test</id>
<name>Test Mirror of ibiblio.org</name>
<url>http://test.maven.codehaus.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>test-plugins</id>
<name>Test Mirror of ibiblio.org Plugin Repository</name>
<url>http://test.maven.codehaus.org/maven2/plugins</url>
<mirrorOf>central-plugins</mirrorOf>
</mirror>
</mirrors>
</settings>

View File

@ -0,0 +1,20 @@
<model>
<id>lifecycle-mappings</id>
<name>LifecycleMappings</name>
<description><![CDATA[
test modello file.
]]></description>
<defaults>
<default>
<key>package</key>
<value>org.apache.maven.it.it0031</value>
</default>
</defaults>
<classes>
<class rootElement="true" xml.tagName="root">
<name>Root</name>
<version>1.0.0</version>
<description>Root element of the test model.</description>
</class>
</classes>
</model>

View File

@ -0,0 +1,3 @@
org.apache.maven.user-settings=settings.xml
model=src/main/mdo/test.mdo
version=1.0.0

View File

@ -0,0 +1 @@
failOnErrorOutput=false

View File

@ -186,17 +186,16 @@
<configuration>
<!-- START SNIPPET: maven-plugin-lifecycle -->
<phases>
<validate>plugin:validatePom</validate>
<generate-resources>plugin:descriptor</generate-resources>
<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>jar:jar</package>
<install>install:install</install>
<deploy>deploy:deploy</deploy>
<!-- install>install:install,plugin:install-mapping</install>
<deploy>deploy:deploy,plugin:deploy-mapping</deploy -->>
<package>jar:jar,plugin:generateUpdatedMapping</package>
<install>install:install,plugin:installMapping</install>
<deploy>deploy:deploy,plugin:deployMapping</deploy>
</phases>
<!-- END SNIPPET: maven-plugin-lifecycle -->
</configuration>

View File

@ -93,7 +93,7 @@ public class DefaultPluginMappingBuilder
try
{
repositoryMetadataManager.resolve( metadata, repository, localRepository, repository.getId() );
repositoryMetadataManager.resolve( metadata, repository, localRepository );
break;
}

View File

@ -0,0 +1,33 @@
package org.apache.maven.plugin.plugin;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
/**
* @phase validate
* @goal validatePom
*/
public class ValidatePluginPomMojo
extends AbstractMojo
{
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
public void execute()
throws MojoExecutionException
{
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
if ( distributionRepository == null )
{
throw new MojoExecutionException( "You must provide a distributionManagement section with a repository element in your POM." );
}
}
}

View File

@ -1,159 +0,0 @@
package org.apache.maven.plugin.plugin.metadata;
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.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import java.io.File;
public abstract class AbstractMetadataPublisherMojo
extends AbstractMojo
{
/**
* @parameter
*/
private String goalPrefix;
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
private ArtifactRepository localRepository;
/**
* @parameter expression="${project.build.directory}/repository-metadata"
* @required
* @readonly
*/
private String outputDirectory;
/**
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
* @required
* @readonly
*/
private RepositoryMetadataManager repositoryMetadataManager;
protected String getGroupId()
{
return project.getGroupId();
}
protected String getArtifactId()
{
return project.getArtifactId();
}
protected String getGoalPrefix()
{
if ( goalPrefix == null )
{
goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( getArtifactId() );
}
return goalPrefix;
}
protected void publish( boolean doDeploy )
throws MojoExecutionException
{
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
String remoteRepositoryId = "local";
if( distributionRepository != null )
{
remoteRepositoryId = distributionRepository.getId();
}
else if ( doDeploy )
{
throw new MojoExecutionException( "You must provide a distribution repository for your plugin." );
}
RepositoryMetadata metadata = createMetadataInstance();
try
{
repositoryMetadataManager.resolve( metadata, distributionRepository, localRepository, remoteRepositoryId );
}
catch ( RepositoryMetadataManagementException e )
{
Throwable cause = e.getCause();
if ( cause == null || ( cause instanceof ResourceDoesNotExistException ) )
{
getLog().debug( "Cannot find remote repository metadata for: " + metadata.getRepositoryPath() + "; creating new metadata resource..." );
metadata.setFile( null );
}
else
{
throw new MojoExecutionException( "Cannot retrieve plugin-mapping metadata for: "
+ metadata.getRepositoryPath(), e );
}
}
updateMetadata( metadata );
if ( distributionRepository != null )
{
try
{
repositoryMetadataManager.install( metadata, localRepository, remoteRepositoryId );
}
catch ( RepositoryMetadataManagementException e )
{
throw new MojoExecutionException( "Error installing plugin-mapping metadata to local repository.", e );
}
if ( doDeploy )
{
try
{
repositoryMetadataManager.deploy( metadata, distributionRepository );
}
catch ( RepositoryMetadataManagementException e )
{
throw new MojoExecutionException(
"Error deploying plugin-mapping metadata to distribution repository: "
+ distributionRepository.getId(), e );
}
}
}
}
protected File getMetadataFile( String path )
{
File metadataFile = new File( outputDirectory, path ).getAbsoluteFile();
File dir = metadataFile.getParentFile();
if ( !dir.exists() )
{
dir.mkdirs();
}
return metadataFile;
}
protected abstract void updateMetadata( RepositoryMetadata metadata )
throws MojoExecutionException;
protected abstract RepositoryMetadata createMetadataInstance();
}

View File

@ -1,125 +0,0 @@
package org.apache.maven.plugin.plugin.metadata;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.mapping.MappedPlugin;
import org.apache.maven.plugin.mapping.PluginMap;
import org.apache.maven.plugin.mapping.io.xpp3.PluginMappingXpp3Reader;
import org.apache.maven.plugin.mapping.io.xpp3.PluginMappingXpp3Writer;
import org.apache.maven.plugin.mapping.metadata.PluginMappingMetadata;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
public abstract class AbstractPluginMappingPublisherMojo
extends AbstractMetadataPublisherMojo
{
protected RepositoryMetadata createMetadataInstance()
{
return new PluginMappingMetadata( getGroupId() );
}
protected void updateMetadata( RepositoryMetadata metadata ) throws MojoExecutionException
{
PluginMappingXpp3Reader mappingReader = new PluginMappingXpp3Reader();
PluginMap pluginMap = null;
Reader reader = null;
File metadataFile = metadata.getFile();
if ( metadataFile != null )
{
try
{
reader = new FileReader( metadataFile );
pluginMap = mappingReader.read( reader );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot read plugin-mapping metadata from file: " + metadataFile, e );
}
catch ( XmlPullParserException e )
{
throw new MojoExecutionException( "Cannot parse plugin-mapping metadata from file: " + metadataFile, e );
}
finally
{
IOUtil.close( reader );
}
}
else
{
pluginMap = new PluginMap();
pluginMap.setGroupId( getGroupId() );
}
MappedPlugin mappedPlugin = new MappedPlugin();
mappedPlugin.setArtifactId( getArtifactId() );
mappedPlugin.setPrefix( getGoalPrefix() );
boolean prefixAlreadyMapped = false;
for ( Iterator it = pluginMap.getPlugins().iterator(); it.hasNext(); )
{
MappedPlugin preExisting = (MappedPlugin) it.next();
if ( preExisting.getPrefix().equals( getGoalPrefix() ) )
{
prefixAlreadyMapped = true;
if ( !preExisting.getArtifactId().equals( 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." );
}
}
}
if ( !prefixAlreadyMapped )
{
pluginMap.addPlugin( mappedPlugin );
Writer writer = null;
try
{
metadataFile = getMetadataFile( metadata.getRepositoryPath() );
writer = new FileWriter( metadataFile );
PluginMappingXpp3Writer mappingWriter = new PluginMappingXpp3Writer();
mappingWriter.write( writer, pluginMap );
metadata.setFile( metadataFile );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error writing repository metadata to build directory.", e );
}
finally
{
IOUtil.close( writer );
}
}
}
}

View File

@ -0,0 +1,200 @@
package org.apache.maven.plugin.plugin.metadata;
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.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.mapping.MappedPlugin;
import org.apache.maven.plugin.mapping.PluginMap;
import org.apache.maven.plugin.mapping.io.xpp3.PluginMappingXpp3Reader;
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.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Iterator;
/**
* @phase package
* @goal generateUpdatedMapping
*/
public class GenerateUpdatedMappingMojo
extends AbstractMojo
{
/**
* @parameter
*/
private String goalPrefix;
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter expression="${project.build.directory}/repository-metadata"
* @required
* @readonly
*/
private String outputDirectory;
/**
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
* @required
* @readonly
*/
private RepositoryMetadataManager repositoryMetadataManager;
/**
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
private ArtifactRepository localRepository;
public void execute() throws MojoExecutionException
{
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
PluginMappingXpp3Reader mappingReader = new PluginMappingXpp3Reader();
PluginMap pluginMap = null;
RepositoryMetadata metadata = new PluginMappingMetadata( project.getGroupId() );
try
{
repositoryMetadataManager.resolve( metadata, distributionRepository, localRepository );
Reader reader = null;
File metadataFile = metadata.getFile();
try
{
reader = new FileReader( metadataFile );
pluginMap = mappingReader.read( reader );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Cannot read plugin-mapping metadata from file: " + metadataFile, e );
}
catch ( XmlPullParserException e )
{
throw new MojoExecutionException( "Cannot parse plugin-mapping metadata from file: " + metadataFile, e );
}
finally
{
IOUtil.close( reader );
}
}
catch ( RepositoryMetadataManagementException e )
{
Throwable cause = e.getCause();
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 );
pluginMap = new PluginMap();
pluginMap.setGroupId( project.getGroupId() );
}
else
{
throw new MojoExecutionException( "Cannot resolve plugin-mapping metadata: " + metadata, e );
}
}
boolean prefixAlreadyMapped = false;
for ( Iterator it = pluginMap.getPlugins().iterator(); it.hasNext(); )
{
MappedPlugin preExisting = (MappedPlugin) it.next();
if ( preExisting.getPrefix().equals( getGoalPrefix() ) )
{
prefixAlreadyMapped = true;
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." );
}
break;
}
}
if ( !prefixAlreadyMapped )
{
MappedPlugin mappedPlugin = new MappedPlugin();
mappedPlugin.setArtifactId( project.getArtifactId() );
mappedPlugin.setPrefix( getGoalPrefix() );
pluginMap.addPlugin( mappedPlugin );
Writer writer = null;
try
{
File updatedMetadataFile = new File( outputDirectory, metadata.getRepositoryPath() ).getAbsoluteFile();
File dir = updatedMetadataFile.getParentFile();
if ( !dir.exists() )
{
dir.mkdirs();
}
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 );
}
}
}
private String getGoalPrefix()
{
if ( goalPrefix == null )
{
goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
}
return goalPrefix;
}
}

View File

@ -1,19 +1,69 @@
package org.apache.maven.plugin.plugin.metadata;
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.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.mapping.metadata.PluginMappingMetadata;
import org.apache.maven.project.MavenProject;
import java.io.File;
/**
* @goal deploy-mapping
* @goal deployMapping
* @phase deploy
*/
public class PluginMappingDeployMojo
extends AbstractPluginMappingPublisherMojo
extends AbstractMojo
{
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
* @required
* @readonly
*/
private RepositoryMetadataManager repositoryMetadataManager;
/**
* @parameter expression="${project.build.directory}/repository-metadata"
* @required
* @readonly
*/
private String outputDirectory;
public void execute()
throws MojoExecutionException
{
publish( true );
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
RepositoryMetadata metadata = new PluginMappingMetadata( project.getGroupId() );
File updatedMetadataFile = new File( outputDirectory, metadata.getRepositoryPath() ).getAbsoluteFile();
if ( !updatedMetadataFile.exists() )
{
throw new MojoExecutionException( "Cannot find updated " + metadata + " in file: \'" + updatedMetadataFile + "\'. This seems to indicate that the 'package' lifecycle phase didn't succeed." );
}
metadata.setFile( updatedMetadataFile );
try
{
repositoryMetadataManager.deploy( metadata, distributionRepository );
}
catch ( RepositoryMetadataManagementException e )
{
throw new MojoExecutionException( "Error updating plugin-mapping metadata.", e );
}
}
}

View File

@ -1,19 +1,78 @@
package org.apache.maven.plugin.plugin.metadata;
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.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.mapping.metadata.PluginMappingMetadata;
import org.apache.maven.project.MavenProject;
import java.io.File;
/**
* @goal install-mapping
* @goal installMapping
* @phase install
*/
public class PluginMappingInstallMojo
extends AbstractPluginMappingPublisherMojo
extends AbstractMojo
{
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/**
* @parameter expression="${component.org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager}"
* @required
* @readonly
*/
private RepositoryMetadataManager repositoryMetadataManager;
/**
* @parameter expression="${localRepository}"
* @required
* @readonly
*/
private ArtifactRepository localRepository;
/**
* @parameter expression="${project.build.directory}/repository-metadata"
* @required
* @readonly
*/
private String outputDirectory;
public void execute()
throws MojoExecutionException
{
publish( false );
ArtifactRepository distributionRepository = project.getDistributionManagementArtifactRepository();
String remoteRepositoryId = distributionRepository.getId();
RepositoryMetadata metadata = new PluginMappingMetadata( project.getGroupId() );
File updatedMetadataFile = new File( outputDirectory, metadata.getRepositoryPath() ).getAbsoluteFile();
if ( !updatedMetadataFile.exists() )
{
throw new MojoExecutionException( "Cannot find updated " + metadata + " in file: \'" + updatedMetadataFile + "\'. This seems to indicate that the 'package' lifecycle phase didn't succeed." );
}
metadata.setFile( updatedMetadataFile );
try
{
repositoryMetadataManager.install( metadata, localRepository, remoteRepositoryId );
}
catch ( RepositoryMetadataManagementException e )
{
throw new MojoExecutionException( "Failed to install " + metadata, e );
}
}
}