Skip to content

Commit

Permalink
Merge pull request #10 from apache/MDEPLOY-267_skip_release_snapshot_…
Browse files Browse the repository at this point in the history
…deply_parameter

[MDEPLOY-267] add parameters to deploy or not non snapshots or release (-DskipRelease or -DskipSnapshot)
  • Loading branch information
olamy committed May 18, 2020
2 parents 02ec0cb + 4291f5e commit 84d0a07
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 4 deletions.
83 changes: 83 additions & 0 deletions 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>
33 changes: 33 additions & 0 deletions 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;
40 changes: 40 additions & 0 deletions 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;
83 changes: 83 additions & 0 deletions 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>
33 changes: 33 additions & 0 deletions 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;
46 changes: 46 additions & 0 deletions 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;
15 changes: 12 additions & 3 deletions src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
Expand Up @@ -124,11 +124,17 @@ public class DeployMojo

/**
* 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.
Expand All @@ -140,7 +146,10 @@ public void execute()
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" );
}
Expand Down
Expand Up @@ -271,7 +271,7 @@ public void testSkippingDeploy()
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();

Expand Down

0 comments on commit 84d0a07

Please sign in to comment.