Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() )
Expand Down Expand Up @@ -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 );
}
}
Original file line number Diff line number Diff line change
@@ -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<Object[]> 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 ) );
}

}
66 changes: 66 additions & 0 deletions src/test/resources/it/settings-with-passphrase.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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.
-->

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>local.central</id>
<url>file://@settings.localRepository@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>file://@settings.localRepository@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<servers>
<server>
<id>gpg.passphrase</id>
<passphrase>TEST</passphrase>
</server>
</servers>

</settings>
117 changes: 117 additions & 0 deletions src/test/resources/it/sign-release-in-default-dir/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?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.gpg.srwopi</groupId>
<artifactId>sign-release-in-default-dir</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<description>
Tests that signed artifacts are placed in the correct default folder structure.
Expected path: '/path/to/maven-gpg-plugin/target/gpg/tarballs'
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>sign-artifacts</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Using assembly plugin to create folder structure -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<outputDirectory>target/tarballs</outputDirectory>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</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-install-plugin</artifactId>
<version>2.2</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</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-source-plugin</artifactId>
<version>2.0.4</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.3.1</version>
</plugin>
</plugins>
</build>

</project>
Loading