Copilot commented on code in PR #16005:
URL: https://github.com/apache/grails-core/pull/16005#discussion_r3606475643
##########
grails-doc/build.gradle:
##########
@@ -125,6 +126,11 @@ combinedGroovydoc.configure { Groovydoc gdoc ->
gdoc.outputs.dir(gdoc.destinationDir)
}
+def auditGroovydocLinks = tasks.register('auditGroovydocLinks',
AuditGroovydocLinksTask) {
+ dependsOn combinedGroovydoc
+ apiDocsDir = combinedGroovydoc.get().destinationDir
+}
Review Comment:
`AuditGroovydocLinksTask` exposes `apiDocsDir` as a `DirectoryProperty`, but
the task registration assigns it via `apiDocsDir = ...`. For Gradle
property-backed task inputs this will not reliably configure the
`DirectoryProperty` (it may create/assign a dynamic property instead), leaving
the input unset at runtime. Configure it via `apiDocsDir.set(...)` (ideally
using providers to avoid calling `combinedGroovydoc.get()` during
configuration).
##########
build-logic/docs-core/src/main/groovy/org/grails/doc/gradle/GroovydocLinkAuditor.groovy:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.grails.doc.gradle
+
+import java.nio.file.Files
+import java.nio.file.Path
+import java.util.regex.Matcher
+import java.util.regex.Pattern
+
+/**
+ * Scans generated Groovydoc HTML for malformed navigation and inner-class
+ * links. Kept free of the Gradle API so it can be unit tested directly -
+ * {@code build-logic/docs-core} deliberately keeps Gradle classes off the
+ * test compile classpath.
+ */
+class GroovydocLinkAuditor {
+
+ // Patterns common to Groovydoc navigation failures
+ private static final Map<Pattern, String> NAV_LINK_PATTERNS = [
+ (Pattern.compile(/href='([^']+?)\/deprecated-list\.html'/)):
"href='deprecated-list.html'",
+ (Pattern.compile(/href='([^']+?)\/help-doc\.html'/)):
"href='help-doc.html'",
+ (Pattern.compile(/href='([^']+?)\/index-all\.html'/)):
"href='index-all.html'",
+ (Pattern.compile(/href='([^']+?)\/overview-summary\.html'/)):
"href='overview-summary.html'"
+ ].asImmutable()
+
+ // Inner class path issues like Query/Order.Direction.html ->
Query.Order.Direction.html
+ private static final Pattern INNER_CLASS_LINK_PATTERN =
+
Pattern.compile(/href='([^']+?)\/([A-Z][A-Za-z0-9_]*?)\/([A-Z][A-Za-z0-9_.]*?\.html)'/)
+
+ static List<String> findViolations(File apiDir) {
+ List<String> violations = []
+
+ apiDir.eachFileRecurse { File file ->
+ if (file.name.endsWith('.html')) {
+ violations.addAll(findViolationsInFile(file))
+ }
+ }
+
+ violations
+ }
+
+ private static List<String> findViolationsInFile(File file) {
+ List<String> violations = []
+ String content = file.text
+
+ NAV_LINK_PATTERNS.each { Pattern pattern, String replacement ->
+ Matcher matcher = pattern.matcher(content)
+ if (matcher.find()) {
+ violations << "Malformed nav link in ${file.name}:
${matcher.group(0)}".toString()
+ }
+ }
Review Comment:
`NAV_LINK_PATTERNS` is a `Map<Pattern, String>` but the map value
(`replacement`) is never used, which is misleading and makes it unclear what
the expected/"correct" link is. Either change this to a `Set<Pattern>` or
include the expected value in the violation message so the map values serve a
purpose.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]