Skip to content

Commit 12fbd63

Browse files
authored
Merge pull request #10 from Syquel/bugfix/MGPG-66
[MGPG-66] fix handling of excluded files
2 parents 4016721 + 4da6921 commit 12fbd63

File tree

3 files changed

+180
-3
lines changed

3 files changed

+180
-3
lines changed
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<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">
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<groupId>org.apache.maven.its.gpg.srwe</groupId>
26+
<artifactId>test</artifactId>
27+
<version>1.0</version>
28+
<packaging>jar</packaging>
29+
30+
<description>
31+
Tests the exclusion of signature files while signing.
32+
</description>
33+
34+
<properties>
35+
<maven.test.skip>true</maven.test.skip>
36+
</properties>
37+
38+
<build>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-compiler-plugin</artifactId>
43+
<version>2.0.2</version>
44+
</plugin>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-gpg-plugin</artifactId>
48+
<version>@project.version@</version>
49+
<configuration>
50+
<passphrase>TEST</passphrase>
51+
</configuration>
52+
<executions>
53+
<execution>
54+
<id>sign-artifacts</id>
55+
<goals>
56+
<goal>sign</goal>
57+
</goals>
58+
</execution>
59+
<execution>
60+
<!-- second signing run to test default exclusion of *.asc files -->
61+
<id>resign-artifacts</id>
62+
<goals>
63+
<goal>sign</goal>
64+
</goals>
65+
</execution>
66+
</executions>
67+
</plugin>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-install-plugin</artifactId>
71+
<version>2.2</version>
72+
<configuration>
73+
<updateReleaseInfo>true</updateReleaseInfo>
74+
</configuration>
75+
</plugin>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-jar-plugin</artifactId>
79+
<version>2.1</version>
80+
</plugin>
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-resources-plugin</artifactId>
84+
<version>2.2</version>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-source-plugin</artifactId>
89+
<version>2.0.4</version>
90+
<executions>
91+
<execution>
92+
<id>attach-sources</id>
93+
<goals>
94+
<goal>jar</goal>
95+
</goals>
96+
</execution>
97+
</executions>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-surefire-plugin</artifactId>
102+
<version>2.3.1</version>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
107+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
/*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
21+
import java.io.File;
22+
import java.nio.charset.StandardCharsets;
23+
import java.nio.file.Files;
24+
import java.util.List;
25+
import org.codehaus.plexus.util.FileUtils;
26+
27+
File artifactDir = new File( localRepositoryPath, "org/apache/maven/its/gpg/srwe/test/1.0" );
28+
29+
String[] expectedFiles = {
30+
"_remote.repositories",
31+
"test-1.0.pom",
32+
"test-1.0.pom.asc",
33+
"test-1.0.jar",
34+
"test-1.0.jar.asc",
35+
"test-1.0-sources.jar",
36+
"test-1.0-sources.jar.asc",
37+
};
38+
39+
for ( File file : artifactDir.listFiles() )
40+
{
41+
String fileName = file.getName();
42+
System.out.println( "Checking if file is expected: " + fileName );
43+
44+
boolean expected = false;
45+
for ( String expectedFile : expectedFiles )
46+
{
47+
if ( expectedFile.equals( fileName ) )
48+
{
49+
expected = true;
50+
break;
51+
}
52+
}
53+
54+
if ( !expected )
55+
{
56+
throw new Exception( "Unexpected file " + file );
57+
}
58+
}

src/main/java/org/apache/maven/plugins/gpg/GpgSignAttachedMojo.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.io.File;
2323
import java.io.IOException;
24+
import java.nio.file.Path;
2425
import java.util.ArrayList;
2526
import java.util.List;
2627

@@ -192,6 +193,12 @@ else if ( project.getAttachedArtifacts().isEmpty() )
192193

193194
File file = artifact.getFile();
194195

196+
if ( isExcluded( artifact ) )
197+
{
198+
getLog().debug( "Skipping generation of signature for excluded " + file );
199+
continue;
200+
}
201+
195202
getLog().debug( "Generating signature for " + file );
196203

197204
File signature = signer.generateSignatureForArtifact( file );
@@ -217,19 +224,24 @@ else if ( project.getAttachedArtifacts().isEmpty() )
217224
/**
218225
* Tests whether or not a name matches against at least one exclude pattern.
219226
*
220-
* @param name The name to match. Must not be <code>null</code>.
227+
* @param artifact The artifact to match. Must not be <code>null</code>.
221228
* @return <code>true</code> when the name matches against at least one exclude pattern, or <code>false</code>
222229
* otherwise.
223230
*/
224-
protected boolean isExcluded( String name )
231+
protected boolean isExcluded( Artifact artifact )
225232
{
233+
final Path projectBasePath = project.getBasedir().toPath();
234+
final Path artifactPath = artifact.getFile().toPath();
235+
final String relativeArtifactPath = projectBasePath.relativize( artifactPath ).toString();
236+
226237
for ( String exclude : excludes )
227238
{
228-
if ( SelectorUtils.matchPath( exclude, name ) )
239+
if ( SelectorUtils.matchPath( exclude, relativeArtifactPath ) )
229240
{
230241
return true;
231242
}
232243
}
244+
233245
return false;
234246
}
235247

0 commit comments

Comments
 (0)