From 6623da7692506efd8ddf2b4b58f098b733a4d28f Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 24 Oct 2005 02:31:33 +0000 Subject: [PATCH] PR: MNG-1279 Submitted by: Philipp Meier Reviewed by: Brett Porter ability to write a pom on install-file git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@327918 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/install/InstallFileMojo.java | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java b/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java index ce10d0bdd9..baf65be1b2 100644 --- a/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java +++ b/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java @@ -17,11 +17,18 @@ package org.apache.maven.plugin.install; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.installer.ArtifactInstallationException; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.project.artifact.ProjectArtifactMetadata; +import org.codehaus.plexus.util.IOUtil; import java.io.File; +import java.io.FileWriter; +import java.io.IOException; /** * Installs a file in local repository. @@ -70,6 +77,12 @@ public class InstallFileMojo */ private File file; + /** + * @parameter expression="${generatePom}" + * @readonly + */ + private boolean generatePom = false; + /** * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}" * @required @@ -80,10 +93,42 @@ public class InstallFileMojo public void execute() throws MojoExecutionException { - // TODO: validate - // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't Artifact artifact = artifactFactory.createArtifact( groupId, artifactId, version, null, packaging ); + // TODO: check if it exists first, and default to true if not + if ( generatePom ) + { + FileWriter fw = null; + try + { + File tempFile = File.createTempFile( "mvninstall", ".pom" ); + tempFile.deleteOnExit(); + + Model model = new Model(); + model.setGroupId( groupId ); + model.setArtifactId( artifactId ); + model.setVersion( version ); + model.setPackaging( packaging ); + model.setDescription( "POM was created from install:install-file" ); + fw = new FileWriter( tempFile ); + tempFile.deleteOnExit(); + new MavenXpp3Writer().write( fw, model ); + ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, tempFile ); + artifact.addMetadata( metadata ); + } + catch ( IOException e ) + { + throw new MojoExecutionException( "Error writing temporary pom file: " + + e.getMessage(), e ); + } + finally + { + IOUtil.close( fw ); + } + } + + // TODO: validate + // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't try { installer.install( file, artifact, localRepository );