Skip to content

Commit 1b40a05

Browse files
laeubiChristoph Läubrich
and
Christoph Läubrich
authored
[MGPG-135] Support Overriding / Enhance the signer in AbstractGpgMojo (#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]>
1 parent 3a31714 commit 1b40a05

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/main/java/org/apache/maven/plugins/gpg/AbstractGpgMojo.java

+19-14
Original file line numberDiff line numberDiff line change
@@ -337,20 +337,7 @@ private void logBestPracticeWarning(String source) {
337337
}
338338

339339
protected AbstractGpgSigner newSigner(MavenProject mavenProject) throws MojoFailureException {
340-
AbstractGpgSigner signer;
341-
if (GpgSigner.NAME.equals(this.signer)) {
342-
signer = new GpgSigner(executable);
343-
} else if (BcSigner.NAME.equals(this.signer)) {
344-
signer = new BcSigner(
345-
session.getRepositorySession(),
346-
keyEnvName,
347-
keyFingerprintEnvName,
348-
agentSocketLocations,
349-
keyFilePath,
350-
keyFingerprint);
351-
} else {
352-
throw new MojoFailureException("Unknown signer: " + this.signer);
353-
}
340+
AbstractGpgSigner signer = createSigner(this.signer);
354341

355342
signer.setLog(getLog());
356343
signer.setInteractive(settings.isInteractiveMode());
@@ -395,6 +382,24 @@ protected AbstractGpgSigner newSigner(MavenProject mavenProject) throws MojoFail
395382
return signer;
396383
}
397384

385+
protected AbstractGpgSigner createSigner(String name) throws MojoFailureException {
386+
AbstractGpgSigner signer;
387+
if (GpgSigner.NAME.equals(name)) {
388+
signer = new GpgSigner(executable);
389+
} else if (BcSigner.NAME.equals(name)) {
390+
signer = new BcSigner(
391+
session.getRepositorySession(),
392+
keyEnvName,
393+
keyFingerprintEnvName,
394+
agentSocketLocations,
395+
keyFilePath,
396+
keyFingerprint);
397+
} else {
398+
throw new MojoFailureException("Unknown signer: " + name);
399+
}
400+
return signer;
401+
}
402+
398403
private boolean isNotBlank(String string) {
399404
return string != null && !string.trim().isEmpty();
400405
}

0 commit comments

Comments
 (0)