From ba3c35c703e9011cd5909da8a156b9519e62ad98 Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Tue, 19 Nov 2024 13:55:21 +0100 Subject: [PATCH] WIP 314 Align with latest config validation --- .../maven/HtmlSanityCheckMojo.java | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/htmlSanityCheck-maven-plugin/src/main/java/org/aim42/htmlsanitychecker/maven/HtmlSanityCheckMojo.java b/htmlSanityCheck-maven-plugin/src/main/java/org/aim42/htmlsanitychecker/maven/HtmlSanityCheckMojo.java index 4c7fe666..39bb8c12 100644 --- a/htmlSanityCheck-maven-plugin/src/main/java/org/aim42/htmlsanitychecker/maven/HtmlSanityCheckMojo.java +++ b/htmlSanityCheck-maven-plugin/src/main/java/org/aim42/htmlsanitychecker/maven/HtmlSanityCheckMojo.java @@ -25,10 +25,10 @@ * initializes the AllChecksRunner, * which does all the checking and reporting work. * + * @author Thomas Ruhroth * @goal sanity-check * @phase verify * @requiresDependencyResolution runtime - * @author Thomas Ruhroth */ @Mojo(name = "sanity-check", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.RUNTIME) public class HtmlSanityCheckMojo extends AbstractMojo { @@ -78,36 +78,33 @@ public void execute() throws MojoExecutionException { // Check if configuration is valid try { - if (myConfig.isValid()) { - // Create output directories - checkingResultsDir.mkdirs(); - if (!checkingResultsDir.isDirectory() || !checkingResultsDir.canWrite()) { - throw new MojoExecutionException("Cannot write to checking results directory."); - } - if (junitResultsDir != null) { - junitResultsDir.mkdirs(); - if (!junitResultsDir.isDirectory() || !junitResultsDir.canWrite()) { - throw new MojoExecutionException("Cannot write to JUnit results directory."); - } + myConfig.validate(); + // Create output directories + checkingResultsDir.mkdirs(); + if (!checkingResultsDir.isDirectory() || !checkingResultsDir.canWrite()) { + throw new MojoExecutionException("Cannot write to checking results directory."); + } + if (junitResultsDir != null) { + junitResultsDir.mkdirs(); + if (!junitResultsDir.isDirectory() || !junitResultsDir.canWrite()) { + throw new MojoExecutionException("Cannot write to JUnit results directory."); } + } - // Perform checks - AllChecksRunner allChecksRunner = new AllChecksRunner(myConfig); - PerRunResults allChecks = allChecksRunner.performAllChecks(); + // Perform checks + AllChecksRunner allChecksRunner = new AllChecksRunner(myConfig); + PerRunResults allChecks = allChecksRunner.performAllChecks(); - // Handle findings - int nrOfFindingsOnAllPages = allChecks.nrOfFindingsOnAllPages(); - getLog().debug("Found " + nrOfFindingsOnAllPages + " error(s) on all checked pages"); + // Handle findings + int nrOfFindingsOnAllPages = allChecks.nrOfFindingsOnAllPages(); + getLog().debug("Found " + nrOfFindingsOnAllPages + " error(s) on all checked pages"); - if (failOnErrors && nrOfFindingsOnAllPages > 0) { - String failureMsg = String.format( - "Your build configuration included 'failOnErrors=true', and %d error(s) were found on all checked pages. See %s for a detailed report.", - nrOfFindingsOnAllPages, checkingResultsDir - ); - throw new MojoExecutionException(failureMsg); - } - } else { - getLog().warn("Fatal configuration errors preventing checks:\n" + myConfig.toString()); + if (failOnErrors && nrOfFindingsOnAllPages > 0) { + String failureMsg = String.format( + "Your build configuration included 'failOnErrors=true', and %d error(s) were found on all checked pages. See %s for a detailed report.", + nrOfFindingsOnAllPages, checkingResultsDir + ); + throw new MojoExecutionException(failureMsg); } } catch (MisconfigurationException e) { throw new MojoExecutionException(e);