Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MGPG-135] Support Overriding / Enhance the signer in AbstractGpgMojo #112

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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