Skip to content

Commit

Permalink
WIP - Build HSC script with srcDir as minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheman committed Jan 11, 2024
1 parent e2b2792 commit e1ab02f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
1 change: 1 addition & 0 deletions htmlSanityCheck-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ compileGroovy {

application {
mainClass = 'org.aim42.htmlsanitycheck.cli.Main'
applicationName = 'hsc'
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ import java.nio.file.Paths
class Main implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(Main.class)

// @Option(names = ["-h", "--help"], usageHelp = true, description = "Display help message")
// void help () {
// logger.info("""SYNOPSIS: htmlSanityCheck
// "-s sourceDir
// "[ -f sourceFile ]+
// "-r resultsDir""")
// }

@Option(names = ["-r", "--resultsDir"], description = "Results Directory")
String resultsDirectoryName = "/tmp/results"

@Parameters(arity = "1..*", description = "at least one File")
@Parameters(arity = "1", description = "base directory", index = "0")
File srcDir

@Parameters(arity = "0..*", description = "at least one File", index = "1..*")
File[] files

static void main(String[] args) {
Expand All @@ -40,26 +35,21 @@ class Main implements Runnable {
cmd.execute(args)
}

private List<File> findFiles(File directory) throws IOException {
private static List<File> findFiles(File directory) throws IOException {
Files.walk(Paths.get(directory.getPath()))
.filter(Files::isRegularFile)
.filter({path -> path.toString().endsWith(".html")})
.collect {it.toFile()}
.filter({ path -> path.toString().endsWith(".html") || path.toString().endsWith(".htm")})
.collect { it.toFile() }
}

void run() {
var configuration = new Configuration()

var resultsDirectory = new File(resultsDirectoryName)

configuration.addConfigurationItem(Configuration.ITEM_NAME_sourceDir, srcDir)
configuration.addConfigurationItem(Configuration.ITEM_NAME_sourceDocuments,
files.collectMany { file ->
if (file.isDirectory()) {
return findFiles(file)
} else {
return [file]
}
}
files ?: findFiles(srcDir)
)
configuration.addConfigurationItem((Configuration.ITEM_NAME_checkingResultsDir), resultsDirectory)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,23 @@ class Configuration {
/**
* checks plausibility of configuration:
* We need at least one html file as input, maybe several
* @param configuration instance
*
* srcDocs needs to be of type {@link FileCollection}
* srcDocs needs to be of type {@link Set<String>}
* to be Gradle-compliant
*/
Boolean isValid() {

// we need at least srcDir and srcDocs!!
File srcDir = getConfigItemByName(Configuration.ITEM_NAME_sourceDir)
Set<String> srcDocs = getConfigItemByName(Configuration.ITEM_NAME_sourceDocuments)
File srcDir = (File) getConfigItemByName(Configuration.ITEM_NAME_sourceDir)
Set<String> srcDocs = (Set<String>) getConfigItemByName(Configuration.ITEM_NAME_sourceDocuments)

// cannot check if source director is null (= unspecified)
// if ((srcDir == null)) {
// throw new MisconfigurationException("source directory must not be null")
// }
//
// if ((!srcDir.exists())) {
// throw new MisconfigurationException("given sourceDir $srcDir does not exist.")
// }
if ((srcDir == null)) {
throw new MisconfigurationException("source directory must not be null")
}

if ((!srcDir.exists())) {
throw new MisconfigurationException("given sourceDir '$srcDir' does not exist")
}

// cannot check if both input params are null
if (srcDocs == null) {
Expand All @@ -261,6 +259,6 @@ class Configuration {
String toString() {
return "Configuration{" +
"configurationItems=" + configurationItems +
'}';
'}'
}
}

0 comments on commit e1ab02f

Please sign in to comment.