diff --git a/pom.xml b/pom.xml index 0bde314..52734f0 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ de.eitco.cicd bom-maven-plugin - 5.0.1-SNAPSHOT + 5.1.0-SNAPSHOT maven-plugin diff --git a/src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java b/src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java index cfc2d0c..7bc0d37 100644 --- a/src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java +++ b/src/main/java/de/eitco/cicd/bom/AbstractBillOfMaterialsMojo.java @@ -41,16 +41,21 @@ public abstract class AbstractBillOfMaterialsMojo extends AbstractMojo { protected Artifact makeBomArtifact() { - Artifact result = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, "pom", null); + Artifact result = makeArtifact("pom"); result.setFile(targetFile); return result; } + protected Artifact makeArtifact(String extension) { + + return artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, extension, null); + } + protected Artifact makeSignatureArtifact() { - Artifact result = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, "pom" + signatureExtension, null); + Artifact result = makeArtifact("pom" + signatureExtension); result.setFile(makeSignatureFile()); diff --git a/src/main/java/de/eitco/cicd/bom/CreateBomChecksumsMojo.java b/src/main/java/de/eitco/cicd/bom/CreateBomChecksumsMojo.java new file mode 100644 index 0000000..30c0970 --- /dev/null +++ b/src/main/java/de/eitco/cicd/bom/CreateBomChecksumsMojo.java @@ -0,0 +1,50 @@ +package de.eitco.cicd.bom; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.install.DualDigester; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; + +@Mojo(name = "checksums", defaultPhase = LifecyclePhase.PROCESS_SOURCES) +public class CreateBomChecksumsMojo extends AbstractBillOfMaterialsMojo { + + private final DualDigester digester = new DualDigester(); + + @Override + public void execute() throws MojoExecutionException { + + File bomFile = makeBomArtifact().getFile(); + + digester.calculate(bomFile); + + attachChecksum(bomFile, ".md5", digester.getMd5()); + attachChecksum(bomFile, ".sha1", digester.getSha1()); + } + + private void attachChecksum(File bomFile, String extension, String checksum) throws MojoExecutionException { + + try { + + File checksumFile = new File(bomFile.getAbsolutePath() + extension); + + Files.writeString(checksumFile.toPath(), checksum); + + Artifact artifact = makeArtifact("pom" + extension); + + artifact.setFile(checksumFile); + project.addAttachedArtifact(artifact); + + } catch (IOException e) { + + throw new MojoExecutionException(e); + } + + } + + +}