Skip to content

Commit bd92129

Browse files
committed
[MARTIFACT-50] add skipModules parameter
1 parent 73c17c3 commit bd92129

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<parent>
27+
<groupId>org.apache.maven.plugins.it</groupId>
28+
<artifactId>multi</artifactId>
29+
<version>1.0-SNAPSHOT</version>
30+
</parent>
31+
<artifactId>multi-mod-skip-module</artifactId>
32+
<name>multi-module module that will be skipped by configuring artifact plugin with skipModules</name>
33+
<description>then should not be added to buildinfo</description>
34+
</project>

src/it/buildinfo-skip-install-deploy/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<modules>
5151
<module>modSkipInstall</module>
5252
<module>modSkipDeploy</module>
53+
<module>modSkipModule</module>
5354
<module>modB</module>
5455
<module>modA</module>
5556
<module>modSkipAtEnd</module>
@@ -66,6 +67,11 @@
6667
<goals>
6768
<goal>buildinfo</goal>
6869
</goals>
70+
<configuration>
71+
<skipModules>
72+
<skipModule>*/*-module</skipModule>
73+
</skipModules>
74+
</configuration>
6975
</execution>
7076
</executions>
7177
</plugin>

src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
import java.io.OutputStreamWriter;
2525
import java.io.PrintWriter;
2626
import java.nio.charset.StandardCharsets;
27-
import java.nio.file.Files;
27+
import java.nio.file.*;
2828
import java.text.SimpleDateFormat;
2929
import java.util.Date;
3030
import java.util.List;
3131
import java.util.Map;
32+
import java.util.stream.Collectors;
3233

3334
import org.apache.maven.archiver.MavenArchiver;
3435
import org.apache.maven.artifact.Artifact;
@@ -90,6 +91,15 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
9091
@Parameter(property = "buildinfo.detect.skip", defaultValue = "true")
9192
private boolean detectSkip;
9293

94+
/**
95+
* Avoid taking fingerprints for modules specified as glob matching against <code>${groupId}/${artifactId}</code>.
96+
* @since 3.5.0
97+
*/
98+
@Parameter
99+
private List<String> skipModules;
100+
101+
private List<PathMatcher> skipModulesMatcher = null;
102+
93103
/**
94104
* Makes the generated {@code .buildinfo} file reproducible, by dropping detailed environment recording: OS will be
95105
* recorded as "Windows" or "Unix", JVM version as major version only.
@@ -274,7 +284,20 @@ private MavenProject getLastProject() {
274284
}
275285

276286
private boolean isSkip(MavenProject project) {
277-
return detectSkip && PluginUtil.isSkip(project);
287+
// manual/configured module skip
288+
boolean skipModule = false;
289+
if (skipModules != null && !skipModules.isEmpty()) {
290+
if (skipModulesMatcher == null) {
291+
FileSystem fs = FileSystems.getDefault();
292+
skipModulesMatcher = skipModules.stream()
293+
.map(i -> fs.getPathMatcher("glob:" + i))
294+
.collect(Collectors.toList());
295+
}
296+
Path path = Paths.get(project.getGroupId() + '/' + project.getArtifactId());
297+
skipModule = skipModulesMatcher.stream().anyMatch(m -> m.matches(path));
298+
}
299+
// detected skip
300+
return skipModule || (detectSkip && PluginUtil.isSkip(project));
278301
}
279302

280303
private Toolchain getToolchain() {

0 commit comments

Comments
 (0)