Skip to content

Commit

Permalink
[MARTIFACT-48] exclude glob on groupId/filename
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Sep 22, 2023
1 parent 4ee0299 commit 4d4c98a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
17 changes: 17 additions & 0 deletions src/it/buildinfo-multi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@

<build>
<plugins>
<plugin>
<groupId>org.spdx</groupId>
<artifactId>spdx-maven-plugin</artifactId>
<version>0.7.0</version>
<executions>
<execution>
<goals>
<goal>createSPDX</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
Expand All @@ -65,6 +77,11 @@
<goals>
<goal>buildinfo</goal>
</goals>
<configuration>
<ignore>
<ignore>*/*.spdx.json</ignore>
</ignore>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
2 changes: 2 additions & 0 deletions src/it/buildinfo-multi/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ assert buildinfo.contains( "version=1.0-SNAPSHOT" )
assert buildinfo.contains( "outputs.1.coordinates=org.apache.maven.plugins.it:multi-modA" )
assert buildinfo.contains( "outputs.1.0.filename=multi-modA-1.0-SNAPSHOT.pom" )
assert buildinfo.contains( "outputs.1.1.filename=multi-modA-1.0-SNAPSHOT.jar" )
assert !buildinfo.contains( "outputs.1.2.filename=" )
assert buildinfo.contains( "outputs.2.coordinates=org.apache.maven.plugins.it:multi-modB" )
assert buildinfo.contains( "outputs.2.0.filename=multi-modB-1.0-SNAPSHOT.pom" )
assert buildinfo.contains( "outputs.2.1.filename=multi-modB-1.0-SNAPSHOT.jar" )
assert !buildinfo.contains( "outputs.2.2.filename=" )
assert !buildinfo.contains( ".buildinfo" )
assert buildinfo.contains( "mvn.aggregate.artifact-id=multi-modB" )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -79,10 +78,10 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
private boolean ignoreJavadoc;

/**
* Artifacts to ignore, specified as <code>extension</code> or <code>classifier.extension</code>.
* Artifacts to ignore, specified as a glob matching against {@code groupId/filename}.
*/
@Parameter(property = "buildinfo.ignore", defaultValue = "")
private Set<String> ignore;
private List<String> ignore;

/**
* Detect projects/modules with install or deploy skipped: avoid taking fingerprints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.nio.file.*;
import java.util.*;
import java.util.stream.Collectors;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.maven.artifact.Artifact;
Expand All @@ -55,7 +50,7 @@ class BuildInfoWriter {
private final Map<Artifact, String> artifacts = new LinkedHashMap<>();
private int projectCount = -1;
private boolean ignoreJavadoc = true;
private Set<String> ignore;
private List<PathMatcher> ignore;
private Toolchain toolchain;

BuildInfoWriter(
Expand Down Expand Up @@ -223,6 +218,7 @@ void printArtifacts(MavenProject project) throws MojoExecutionException {
continue;
}
if (isIgnore(attached)) {
// TODO keep track of ignored attachments
continue;
}
printArtifact(prefix, n++, attached);
Expand Down Expand Up @@ -317,15 +313,14 @@ void setIgnoreJavadoc(boolean ignoreJavadoc) {
this.ignoreJavadoc = ignoreJavadoc;
}

void setIgnore(Set<String> ignore) {
this.ignore = ignore;
void setIgnore(List<String> ignore) {
FileSystem fs = FileSystems.getDefault();
this.ignore = ignore.stream().map(i -> fs.getPathMatcher("glob:" + i)).collect(Collectors.toList());
}

private boolean isIgnore(Artifact attached) {
String classifier = attached.getClassifier();
String extension = attached.getType();
String search = (classifier == null) ? "" : (classifier + '.') + extension;
return ignore.contains(search);
Path path = Paths.get(attached.getGroupId() + '/' + getArtifactFilename(attached));
return ignore.stream().anyMatch(m -> m.matches(path));
}

public void setToolchain(Toolchain toolchain) {
Expand Down

0 comments on commit 4d4c98a

Please sign in to comment.