Skip to content

Commit

Permalink
Adopt to new GPG Mojo
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Nov 4, 2024
1 parent cbcf9fa commit ed2b986
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
4 changes: 4 additions & 0 deletions tycho-gpg-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<maven>${minimal-maven-version}</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@

import java.io.File;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;

public abstract class AbstractGpgMojoExtension extends AbstractGpgMojo {

@Override
protected ProxySignerWithPublicKeyAccess newSigner(MavenProject project)
throws MojoExecutionException, MojoFailureException {
protected ProxySignerWithPublicKeyAccess newSigner(MavenProject project) throws MojoFailureException {
return new ProxySignerWithPublicKeyAccess(super.newSigner(project), getSigner(), getPGPInfo(), getSecretKeys());
}

@Override
protected AbstractGpgSigner createSigner(String name) throws MojoFailureException {
return super.createSigner(getSigner());
}

protected String getSigner() {
return "gpg";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,14 @@ private String getKeys(boolean isPublic) throws MojoExecutionException {
throw new MojoExecutionException("Unable to execute gpg command", e);
}
}

@Override
public String signerName() {
return signer.signerName();
}

@Override
public String getKeyInfo() {
return signer.getKeyInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import java.security.Security;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.gpg.AbstractGpgSigner;
import org.apache.maven.plugins.gpg.BcSigner;
import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.bcpg.CompressionAlgorithmTags;
import org.bouncycastle.bcpg.HashAlgorithmTags;
Expand Down Expand Up @@ -57,6 +59,7 @@
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
import org.bouncycastle.openpgp.operator.bc.BcPGPKeyPair;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
import org.bouncycastle.util.encoders.Hex;

public class BouncyCastleSigner extends AbstractGpgSigner {

Expand Down Expand Up @@ -349,4 +352,18 @@ public static void main(String[] args) throws Exception {
signer.generateSignature(target.toFile());
}
}

@Override
public String signerName() {
return BcSigner.NAME;
}

@Override
public String getKeyInfo() {
Iterator<String> userIds = secretKey.getPublicKey().getUserIDs();
if (userIds.hasNext()) {
return userIds.next();
}
return Hex.toHexString(secretKey.getPublicKey().getFingerprint());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected File getSecretKeys() {
}

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
public void doExecute() throws MojoExecutionException, MojoFailureException {

var signer = newSigner(project);
var keys = KeyStore.create();
Expand Down

0 comments on commit ed2b986

Please sign in to comment.