[MDEPLOY-89] Skip won't work if distribution management is not specified
authorBenjamin Bentmann <bentmann@apache.org>
Sun, 20 Dec 2009 17:30:52 +0000 (17:30 +0000)
committerBenjamin Bentmann <bentmann@apache.org>
Sun, 20 Dec 2009 17:30:52 +0000 (17:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@892616 13f79535-47bb-0310-9956-ffa450edef68

src/it/skip/pom.xml [new file with mode: 0644]
src/it/skip/setup.bsh [new file with mode: 0644]
src/main/java/org/apache/maven/plugin/deploy/AbstractDeployMojo.java
src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java
src/test/java/org/apache/maven/plugin/deploy/DeployMojoTest.java
src/test/java/org/apache/maven/plugin/deploy/stubs/MavenProjectStub.java [new file with mode: 0644]
src/test/resources/unit/basic-deploy-pom/plugin-config.xml
src/test/resources/unit/basic-deploy-scp/plugin-config.xml
src/test/resources/unit/basic-deploy-test/plugin-config.xml
src/test/resources/unit/basic-deploy-with-attached-artifacts/plugin-config.xml

diff --git a/src/it/skip/pom.xml b/src/it/skip/pom.xml
new file mode 100644 (file)
index 0000000..0b50d38
--- /dev/null
@@ -0,0 +1,78 @@
+<?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.skip</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+
+  <description>
+    Tests the skipping of deployment upon user request via configuration.
+  </description>
+
+  <!-- NOTE: This must pass although the POM does not define <distributionManagement> (MDEPLOY-89) -->
+
+  <properties>
+    <maven.test.skip>true</maven.test.skip>
+  </properties>
+
+  <build>
+    <plugins>
+      <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>
+        <configuration>
+          <skip>true</skip>
+        </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>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-site-plugin</artifactId>
+        <version>2.0-beta-5</version>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/skip/setup.bsh b/src/it/skip/setup.bsh
new file mode 100644 (file)
index 0000000..b30a43f
--- /dev/null
@@ -0,0 +1,10 @@
+import java.io.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/deploy/skip" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
index 5382a68..a72416f 100644 (file)
@@ -44,7 +44,7 @@ public abstract class AbstractDeployMojo
     protected ArtifactFactory artifactFactory;
 
     /**
-     * @parameter expression="${localRepository}"
+     * @parameter default-value="${localRepository}"
      * @required
      * @readonly
      */
index 3562f41..b14ac57 100644 (file)
@@ -27,6 +27,7 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.artifact.ProjectArtifactMetadata;
 import org.codehaus.plexus.PlexusConstants;
 import org.codehaus.plexus.PlexusContainer;
@@ -58,6 +59,13 @@ public class DeployMojo
     private static final Pattern ALT_REPO_SYNTAX_PATTERN = Pattern.compile( "(.+)::(.+)::(.+)" );
 
     /**
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+
+    /**
      * @parameter default-value="${project.artifact}"
      * @required
      * @readonly
@@ -79,12 +87,6 @@ public class DeployMojo
     private File pomFile;
 
     /**
-     * @parameter expression="${project.distributionManagementArtifactRepository}"
-     * @readonly
-     */
-    private ArtifactRepository deploymentRepository;
-
-    /**
      * Specifies an alternative repository to which the project artifacts should be deployed ( other
      * than those specified in &lt;distributionManagement&gt; ).
      * <br/>
@@ -204,14 +206,6 @@ public class DeployMojo
     private ArtifactRepository getDeploymentRepository()
         throws MojoExecutionException, MojoFailureException
     {
-        if ( deploymentRepository == null && altDeploymentRepository == null )
-        {
-            String msg = "Deployment failed: repository element was not specified in the pom inside"
-                + " distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter";
-
-            throw new MojoExecutionException( msg );
-        }
-
         ArtifactRepository repo = null;
 
         if ( altDeploymentRepository != null )
@@ -247,7 +241,15 @@ public class DeployMojo
         
         if ( repo == null )
         {
-            repo = deploymentRepository;
+            repo = project.getDistributionManagementArtifactRepository();
+        }
+
+        if ( repo == null )
+        {
+            String msg = "Deployment failed: repository element was not specified in the POM inside"
+                + " distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter";
+
+            throw new MojoExecutionException( msg );
         }
 
         return repo;
index 3253a9e..219e353 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.maven.plugin.deploy.stubs.DeployArtifactStub;
 import org.apache.maven.plugin.deploy.stubs.ArtifactDeployerStub;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.FileUtils;
 
 /**
@@ -64,16 +65,27 @@ public class DeployMojoTest
         
         localRepo = new File( LOCAL_REPO );
 
-        if( localRepo.exists() )
+        if ( localRepo.exists() )
         {
             FileUtils.deleteDirectory( localRepo );
         }
 
-        if( remoteRepo.exists() )
+        if ( remoteRepo.exists() )
         {
             FileUtils.deleteDirectory( remoteRepo );
         }
     }
+
+    public void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+        
+        if( remoteRepo.exists() )
+        {
+            //FileUtils.deleteDirectory( remoteRepo );
+        }
+    }
     
     public void testDeployTestEnvironment()
         throws Exception
@@ -110,7 +122,7 @@ public class DeployMojoTest
         
         artifact.setFile( file );        
         
-        ArtifactRepositoryStub repo = ( ArtifactRepositoryStub ) getVariableValueFromObject( mojo, "deploymentRepository" );
+        ArtifactRepositoryStub repo = getRepoStub( mojo );
 
         assertNotNull( repo );
         
@@ -212,7 +224,7 @@ public class DeployMojoTest
 
         artifact.setFile( file );
 
-        ArtifactRepositoryStub repo = (ArtifactRepositoryStub) getVariableValueFromObject( mojo, "deploymentRepository" );
+        ArtifactRepositoryStub repo = getRepoStub( mojo );
 
         assertNotNull( repo );
 
@@ -258,7 +270,7 @@ public class DeployMojoTest
         
         artifact.setArtifactHandlerExtension( packaging );
         
-        ArtifactRepositoryStub repo = ( ArtifactRepositoryStub ) getVariableValueFromObject( mojo, "deploymentRepository" ); 
+        ArtifactRepositoryStub repo = getRepoStub( mojo );
         
         repo.setAppendToUrl( "basic-deploy-pom" );
         
@@ -315,7 +327,7 @@ public class DeployMojoTest
         
         artifact.setFile( testPom );
         
-        ArtifactRepositoryStub repo = ( ArtifactRepositoryStub ) getVariableValueFromObject( mojo, "deploymentRepository" ); 
+        ArtifactRepositoryStub repo = getRepoStub( mojo );
         
         repo.setAppendToUrl( "basic-deploy-updateReleaseParam" );        
         
@@ -373,7 +385,7 @@ public class DeployMojoTest
         
         List attachedArtifacts = ( ArrayList ) getVariableValueFromObject( mojo, "attachedArtifacts" );
 
-        ArtifactRepositoryStub repo = ( ArtifactRepositoryStub ) getVariableValueFromObject( mojo, "deploymentRepository" ); 
+        ArtifactRepositoryStub repo = getRepoStub( mojo );
         
         repo.setAppendToUrl( "basic-deploy-with-attached-artifacts" );          
         
@@ -543,15 +555,12 @@ public class DeployMojoTest
         }
         return expectedFiles.size();
     }    
-    
-    public void tearDown()
+
+    private ArtifactRepositoryStub getRepoStub( Object mojo )
         throws Exception
     {
-        super.tearDown();
-        
-        if( remoteRepo.exists() )
-        {
-            //FileUtils.deleteDirectory( remoteRepo );
-        }
+        MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
+        return (ArtifactRepositoryStub) project.getDistributionManagementArtifactRepository();
     }
+
 }
diff --git a/src/test/java/org/apache/maven/plugin/deploy/stubs/MavenProjectStub.java b/src/test/java/org/apache/maven/plugin/deploy/stubs/MavenProjectStub.java
new file mode 100644 (file)
index 0000000..3c8531f
--- /dev/null
@@ -0,0 +1,35 @@
+package org.apache.maven.plugin.deploy.stubs;
+
+/*
+ * 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 org.apache.maven.artifact.repository.ArtifactRepository;
+
+public class MavenProjectStub
+    extends org.apache.maven.plugin.testing.stubs.MavenProjectStub
+{
+
+    private ArtifactRepositoryStub deploymentRepository;
+
+    public ArtifactRepository getDistributionManagementArtifactRepository()
+    {
+        return deploymentRepository;
+    }
+
+}
index 6798337..06ca0c7 100644 (file)
@@ -28,7 +28,9 @@ under the License.
           <artifact implementation="org.apache.maven.plugin.deploy.stubs.DeployArtifactStub" />
           <attachedArtifacts />
           <localRepository>${localRepository}</localRepository>
-          <deploymentRepository implementation="org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub" />
+          <project implementation="org.apache.maven.plugin.deploy.stubs.MavenProjectStub">
+            <deploymentRepository implementation="org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub" />
+          </project>
           <updateReleaseInfo>true</updateReleaseInfo>
         </configuration>
       </plugin>
index 6604af0..c224f89 100644 (file)
@@ -28,7 +28,9 @@ under the License.
           <artifact implementation="org.apache.maven.plugin.deploy.stubs.DeployArtifactStub" />
           <attachedArtifacts />
           <localRepository>${localRepository}</localRepository>
-          <deploymentRepository implementation="org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub2" />
+          <project implementation="org.apache.maven.plugin.deploy.stubs.MavenProjectStub">
+            <deploymentRepository implementation="org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub2" />
+          </project>
           <updateReleaseInfo>false</updateReleaseInfo>
           <deployer implementation="org.apache.maven.plugin.deploy.stubs.ArtifactDeployerStub" />
         </configuration>
index 1957494..8e98c99 100644 (file)
Binary files a/src/test/resources/unit/basic-deploy-test/plugin-config.xml and b/src/test/resources/unit/basic-deploy-test/plugin-config.xml differ
index 3480fde..1db6aa5 100644 (file)
@@ -30,7 +30,9 @@ under the License.
             <attachedArtifact implementation="org.apache.maven.plugin.deploy.stubs.AttachedArtifactStub" />
           </attachedArtifacts>
           <localRepository>${localRepository}</localRepository>
-          <deploymentRepository implementation="org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub" />
+          <project implementation="org.apache.maven.plugin.deploy.stubs.MavenProjectStub">
+            <deploymentRepository implementation="org.apache.maven.plugin.deploy.stubs.ArtifactRepositoryStub" />
+          </project>
           <updateReleaseInfo>true</updateReleaseInfo>
         </configuration>
       </plugin>