borinquenkid commented on code in PR #15686:
URL: https://github.com/apache/grails-core/pull/15686#discussion_r3336934081


##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStyleExtension.groovy:
##########
@@ -30,13 +30,13 @@ import org.gradle.api.model.ObjectFactory
 class GrailsCodeStyleExtension {
 
     /**
-     * Defaults to project.buildDir/checkstyle.
+     * Defaults to project.rootProject.buildDir/codestyle/checkstyle.

Review Comment:
   Done



##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy:
##########
@@ -0,0 +1,501 @@
+/*
+ *  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 java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
+
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
+
+import org.gradle.api.GradleException
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.file.Directory
+import org.gradle.api.file.FileCollection
+import org.gradle.api.logging.Logger
+import org.gradle.api.logging.Logging
+import org.gradle.api.plugins.AppliedPlugin
+import org.gradle.api.plugins.quality.Checkstyle
+import org.gradle.api.plugins.quality.CodeNarc
+import org.gradle.api.plugins.quality.Pmd
+import org.gradle.api.provider.Provider
+import org.gradle.api.tasks.TaskProvider
+import org.gradle.testing.jacoco.tasks.JacocoReport
+
+import com.github.spotbugs.snom.SpotBugsTask
+import groovy.xml.XmlSlurper

Review Comment:
   Done



##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy:
##########
@@ -0,0 +1,501 @@
+/*
+ *  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 java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
+
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
+
+import org.gradle.api.GradleException
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.file.Directory
+import org.gradle.api.file.FileCollection
+import org.gradle.api.logging.Logger
+import org.gradle.api.logging.Logging
+import org.gradle.api.plugins.AppliedPlugin
+import org.gradle.api.plugins.quality.Checkstyle
+import org.gradle.api.plugins.quality.CodeNarc
+import org.gradle.api.plugins.quality.Pmd
+import org.gradle.api.provider.Provider
+import org.gradle.api.tasks.TaskProvider
+import org.gradle.testing.jacoco.tasks.JacocoReport
+
+import com.github.spotbugs.snom.SpotBugsTask
+import groovy.xml.XmlSlurper
+
+/**
+ * Root-only convention plugin that aggregates code-style violation XML 
reports and JaCoCo coverage
+ * CSV reports into human-readable Markdown files under 
build/reports/violations/.
+ *
+ * Apply this plugin to the root project only. Subprojects should apply
+ * grails-code-style and grails-jacoco individually.
+ *
+ * Tasks registered:
+ *   aggregateStyleViolations    — CodeNarc + Checkstyle only
+ *   aggregateAnalysisViolations — PMD + SpotBugs only (requires opt-in 
properties)
+ *   aggregateViolations         — depends on both of the above
+ *   aggregateJacocoCoverage     — JaCoCo CSV → Markdown
+ */
+@CompileStatic
+class GrailsViolationAggregationPlugin implements Plugin<Project> {
+
+    private static final Logger LOGGER = 
Logging.getLogger(GrailsViolationAggregationPlugin)
+
+    /**
+     * Comma-separated list of fully-qualified class-name prefixes to exclude 
from the aggregated
+     * JaCoCo coverage report. Configure via {@code 
-Pgrails.jacoco.aggregation.excludedClassPrefixes=...}
+     * or in {@code gradle.properties}.
+     *
+     * <p>Defaults to {@link #DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES}: the 
Hibernate 7 support classes
+     * share fully-qualified names with their Hibernate 5 counterparts, and 
JaCoCo cannot aggregate
+     * coverage for two different classes with the same name (it fails with
+     * "Can't add different class with same name"). Excluding one variant 
keeps the aggregate valid.
+     */
+    static final String JACOCO_EXCLUDED_CLASS_PREFIXES_PROPERTY = 
'grails.jacoco.aggregation.excludedClassPrefixes'
+
+    static final String DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES = 
'org.grails.orm.hibernate.support.hibernate7.'
+
+    @Override
+    void apply(Project project) {
+        if (project != project.rootProject) {
+            throw new GradleException(
+                'GrailsViolationAggregationPlugin must be applied to the root 
project only. ' +
+                'Apply grails-code-style and grails-jacoco to subprojects 
instead.'
+            )
+        }
+
+        Provider<Directory> violationsDir = 
project.layout.buildDirectory.dir('reports/violations')

Review Comment:
   Done



##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy:
##########
@@ -0,0 +1,501 @@
+/*
+ *  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 java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
+
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
+
+import org.gradle.api.GradleException
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.file.Directory
+import org.gradle.api.file.FileCollection
+import org.gradle.api.logging.Logger
+import org.gradle.api.logging.Logging
+import org.gradle.api.plugins.AppliedPlugin
+import org.gradle.api.plugins.quality.Checkstyle
+import org.gradle.api.plugins.quality.CodeNarc
+import org.gradle.api.plugins.quality.Pmd
+import org.gradle.api.provider.Provider
+import org.gradle.api.tasks.TaskProvider
+import org.gradle.testing.jacoco.tasks.JacocoReport
+
+import com.github.spotbugs.snom.SpotBugsTask
+import groovy.xml.XmlSlurper
+
+/**
+ * Root-only convention plugin that aggregates code-style violation XML 
reports and JaCoCo coverage
+ * CSV reports into human-readable Markdown files under 
build/reports/violations/.
+ *
+ * Apply this plugin to the root project only. Subprojects should apply
+ * grails-code-style and grails-jacoco individually.
+ *
+ * Tasks registered:
+ *   aggregateStyleViolations    — CodeNarc + Checkstyle only
+ *   aggregateAnalysisViolations — PMD + SpotBugs only (requires opt-in 
properties)
+ *   aggregateViolations         — depends on both of the above
+ *   aggregateJacocoCoverage     — JaCoCo CSV → Markdown
+ */
+@CompileStatic
+class GrailsViolationAggregationPlugin implements Plugin<Project> {
+
+    private static final Logger LOGGER = 
Logging.getLogger(GrailsViolationAggregationPlugin)
+
+    /**
+     * Comma-separated list of fully-qualified class-name prefixes to exclude 
from the aggregated
+     * JaCoCo coverage report. Configure via {@code 
-Pgrails.jacoco.aggregation.excludedClassPrefixes=...}
+     * or in {@code gradle.properties}.
+     *
+     * <p>Defaults to {@link #DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES}: the 
Hibernate 7 support classes
+     * share fully-qualified names with their Hibernate 5 counterparts, and 
JaCoCo cannot aggregate
+     * coverage for two different classes with the same name (it fails with
+     * "Can't add different class with same name"). Excluding one variant 
keeps the aggregate valid.
+     */
+    static final String JACOCO_EXCLUDED_CLASS_PREFIXES_PROPERTY = 
'grails.jacoco.aggregation.excludedClassPrefixes'
+
+    static final String DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES = 
'org.grails.orm.hibernate.support.hibernate7.'
+
+    @Override
+    void apply(Project project) {
+        if (project != project.rootProject) {
+            throw new GradleException(
+                'GrailsViolationAggregationPlugin must be applied to the root 
project only. ' +
+                'Apply grails-code-style and grails-jacoco to subprojects 
instead.'
+            )
+        }
+
+        Provider<Directory> violationsDir = 
project.layout.buildDirectory.dir('reports/violations')
+        Provider<Directory> styleXmlDir = 
project.layout.buildDirectory.dir('reports/codestyle')

Review Comment:
   Done



##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy:
##########
@@ -0,0 +1,501 @@
+/*
+ *  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 java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
+
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
+
+import org.gradle.api.GradleException
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.file.Directory
+import org.gradle.api.file.FileCollection
+import org.gradle.api.logging.Logger
+import org.gradle.api.logging.Logging
+import org.gradle.api.plugins.AppliedPlugin
+import org.gradle.api.plugins.quality.Checkstyle
+import org.gradle.api.plugins.quality.CodeNarc
+import org.gradle.api.plugins.quality.Pmd
+import org.gradle.api.provider.Provider
+import org.gradle.api.tasks.TaskProvider
+import org.gradle.testing.jacoco.tasks.JacocoReport
+
+import com.github.spotbugs.snom.SpotBugsTask
+import groovy.xml.XmlSlurper
+
+/**
+ * Root-only convention plugin that aggregates code-style violation XML 
reports and JaCoCo coverage
+ * CSV reports into human-readable Markdown files under 
build/reports/violations/.
+ *
+ * Apply this plugin to the root project only. Subprojects should apply
+ * grails-code-style and grails-jacoco individually.
+ *
+ * Tasks registered:
+ *   aggregateStyleViolations    — CodeNarc + Checkstyle only
+ *   aggregateAnalysisViolations — PMD + SpotBugs only (requires opt-in 
properties)
+ *   aggregateViolations         — depends on both of the above
+ *   aggregateJacocoCoverage     — JaCoCo CSV → Markdown
+ */
+@CompileStatic
+class GrailsViolationAggregationPlugin implements Plugin<Project> {
+
+    private static final Logger LOGGER = 
Logging.getLogger(GrailsViolationAggregationPlugin)
+
+    /**
+     * Comma-separated list of fully-qualified class-name prefixes to exclude 
from the aggregated
+     * JaCoCo coverage report. Configure via {@code 
-Pgrails.jacoco.aggregation.excludedClassPrefixes=...}
+     * or in {@code gradle.properties}.
+     *
+     * <p>Defaults to {@link #DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES}: the 
Hibernate 7 support classes
+     * share fully-qualified names with their Hibernate 5 counterparts, and 
JaCoCo cannot aggregate
+     * coverage for two different classes with the same name (it fails with
+     * "Can't add different class with same name"). Excluding one variant 
keeps the aggregate valid.
+     */
+    static final String JACOCO_EXCLUDED_CLASS_PREFIXES_PROPERTY = 
'grails.jacoco.aggregation.excludedClassPrefixes'
+
+    static final String DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES = 
'org.grails.orm.hibernate.support.hibernate7.'
+
+    @Override
+    void apply(Project project) {
+        if (project != project.rootProject) {
+            throw new GradleException(
+                'GrailsViolationAggregationPlugin must be applied to the root 
project only. ' +
+                'Apply grails-code-style and grails-jacoco to subprojects 
instead.'
+            )
+        }
+
+        Provider<Directory> violationsDir = 
project.layout.buildDirectory.dir('reports/violations')
+        Provider<Directory> styleXmlDir = 
project.layout.buildDirectory.dir('reports/codestyle')
+        Provider<Directory> analysisXmlDir = 
project.layout.buildDirectory.dir('reports/codeanalysis')

Review Comment:
   Done



##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy:
##########
@@ -0,0 +1,501 @@
+/*
+ *  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 java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
+
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
+
+import org.gradle.api.GradleException
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.file.Directory
+import org.gradle.api.file.FileCollection
+import org.gradle.api.logging.Logger
+import org.gradle.api.logging.Logging
+import org.gradle.api.plugins.AppliedPlugin
+import org.gradle.api.plugins.quality.Checkstyle
+import org.gradle.api.plugins.quality.CodeNarc
+import org.gradle.api.plugins.quality.Pmd
+import org.gradle.api.provider.Provider
+import org.gradle.api.tasks.TaskProvider
+import org.gradle.testing.jacoco.tasks.JacocoReport
+
+import com.github.spotbugs.snom.SpotBugsTask
+import groovy.xml.XmlSlurper
+
+/**
+ * Root-only convention plugin that aggregates code-style violation XML 
reports and JaCoCo coverage
+ * CSV reports into human-readable Markdown files under 
build/reports/violations/.
+ *
+ * Apply this plugin to the root project only. Subprojects should apply
+ * grails-code-style and grails-jacoco individually.
+ *
+ * Tasks registered:
+ *   aggregateStyleViolations    — CodeNarc + Checkstyle only
+ *   aggregateAnalysisViolations — PMD + SpotBugs only (requires opt-in 
properties)
+ *   aggregateViolations         — depends on both of the above
+ *   aggregateJacocoCoverage     — JaCoCo CSV → Markdown
+ */
+@CompileStatic
+class GrailsViolationAggregationPlugin implements Plugin<Project> {
+
+    private static final Logger LOGGER = 
Logging.getLogger(GrailsViolationAggregationPlugin)
+
+    /**
+     * Comma-separated list of fully-qualified class-name prefixes to exclude 
from the aggregated
+     * JaCoCo coverage report. Configure via {@code 
-Pgrails.jacoco.aggregation.excludedClassPrefixes=...}
+     * or in {@code gradle.properties}.
+     *
+     * <p>Defaults to {@link #DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES}: the 
Hibernate 7 support classes
+     * share fully-qualified names with their Hibernate 5 counterparts, and 
JaCoCo cannot aggregate
+     * coverage for two different classes with the same name (it fails with
+     * "Can't add different class with same name"). Excluding one variant 
keeps the aggregate valid.
+     */
+    static final String JACOCO_EXCLUDED_CLASS_PREFIXES_PROPERTY = 
'grails.jacoco.aggregation.excludedClassPrefixes'
+
+    static final String DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES = 
'org.grails.orm.hibernate.support.hibernate7.'
+
+    @Override
+    void apply(Project project) {
+        if (project != project.rootProject) {
+            throw new GradleException(
+                'GrailsViolationAggregationPlugin must be applied to the root 
project only. ' +
+                'Apply grails-code-style and grails-jacoco to subprojects 
instead.'
+            )
+        }
+
+        Provider<Directory> violationsDir = 
project.layout.buildDirectory.dir('reports/violations')
+        Provider<Directory> styleXmlDir = 
project.layout.buildDirectory.dir('reports/codestyle')
+        Provider<Directory> analysisXmlDir = 
project.layout.buildDirectory.dir('reports/codeanalysis')
+
+        TaskProvider<Task> styleTask = registerStyleAggregation(project, 
styleXmlDir, violationsDir)
+        TaskProvider<Task> analysisTask = registerAnalysisAggregation(project, 
analysisXmlDir, violationsDir)
+        registerJacocoAggregation(project, violationsDir)
+
+        project.tasks.register('aggregateViolations') { Task task ->
+            task.group = 'verification'
+            task.description = 'Aggregates all violation reports (style + 
analysis) into build/reports/violations/'
+            task.dependsOn(styleTask, analysisTask)
+        }
+    }
+
+    private static TaskProvider<Task> registerStyleAggregation(Project root, 
Provider<Directory> styleXmlDir, Provider<Directory> violationsDir) {
+        // Wire property flags as Providers — values are resolved at task 
execution time, not at apply() time,
+        // and Providers are configuration-cache safe to capture in task 
actions
+        Provider<Boolean> checkStyleTests = GradleUtils.booleanProvider(root, 
GrailsCodeStylePlugin.TEST_STYLING_PROPERTY)
+        Provider<Boolean> codenarcEnabled = GradleUtils.booleanProvider(root, 
GrailsCodeStylePlugin.CODENARC_ENABLED_PROPERTY, true)
+        Provider<Boolean> checkstyleEnabled = 
GradleUtils.booleanProvider(root, 
GrailsCodeStylePlugin.CHECKSTYLE_ENABLED_PROPERTY, true)
+
+        TaskProvider<Task> aggregateTask = 
root.tasks.register('aggregateStyleViolations') { Task task ->
+            task.group = 'verification'
+            task.description = 'Aggregates CodeNarc and Checkstyle violation 
reports into build/reports/violations/'
+            
task.outputs.file(root.file('build/reports/violations/CODENARC_VIOLATIONS.md'))
+            
task.outputs.file(root.file('build/reports/violations/CHECKSTYLE_VIOLATIONS.md'))
+            task.doLast {
+                parseStyleViolations(styleXmlDir.get(), violationsDir.get(),
+                    checkStyleTests.get(), codenarcEnabled.get(), 
checkstyleEnabled.get())
+            }
+        }
+        root.subprojects { Project sub ->
+            sub.pluginManager.withPlugin('codenarc') { AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(CodeNarc))
+                }
+            }
+            sub.pluginManager.withPlugin('checkstyle') { AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(Checkstyle))
+                }
+            }
+        }
+        aggregateTask
+    }
+
+    private static TaskProvider<Task> registerAnalysisAggregation(Project 
root, Provider<Directory> analysisXmlDir, Provider<Directory> violationsDir) {
+        Provider<Boolean> checkAnalysisTests = 
GradleUtils.booleanProvider(root, 
GrailsCodeAnalysisPlugin.TEST_ANALYSIS_PROPERTY)
+        Provider<Boolean> pmdEnabled = GradleUtils.booleanProvider(root, 
GrailsCodeAnalysisPlugin.PMD_ENABLED_PROPERTY)
+        Provider<Boolean> spotbugsEnabled = GradleUtils.booleanProvider(root, 
GrailsCodeAnalysisPlugin.SPOTBUGS_ENABLED_PROPERTY)
+
+        TaskProvider<Task> aggregateTask = 
root.tasks.register('aggregateAnalysisViolations') { Task task ->
+            task.group = 'verification'
+            task.description = 'Aggregates PMD and SpotBugs violation reports 
into build/reports/violations/'
+            
task.outputs.file(root.file('build/reports/violations/PMD_VIOLATIONS.md'))
+            
task.outputs.file(root.file('build/reports/violations/SPOTBUGS_VIOLATIONS.md'))
+            task.doLast {
+                parseAnalysisViolations(analysisXmlDir.get(), 
violationsDir.get(),
+                    checkAnalysisTests.get(), pmdEnabled.get(), 
spotbugsEnabled.get())
+            }
+        }
+        root.subprojects { Project sub ->
+            sub.pluginManager.withPlugin('pmd') { AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(Pmd))
+                }
+            }
+            sub.pluginManager.withPlugin('com.github.spotbugs') { 
AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(SpotBugsTask))
+                }
+            }
+        }
+        aggregateTask
+    }
+
+    private static void registerJacocoAggregation(Project root, 
Provider<Directory> violationsDir) {
+        // Collect all potential CSV paths at configuration time — Project 
must not be referenced from task actions
+        FileCollection jacocoCsvFiles = root.files(
+            root.allprojects.collect { Project p -> 
p.file('build/reports/jacoco/test/jacocoTestReport.csv') }
+        )
+
+        // Resolve the excluded class-name prefixes as a Provider so the value 
is captured
+        // configuration-cache-safely and read at task execution time.
+        Provider<List<String>> excludedClassPrefixes = root.providers
+            .gradleProperty(JACOCO_EXCLUDED_CLASS_PREFIXES_PROPERTY)
+            .orElse(DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES)
+            .map { String value ->
+                value.split(',').collect { it.trim() }.findAll { !it.isEmpty() 
}
+            }
+
+        TaskProvider<Task> aggregateTask = 
root.tasks.register('aggregateJacocoCoverage') { Task task ->
+            task.group = 'verification'
+            task.description = 'Aggregates JaCoCo coverage reports from all 
subprojects into build/reports/violations/'
+            task.inputs.files(jacocoCsvFiles).optional(true)
+            task.inputs.property('excludedClassPrefixes', 
excludedClassPrefixes)
+            
task.outputs.file(root.file('build/reports/violations/JACOCO_COVERAGE.md'))
+            task.doLast {
+                parseJacocoCoverage(jacocoCsvFiles, violationsDir.get(), 
excludedClassPrefixes.get())
+            }
+        }
+        root.subprojects { Project sub ->
+            sub.pluginManager.withPlugin('jacoco') { AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(JacocoReport))
+                }
+            }
+        }
+    }
+
+    @CompileDynamic
+    private static void parseStyleViolations(Directory styleXmlDir, Directory 
violationsDir,
+            boolean checkStyleTests, boolean codenarcEnabled, boolean 
checkstyleEnabled) {
+        def slurper = new XmlSlurper()

Review Comment:
   Done



##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy:
##########
@@ -0,0 +1,501 @@
+/*
+ *  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 java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
+
+import groovy.transform.CompileDynamic
+import groovy.transform.CompileStatic
+
+import org.gradle.api.GradleException
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.file.Directory
+import org.gradle.api.file.FileCollection
+import org.gradle.api.logging.Logger
+import org.gradle.api.logging.Logging
+import org.gradle.api.plugins.AppliedPlugin
+import org.gradle.api.plugins.quality.Checkstyle
+import org.gradle.api.plugins.quality.CodeNarc
+import org.gradle.api.plugins.quality.Pmd
+import org.gradle.api.provider.Provider
+import org.gradle.api.tasks.TaskProvider
+import org.gradle.testing.jacoco.tasks.JacocoReport
+
+import com.github.spotbugs.snom.SpotBugsTask
+import groovy.xml.XmlSlurper
+
+/**
+ * Root-only convention plugin that aggregates code-style violation XML 
reports and JaCoCo coverage
+ * CSV reports into human-readable Markdown files under 
build/reports/violations/.
+ *
+ * Apply this plugin to the root project only. Subprojects should apply
+ * grails-code-style and grails-jacoco individually.
+ *
+ * Tasks registered:
+ *   aggregateStyleViolations    — CodeNarc + Checkstyle only
+ *   aggregateAnalysisViolations — PMD + SpotBugs only (requires opt-in 
properties)
+ *   aggregateViolations         — depends on both of the above
+ *   aggregateJacocoCoverage     — JaCoCo CSV → Markdown
+ */
+@CompileStatic
+class GrailsViolationAggregationPlugin implements Plugin<Project> {
+
+    private static final Logger LOGGER = 
Logging.getLogger(GrailsViolationAggregationPlugin)
+
+    /**
+     * Comma-separated list of fully-qualified class-name prefixes to exclude 
from the aggregated
+     * JaCoCo coverage report. Configure via {@code 
-Pgrails.jacoco.aggregation.excludedClassPrefixes=...}
+     * or in {@code gradle.properties}.
+     *
+     * <p>Defaults to {@link #DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES}: the 
Hibernate 7 support classes
+     * share fully-qualified names with their Hibernate 5 counterparts, and 
JaCoCo cannot aggregate
+     * coverage for two different classes with the same name (it fails with
+     * "Can't add different class with same name"). Excluding one variant 
keeps the aggregate valid.
+     */
+    static final String JACOCO_EXCLUDED_CLASS_PREFIXES_PROPERTY = 
'grails.jacoco.aggregation.excludedClassPrefixes'
+
+    static final String DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES = 
'org.grails.orm.hibernate.support.hibernate7.'
+
+    @Override
+    void apply(Project project) {
+        if (project != project.rootProject) {
+            throw new GradleException(
+                'GrailsViolationAggregationPlugin must be applied to the root 
project only. ' +
+                'Apply grails-code-style and grails-jacoco to subprojects 
instead.'
+            )
+        }
+
+        Provider<Directory> violationsDir = 
project.layout.buildDirectory.dir('reports/violations')
+        Provider<Directory> styleXmlDir = 
project.layout.buildDirectory.dir('reports/codestyle')
+        Provider<Directory> analysisXmlDir = 
project.layout.buildDirectory.dir('reports/codeanalysis')
+
+        TaskProvider<Task> styleTask = registerStyleAggregation(project, 
styleXmlDir, violationsDir)
+        TaskProvider<Task> analysisTask = registerAnalysisAggregation(project, 
analysisXmlDir, violationsDir)
+        registerJacocoAggregation(project, violationsDir)
+
+        project.tasks.register('aggregateViolations') { Task task ->
+            task.group = 'verification'
+            task.description = 'Aggregates all violation reports (style + 
analysis) into build/reports/violations/'
+            task.dependsOn(styleTask, analysisTask)
+        }
+    }
+
+    private static TaskProvider<Task> registerStyleAggregation(Project root, 
Provider<Directory> styleXmlDir, Provider<Directory> violationsDir) {
+        // Wire property flags as Providers — values are resolved at task 
execution time, not at apply() time,
+        // and Providers are configuration-cache safe to capture in task 
actions
+        Provider<Boolean> checkStyleTests = GradleUtils.booleanProvider(root, 
GrailsCodeStylePlugin.TEST_STYLING_PROPERTY)
+        Provider<Boolean> codenarcEnabled = GradleUtils.booleanProvider(root, 
GrailsCodeStylePlugin.CODENARC_ENABLED_PROPERTY, true)
+        Provider<Boolean> checkstyleEnabled = 
GradleUtils.booleanProvider(root, 
GrailsCodeStylePlugin.CHECKSTYLE_ENABLED_PROPERTY, true)
+
+        TaskProvider<Task> aggregateTask = 
root.tasks.register('aggregateStyleViolations') { Task task ->
+            task.group = 'verification'
+            task.description = 'Aggregates CodeNarc and Checkstyle violation 
reports into build/reports/violations/'
+            
task.outputs.file(root.file('build/reports/violations/CODENARC_VIOLATIONS.md'))
+            
task.outputs.file(root.file('build/reports/violations/CHECKSTYLE_VIOLATIONS.md'))
+            task.doLast {
+                parseStyleViolations(styleXmlDir.get(), violationsDir.get(),
+                    checkStyleTests.get(), codenarcEnabled.get(), 
checkstyleEnabled.get())
+            }
+        }
+        root.subprojects { Project sub ->
+            sub.pluginManager.withPlugin('codenarc') { AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(CodeNarc))
+                }
+            }
+            sub.pluginManager.withPlugin('checkstyle') { AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(Checkstyle))
+                }
+            }
+        }
+        aggregateTask
+    }
+
+    private static TaskProvider<Task> registerAnalysisAggregation(Project 
root, Provider<Directory> analysisXmlDir, Provider<Directory> violationsDir) {
+        Provider<Boolean> checkAnalysisTests = 
GradleUtils.booleanProvider(root, 
GrailsCodeAnalysisPlugin.TEST_ANALYSIS_PROPERTY)
+        Provider<Boolean> pmdEnabled = GradleUtils.booleanProvider(root, 
GrailsCodeAnalysisPlugin.PMD_ENABLED_PROPERTY)
+        Provider<Boolean> spotbugsEnabled = GradleUtils.booleanProvider(root, 
GrailsCodeAnalysisPlugin.SPOTBUGS_ENABLED_PROPERTY)
+
+        TaskProvider<Task> aggregateTask = 
root.tasks.register('aggregateAnalysisViolations') { Task task ->
+            task.group = 'verification'
+            task.description = 'Aggregates PMD and SpotBugs violation reports 
into build/reports/violations/'
+            
task.outputs.file(root.file('build/reports/violations/PMD_VIOLATIONS.md'))
+            
task.outputs.file(root.file('build/reports/violations/SPOTBUGS_VIOLATIONS.md'))
+            task.doLast {
+                parseAnalysisViolations(analysisXmlDir.get(), 
violationsDir.get(),
+                    checkAnalysisTests.get(), pmdEnabled.get(), 
spotbugsEnabled.get())
+            }
+        }
+        root.subprojects { Project sub ->
+            sub.pluginManager.withPlugin('pmd') { AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(Pmd))
+                }
+            }
+            sub.pluginManager.withPlugin('com.github.spotbugs') { 
AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(SpotBugsTask))
+                }
+            }
+        }
+        aggregateTask
+    }
+
+    private static void registerJacocoAggregation(Project root, 
Provider<Directory> violationsDir) {
+        // Collect all potential CSV paths at configuration time — Project 
must not be referenced from task actions
+        FileCollection jacocoCsvFiles = root.files(
+            root.allprojects.collect { Project p -> 
p.file('build/reports/jacoco/test/jacocoTestReport.csv') }
+        )
+
+        // Resolve the excluded class-name prefixes as a Provider so the value 
is captured
+        // configuration-cache-safely and read at task execution time.
+        Provider<List<String>> excludedClassPrefixes = root.providers
+            .gradleProperty(JACOCO_EXCLUDED_CLASS_PREFIXES_PROPERTY)
+            .orElse(DEFAULT_JACOCO_EXCLUDED_CLASS_PREFIXES)
+            .map { String value ->
+                value.split(',').collect { it.trim() }.findAll { !it.isEmpty() 
}
+            }
+
+        TaskProvider<Task> aggregateTask = 
root.tasks.register('aggregateJacocoCoverage') { Task task ->
+            task.group = 'verification'
+            task.description = 'Aggregates JaCoCo coverage reports from all 
subprojects into build/reports/violations/'
+            task.inputs.files(jacocoCsvFiles).optional(true)
+            task.inputs.property('excludedClassPrefixes', 
excludedClassPrefixes)
+            
task.outputs.file(root.file('build/reports/violations/JACOCO_COVERAGE.md'))
+            task.doLast {
+                parseJacocoCoverage(jacocoCsvFiles, violationsDir.get(), 
excludedClassPrefixes.get())
+            }
+        }
+        root.subprojects { Project sub ->
+            sub.pluginManager.withPlugin('jacoco') { AppliedPlugin p ->
+                aggregateTask.configure { Task task ->
+                    task.dependsOn(sub.tasks.withType(JacocoReport))
+                }
+            }
+        }
+    }
+
+    @CompileDynamic
+    private static void parseStyleViolations(Directory styleXmlDir, Directory 
violationsDir,
+            boolean checkStyleTests, boolean codenarcEnabled, boolean 
checkstyleEnabled) {
+        def slurper = new XmlSlurper()
+        
slurper.setFeature('http://apache.org/xml/features/disallow-doctype-decl', true)
+        
slurper.setFeature('http://apache.org/xml/features/nonvalidating/load-external-dtd',
 false)
+        
slurper.setFeature('http://xml.org/sax/features/external-general-entities', 
false)
+        
slurper.setFeature('http://xml.org/sax/features/external-parameter-entities', 
false)
+        slurper.setFeature('http://xml.org/sax/features/namespaces', false)
+
+        def getModule = { String fileName ->
+            def lastDash = fileName.lastIndexOf('-')
+            lastDash != -1 ? fileName.substring(0, lastDash) : fileName
+        }
+
+        def isTestFile = { String fileName ->
+            fileName.toLowerCase().contains('test') || 
fileName.toLowerCase().contains('integrationtest')
+        }
+
+        def shouldSkipClass = { boolean includeTests, String className, String 
filePath = null ->
+            if (includeTests) {
+                return false
+            }
+            if (filePath && (filePath.contains('src/test/') || 
filePath.contains('src/integrationTest/'))) {
+                return true
+            }
+            !filePath && (className.contains('Spec') || 
className.contains('Test') || className.contains('Tests'))
+        }
+
+        def writeReport = { String fileName, List violations, String title ->

Review Comment:
   Done



-- 
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]


Reply via email to