You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gb...@apache.org on 2016/11/18 22:35:24 UTC

svn commit: r1770444 - in /maven/plugins/trunk/maven-install-plugin/src: it/minstall-55/verify.bsh main/java/org/apache/maven/plugin/install/InstallFileMojo.java

Author: gboue
Date: Fri Nov 18 22:35:24 2016
New Revision: 1770444

URL: http://svn.apache.org/viewvc?rev=1770444&view=rev
Log:
[MINSTALL-110] install-file should also install bundled pom.xml from artifact.

Follow-up: make sure the POM file extracted from the archive is into a temporary folder, and that it is correctly deleted after installation.

Modified:
    maven/plugins/trunk/maven-install-plugin/src/it/minstall-55/verify.bsh
    maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java

Modified: maven/plugins/trunk/maven-install-plugin/src/it/minstall-55/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/minstall-55/verify.bsh?rev=1770444&r1=1770443&r2=1770444&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/it/minstall-55/verify.bsh (original)
+++ maven/plugins/trunk/maven-install-plugin/src/it/minstall-55/verify.bsh Fri Nov 18 22:35:24 2016
@@ -37,4 +37,10 @@ for ( String path : paths )
     }
 }
 
+File file = new File( basedir, "test-0.1.pom" );
+if ( !file.isFile() )
+{
+    throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
+}
+
 return true;

Modified: maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java?rev=1770444&r1=1770443&r2=1770444&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java (original)
+++ maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java Fri Nov 18 22:35:24 2016
@@ -213,13 +213,16 @@ public class InstallFileMojo
             getLog().debug( "localRepoPath: " + repositoryManager.getLocalRepositoryBasedir( buildingRequest ) );
         }
 
+        File temporaryPom = null;
+
         if ( pomFile != null )
         {
             processModel( readModel( pomFile ) );
         }
         else
         {
-            readingPomFromJarFile();
+            temporaryPom = readingPomFromJarFile();
+            pomFile = temporaryPom;
         }
 
         validateArtifactInformation();
@@ -261,8 +264,8 @@ public class InstallFileMojo
             }
             else
             {
-                File generatedPomFile = generatePomFile();
-                ProjectArtifactMetadata pomMetadata = new ProjectArtifactMetadata( artifact, generatedPomFile );
+                temporaryPom = generatePomFile();
+                ProjectArtifactMetadata pomMetadata = new ProjectArtifactMetadata( artifact, temporaryPom );
                 if ( Boolean.TRUE.equals( generatePom )
                     || ( generatePom == null && !getLocalRepoFile( buildingRequest, pomMetadata ).exists() ) )
                 {
@@ -273,7 +276,7 @@ public class InstallFileMojo
                     }
                     else
                     {
-                        project.setFile( generatedPomFile );
+                        project.setFile( temporaryPom );
                     }
                 }
                 else if ( generatePom == null )
@@ -306,6 +309,14 @@ public class InstallFileMojo
         {
             throw new MojoExecutionException( e.getMessage(), e );
         }
+        finally
+        {
+            if ( temporaryPom != null )
+            {
+                // noinspection ResultOfMethodCallIgnored
+                temporaryPom.delete();
+            }
+        }
     }
     
     /**
@@ -336,10 +347,10 @@ public class InstallFileMojo
         }
     }
 
-    private void readingPomFromJarFile()
+    private File readingPomFromJarFile()
         throws MojoExecutionException
     {
-        boolean foundPom = false;
+        File pomFile = null;
 
         JarFile jarFile = null;
         try
@@ -358,8 +369,6 @@ public class InstallFileMojo
                 {
                     getLog().debug( "Using " + entry.getName() + " as pomFile" );
 
-                    foundPom = true;
-
                     InputStream pomInputStream = null;
                     OutputStream pomOutputStream = null;
 
@@ -372,7 +381,7 @@ public class InstallFileMojo
                         {
                             base = base.substring( 0, base.lastIndexOf( '.' ) );
                         }
-                        pomFile = new File( file.getParentFile(), base + ".pom" );
+                        pomFile = File.createTempFile( base, ".pom" );
                         
                         pomOutputStream = new FileOutputStream( pomFile );
                         
@@ -396,7 +405,7 @@ public class InstallFileMojo
                 }
             }
 
-            if ( !foundPom )
+            if ( pomFile == null )
             {
                 getLog().info( "pom.xml not found in " + file.getName() );
             }
@@ -419,6 +428,7 @@ public class InstallFileMojo
                 }
             }
         }
+        return pomFile;
     }
 
     /**