From 5db2c4cf56489ab0994347b6ef1bef1e1d1305d1 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Thu, 24 Mar 2005 12:22:05 +0000 Subject: [PATCH] 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 --- .../artifact/metadata/MavenMetadata.java | 39 +++++++++++++++---- .../maven/plugin/deploy/DeployMojo.java | 4 +- .../maven/plugin/install/InstallMojo.java | 4 +- 3 files changed, 36 insertions(+), 11 deletions(-) rename maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ModelMetadata.java => maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java (59%) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ModelMetadata.java b/maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java similarity index 59% rename from maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ModelMetadata.java rename to maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java index 327d813950..7a8b9e828e 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ModelMetadata.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/metadata/MavenMetadata.java @@ -20,10 +20,14 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.repository.ArtifactRepository; 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.IOException; +import java.io.FileReader; +import java.io.FileWriter; /** * Attach a POM to an artifact. @@ -31,12 +35,12 @@ import java.io.IOException; * @author Brett Porter * @version $Id$ */ -public class ModelMetadata +public class MavenMetadata extends AbstractArtifactMetadata { private final File file; - public ModelMetadata( Artifact artifact, File file ) + public MavenMetadata( Artifact artifact, File file ) { super( artifact, "pom" ); this.file = file; @@ -45,17 +49,38 @@ public class ModelMetadata public void storeInLocalRepository( ArtifactRepository localRepository ) throws ArtifactMetadataRetrievalException { + File destination; try { - FileUtils.copyFile( file, new File( localRepository.getBasedir(), localRepository.pathOfMetadata( this ) ) ); + destination = new File( localRepository.getBasedir(), localRepository.pathOfMetadata( this ) ); } catch ( ArtifactPathFormatException 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 ); } } diff --git a/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java b/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java index d2667403e5..ce52dcc766 100644 --- a/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java +++ b/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java @@ -21,7 +21,7 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.deployer.ArtifactDeployer; import org.apache.maven.artifact.deployer.ArtifactDeploymentException; 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.plugin.AbstractPlugin; import org.apache.maven.plugin.PluginExecutionException; @@ -93,7 +93,7 @@ public class DeployMojo File pom = new File( project.getFile().getParentFile(), "pom.xml" ); if ( !isPomArtifact ) { - ArtifactMetadata metadata = new ModelMetadata( artifact, pom ); + ArtifactMetadata metadata = new MavenMetadata( artifact, pom ); artifact.addMetadata( metadata ); } diff --git a/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java b/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java index f0af537627..1f3639a178 100644 --- a/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java +++ b/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallMojo.java @@ -21,7 +21,7 @@ import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.installer.ArtifactInstallationException; import org.apache.maven.artifact.installer.ArtifactInstaller; 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.plugin.AbstractPlugin; import org.apache.maven.plugin.PluginExecutionException; @@ -72,7 +72,7 @@ public class InstallMojo File pom = new File( project.getFile().getParentFile(), "pom.xml" ); if ( !isPomArtifact ) { - ArtifactMetadata metadata = new ModelMetadata( artifact, pom ); + ArtifactMetadata metadata = new MavenMetadata( artifact, pom ); artifact.addMetadata( metadata ); }