rewrite POM with new version on deployment

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-03-24 12:22:05 +00:00
parent b9de151229
commit 5db2c4cf56
3 changed files with 36 additions and 11 deletions

View File

@ -20,10 +20,14 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException; import org.apache.maven.artifact.repository.layout.ArtifactPathFormatException;
import org.codehaus.plexus.util.FileUtils; import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.codehaus.plexus.util.IOUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.FileReader;
import java.io.FileWriter;
/** /**
* Attach a POM to an artifact. * Attach a POM to an artifact.
@ -31,12 +35,12 @@ import java.io.IOException;
* @author <a href="mailto:brett@apache.org">Brett Porter</a> * @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$ * @version $Id$
*/ */
public class ModelMetadata public class MavenMetadata
extends AbstractArtifactMetadata extends AbstractArtifactMetadata
{ {
private final File file; private final File file;
public ModelMetadata( Artifact artifact, File file ) public MavenMetadata( Artifact artifact, File file )
{ {
super( artifact, "pom" ); super( artifact, "pom" );
this.file = file; this.file = file;
@ -45,17 +49,38 @@ public class ModelMetadata
public void storeInLocalRepository( ArtifactRepository localRepository ) public void storeInLocalRepository( ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException throws ArtifactMetadataRetrievalException
{ {
File destination;
try try
{ {
FileUtils.copyFile( file, new File( localRepository.getBasedir(), localRepository.pathOfMetadata( this ) ) ); destination = new File( localRepository.getBasedir(), localRepository.pathOfMetadata( this ) );
} }
catch ( ArtifactPathFormatException e ) catch ( ArtifactPathFormatException e )
{ {
throw new ArtifactMetadataRetrievalException( "Unable to install POM", e ); throw new ArtifactMetadataRetrievalException( "Unable to install POM", e );
} }
catch ( IOException e )
FileReader reader = null;
FileWriter writer = null;
try
{ {
throw new ArtifactMetadataRetrievalException( "Unable to install POM", e ); reader = new FileReader( file );
writer = new FileWriter( destination );
MavenXpp3Reader modelReader = new MavenXpp3Reader();
Model model = modelReader.read( reader );
model.setVersion( getArtifact().getVersion() );
MavenXpp3Writer modelWriter = new MavenXpp3Writer();
modelWriter.write( writer, model );
}
catch ( Exception e )
{
throw new ArtifactMetadataRetrievalException( "Error rewriting POM", e );
}
finally
{
IOUtil.close( reader );
IOUtil.close( writer );
} }
} }

View File

@ -21,7 +21,7 @@ import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.deployer.ArtifactDeployer; import org.apache.maven.artifact.deployer.ArtifactDeployer;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException; import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ModelMetadata; import org.apache.maven.artifact.metadata.MavenMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractPlugin; import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionException; import org.apache.maven.plugin.PluginExecutionException;
@ -93,7 +93,7 @@ public class DeployMojo
File pom = new File( project.getFile().getParentFile(), "pom.xml" ); File pom = new File( project.getFile().getParentFile(), "pom.xml" );
if ( !isPomArtifact ) if ( !isPomArtifact )
{ {
ArtifactMetadata metadata = new ModelMetadata( artifact, pom ); ArtifactMetadata metadata = new MavenMetadata( artifact, pom );
artifact.addMetadata( metadata ); artifact.addMetadata( metadata );
} }

View File

@ -21,7 +21,7 @@ import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.installer.ArtifactInstallationException; import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.artifact.installer.ArtifactInstaller; import org.apache.maven.artifact.installer.ArtifactInstaller;
import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ModelMetadata; import org.apache.maven.artifact.metadata.MavenMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractPlugin; import org.apache.maven.plugin.AbstractPlugin;
import org.apache.maven.plugin.PluginExecutionException; import org.apache.maven.plugin.PluginExecutionException;
@ -72,7 +72,7 @@ public class InstallMojo
File pom = new File( project.getFile().getParentFile(), "pom.xml" ); File pom = new File( project.getFile().getParentFile(), "pom.xml" );
if ( !isPomArtifact ) if ( !isPomArtifact )
{ {
ArtifactMetadata metadata = new ModelMetadata( artifact, pom ); ArtifactMetadata metadata = new MavenMetadata( artifact, pom );
artifact.addMetadata( metadata ); artifact.addMetadata( metadata );
} }