Skip to content

Commit

Permalink
Improve log output of SignRepositoryArtifactsMojo and adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 24, 2024
1 parent 44e4f58 commit c76b4cd
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -231,11 +232,13 @@ public void execute() throws MojoExecutionException, MojoFailureException {

private void handle(IArtifactDescriptor artifactDescriptor, File artifact, ProxySignerWithPublicKeyAccess signer,
KeyStore allKeys) {
Log log = getLog();
if (artifact != null) {
var existingKeys = artifactDescriptor.getProperty(PGPSignatureVerifier.PGP_SIGNER_KEYS_PROPERTY_NAME);
var existingSignatures = artifactDescriptor.getProperty(PGPSignatureVerifier.PGP_SIGNATURES_PROPERTY_NAME);

if (existingSignatures != null && pgpKeyBehavior == PGPKeyBehavior.skip) {
log.debug(artifact + " is already pgp signed and these should be skipped!");
return;
}

Expand All @@ -245,6 +248,7 @@ private void handle(IArtifactDescriptor artifactDescriptor, File artifact, Proxy
var classifier = artifactKey.getClassifier();
var isBinary = "binary".equals(classifier);
if (skipBinaries && isBinary) {
log.debug(artifact + " is a binary and these should be skipped!");
return;
}

Expand All @@ -253,18 +257,22 @@ private void handle(IArtifactDescriptor artifactDescriptor, File artifact, Proxy
var signedContent = signedContentFactory.getSignedContent(artifact);
if (signedContent.isSigned()) {
if (skipIfJarsigned) {
log.debug(artifact + " is already signed and signed jars should be skipped!");
return;
}
if (skipIfJarsignedAndAnchored) {
for (var signerInfo : signedContent.getSignerInfos()) {
if (signerInfo.getTrustAnchor() != null) {
log.debug(artifact
+ " is already signed and signed jars should be skipped if anchored!");
return;
}
}
}
}
} catch (Exception e) {
//$FALL-THROUGH$ Treat as unsigned.
log.error("Can't check signature " + artifact + " :: " + e, e);
}
}
}
Expand Down Expand Up @@ -294,6 +302,8 @@ private void handle(IArtifactDescriptor artifactDescriptor, File artifact, Proxy
} catch (MojoExecutionException | IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else {
log.error("No artifact file for " + artifactDescriptor);
}
}
}
Loading

0 comments on commit c76b4cd

Please sign in to comment.