You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@grails.apache.org by bo...@apache.org on 2026/07/17 22:10:08 UTC
(grails-core) 02/03: refactor: rename groovydoc link check to audit task and remove property control
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch fix/groovydoc-links
in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit b168d32ffbf4cd35538c623c2633e8ebdd43a15d
Author: Sanjana <sa...@gmail.com>
AuthorDate: Wed Apr 22 01:39:40 2026 +0530
refactor: rename groovydoc link check to audit task and remove property control
---
...sTask.groovy => AuditGroovydocLinksTask.groovy} | 45 +++++-----------------
grails-doc/build.gradle | 7 ++--
2 files changed, 13 insertions(+), 39 deletions(-)
diff --git a/build-logic/docs-core/src/main/groovy/org/grails/doc/gradle/FixGroovydocLinksTask.groovy b/build-logic/docs-core/src/main/groovy/org/grails/doc/gradle/AuditGroovydocLinksTask.groovy
similarity index 67%
rename from build-logic/docs-core/src/main/groovy/org/grails/doc/gradle/FixGroovydocLinksTask.groovy
rename to build-logic/docs-core/src/main/groovy/org/grails/doc/gradle/AuditGroovydocLinksTask.groovy
index cc9d959778..f4a567e925 100644
--- a/build-logic/docs-core/src/main/groovy/org/grails/doc/gradle/FixGroovydocLinksTask.groovy
+++ b/build-logic/docs-core/src/main/groovy/org/grails/doc/gradle/AuditGroovydocLinksTask.groovy
@@ -27,24 +27,17 @@ import java.util.regex.Matcher
import java.util.regex.Pattern
/**
- * A task that repairs malformed navigation links in generated Groovydocs.
+ * A task that audits generated Groovydocs for malformed navigation links.
* Specifically targets 'phantom' links and relative path issues in navigation files
* like overview-summary.html, deprecated-list.html, and help-doc.html.
*/
-abstract class FixGroovydocLinksTask extends DefaultTask {
-
- /**
- * If true, the task will fail the build if any malformed links are found.
- * If false, the task will attempt to repair the links (patching mode).
- */
- @org.gradle.api.tasks.Input
- boolean auditMode = false
+abstract class AuditGroovydocLinksTask extends DefaultTask {
@InputDirectory
abstract DirectoryProperty getApiDocsDir()
@TaskAction
- void fixLinks() {
+ void auditLinks() {
File apiDir = apiDocsDir.get().asFile
if (!apiDir.exists()) {
logger.warn "API documentation directory does not exist: ${apiDir.absolutePath}"
@@ -59,24 +52,20 @@ abstract class FixGroovydocLinksTask extends DefaultTask {
(Pattern.compile(/href='([^']+?)\/overview-summary\.html'/)): "href='overview-summary.html'"
]
- int totalFixes = 0
List<String> violations = []
apiDir.eachFileRecurse { File file ->
if (file.name.endsWith(".html")) {
String content = file.text
- boolean changed = false
replacements.each { pattern, replacement ->
Matcher matcher = pattern.matcher(content)
if (matcher.find()) {
- content = matcher.replaceAll(replacement)
- changed = true
- violations << "Malformed nav link in ${file.name}"
+ violations << "Malformed nav link in ${file.name}: ${matcher.group(0)}"
}
}
- // Fix specific inner class path issues like Query/Order.Direction.html -> Query.Order.Direction.html
+ // Check specific inner class path issues like Query/Order.Direction.html -> Query.Order.Direction.html
Pattern innerClassPattern = Pattern.compile(/href='([^']+?)\/([A-Z][A-Za-z0-9_]*?)\/([A-Z][A-Za-z0-9_.]*?\.html)'/)
Matcher innerMatcher = innerClassPattern.matcher(content)
while (innerMatcher.find()) {
@@ -88,30 +77,16 @@ abstract class FixGroovydocLinksTask extends DefaultTask {
Path targetPath = currentPath.resolve(relPath).resolve("${outer}.${inner}").normalize()
if (Files.exists(targetPath)) {
- String newHref = "href='${relPath}/${outer}.${inner}'"
- content = content.replace(innerMatcher.group(0), newHref)
- changed = true
- violations << "Malformed inner class link in ${file.name}: ${innerMatcher.group(0)} -> ${newHref}"
- }
- }
-
- if (changed) {
- totalFixes++
- if (!auditMode) {
- file.text = content
+ violations << "Malformed inner class link in ${file.name}: ${innerMatcher.group(0)}"
}
}
}
}
- if (totalFixes > 0) {
- if (auditMode) {
- violations.take(10).each { logger.error(it) }
- if (violations.size() > 10) logger.error("... and ${violations.size() - 10} more")
- throw new org.gradle.api.GradleException("Found ${violations.size()} malformed links in Groovydoc. Please fix the source issue rather than patching. See logs for details.")
- } else {
- logger.lifecycle "Repaired ${totalFixes} HTML files in ${apiDir.absolutePath}"
- }
+ if (!violations.isEmpty()) {
+ violations.take(10).each { logger.error(it) }
+ if (violations.size() > 10) logger.error("... and ${violations.size() - 10} more")
+ throw new org.gradle.api.GradleException("Found ${violations.size()} malformed links in Groovydoc. Please fix the source issue rather than patching. See logs for details.")
} else {
logger.lifecycle "No malformed Groovydoc links found in ${apiDir.absolutePath}"
}
diff --git a/grails-doc/build.gradle b/grails-doc/build.gradle
index 0bb7904fbc..ddba680a44 100644
--- a/grails-doc/build.gradle
+++ b/grails-doc/build.gradle
@@ -21,7 +21,7 @@ import grails.doc.git.FetchTagsTask
import grails.doc.dropdown.CreateReleaseDropDownTask
import grails.doc.gradle.PublishGuideTask
import groovy.json.JsonSlurper
-import org.grails.doc.gradle.FixGroovydocLinksTask
+import org.grails.doc.gradle.AuditGroovydocLinksTask
import java.util.zip.ZipFile
@@ -126,10 +126,9 @@ combinedGroovydoc.configure { Groovydoc gdoc ->
gdoc.outputs.dir(gdoc.destinationDir)
}
-def fixGroovydocLinks = tasks.register('fixGroovydocLinks', FixGroovydocLinksTask) {
+def auditGroovydocLinks = tasks.register('auditGroovydocLinks', AuditGroovydocLinksTask) {
dependsOn combinedGroovydoc
apiDocsDir = combinedGroovydoc.get().destinationDir
- auditMode = project.hasProperty('auditGroovydocLinks')
}
String getVersion(String artifact) {
@@ -661,7 +660,7 @@ createReleaseDropdownTask.configure {
def docsTask = tasks.register('docs', Sync)
docsTask.configure { Sync it ->
- it.dependsOn(combinedGroovydoc, fixGroovydocLinks, createReleaseDropdownTask, ':grails-data-docs-stage:docs', ':grails-data-docs-stage:groovydoc')
+ it.dependsOn(combinedGroovydoc, auditGroovydocLinks, createReleaseDropdownTask, ':grails-data-docs-stage:docs', ':grails-data-docs-stage:groovydoc')
it.group = 'documentation'
def manualDocsDir = project.layout.buildDirectory.dir('modified-guide')