[MDEPLOY-78] Deploy with classifier does not deploy pom
authorBenjamin Bentmann <bentmann@apache.org>
Sun, 15 Mar 2009 21:43:33 +0000 (21:43 +0000)
committerBenjamin Bentmann <bentmann@apache.org>
Sun, 15 Mar 2009 21:43:33 +0000 (21:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@754768 13f79535-47bb-0310-9956-ffa450edef68

pom.xml
src/it/no-main-artifact-1/pom.xml [new file with mode: 0644]
src/it/no-main-artifact-1/setup.bsh [new file with mode: 0644]
src/it/no-main-artifact-1/verify.bsh [new file with mode: 0644]
src/it/no-main-artifact-2/pom.xml [new file with mode: 0644]
src/it/no-main-artifact-2/setup.bsh [new file with mode: 0644]
src/it/no-main-artifact-2/verify.bsh [new file with mode: 0644]
src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
src/main/java/org/apache/maven/plugin/deploy/DeployFileMojo.java
src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java

diff --git a/pom.xml b/pom.xml
index 0ad2fa6..5a219d7 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -116,6 +116,10 @@ under the License.
                 <pomInclude>*/pom.xml</pomInclude>
                 <pomInclude>*/non-default-pom.xml</pomInclude>
               </pomIncludes>
+              <pomExcludes>
+                <!-- TODO: Enabled this test once maven-install-plugin:2.3 is released and can be used -->
+                <pomExclude>no-main-artifact-1/*</pomExclude>
+              </pomExcludes>
               <preBuildHookScript>setup</preBuildHookScript>
               <postBuildHookScript>verify</postBuildHookScript>
               <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
diff --git a/src/it/no-main-artifact-1/pom.xml b/src/it/no-main-artifact-1/pom.xml
new file mode 100644 (file)
index 0000000..2c2f951
--- /dev/null
@@ -0,0 +1,106 @@
+<?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.nma1</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <description>
+    Tests the installation of a non-POM project that has no main artifact file but only attached artifacts (see
+    MDEPLOY-78). This variant of the test checks the build when target/classes is non-existent.
+  </description>
+
+  <properties>
+    <maven.test.skip>true</maven.test.skip>
+  </properties>
+
+  <distributionManagement>
+    <repository>
+      <id>it</id>
+      <url>file:///${basedir}/target/repo</url>
+    </repository>
+  </distributionManagement>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>1.1</version>
+        <configuration>
+          <tasks>
+            <!--
+            NOTE: The Compiler Plugin sets this as the main artifact file, should be non-existent for this test.
+            -->
+            <delete dir="target/classes"/>
+          </tasks>
+        </configuration>
+        <executions>
+          <execution>
+            <id>delete-output-dir</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.1</version>
+        <configuration>
+          <classifier>it</classifier>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-install-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3.1</version>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/no-main-artifact-1/setup.bsh b/src/it/no-main-artifact-1/setup.bsh
new file mode 100644 (file)
index 0000000..ca06fe5
--- /dev/null
@@ -0,0 +1,14 @@
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/deploy/nma1" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+file = new File( basedir, "target/repo" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
diff --git a/src/it/no-main-artifact-1/verify.bsh b/src/it/no-main-artifact-1/verify.bsh
new file mode 100644 (file)
index 0000000..45f849f
--- /dev/null
@@ -0,0 +1,21 @@
+import java.io.*;
+import java.util.*;
+
+String[] paths =
+{
+    "org/apache/maven/its/deploy/nma1/test/maven-metadata.xml",
+    "org/apache/maven/its/deploy/nma1/test/1.0/test-1.0.pom",
+    "org/apache/maven/its/deploy/nma1/test/1.0/test-1.0-it.jar",
+};
+
+for ( String path : paths )
+{
+    File file = new File( new File( basedir, "target/repo" ), path );
+    System.out.println( "Checking for existence of " + file );
+    if ( !file.isFile() )
+    {
+        throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
+    }
+}
+
+return true;
diff --git a/src/it/no-main-artifact-2/pom.xml b/src/it/no-main-artifact-2/pom.xml
new file mode 100644 (file)
index 0000000..e063973
--- /dev/null
@@ -0,0 +1,106 @@
+<?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.nma2</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <description>
+    Tests the installation of a non-POM project that has no main artifact file but only attached artifacts (see
+    MDEPLOY-78). This variant of the test checks the build when target/classes is existent.
+  </description>
+
+  <properties>
+    <maven.test.skip>true</maven.test.skip>
+  </properties>
+
+  <distributionManagement>
+    <repository>
+      <id>it</id>
+      <url>file:///${basedir}/target/repo</url>
+    </repository>
+  </distributionManagement>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>1.1</version>
+        <configuration>
+          <tasks>
+            <!--
+            NOTE: The Compiler Plugin sets this as the main artifact file, should be existent for this test.
+            -->
+            <mkdir dir="target/classes"/>
+          </tasks>
+        </configuration>
+        <executions>
+          <execution>
+            <id>make-output-dir</id>
+            <phase>verify</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.1</version>
+        <configuration>
+          <classifier>it</classifier>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-install-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.2</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.3.1</version>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/no-main-artifact-2/setup.bsh b/src/it/no-main-artifact-2/setup.bsh
new file mode 100644 (file)
index 0000000..33fcbbe
--- /dev/null
@@ -0,0 +1,14 @@
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/deploy/nma2" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+file = new File( basedir, "target/repo" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
diff --git a/src/it/no-main-artifact-2/verify.bsh b/src/it/no-main-artifact-2/verify.bsh
new file mode 100644 (file)
index 0000000..2a7c656
--- /dev/null
@@ -0,0 +1,21 @@
+import java.io.*;
+import java.util.*;
+
+String[] paths =
+{
+    "org/apache/maven/its/deploy/nma2/test/maven-metadata.xml",
+    "org/apache/maven/its/deploy/nma2/test/1.0/test-1.0.pom",
+    "org/apache/maven/its/deploy/nma2/test/1.0/test-1.0-it.jar",
+};
+
+for ( String path : paths )
+{
+    File file = new File( new File( basedir, "target/repo" ), path );
+    System.out.println( "Checking for existence of " + file );
+    if ( !file.isFile() )
+    {
+        throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
+    }
+}
+
+return true;
index fcdb0b6..5c3c08b 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.maven.plugin.deploy;
  */
 
 import org.apache.maven.artifact.deployer.ArtifactDeployer;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -37,6 +38,13 @@ public abstract class AbstractDeployMojo
     private ArtifactDeployer deployer;
 
     /**
+     * Component used to create an artifact.
+     *
+     * @component
+     */
+    protected ArtifactFactory artifactFactory;
+
+    /**
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
index 0bdbaec..b876e65 100644 (file)
@@ -21,7 +21,6 @@ package org.apache.maven.plugin.deploy;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
@@ -133,13 +132,6 @@ public class DeployFileMojo
     private String url;
 
     /**
-     * Component used to create an artifact
-     *
-     * @component
-     */
-    private ArtifactFactory artifactFactory;
-
-    /**
      * Component used to create a repository
      *
      * @component
index f060454..81a6db1 100644 (file)
@@ -168,13 +168,24 @@ public class DeployMojo
             {
                 File file = artifact.getFile();
 
-                if ( file != null && !file.isDirectory() )
+                if ( file != null && file.isFile() )
                 {
                     getDeployer().deploy( file, artifact, repo, getLocalRepository() );
                 }
                 else if ( !attachedArtifacts.isEmpty() )
                 {
-                    getLog().info( "No primary artifact to deploy, deploy attached artifacts instead." );
+                    getLog().info( "No primary artifact to deploy, deploying attached artifacts instead." );
+
+                    Artifact pomArtifact =
+                        artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
+                                                               artifact.getBaseVersion() );
+                    pomArtifact.setFile( pomFile );
+                    if ( updateReleaseInfo )
+                    {
+                        pomArtifact.setRelease( true );
+                    }
+
+                    getDeployer().deploy( pomFile, pomArtifact, repo, getLocalRepository() );
                 }
                 else
                 {