Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Configuration {
@Builder.Default
Set<Pattern> excludes = new HashSet<>();
@Builder.Default
Set<String> indexFilenames = defaultIndeFilenames();
Set<String> indexFilenames = defaultIndexFilenames();

/*
* Explanation for configuring http status codes:
Expand All @@ -77,13 +77,13 @@ public Configuration() {
this.ignoreIPAddresses = false;// warning if numerical IP addresses
this.ignoreLocalhost = false;// warning if localhost-URLs
this.indexFilenames
= defaultIndeFilenames();
= defaultIndexFilenames();
this.prefixOnlyHrefExtensions = Web.POSSIBLE_EXTENSIONS;

this.checksToExecute = AllCheckers.CHECKER_CLASSES;
}

private static Set<String> defaultIndeFilenames() {
private static Set<String> defaultIndexFilenames() {
return Arrays.stream("index.html,index.htm".split(",")).collect(Collectors.toSet());
}

Expand Down
2 changes: 1 addition & 1 deletion htmlSanityCheck-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Type: Directory.
+
Type: `org.gradle.api.file.FileCollection`.
+
Default: All files in `+{sourceDir}+` whose names end with `.html`.
Default: All files in `+{sourceDir}+` whose names end with `.html` or `.htm`.

`checkingResultsDir` (optional):: Directory where the checking results are written to.
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class HtmlSanityCheckTask extends DefaultTask {
if (sourceDocuments == null) {
sourceDocuments = project.fileTree(sourceDir)
sourceDocuments.include('**/*.html')
sourceDocuments.include('**/*.htm')
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,32 @@ class HtmlSanityCheckTaskSpec extends HtmlSanityCheckBaseSpec {
e.message.contains("Your build configuration included 'failOnErrors=true', and 1 error(s) were found on all checked pages.")
}

def "should include .htm files when auto-populating sourceDocuments"() {
given:
// Create .htm file
def htmFile = new File(sourceDir, "document.htm")
htmFile << VALID_HTML

// Create .html file
htmlFile << VALID_HTML

// Create subdirectory with .htm file
def subDir = new File(sourceDir, "docs")
subDir.mkdirs()
def nestedHtmFile = new File(subDir, "nested.htm")
nestedHtmFile << VALID_HTML

when:
task.setSourceDir(testProjectDir.root)

then:
task.sourceDocuments != null
// Verify that sourceDocuments includes both .html and .htm files
def fileNames = task.sourceDocuments.files.collect { it.name }
fileNames.contains("test.html")
fileNames.contains("document.htm")
fileNames.contains("nested.htm")
task.sourceDocuments.files.size() == 3
}

}
4 changes: 2 additions & 2 deletions htmlSanityCheck-maven-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Use the following snippet inside a Maven build file:
</executions>
<configuration>
<sourceDocuments>
<file>src/file-to-test.html</file> <2>
<sourceDocument>src/file-to-test.html</sourceDocument> <2>
</sourceDocuments>
<sourceDir>src</sourceDir> <3>
</configuration>
Expand Down Expand Up @@ -79,7 +79,7 @@ Type: Directory.
+
Type: `org.maven.api.file.FileCollection`.
+
Default: All files in `+{sourceDir}+` whose names end with `.html`.
Default: All files in `+{sourceDir}+` whose names end with `.html` or `.htm`.

`checkingResultsDir` (optional):: Directory where the checking results are written to.
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,16 @@ void logBuildParameter(Configuration myConfig) {
}

protected Configuration setupConfiguration() {
// Auto-populate sourceDocuments from sourceDir if not specified
// (same pattern as Gradle plugin and CLI)
Set<File> documentsToCheck = sourceDocuments;
if (documentsToCheck == null && sourceDir != null) {
documentsToCheck = findHtmlFiles(sourceDir);
}

Configuration result = Configuration.builder()
.excludes(excludes.stream().map(Pattern::compile).collect(Collectors.toSet()))
.sourceDocuments(sourceDocuments)
.sourceDocuments(documentsToCheck)
.sourceDir(sourceDir)
.checkingResultsDir(checkingResultsDir)
.junitResultsDir(junitResultsDir)
Expand Down Expand Up @@ -301,6 +308,33 @@ protected Configuration setupConfiguration() {

return result;
}

/**
* Recursively finds all HTML files in the given directory.
* Searches for files with .html and .htm extensions.
*
* @param directory the directory to search
* @return set of HTML files found
*/
private Set<File> findHtmlFiles(File directory) {
Set<File> htmlFiles = new HashSet<>();
if (directory == null || !directory.exists() || !directory.isDirectory()) {
return htmlFiles;
}

File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
// Recursively search subdirectories
htmlFiles.addAll(findHtmlFiles(file));
} else if (file.isFile() && (file.getName().endsWith(".html") || file.getName().endsWith(".htm"))) {
htmlFiles.add(file);
}
}
}
return htmlFiles;
}
}

/*========================================================================
Expand Down
Loading
Loading