From 1610c253524e4b04b63fe098e0b1948f5d0667d8 Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Sat, 14 Dec 2024 12:33:56 +0100 Subject: [PATCH] Perform retries (on UnknownHostExceptions) If an UnknownHostException occurs (#270), we retry (configurable) times, as this is sometimes due to DNS (caching) errors with Java (or the underlying OS). Fix typos and wording (#343). --- .../aim42/htmlsanitycheck/Configuration.java | 2 + .../check/BrokenHttpLinksChecker.java | 39 ++++++++++--------- .../check/BrokenHttpLinksCheckerSpec.groovy | 7 ++-- htmlSanityCheck-gradle-plugin/README.adoc | 38 +++++++++++------- .../gradle/HtmlSanityCheckTask.groovy | 4 ++ integration-test/gradle-plugin/build.gradle | 2 +- 6 files changed, 54 insertions(+), 38 deletions(-) diff --git a/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/Configuration.java b/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/Configuration.java index a50b03b0..aa623da4 100644 --- a/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/Configuration.java +++ b/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/Configuration.java @@ -45,6 +45,8 @@ public class Configuration { @Getter(AccessLevel.NONE) @Builder.Default Boolean ignoreIPAddresses = false; + @Builder.Default + Integer retries = 0; /* * Explanation for configuring http status codes: * The standard http status codes are defined in class @link NetUtil and can diff --git a/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/check/BrokenHttpLinksChecker.java b/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/check/BrokenHttpLinksChecker.java index 840a90c6..012962e8 100644 --- a/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/check/BrokenHttpLinksChecker.java +++ b/htmlSanityCheck-core/src/main/java/org/aim42/htmlsanitycheck/check/BrokenHttpLinksChecker.java @@ -17,7 +17,7 @@ /** - * Check html anchor href attributes + * Check HTML anchor href attributes * * @see https://www.w3schools.com/tags/att_a_href.asp */ @@ -32,15 +32,13 @@ class BrokenHttpLinksChecker extends Checker { private final Set successCodes; private final Set warningCodes; private final Set errorCodes; - // all href attributes with http(s) protocol, - // including potential duplicates - // need that to calculate "nrOfOccurrences" - // the pure http/https-hrefs a set, duplicates are removed here + // all href attributes with http(s) protocol, including potential duplicates, need + // to calculate "nrOfOccurrences" the pure http/https-hrefs a set, duplicates are removed here private Set hrefSet; - BrokenHttpLinksChecker(Configuration pConfig) { - super(pConfig); + BrokenHttpLinksChecker(Configuration configuration) { + super(configuration); errorCodes = getMyConfig().getHttpErrorCodes(); warningCodes = getMyConfig().getHttpWarningCodes(); @@ -59,7 +57,7 @@ protected void initCheckingResultsDescription() { protected SingleCheckResults check(final HtmlPage pageToCheck) { log.trace("Checking '{}'", pageToCheck.getFile()); - //get set of all a-tags "