diff --git a/src/main/java/org/apache/maven/plugins/gpg/AbstractGpgSigner.java b/src/main/java/org/apache/maven/plugins/gpg/AbstractGpgSigner.java index 78f50f6..977a575 100644 --- a/src/main/java/org/apache/maven/plugins/gpg/AbstractGpgSigner.java +++ b/src/main/java/org/apache/maven/plugins/gpg/AbstractGpgSigner.java @@ -174,14 +174,11 @@ public File generateSignatureForArtifact( File file ) while ( ( signatureDirectory = signatureDirectory.getParentFile() ) != null ) { - if ( !signatureDirectory.equals( baseDir ) ) - { - fileDirectory = signatureDirectory.getName() + File.separatorChar + fileDirectory; - } - else + if ( isPossibleRootOfArtifact( signatureDirectory ) ) { break; } + fileDirectory = signatureDirectory.getName() + File.separatorChar + fileDirectory; } signatureDirectory = new File( outputDir, fileDirectory ); if ( !signatureDirectory.exists() ) @@ -254,4 +251,11 @@ private char[] readPassword( String prompt ) { return System.console().readPassword(); } + + private boolean isPossibleRootOfArtifact( File signatureDirectory ) + { + return signatureDirectory.equals( outputDir ) + || signatureDirectory.equals( buildDir ) + || signatureDirectory.equals( baseDir ); + } } diff --git a/src/test/java/org/apache/maven/plugins/gpg/it/GpgSignArtifactIT.java b/src/test/java/org/apache/maven/plugins/gpg/it/GpgSignArtifactIT.java new file mode 100644 index 0000000..0cd72de --- /dev/null +++ b/src/test/java/org/apache/maven/plugins/gpg/it/GpgSignArtifactIT.java @@ -0,0 +1,92 @@ +package org.apache.maven.plugins.gpg.it; + +/* + * 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.shared.invoker.InvocationRequest; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.arrayContainingInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.runners.Parameterized.Parameter; +import static org.junit.runners.Parameterized.Parameters; + +@RunWith( Parameterized.class ) +public class GpgSignArtifactIT +{ + private final File mavenHome; + private final File localRepository; + private final File mavenUserSettings; + private final File gpgHome; + + public GpgSignArtifactIT() throws Exception + { + this.mavenHome = new File( System.getProperty( "maven.home" ) ); + this.localRepository = new File( System.getProperty( "localRepositoryPath" ) ); + this.mavenUserSettings = InvokerTestUtils.getTestResource( "/it/settings-with-passphrase.xml" ); + this.gpgHome = new File( System.getProperty( "gpg.homedir" ) ); + } + + @Parameters + public static Collection data() + { + return Arrays.asList( new Object[][] { + { "/it/sign-release-in-default-dir/pom.xml", "/target/gpg/tarballs/", + new String[] { "sign-release-in-default-dir-1.0.jar.asc" }}, + { "/it/sign-release-in-output-dir/pom.xml", "/target/signed-files/tarballs/", + new String[] { "sign-release-in-output-dir-1.0.jar.asc" }}, + { "/it/sign-release-in-root-dir/pom.xml", "/signed-files/tarballs/", + new String[] { "sign-release-in-root-dir-1.0.jar.asc" }}, + { "/it/sign-release-in-same-dir/pom.xml", "/target/tarballs/", + new String[] { "sign-release-in-same-dir-1.0.jar", "sign-release-in-same-dir-1.0.jar.asc" }}, + } ); + } + + @Parameter + public String pomPath; + @Parameter( 1 ) + public String expectedFileLocation; + @Parameter( 2 ) + public String[] expectedFiles; + + @Test + public void testPlacementOfArtifactInOutputDirectory() throws Exception + { + // given + final File pomFile = InvokerTestUtils.getTestResource( pomPath ); + final InvocationRequest request = InvokerTestUtils.createRequest( pomFile, mavenUserSettings, gpgHome ); + final File integrationTestRootDirectory = new File( pomFile.getParent() ); + final File expectedOutputDirectory = new File( integrationTestRootDirectory + expectedFileLocation ); + + // when + InvokerTestUtils.executeRequest( request, mavenHome, localRepository ); + + // then + assertThat( expectedOutputDirectory.exists(), equalTo( true ) ); + assertThat( expectedOutputDirectory.list(), arrayContainingInAnyOrder( expectedFiles ) ); + } + +} diff --git a/src/test/resources/it/settings-with-passphrase.xml b/src/test/resources/it/settings-with-passphrase.xml new file mode 100644 index 0000000..75aa832 --- /dev/null +++ b/src/test/resources/it/settings-with-passphrase.xml @@ -0,0 +1,66 @@ + + + + + + + + + it-repo + + true + + + + local.central + file://@settings.localRepository@ + + true + + + true + + + + + + local.central + file://@settings.localRepository@ + + true + + + true + + + + + + + + + gpg.passphrase + TEST + + + + diff --git a/src/test/resources/it/sign-release-in-default-dir/pom.xml b/src/test/resources/it/sign-release-in-default-dir/pom.xml new file mode 100644 index 0000000..da1d947 --- /dev/null +++ b/src/test/resources/it/sign-release-in-default-dir/pom.xml @@ -0,0 +1,117 @@ + + + + + + 4.0.0 + + org.apache.maven.its.gpg.srwopi + sign-release-in-default-dir + 1.0 + jar + + + Tests that signed artifacts are placed in the correct default folder structure. + Expected path: '/path/to/maven-gpg-plugin/target/gpg/tarballs' + + + + + + org.apache.maven.plugins + maven-gpg-plugin + @project.version@ + + + sign-artifacts + + sign + + + + + + + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + target/tarballs + false + + + + make-assembly + package + + single + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + + org.apache.maven.plugins + maven-install-plugin + 2.2 + + true + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + org.apache.maven.plugins + maven-resources-plugin + 2.2 + + + org.apache.maven.plugins + maven-source-plugin + 2.0.4 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.3.1 + + + + + diff --git a/src/test/resources/it/sign-release-in-output-dir/pom.xml b/src/test/resources/it/sign-release-in-output-dir/pom.xml new file mode 100644 index 0000000..ab51394 --- /dev/null +++ b/src/test/resources/it/sign-release-in-output-dir/pom.xml @@ -0,0 +1,120 @@ + + + + + + 4.0.0 + + org.apache.maven.its.gpg.srwopi + sign-release-in-output-dir + 1.0 + jar + + + Tests that signed artifacts are placed in the correct configured folder structure. + Expected path: '/path/to/maven-gpg-plugin/target/signed-files/tarballs' + + + + + + org.apache.maven.plugins + maven-gpg-plugin + @project.version@ + + target/signed-files + + + + sign-artifacts + + sign + + + + + + + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + target/tarballs + false + + + + make-assembly + package + + single + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + + org.apache.maven.plugins + maven-install-plugin + 2.2 + + true + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + org.apache.maven.plugins + maven-resources-plugin + 2.2 + + + org.apache.maven.plugins + maven-source-plugin + 2.0.4 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.3.1 + + + + + diff --git a/src/test/resources/it/sign-release-in-root-dir/pom.xml b/src/test/resources/it/sign-release-in-root-dir/pom.xml new file mode 100644 index 0000000..d4c231c --- /dev/null +++ b/src/test/resources/it/sign-release-in-root-dir/pom.xml @@ -0,0 +1,120 @@ + + + + + + 4.0.0 + + org.apache.maven.its.gpg.srwopi + sign-release-in-root-dir + 1.0 + jar + + + Tests that signed artifacts are placed in the correct configured folder structure. + Expected path: '/path/to/maven-gpg-plugin/signed-files/tarballs' + + + + + + org.apache.maven.plugins + maven-gpg-plugin + @project.version@ + + signed-files + + + + sign-artifacts + + sign + + + + + + + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + target/tarballs + false + + + + make-assembly + package + + single + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + + org.apache.maven.plugins + maven-install-plugin + 2.2 + + true + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + org.apache.maven.plugins + maven-resources-plugin + 2.2 + + + org.apache.maven.plugins + maven-source-plugin + 2.0.4 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.3.1 + + + + + diff --git a/src/test/resources/it/sign-release-in-same-dir/pom.xml b/src/test/resources/it/sign-release-in-same-dir/pom.xml new file mode 100644 index 0000000..77f4c98 --- /dev/null +++ b/src/test/resources/it/sign-release-in-same-dir/pom.xml @@ -0,0 +1,121 @@ + + + + + + 4.0.0 + + org.apache.maven.its.gpg.srwopi + sign-release-in-same-dir + 1.0 + jar + + + Tests that signed artifacts are placed in the correct configured folder structure. + Expected path: '/path/to/maven-gpg-plugin/target/tarballs' + Contains both the original file and the signed file + + + + + + org.apache.maven.plugins + maven-gpg-plugin + @project.version@ + + target/tarballs + + + + sign-artifacts + + sign + + + + + + + maven-assembly-plugin + 3.3.0 + + + jar-with-dependencies + + target/tarballs + false + + + + make-assembly + package + + single + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + + org.apache.maven.plugins + maven-install-plugin + 2.2 + + true + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1 + + + org.apache.maven.plugins + maven-resources-plugin + 2.2 + + + org.apache.maven.plugins + maven-source-plugin + 2.0.4 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.3.1 + + + + +