Skip to content

Commit

Permalink
[MGPG-135] Support Overriding / Enhance the signer in AbstractGpgMojo (
Browse files Browse the repository at this point in the history
…#112)

Currently AbstractGpgMojo has a fixed set of supported signers (and how
they are constructed), it would be good to allow extensions (e.g. Tycho
is also using AbstractGpgMojo) to possibly override that aspect.

This extracts the creation of the signer into a (protected) method so
different types or alternative implementations can be used.

Co-authored-by: Christoph Läubrich <[email protected]>
  • Loading branch information
laeubi and Christoph Läubrich authored Aug 14, 2024
1 parent 3a31714 commit 1b40a05
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,7 @@ private void logBestPracticeWarning(String source) {
}

protected AbstractGpgSigner newSigner(MavenProject mavenProject) throws MojoFailureException {
AbstractGpgSigner signer;
if (GpgSigner.NAME.equals(this.signer)) {
signer = new GpgSigner(executable);
} else if (BcSigner.NAME.equals(this.signer)) {
signer = new BcSigner(
session.getRepositorySession(),
keyEnvName,
keyFingerprintEnvName,
agentSocketLocations,
keyFilePath,
keyFingerprint);
} else {
throw new MojoFailureException("Unknown signer: " + this.signer);
}
AbstractGpgSigner signer = createSigner(this.signer);

signer.setLog(getLog());
signer.setInteractive(settings.isInteractiveMode());
Expand Down Expand Up @@ -395,6 +382,24 @@ protected AbstractGpgSigner newSigner(MavenProject mavenProject) throws MojoFail
return signer;
}

protected AbstractGpgSigner createSigner(String name) throws MojoFailureException {
AbstractGpgSigner signer;
if (GpgSigner.NAME.equals(name)) {
signer = new GpgSigner(executable);
} else if (BcSigner.NAME.equals(name)) {
signer = new BcSigner(
session.getRepositorySession(),
keyEnvName,
keyFingerprintEnvName,
agentSocketLocations,
keyFilePath,
keyFingerprint);
} else {
throw new MojoFailureException("Unknown signer: " + name);
}
return signer;
}

private boolean isNotBlank(String string) {
return string != null && !string.trim().isEmpty();
}
Expand Down

0 comments on commit 1b40a05

Please sign in to comment.