Skip to content

Commit

Permalink
Debugging the cause of random PGP failures
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jan 18, 2024
1 parent 253632e commit 8637706
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
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);
}
}
}
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);
}
}
}
Expand Up @@ -228,7 +228,9 @@ public void testSigningSkipIfJarSignedAndAnchored() throws Exception {
assertEquals(1, data.repositoryKeys.size(), "Exactly one key is expected");

assertEquals(
"[org.eclipse.equinox.common, org.eclipse.equinox.common.source, org.eclipse.osgi, org.eclipse.osgi.source, org.eclipse.platform_root]",
"[org.eclipse.equinox.common, org.eclipse.equinox.common.source, org.eclipse.osgi, org.eclipse.osgi.source, org.eclipse.platform_root] "
+ System.lineSeparator()
+ getLogLines(verifier).stream().collect(Collectors.joining(System.lineSeparator())),
data.unsignedIUs.toString(), "Unexpected unsigned IUs.");

Set<String> signedIUs = data.signedIUs.keySet();
Expand Down
Expand Up @@ -249,7 +249,7 @@ protected String toURI(File file) throws IOException {
}

public static void verifyTextInLogMatches(Verifier verifier, Pattern pattern) throws VerificationException {
List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
List<String> lines = getLogLines(verifier);

for (String line : lines) {
if (pattern.matcher(Verifier.stripAnsi(line)).find()) {
Expand All @@ -260,7 +260,7 @@ public static void verifyTextInLogMatches(Verifier verifier, Pattern pattern) th
}

public static void verifyTextNotInLog(Verifier verifier, String text) throws VerificationException {
List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
List<String> lines = getLogLines(verifier);

for (String line : lines) {
if (Verifier.stripAnsi(line).contains(text)) {
Expand All @@ -269,14 +269,18 @@ public static void verifyTextNotInLog(Verifier verifier, String text) throws Ver
}
}

public static List<String> getLogLines(Verifier verifier) throws VerificationException {
return verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
}

/**
* Variant of verifyErrorFreeLog that do not skip stacktraces
*
* @param verifier
* @throws VerificationException
*/
protected static void verifyErrorFreeLog(Verifier verifier) throws VerificationException {
List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
List<String> lines = getLogLines(verifier);
int size = lines.size();
Pattern pattern = Pattern.compile("\\[\\w+\\]");
for (int i = 0; i < size; i++) {
Expand Down

0 comments on commit 8637706

Please sign in to comment.