You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2005/10/24 04:31:35 UTC
svn commit: r327918 -
/maven/components/trunk/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
Author: brett
Date: Sun Oct 23 19:31:33 2005
New Revision: 327918
URL: http://svn.apache.org/viewcvs?rev=327918&view=rev
Log:
PR: MNG-1279
Submitted by: Philipp Meier
Reviewed by: Brett Porter
ability to write a pom on install-file
Modified:
maven/components/trunk/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
Modified: maven/components/trunk/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java?rev=327918&r1=327917&r2=327918&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java Sun Oct 23 19:31:33 2005
@@ -17,11 +17,18 @@
*/
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.
@@ -71,6 +78,12 @@
private File file;
/**
+ * @parameter expression="${generatePom}"
+ * @readonly
+ */
+ private boolean generatePom = false;
+
+ /**
* @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
* @required
* @readonly
@@ -80,10 +93,42 @@
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 );