[MDEPLOY-267] change type of skip parameter to String with possible values releases,snapshots,true default will be false

Signed-off-by: olivier lamy <olamy@apache.org>
diff --git a/src/it/skip-release-jar/pom.xml b/src/it/skip-release-jar/pom.xml
new file mode 100644
index 0000000..3e57a45
--- /dev/null
+++ b/src/it/skip-release-jar/pom.xml
@@ -0,0 +1,83 @@
+<?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.srj</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>jar</packaging>
+
+  <description>
+    Tests the deployment of a simple release JAR has been skipped.
+  </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-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>releases</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-jar-plugin</artifactId>
+        <version>2.1</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/skip-release-jar/setup.bsh b/src/it/skip-release-jar/setup.bsh
new file mode 100644
index 0000000..bb1b4e8
--- /dev/null
+++ b/src/it/skip-release-jar/setup.bsh
@@ -0,0 +1,33 @@
+/*
+ * 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 org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/deploy/srj" );
+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/skip-release-jar/verify.bsh b/src/it/skip-release-jar/verify.bsh
new file mode 100644
index 0000000..6fe5701
--- /dev/null
+++ b/src/it/skip-release-jar/verify.bsh
@@ -0,0 +1,40 @@
+/*
+ * 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.*;
+
+String[] paths =
+{
+    "org/apache/maven/its/deploy/srj/test/maven-metadata.xml",
+    "org/apache/maven/its/deploy/srj/test/1.0/test-1.0.pom",
+    "org/apache/maven/its/deploy/srj/test/1.0/test-1.0.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( "File has been deployed: " + file.getAbsolutePath() );
+    }
+}
+
+return true;
diff --git a/src/it/skip-snapshot-jar/pom.xml b/src/it/skip-snapshot-jar/pom.xml
new file mode 100644
index 0000000..a58a66f
--- /dev/null
+++ b/src/it/skip-snapshot-jar/pom.xml
@@ -0,0 +1,83 @@
+<?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.ssj</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <description>
+    Tests the deployment of a simple snapshot JAR has been skipped.
+  </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-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>snapshots</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-jar-plugin</artifactId>
+        <version>2.1</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/skip-snapshot-jar/setup.bsh b/src/it/skip-snapshot-jar/setup.bsh
new file mode 100644
index 0000000..f35751b
--- /dev/null
+++ b/src/it/skip-snapshot-jar/setup.bsh
@@ -0,0 +1,33 @@
+/*
+ * 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 org.codehaus.plexus.util.*;
+
+File file = new File( localRepositoryPath, "org/apache/maven/its/deploy/ssj" );
+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/skip-snapshot-jar/verify.bsh b/src/it/skip-snapshot-jar/verify.bsh
new file mode 100644
index 0000000..1c35d56
--- /dev/null
+++ b/src/it/skip-snapshot-jar/verify.bsh
@@ -0,0 +1,46 @@
+/*
+ * 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.*;
+
+String[] paths =
+{
+    "org/apache/maven/its/deploy/ssj/test/maven-metadata.xml",
+    "org/apache/maven/its/deploy/ssj/test/1.0.0-SNAPSHOT/test-1.0.0-SNAPSHOT.pom",
+    "org/apache/maven/its/deploy/ssj/test/1.0.0-SNAPSHOT/test-1.0.0-SNAPSHOT.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 IllegalStateException( "File has been deployed: " + file.getAbsolutePath() );
+    }
+}
+
+File directory = new File( new File( basedir, "target/repo" ), "org/apache/maven/its/deploy/ssj/test/1.0.0-SNAPSHOT/" );
+if ( directory.exists() )
+{
+    throw new IllegalStateException( "directory exists: " + directory.getAbsolutePath() );
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index 0953ff6..5bc471d 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -124,11 +124,17 @@
 
     /**
      * Set this to 'true' to bypass artifact deploy
-     * 
+     * Since since 3.0.0-M2 it's not anymore a real boolean as it can have more than 2 values:
+     * <ul>
+     *     <li><code>true</code>: will skip as usual</li>
+     *     <li><code>releases</code>: will skip if current version of the project is a release</li>
+     *     <li><code>snapshots</code>: will skip if current version of the project is a snapshot</li>
+     *     <li>any other values will be considered as <code>false</code></li>
+     * </ul>
      * @since 2.4
      */
     @Parameter( property = "maven.deploy.skip", defaultValue = "false" )
-    private boolean skip;
+    private String skip = Boolean.FALSE.toString();
 
     /**
      * Component used to deploy project.
@@ -140,7 +146,10 @@
         throws MojoExecutionException, MojoFailureException
     {
         boolean addedDeployRequest = false;
-        if ( skip )
+        if ( Boolean.parseBoolean( skip )
+            || ( "releases".equals( skip ) && !ArtifactUtils.isSnapshot( project.getVersion() ) )
+            || ( "snapshots".equals( skip ) && ArtifactUtils.isSnapshot( project.getVersion() ) )
+        )
         {
             getLog().info( "Skipping artifact deployment" );
         }
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index 6c6f938..ee762ef 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -271,7 +271,7 @@
         assertEquals( "file", repo.getProtocol() );
         assertEquals( "file://" + getBasedir() + "/target/remote-repo/basic-deploy-test", repo.getUrl() );
 
-        setVariableValueToObject( mojo, "skip", Boolean.TRUE );
+        setVariableValueToObject( mojo, "skip", Boolean.TRUE.toString() );
         
         mojo.execute();