diff --git a/takari-lifecycle-plugin/pom.xml b/takari-lifecycle-plugin/pom.xml index 319d8e20..a9410e04 100644 --- a/takari-lifecycle-plugin/pom.xml +++ b/takari-lifecycle-plugin/pom.xml @@ -201,12 +201,6 @@ commons-exec 1.4.0 - - - io.takari - jpgp - 1.0.13 - io.takari.m2e.workspace diff --git a/takari-lifecycle-plugin/src/main/java/io/takari/maven/plugins/pgp/SignArtifactMojo.java b/takari-lifecycle-plugin/src/main/java/io/takari/maven/plugins/pgp/SignArtifactMojo.java deleted file mode 100644 index 808ed046..00000000 --- a/takari-lifecycle-plugin/src/main/java/io/takari/maven/plugins/pgp/SignArtifactMojo.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2014-2024 Takari, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-v10.html - */ -package io.takari.maven.plugins.pgp; - -import static java.nio.file.Files.copy; -import static java.nio.file.Files.createDirectories; - -import io.takari.jpgp.ImmutablePgpSigningRequest; -import io.takari.jpgp.PgpSigner; -import io.takari.maven.plugins.TakariLifecycleMojo; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.List; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Mojo(name = "signArtifact", configurator = "takari", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true) -public class SignArtifactMojo extends TakariLifecycleMojo { - - public static final String PGP_SIGNATURE_EXTENSION = ".asc"; - private final Logger logger = LoggerFactory.getLogger(SignArtifactMojo.class); - - @Parameter(property = "gpg.skip", defaultValue = "false") - private boolean skip; - - @Parameter(property = "gpg.passphrase") - private String passphrase; - - @Override - protected void executeMojo() throws MojoExecutionException { - - if (skip) { - logger.info("Skipping PGP signature generation as per configuration."); - return; - } - - List mavenFilesToSign = new ArrayList<>(); - if (!"pom".equals(project.getPackaging())) { - // - // Primary artifact - // - org.apache.maven.artifact.Artifact artifact = project.getArtifact(); - File file = artifact.getFile(); - if (file == null) { - logger.info("There is no artifact present. Make sure you run this after the package phase."); - return; - } - mavenFilesToSign.add( - new SignedFile(file.toPath(), artifact.getArtifactHandler().getExtension())); - } - - // - // POM - // - File pomToSign = - new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".pom"); - try { - createDirectories(pomToSign.getParentFile().toPath()); - copy(project.getFile().toPath(), pomToSign.toPath(), StandardCopyOption.REPLACE_EXISTING); - mavenFilesToSign.add(new SignedFile(pomToSign.toPath(), "pom")); - } catch (IOException e) { - throw new MojoExecutionException("Error copying POM for signing.", e); - } - - // - // Attached artifacts - // - for (org.apache.maven.artifact.Artifact a : project.getAttachedArtifacts()) { - mavenFilesToSign.add( - new SignedFile(a.getFile().toPath(), a.getArtifactHandler().getExtension(), a.getClassifier())); - } - - logger.debug("Signing the following files with PGP:"); - mavenFilesToSign.forEach(s -> logger.debug(s.toString())); - PgpSigner pgpArtifactSigner = - new PgpSigner(ImmutablePgpSigningRequest.builder().build()); - for (SignedFile pgpSignedFile : mavenFilesToSign) { - Path file = pgpSignedFile.file(); - try { - File pgpSignature = pgpArtifactSigner.sign(file.toFile()); - projectHelper.attachArtifact( - project, - pgpSignedFile.extension() + PGP_SIGNATURE_EXTENSION, - pgpSignedFile.classifier(), - pgpSignature); - } catch (Exception e) { - throw new MojoExecutionException("Error signing artifact " + file + ".", e); - } - } - } -} diff --git a/takari-lifecycle-plugin/src/main/java/io/takari/maven/plugins/pgp/SignedFile.java b/takari-lifecycle-plugin/src/main/java/io/takari/maven/plugins/pgp/SignedFile.java deleted file mode 100644 index 8074d472..00000000 --- a/takari-lifecycle-plugin/src/main/java/io/takari/maven/plugins/pgp/SignedFile.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2014-2024 Takari, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-v10.html - */ -package io.takari.maven.plugins.pgp; - -// -// Copyright 2021 The Sigstore Authors. -// -// Licensed 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. -// - -import java.nio.file.Path; - -public class SignedFile { - - private final Path file; - private final String extension; - private final String classifier; - - public SignedFile(Path file, String extension) { - this(file, extension, null); - } - - public SignedFile(Path file, String extension, String classifier) { - this.file = file; - this.extension = extension; - this.classifier = classifier; - } - - public Path file() { - return file; - } - - public String extension() { - return extension; - } - - public String classifier() { - return classifier; - } - - @Override - public String toString() { - return "SignedFile{" + "file=" - + file + ", extension='" - + extension + '\'' + ", classifier='" - + classifier + '\'' + '}'; - } -}