From 23ab0535647d38efee5defe56b458b93d65a4ad3 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Tue, 19 Jul 2022 15:58:26 +0200 Subject: [PATCH] [MINSTALL-160] Generated POM is not installed if original POM exists (#36) When using generatePom=true with install-file Mojo, it will despite this copy existing POM if it is found embedded in JAR (and if it was built with Maven, it will find it). The generatePom should reuse POM values embedded from JAR but should generate (and install) new "empty POM" instead. --- src/it/MINSTALL-52/verify.groovy | 3 ++- .../org/apache/maven/plugins/install/InstallFileMojo.java | 8 ++++++-- .../apache/maven/plugins/install/InstallFileMojoTest.java | 6 ------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/it/MINSTALL-52/verify.groovy b/src/it/MINSTALL-52/verify.groovy index 21f7323..617b5ae 100644 --- a/src/it/MINSTALL-52/verify.groovy +++ b/src/it/MINSTALL-52/verify.groovy @@ -22,4 +22,5 @@ assert new File( basedir, "../../local-repo/org/apache/maven/plugins/install/its File buildLog = new File( basedir, 'build.log' ) assert buildLog.exists() -assert buildLog.text.contains( "[DEBUG] Using META-INF/maven/org.apache.maven.plugins.install.its/minstall52/pom.xml as pomFile" ) +assert buildLog.text.contains( "[DEBUG] Loading META-INF/maven/org.apache.maven.plugins.install.its/minstall52/pom.xml" ) +assert buildLog.text.contains( "[DEBUG] Using JAR embedded POM as pomFile" ) diff --git a/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java b/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java index aab859f..a006dac 100644 --- a/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java +++ b/src/main/java/org/apache/maven/plugins/install/InstallFileMojo.java @@ -206,7 +206,11 @@ public void execute() else { temporaryPom = readingPomFromJarFile(); - pomFile = temporaryPom; + if ( !Boolean.TRUE.equals( generatePom ) ) + { + pomFile = temporaryPom; + getLog().debug( "Using JAR embedded POM as pomFile" ); + } } if ( groupId == null || artifactId == null || version == null || packaging == null ) @@ -322,7 +326,7 @@ private File readingPomFromJarFile() if ( pomEntry.matcher( entry.getName() ).matches() ) { - getLog().debug( "Using " + entry.getName() + " as pomFile" ); + getLog().debug( "Loading " + entry.getName() ); InputStream pomInputStream = null; OutputStream pomOutputStream = null; diff --git a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java index c135d95..7efd90c 100644 --- a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java @@ -92,9 +92,6 @@ public void testBasicInstallFile() assignValuesForParameter( mojo ); mojo.execute(); - - File pomFile = (File) getVariableValueFromObject( mojo, "pomFile" ); - org.codehaus.plexus.util.FileUtils.forceDelete( pomFile ); File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "." + packaging ); @@ -122,9 +119,6 @@ public void testInstallFileWithClassifier() mojo.execute(); - File pomFile = (File) getVariableValueFromObject( mojo, "pomFile" ); - org.codehaus.plexus.util.FileUtils.forceDelete( pomFile ); - File installedArtifact = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "-" + classifier + "." + packaging );