You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2015/01/02 18:56:20 UTC
svn commit: r1649085 - in /maven/plugins/trunk/maven-install-plugin/src:
it/MINSTALL-52/ main/java/org/apache/maven/plugin/install/
test/resources/unit/install-file-basic-test/target/
test/resources/unit/install-file-test-generatePom/target/ test/resou...
Author: rfscholte
Date: Fri Jan 2 17:56:19 2015
New Revision: 1649085
URL: http://svn.apache.org/r1649085
Log:
[MINSTALL-110] install-file should also install bundled pom.xml from artifact
Adjusted src/it/MINSTALL-52/verify.groovy according to changes
Removed META-INF/maven from src/test/resources/unit/install-file-test-generatePom/target/maven-install-test-1.0-SNAPSHOT.jar to force generation of a pom
pom will be written to target directory, ignore these poms in target directories for unittests (which are under src/test/resources).
Modified:
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/verify.groovy
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-basic-test/target/ (props changed)
maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-test-generatePom/target/ (props changed)
maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-test-generatePom/target/maven-install-test-1.0-SNAPSHOT.jar
maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-with-classifier/target/ (props changed)
Modified: maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/verify.groovy?rev=1649085&r1=1649084&r2=1649085&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/verify.groovy (original)
+++ maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/verify.groovy Fri Jan 2 17:56:19 2015
@@ -22,4 +22,4 @@ assert new File( basedir, "../../local-r
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 for groupId, artifactId, packaging and version" )
+assert buildLog.text.contains( "[DEBUG] Using META-INF/maven/org.apache.maven.plugins.install.its/minstall52/pom.xml as pomFile" )
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=1649085&r1=1649084&r2=1649085&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 Jan 2 17:56:19 2015
@@ -21,8 +21,10 @@ package org.apache.maven.plugin.install;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.net.MalformedURLException;
@@ -51,10 +53,10 @@ import org.apache.maven.plugins.annotati
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
-import org.apache.maven.shared.utils.io.IOUtil;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.apache.maven.shared.utils.ReaderFactory;
import org.apache.maven.shared.utils.WriterFactory;
+import org.apache.maven.shared.utils.io.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* Installs a file in the local repository.
@@ -217,11 +219,12 @@ public class InstallFileMojo
{
boolean foundPom = false;
+ JarFile jarFile = null;
try
{
Pattern pomEntry = Pattern.compile( "META-INF/maven/.*/pom\\.xml" );
- JarFile jarFile = new JarFile( file );
+ jarFile = new JarFile( file );
Enumeration<JarEntry> jarEntries = jarFile.entries();
@@ -231,28 +234,36 @@ public class InstallFileMojo
if ( pomEntry.matcher( entry.getName() ).matches() )
{
- // CHECKSTYLE_OFF: LineLength
- getLog().debug( "Using " + entry.getName() + " for groupId, artifactId, packaging and version" );
- // CHECKSTYLE_ON: LineLength
+ getLog().debug( "Using " + entry.getName() + " as pomFile" );
foundPom = true;
InputStream pomInputStream = null;
+ OutputStream pomOutputStream = null;
try
{
pomInputStream = jarFile.getInputStream( entry );
+
+ String base = file.getName();
+ if ( base.indexOf( '.' ) > 0 )
+ {
+ base = base.substring( 0, base.lastIndexOf( '.' ) );
+ }
+ pomFile = new File( file.getParentFile(), base + ".pom" );
+
+ pomOutputStream = new FileOutputStream( pomFile );
+
+ IOUtil.copy( pomInputStream, pomOutputStream );
- processModel( readModel( pomInputStream ) );
+ processModel( readModel( pomFile ) );
break;
}
finally
{
- if ( pomInputStream != null )
- {
- pomInputStream.close();
- }
+ IOUtil.close( pomInputStream );
+ IOUtil.close( pomOutputStream );
}
}
}
@@ -266,7 +277,20 @@ public class InstallFileMojo
{
// ignore, artifact not packaged by Maven
}
-
+ finally
+ {
+ if( jarFile != null )
+ {
+ try
+ {
+ jarFile.close();
+ }
+ catch ( IOException e )
+ {
+ // we did our best
+ }
+ }
+ }
}
validateArtifactInformation();
@@ -382,40 +406,6 @@ public class InstallFileMojo
throws MojoExecutionException
{
Reader reader = null;
- try
- {
- reader = ReaderFactory.newXmlReader( pomFile );
- return new MavenXpp3Reader().read( reader );
- }
- catch ( FileNotFoundException e )
- {
- throw new MojoExecutionException( "File not found " + pomFile, e );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error reading POM " + pomFile, e );
- }
- catch ( XmlPullParserException e )
- {
- throw new MojoExecutionException( "Error parsing POM " + pomFile, e );
- }
- finally
- {
- IOUtil.close( reader );
- }
- }
-
- /**
- * Parses a POM.
- *
- * @param pomFile The path of the POM file to parse, must not be <code>null</code>.
- * @return The model from the POM file, never <code>null</code>.
- * @throws MojoExecutionException If the POM could not be parsed.
- */
- private Model readModel( InputStream pomFile )
- throws MojoExecutionException
- {
- Reader reader = null;
try
{
reader = ReaderFactory.newXmlReader( pomFile );
Propchange: maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-basic-test/target/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jan 2 17:56:19 2015
@@ -0,0 +1 @@
+maven-install-test-1.0-SNAPSHOT.pom
Propchange: maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-test-generatePom/target/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jan 2 17:56:19 2015
@@ -0,0 +1 @@
+maven-install-test-1.0-SNAPSHOT.pom
Modified: maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-test-generatePom/target/maven-install-test-1.0-SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-test-generatePom/target/maven-install-test-1.0-SNAPSHOT.jar?rev=1649085&r1=1649084&r2=1649085&view=diff
==============================================================================
Binary files - no diff available.
Propchange: maven/plugins/trunk/maven-install-plugin/src/test/resources/unit/install-file-with-classifier/target/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jan 2 17:56:19 2015
@@ -0,0 +1 @@
+maven-install-test-1.0-SNAPSHOT.pom