Skip to content

Commit 2be0a00

Browse files
authored
[MGPG-115] Show more info about key used to sign (#84)
Just show some usable feedback which key is used to sign. --- https://issues.apache.org/jira/browse/MGPG-115
1 parent 3631830 commit 2be0a00

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

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

+14
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,24 @@ public void setPublicKeyring(String path) {
124124

125125
public abstract String signerName();
126126

127+
/**
128+
* Must be invoked BEFORE signing!
129+
*
130+
* @since 3.2.0
131+
*/
127132
public void prepare() throws MojoFailureException {}
128133

134+
/**
135+
* Should return some identification about the used key for logging purposes.
136+
* Can be invoked only AFTER {@link #prepare()} was invoked.
137+
*
138+
* @since 3.2.2
139+
*/
140+
public abstract String getKeyInfo();
141+
129142
/**
130143
* Create a detached signature file for the provided file.
144+
* Can be invoked only AFTER {@link #prepare()} was invoked.
131145
*
132146
* @param file The file to sign
133147
* @return A reference to the generated signature file

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

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.time.LocalDateTime;
3434
import java.time.ZoneId;
3535
import java.util.Arrays;
36+
import java.util.Iterator;
3637
import java.util.List;
3738
import java.util.Locale;
3839
import java.util.stream.Collectors;
@@ -361,6 +362,15 @@ public void prepare() throws MojoFailureException {
361362
}
362363
}
363364

365+
@Override
366+
public String getKeyInfo() {
367+
Iterator<String> userIds = secretKey.getPublicKey().getUserIDs();
368+
if (userIds.hasNext()) {
369+
return userIds.next();
370+
}
371+
return Hex.toHexString(secretKey.getPublicKey().getFingerprint());
372+
}
373+
364374
@Override
365375
protected void generateSignatureForFile(File file, File signature) throws MojoExecutionException {
366376
try (InputStream in = Files.newInputStream(file.toPath());

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
8888
signer.setBaseDirectory(project.getBasedir());
8989

9090
getLog().info("Signer '" + signer.signerName() + "' is signing " + items.size() + " file"
91-
+ ((items.size() > 1) ? "s" : ""));
91+
+ ((items.size() > 1) ? "s" : "") + " with key " + signer.getKeyInfo());
9292

9393
for (FilesCollector.Item item : items) {
9494
getLog().debug("Generating signature for " + item.getFile());

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class GpgSigner extends AbstractGpgSigner {
3636
public static final String NAME = "gpg";
37-
private String executable;
37+
private final String executable;
3838

3939
public GpgSigner(String executable) {
4040
this.executable = executable;
@@ -45,6 +45,11 @@ public String signerName() {
4545
return NAME;
4646
}
4747

48+
@Override
49+
public String getKeyInfo() {
50+
return keyname != null ? keyname : "default";
51+
}
52+
4853
/**
4954
* {@inheritDoc}
5055
*/

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
340340
signer.setBaseDirectory(new File("").getAbsoluteFile());
341341

342342
getLog().info("Signer '" + signer.signerName() + "' is signing " + artifacts.size() + " file"
343-
+ ((artifacts.size() > 1) ? "s" : ""));
343+
+ ((artifacts.size() > 1) ? "s" : "") + " with key " + signer.getKeyInfo());
344344

345345
ArrayList<Artifact> signatures = new ArrayList<>();
346346
for (Artifact a : artifacts) {

0 commit comments

Comments
 (0)