jamesfredley commented on code in PR #15420: URL: https://github.com/apache/grails-core/pull/15420#discussion_r2833829582
########## build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsGroovydocPlugin.groovy: ########## @@ -0,0 +1,186 @@ +/* + * 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.apache.grails.buildsrc + +import groovy.transform.CompileDynamic +import groovy.transform.CompileStatic + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.attributes.Bundling +import org.gradle.api.attributes.Category +import org.gradle.api.attributes.Usage +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer +import org.gradle.api.tasks.javadoc.Groovydoc + +@CompileStatic +class GrailsGroovydocPlugin implements Plugin<Project> { + + static final String MATOMO_FOOTER = '''\ +<!-- Matomo --> +<script> + var _paq = window._paq = window._paq || []; + /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ + _paq.push(["setDoNotTrack", true]); + _paq.push(["disableCookies"]); + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function() { + var u="https://analytics.apache.org/"; + _paq.push(['setTrackerUrl', u+'matomo.php']); + _paq.push(['setSiteId', '79']); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); + })(); +</script> +<!-- End Matomo Code -->''' + + @Override + void apply(Project project) { + GrailsGroovydocExtension extension = project.extensions.create( + 'grailsGroovydoc', GrailsGroovydocExtension, project + ) + registerDocumentationConfiguration(project) + configureGroovydocDefaults(project) + configureAntBuilderExecution(project, extension) + } + + private static void registerDocumentationConfiguration(Project project) { + if (project.configurations.names.contains('documentation')) { + return + } + project.configurations.register('documentation') { Configuration config -> + config.canBeConsumed = false + config.canBeResolved = true + config.attributes { container -> + container.attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category, Category.LIBRARY)) + container.attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling, Bundling.EXTERNAL)) + container.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, Usage.JAVA_RUNTIME)) + } + } + } + + @CompileDynamic + private static void configureGroovydocDefaults(Project project) { + project.tasks.withType(Groovydoc).configureEach { Groovydoc gdoc -> + gdoc.includeAuthor = false + gdoc.includeMainForScripts = false + gdoc.processScripts = false + gdoc.noTimestamp = true + gdoc.noVersionStamp = false + gdoc.footer = MATOMO_FOOTER + if (project.configurations.names.contains('documentation')) { + gdoc.groovyClasspath = project.configurations.getByName('documentation') + } + } + } + + @CompileDynamic + private static void configureAntBuilderExecution(Project project, GrailsGroovydocExtension extension) { + project.tasks.withType(Groovydoc).configureEach { Groovydoc gdoc -> + gdoc.actions.clear() + gdoc.doLast { + File destDir = gdoc.destinationDir + destDir.mkdirs() + + List<File> sourceDirs = resolveSourceDirectories(gdoc, project) + if (sourceDirs.isEmpty()) { + project.logger.lifecycle("Skipping groovydoc for ${gdoc.name}: no source directories found") + return + } + + Configuration docConfig = project.configurations.findByName('documentation') + if (!docConfig) { + project.logger.warn("Skipping groovydoc for ${gdoc.name}: 'documentation' configuration not found") + return + } + + project.ant.taskdef( + name: 'groovydoc', + classname: 'org.codehaus.groovy.ant.Groovydoc', + classpath: docConfig.asPath + ) + + List<Map<String, String>> links = resolveLinks(gdoc) + String sourcepath = sourceDirs.collect { it.absolutePath }.join(File.pathSeparator) + + Map<String, Object> antArgs = [ + destdir: destDir.absolutePath, + sourcepath: sourcepath, + packagenames: '**.*', + windowtitle: gdoc.windowTitle ?: '', Review Comment: This is not correct. The Ant `groovydoc` task does not have a separate `classpath` attribute - the `taskdef` classloader (loaded with the `documentation` configuration) IS the type resolution classpath. Groovydoc parses sources syntactically rather than compiling them, so the `taskdef` classpath provides everything needed for type resolution. The `documentation` configuration includes `groovy-all`, `groovy-ant`, `groovy-templates`, and any project-specific runtime dependencies. This is verified working - all 6,295+ HTML files generate correctly across all 7 groovydoc builds. ########## build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsGroovydocPlugin.groovy: ########## @@ -0,0 +1,186 @@ +/* + * 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.apache.grails.buildsrc + +import groovy.transform.CompileDynamic +import groovy.transform.CompileStatic + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.attributes.Bundling +import org.gradle.api.attributes.Category +import org.gradle.api.attributes.Usage +import org.gradle.api.provider.Provider +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer +import org.gradle.api.tasks.javadoc.Groovydoc + +@CompileStatic +class GrailsGroovydocPlugin implements Plugin<Project> { + + static final String MATOMO_FOOTER = '''\ +<!-- Matomo --> +<script> + var _paq = window._paq = window._paq || []; + /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ + _paq.push(["setDoNotTrack", true]); + _paq.push(["disableCookies"]); + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function() { + var u="https://analytics.apache.org/"; + _paq.push(['setTrackerUrl', u+'matomo.php']); + _paq.push(['setSiteId', '79']); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); + })(); +</script> +<!-- End Matomo Code -->''' + + @Override + void apply(Project project) { + GrailsGroovydocExtension extension = project.extensions.create( + 'grailsGroovydoc', GrailsGroovydocExtension, project + ) + registerDocumentationConfiguration(project) + configureGroovydocDefaults(project) + configureAntBuilderExecution(project, extension) + } + + private static void registerDocumentationConfiguration(Project project) { + if (project.configurations.names.contains('documentation')) { + return + } + project.configurations.register('documentation') { Configuration config -> + config.canBeConsumed = false + config.canBeResolved = true + config.attributes { container -> + container.attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category, Category.LIBRARY)) + container.attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling, Bundling.EXTERNAL)) + container.attribute(Usage.USAGE_ATTRIBUTE, project.objects.named(Usage, Usage.JAVA_RUNTIME)) + } + } + } + + @CompileDynamic + private static void configureGroovydocDefaults(Project project) { + project.tasks.withType(Groovydoc).configureEach { Groovydoc gdoc -> + gdoc.includeAuthor = false + gdoc.includeMainForScripts = false + gdoc.processScripts = false + gdoc.noTimestamp = true + gdoc.noVersionStamp = false + gdoc.footer = MATOMO_FOOTER + if (project.configurations.names.contains('documentation')) { + gdoc.groovyClasspath = project.configurations.getByName('documentation') + } + } + } + + @CompileDynamic + private static void configureAntBuilderExecution(Project project, GrailsGroovydocExtension extension) { + project.tasks.withType(Groovydoc).configureEach { Groovydoc gdoc -> + gdoc.actions.clear() + gdoc.doLast { + File destDir = gdoc.destinationDir + destDir.mkdirs() + + List<File> sourceDirs = resolveSourceDirectories(gdoc, project) + if (sourceDirs.isEmpty()) { + project.logger.lifecycle("Skipping groovydoc for ${gdoc.name}: no source directories found") + return + } Review Comment: Acknowledged, though this is not a practical issue. The Ant groovydoc task uses `sourcepath` + `packagenames` by design - it does not support nested `fileset` elements. The excludes configured on the Gradle task (`META-INF/**`, `*.yml`, `*.properties`, `*.xml`, `Application.groovy`, `Bootstrap.groovy`, `resources.groovy`) are either non-code files that groovydoc naturally ignores (it only processes `.groovy` and `.java` files) or convention files that do not exist in framework source directories. The generated output is identical to what the previous per-module AntBuilder configurations produced. -- 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]
