Skip to content

Commit

Permalink
Merge branch 'gnodet-supports-build-consumer-pom'
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Sep 19, 2023
2 parents 90281bc + b1ba0f1 commit f52d02c
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
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;
Expand Down Expand Up @@ -162,6 +165,11 @@ void printArtifacts(MavenProject project) throws MojoExecutionException {
p.println(prefix + "coordinates=" + project.getGroupId() + ':' + project.getArtifactId());
}

Artifact consumerPom = project.getAttachedArtifacts().stream()
.filter(a -> "pom".equals(a.getType()) && "consumer".equals(a.getClassifier()))
.findAny()
.orElse(null);

int n = 0;
Artifact pomArtifact = new DefaultArtifact(
project.getGroupId(),
Expand All @@ -171,13 +179,23 @@ void printArtifacts(MavenProject project) throws MojoExecutionException {
"pom",
"",
artifactHandlerManager.getArtifactHandler("pom"));
pomArtifact.setFile(project.getFile());
if (consumerPom != null) {
try {
Path pomFile = Files.createTempFile(Paths.get(project.getBuild().getDirectory()), "consumer-", ".pom");
Files.copy(consumerPom.getFile().toPath(), pomFile, StandardCopyOption.REPLACE_EXISTING);
pomArtifact.setFile(pomFile.toFile());
} catch (IOException e) {
p.println("Error processing consumer POM: " + e);
}
} else {
pomArtifact.setFile(project.getFile());
}

artifacts.put(pomArtifact, prefix + n);
printFile(
prefix + n++,
pomArtifact.getGroupId(),
project.getFile(),
pomArtifact.getFile(),
project.getArtifactId() + '-' + project.getVersion() + ".pom");

if (project.getArtifact() == null) {
Expand All @@ -189,6 +207,10 @@ void printArtifacts(MavenProject project) throws MojoExecutionException {
}

for (Artifact attached : project.getAttachedArtifacts()) {
if (attached == consumerPom) {
// ignore consumer pom
continue;
}
if (attached.getType().endsWith(".asc")) {
// ignore pgp signatures
continue;
Expand Down

0 comments on commit f52d02c

Please sign in to comment.