Skip to content

Commit

Permalink
[MARTIFACT-50] add skipModules parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Sep 28, 2023
1 parent 73c17c3 commit bd92129
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
34 changes: 34 additions & 0 deletions src/it/buildinfo-skip-install-deploy/modSkipModule/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>

<parent>
<groupId>org.apache.maven.plugins.it</groupId>
<artifactId>multi</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>multi-mod-skip-module</artifactId>
<name>multi-module module that will be skipped by configuring artifact plugin with skipModules</name>
<description>then should not be added to buildinfo</description>
</project>
6 changes: 6 additions & 0 deletions src/it/buildinfo-skip-install-deploy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<modules>
<module>modSkipInstall</module>
<module>modSkipDeploy</module>
<module>modSkipModule</module>
<module>modB</module>
<module>modA</module>
<module>modSkipAtEnd</module>
Expand All @@ -66,6 +67,11 @@
<goals>
<goal>buildinfo</goal>
</goals>
<configuration>
<skipModules>
<skipModule>*/*-module</skipModule>
</skipModules>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

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

/**
* Avoid taking fingerprints for modules specified as glob matching against <code>${groupId}/${artifactId}</code>.
* @since 3.5.0
*/
@Parameter
private List<String> skipModules;

private List<PathMatcher> skipModulesMatcher = null;

/**
* Makes the generated {@code .buildinfo} file reproducible, by dropping detailed environment recording: OS will be
* recorded as "Windows" or "Unix", JVM version as major version only.
Expand Down Expand Up @@ -274,7 +284,20 @@ private MavenProject getLastProject() {
}

private boolean isSkip(MavenProject project) {
return detectSkip && PluginUtil.isSkip(project);
// manual/configured module skip
boolean skipModule = false;
if (skipModules != null && !skipModules.isEmpty()) {
if (skipModulesMatcher == null) {
FileSystem fs = FileSystems.getDefault();
skipModulesMatcher = skipModules.stream()
.map(i -> fs.getPathMatcher("glob:" + i))
.collect(Collectors.toList());
}
Path path = Paths.get(project.getGroupId() + '/' + project.getArtifactId());
skipModule = skipModulesMatcher.stream().anyMatch(m -> m.matches(path));
}
// detected skip
return skipModule || (detectSkip && PluginUtil.isSkip(project));
}

private Toolchain getToolchain() {
Expand Down

0 comments on commit bd92129

Please sign in to comment.