Skip to content

Commit

Permalink
WIP 314 Align with latest config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheman committed Nov 19, 2024
1 parent ad58bcd commit ba3c35c
Showing 1 changed file with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ba3c35c

Please sign in to comment.