[MDEPLOY-106] Packaging should default to file extension if non is specified.
authorPaul Gier <pgier@apache.org>
Thu, 24 Feb 2011 17:23:43 +0000 (17:23 +0000)
committerPaul Gier <pgier@apache.org>
Thu, 24 Feb 2011 17:23:43 +0000 (17:23 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1074223 13f79535-47bb-0310-9956-ffa450edef68

src/it/deploy-default-packaging/invoker.properties [new file with mode: 0644]
src/it/deploy-default-packaging/lib/test-1.1.jar [new file with mode: 0644]
src/it/deploy-default-packaging/pom.xml [new file with mode: 0644]
src/it/deploy-default-packaging/setup.bsh [new file with mode: 0644]
src/it/deploy-default-packaging/test.properties [new file with mode: 0644]
src/it/deploy-default-packaging/verify.bsh [new file with mode: 0644]
src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java

diff --git a/src/it/deploy-default-packaging/invoker.properties b/src/it/deploy-default-packaging/invoker.properties
new file mode 100644 (file)
index 0000000..407c533
--- /dev/null
@@ -0,0 +1,2 @@
+# Clean build of the jars
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:deploy-file 
diff --git a/src/it/deploy-default-packaging/lib/test-1.1.jar b/src/it/deploy-default-packaging/lib/test-1.1.jar
new file mode 100644 (file)
index 0000000..40a41c3
Binary files /dev/null and b/src/it/deploy-default-packaging/lib/test-1.1.jar differ
diff --git a/src/it/deploy-default-packaging/pom.xml b/src/it/deploy-default-packaging/pom.xml
new file mode 100644 (file)
index 0000000..6394e35
--- /dev/null
@@ -0,0 +1,85 @@
+<?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.its.deploy</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>deploy-attached-sources</name>
+  <description>sample jar project with attached sources</description>
+  <url>http://jira.codehaus.org/browse/MDEPLOY-106</url>
+
+  <distributionManagement>
+    <repository>
+      <id>repo1</id>
+      <name>Maven Central Repository</name>
+      <url>scp://foo.org/m2/release</url>
+    </repository>
+    <snapshotRepository>
+      <id>repo1</id>
+      <name>Maven Central Repository</name>
+      <url>scp://foo.org/m2/snapshot</url>
+    </snapshotRepository>
+  </distributionManagement>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <version>2.1.2</version>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <goals>
+              <goal>jar-no-fork</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>2.7</version>
+        <executions>
+          <execution>
+            <id>attach-javadoc</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <!-- Deployments will be written to ${basedir}/target -->
+          <altDeploymentRepository>mine::default::file://${basedir}/target</altDeploymentRepository>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/deploy-default-packaging/setup.bsh b/src/it/deploy-default-packaging/setup.bsh
new file mode 100644 (file)
index 0000000..50f77bd
--- /dev/null
@@ -0,0 +1,7 @@
+import java.io.*;
+import java.util.*;
+
+file = new File( basedir, "target/repo" );
+file.mkdirs();
+
+return true;
diff --git a/src/it/deploy-default-packaging/test.properties b/src/it/deploy-default-packaging/test.properties
new file mode 100644 (file)
index 0000000..ac3d073
--- /dev/null
@@ -0,0 +1,6 @@
+# Properties passed to invocations of the deploy plugin
+groupId = org.apache.maven.test
+artifactId = test
+version = 1.1
+file = ${basedir}/lib/test-1.1.jar
+url = file://${basedir}/target/repo
diff --git a/src/it/deploy-default-packaging/verify.bsh b/src/it/deploy-default-packaging/verify.bsh
new file mode 100644 (file)
index 0000000..b72870a
--- /dev/null
@@ -0,0 +1,51 @@
+
+/*
+ * 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.
+ */
+
+import java.io.*;
+import java.util.*;
+import java.util.jar.*;
+import org.codehaus.plexus.util.*;
+
+boolean result = true;
+
+try
+{
+    File target = new File( basedir, "target" );
+    if ( !target.exists() || !target.isDirectory() )
+    {
+        System.err.println( "target file is missing or not a directory." );
+        return false;
+    }
+    
+    File deployedFile = new File ( target, "repo/org/apache/maven/test/test/1.1/test-1.1.jar" );
+    if ( !deployedFile.isFile() )
+    {
+        System.err.println( "Deployed file is missing or is not a directory: " + deployedFile);
+        return false;
+    }   
+        
+}
+catch( Throwable e )
+{
+    e.printStackTrace();
+    result = false;
+}
+
+return result;
index e946592..cec467c 100644 (file)
@@ -35,6 +35,7 @@ import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 import org.apache.maven.project.validation.ModelValidationResult;
 import org.apache.maven.project.validation.ModelValidator;
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.StringUtils;
@@ -98,6 +99,7 @@ public class DeployFileMojo
 
     /**
      * Type of the artifact to be deployed.  Retrieved from POM file if specified.
+     * Defaults to file extension if not specified via command line or POM.
      *
      * @parameter expression="${packaging}"
      */
@@ -209,6 +211,11 @@ public class DeployFileMojo
 
             processModel( model );
         }
+        
+        if ( packaging == null && file != null )
+        {
+            packaging = FileUtils.getExtension( file.getName() );
+        }
     }
 
     public void execute()
@@ -216,15 +223,15 @@ public class DeployFileMojo
     {
         failIfOffline();
 
-        initProperties();
-
-        validateArtifactInformation();
-
         if ( !file.exists() )
         {
             throw new MojoExecutionException( file.getPath() + " not found." );
         }
 
+        initProperties();
+
+        validateArtifactInformation();
+
         ArtifactRepositoryLayout layout = getLayout( repositoryLayout );
 
         ArtifactRepository deploymentRepository =