Author: rfscholte
Date: Wed Jul 10 20:17:59 2013
New Revision: 1501956
URL: http://svn.apache.org/r1501956
Log:
[MINSTALL-52] install:install-file should default to a pom file found in the
jar if available
Added:
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/invoker.properties
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/pom.xml
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/test.properties
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/verify.groovy
Modified:
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
Added:
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/invoker.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/invoker.properties?rev=1501956&view=auto
==============================================================================
---
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/invoker.properties
(added)
+++
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/invoker.properties
Wed Jul 10 20:17:59 2013
@@ -0,0 +1 @@
+invoker.goals = package install:install-file
\ No newline at end of file
Added: maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/pom.xml
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/pom.xml?rev=1501956&view=auto
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/pom.xml (added)
+++ maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/pom.xml Wed Jul
10 20:17:59 2013
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.install.its</groupId>
+ <artifactId>minstall52</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <description>
+ Test to verify that the pom inside the jar in used when installing the file
+ </description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added:
maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/test.properties
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/test.properties?rev=1501956&view=auto
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/test.properties
(added)
+++ maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/test.properties
Wed Jul 10 20:17:59 2013
@@ -0,0 +1 @@
+file = target/minstall52-1.0-SNAPSHOT.jar
\ No newline at end of file
Added: 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=1501956&view=auto
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/verify.groovy
(added)
+++ maven/plugins/trunk/maven-install-plugin/src/it/MINSTALL-52/verify.groovy
Wed Jul 10 20:17:59 2013
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+assert new File( basedir,
"../../local-repo/org/apache/maven/plugins/install/its/minstall52/1.0-SNAPSHOT/minstall52-1.0-SNAPSHOT.jar"
).exists()
+assert new File( basedir,
"../../local-repo/org/apache/maven/plugins/install/its/minstall52/1.0-SNAPSHOT/minstall52-1.0-SNAPSHOT.pom"
).exists()
+
+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" )
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=1501956&r1=1501955&r2=1501956&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
Wed Jul 10 20:17:59 2013
@@ -19,6 +19,21 @@ package org.apache.maven.plugin.install;
* under the License.
*/
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.net.MalformedURLException;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.regex.Pattern;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.installer.ArtifactInstallationException;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
@@ -41,16 +56,6 @@ import org.codehaus.plexus.util.ReaderFa
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.MalformedURLException;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Map;
-
/**
* Installs a file in the local repository.
*
@@ -63,25 +68,25 @@ public class InstallFileMojo
{
/**
- * GroupId of the artifact to be installed. Retrieved from POM file if one
is specified.
+ * GroupId of the artifact to be installed. Retrieved from POM file if one
is specified or extracted from {@code pom.xml} in jar if available.
*/
@Parameter( property = "groupId" )
protected String groupId;
/**
- * ArtifactId of the artifact to be installed. Retrieved from POM file if
one is specified.
+ * ArtifactId of the artifact to be installed. Retrieved from POM file if
one is specified or extracted from {@code pom.xml} in jar if available.
*/
@Parameter( property = "artifactId" )
protected String artifactId;
/**
- * Version of the artifact to be installed. Retrieved from POM file if one
is specified.
+ * Version of the artifact to be installed. Retrieved from POM file if one
is specified or extracted from {@code pom.xml} in jar if available.
*/
@Parameter( property = "version" )
protected String version;
/**
- * Packaging type of the artifact to be installed. Retrieved from POM file
if one is specified.
+ * Packaging type of the artifact to be installed. Retrieved from POM file
if one is specified or extracted from {@code pom.xml} in jar if available.
*/
@Parameter( property = "packaging" )
protected String packaging;
@@ -203,6 +208,59 @@ public class InstallFileMojo
{
processModel( readModel( pomFile ) );
}
+ else
+ {
+ boolean foundPom = false;
+
+ try
+ {
+ Pattern pomEntry = Pattern.compile(
"META-INF/maven/.*/pom\\.xml" );
+
+ JarFile jarFile = new JarFile( file );
+
+ Enumeration<JarEntry> jarEntries = jarFile.entries();
+
+ while( jarEntries.hasMoreElements() )
+ {
+ JarEntry entry = jarEntries.nextElement();
+
+ if( pomEntry.matcher( entry.getName() ).matches() )
+ {
+ getLog().debug( "Using " + entry.getName() + " for
groupId, artifactId, packaging and version" );
+
+ foundPom = true;
+
+ InputStream pomInputStream = null;
+
+ try
+ {
+ pomInputStream = jarFile.getInputStream( entry );
+
+ processModel( readModel( pomInputStream ) );
+
+ break;
+ }
+ finally
+ {
+ if ( pomInputStream != null )
+ {
+ pomInputStream.close();
+ }
+ }
+ }
+ }
+
+ if ( !foundPom )
+ {
+ getLog().info( "pom.xml not found in " + file.getName() );
+ }
+ }
+ catch ( IOException e )
+ {
+ // ignore, artifact not packaged by Maven
+ }
+
+ }
validateArtifactInformation();
@@ -335,6 +393,40 @@ public class InstallFileMojo
}
/**
+ * 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 );
+ 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 );
+ }
+ }
+
+ /**
* Populates missing mojo parameters from the specified POM.
*
* @param model The POM to extract missing artifact coordinates from, must
not be <code>null</code>.