Skip to content

Commit

Permalink
#318 Rename Main to HscCommand
Browse files Browse the repository at this point in the history
(and fix rebase conflict)
  • Loading branch information
ascheman authored and Gerd Aschemann (EXT) committed Nov 19, 2024
1 parent 6001c57 commit 57fd1c1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion htmlSanityCheck-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ compileGroovy {
}

application {
mainClass = 'org.aim42.htmlsanitycheck.cli.Main'
mainClass = 'org.aim42.htmlsanitycheck.cli.HscCommand'
applicationName = 'hsc'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import java.nio.file.Paths
description = "Check HTML files for Sanity",
showDefaultValues = true
)
class Main implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(Main.class)
class HscCommand implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(HscCommand.class)

MainRunner runner
HscRunner runner

protected Main(MainRunner runner) {
protected HscCommand(HscRunner runner) {
this.runner = runner
}

Expand All @@ -48,11 +48,11 @@ class Main implements Runnable {
File[] srcDocs

static void main(String[] args) {
MainRunner mainRunner = new MainRunner()
Main main = new Main(mainRunner)
CommandLine cmd = new CommandLine(main)
mainRunner.setMain(main)
mainRunner.setCmd(cmd)
HscRunner hscRunner = new HscRunner()
HscCommand hscCommand = new HscCommand(hscRunner)
CommandLine cmd = new CommandLine(hscCommand)
hscRunner.setHscCommand(hscCommand)
hscRunner.setCmd(cmd)
cmd.execute(args)
}

Expand All @@ -65,46 +65,48 @@ class Main implements Runnable {
.collect { it.toFile() }
}

static class MainRunner {
static class HscRunner {

Main main
HscCommand hscCommand
CommandLine cmd

void run() {
if (main.versionRequested) {
if (hscCommand.versionRequested) {
System.out.println("Version: ${ProductInformation.VERSION}")
return
}

def srcDocuments = main.srcDocs ?: main.findFiles()
def srcDocuments = hscCommand.srcDocs ?: hscCommand.findFiles()
if (!srcDocuments) {
System.err.println("Please specify at least one src document (either explicitly or implicitly)")
cmd.usage(System.out)
System.exit(1)
}

var resultsDirectory = new File(main.resultsDirectoryName)
var resultsDirectory = new File(hscCommand.resultsDirectoryName)
var configuration = Configuration.builder()
.sourceDir(main.srcDir)
.sourceDir(hscCommand.srcDir)
.sourceDocuments(srcDocuments as Set)
.checkingResultsDir(resultsDirectory)
.checksToExecute(AllCheckers.CHECKER_CLASSES)
.build()

if (configuration.isValid()) {
// create output directory for checking results
resultsDirectory.mkdirs()
// if we have no valid configuration, abort with exception
configuration.validate()
logger.fine("Starting HTML sanity check")
// create output directory for checking results
resultsDirectory.mkdirs()

// create an AllChecksRunner...
var allChecksRunner = new AllChecksRunner(configuration)
// create an AllChecksRunner...
var allChecksRunner = new AllChecksRunner(configuration)

// ... and perform the actual checks
var allChecks = allChecksRunner.performAllChecks()
// ... and perform the actual checks
var allChecks = allChecksRunner.performAllChecks()

// check for findings and fail build if requested
var nrOfFindingsOnAllPages = allChecks.nrOfFindingsOnAllPages()
logger.debug("Found ${nrOfFindingsOnAllPages} error(s) on all checked pages")
}
// check for findings and fail build if requested
var nrOfFindingsOnAllPages = allChecks.nrOfFindingsOnAllPages()
logger.fine("Found ${nrOfFindingsOnAllPages} error(s) on all checked pages")
logger.finer("Finishing HTML sanity check")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import picocli.CommandLine
import spock.lang.Specification
import spock.lang.Unroll

import java.nio.file.Files

class MainCliSpec extends Specification {
class HscCommandSpec extends Specification {

private final static VALID_HTML = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head></head><body></body><html>"""
private final static INVALID_HTML = """<body><span id="id"/><span id="id"/></body> """
Expand Down Expand Up @@ -38,8 +36,8 @@ class MainCliSpec extends Specification {
@Unroll
def "test hsc with #args"() {
given:
Main.MainRunner myAppRunner = Mock(Main.MainRunner)
def cmdLine = new CommandLine(new Main(myAppRunner))
HscCommand.HscRunner myAppRunner = Mock(HscCommand.HscRunner)
def cmdLine = new CommandLine(new HscCommand(myAppRunner))

when:
def exitCode = cmdLine.execute(args.split())
Expand All @@ -65,7 +63,7 @@ class MainCliSpec extends Specification {
String[] args = ["-h"]

when:
Main.main(args)
HscCommand.main(args)

then:
errContent.toString().contains("Usage: hsc")
Expand All @@ -82,7 +80,7 @@ class MainCliSpec extends Specification {
String[] args = [testProjectDir.getRoot()]

when:
Main.main(args)
HscCommand.main(args)

then:
mockSecurityManager.exitCalled == 1
Expand All @@ -99,7 +97,7 @@ class MainCliSpec extends Specification {
String[] args = [testProjectDir.getRoot()]

when:
Main.main(args)
HscCommand.main(args)

then:
outContent.toString().contains("found 0 issue, 100% successful.")
Expand Down

0 comments on commit 57fd1c1

Please sign in to comment.