Author: rfscholte
Date: Sat Jan  3 14:49:38 2015
New Revision: 1649209

URL: http://svn.apache.org/r1649209
Log:
[MDEPLOY-178] Use information provided in pom.xml of JAR

Added:
    
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/
   (with props)
    
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/invoker.properties
    
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/pom.xml
    
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/test.properties
    
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy
Modified:
    
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java

Propchange: 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/
------------------------------------------------------------------------------
--- bugtraq:logregex (added)
+++ bugtraq:logregex Sat Jan  3 14:49:38 2015
@@ -0,0 +1 @@
+MDEPLOY-\d+

Propchange: 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/
------------------------------------------------------------------------------
    bugtraq:url = http://jira.codehaus.org/browse/%BUGID%

Added: 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/invoker.properties?rev=1649209&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/invoker.properties
 (added)
+++ 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/invoker.properties
 Sat Jan  3 14:49:38 2015
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = package deploy:deploy-file
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/pom.xml?rev=1649209&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/pom.xml
 Sat Jan  3 14:49:38 2015
@@ -0,0 +1,46 @@
+<?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.deploy.its</groupId>
+  <artifactId>mdeploy178</artifactId>
+  <version>1.0</version>
+
+  <description>
+    Test to verify that the pom inside the jar in used when deploying the file
+  </description>
+
+  <url>https://jira.codehaus.org/browse/MDEPLOY-178</url>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Added: 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/test.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/test.properties?rev=1649209&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/test.properties
 (added)
+++ 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/test.properties
 Sat Jan  3 14:49:38 2015
@@ -0,0 +1,19 @@
+# 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.
+
+file = target/mdeploy178-1.0.jar
+url = file:target/repo
\ No newline at end of file

Added: 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy?rev=1649209&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy
 (added)
+++ 
maven/plugins/trunk/maven-deploy-plugin/src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy
 Sat Jan  3 14:49:38 2015
@@ -0,0 +1,29 @@
+/*
+ * 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, 
"target/repo/org/apache/maven/plugins/deploy/its/mdeploy178/1.0/mdeploy178-1.0.jar"
 ).exists()
+File deployedPom = new File( basedir, 
"target/repo/org/apache/maven/plugins/deploy/its/mdeploy178/1.0/mdeploy178-1.0.pom"
 )
+assert deployedPom.exists()
+
+File buildLog = new File( basedir, 'build.log' )
+assert buildLog.exists()
+assert buildLog.text.contains( "[DEBUG] Using 
META-INF/maven/org.apache.maven.plugins.deploy.its/mdeploy178/pom.xml as 
pomFile" )
+
+def pomProject = new XmlSlurper().parse( deployedPom )
+assert "https://jira.codehaus.org/browse/MDEPLOY-178".equals( 
pomProject.url.text() )
\ No newline at end of file

Modified: 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java?rev=1649209&r1=1649208&r2=1649209&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
 Sat Jan  3 14:49:38 2015
@@ -21,10 +21,17 @@ package org.apache.maven.plugin.deploy;
 
 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.util.Enumeration;
 import java.util.List;
+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.deployer.ArtifactDeploymentException;
@@ -202,14 +209,86 @@ public class DeployFileMojo
     void initProperties()
         throws MojoExecutionException
     {
-        // Process the supplied POM (if there is one)
         if ( pomFile != null )
         {
-            generatePom = false;
-
-            Model model = readModel( pomFile );
+            processModel( readModel( pomFile ) );
+        }
+        else
+        {
+            boolean foundPom = false;
 
-            processModel( model );
+            JarFile jarFile = null;
+            try
+            {
+                Pattern pomEntry = Pattern.compile( 
"META-INF/maven/.*/pom\\.xml" );
+
+                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() + " 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( pomFile ) );
+
+                            break;
+                        }
+                        finally
+                        {
+                            IOUtil.close( pomInputStream );
+                            IOUtil.close( pomOutputStream );
+                        }
+                    }
+                }
+
+                if ( !foundPom )
+                {
+                    getLog().info( "pom.xml not found in " + file.getName() );
+                }
+            }
+            catch ( IOException e )
+            {
+                // ignore, artifact not packaged by Maven
+            }
+            finally
+            {
+                if ( jarFile != null )
+                {
+                    try
+                    {
+                        jarFile.close();
+                    }
+                    catch ( IOException e )
+                    {
+                        // we did our best
+                    }
+                }
+            }
         }
 
         if ( packaging == null && file != null )


Reply via email to