jdaugherty commented on code in PR #15568:
URL: https://github.com/apache/grails-core/pull/15568#discussion_r3254917898
##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStylePlugin.groovy:
##########
@@ -32,33 +37,405 @@ import org.gradle.api.plugins.quality.CheckstylePlugin
import org.gradle.api.plugins.quality.CodeNarc
import org.gradle.api.plugins.quality.CodeNarcExtension
import org.gradle.api.plugins.quality.CodeNarcPlugin
-
-@CompileStatic
+import org.gradle.api.plugins.quality.Pmd
+import org.gradle.api.plugins.quality.PmdExtension
+import org.gradle.api.plugins.quality.PmdPlugin
+
+import com.github.spotbugs.snom.Confidence
+import com.github.spotbugs.snom.Effort
+import com.github.spotbugs.snom.SpotBugsExtension
+import com.github.spotbugs.snom.SpotBugsPlugin
+import com.github.spotbugs.snom.SpotBugsTask
+import org.gradle.api.tasks.testing.Test
+import org.gradle.testing.jacoco.plugins.JacocoPlugin
+import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
+import org.gradle.testing.jacoco.tasks.JacocoReport
+
+/**
+ * Convention plugin for Grails code style enforcement.
+ */
+@CompileDynamic
class GrailsCodeStylePlugin implements Plugin<Project> {
static String CHECKSTYLE_DIR_PROPERTY = 'grails.codestyle.dir.checkstyle'
+ static String CHECKSTYLE_ENABLED_PROPERTY =
'grails.codestyle.enabled.checkstyle'
static String CHECKSTYLE_CONFIG_FILE_NAME = 'checkstyle.xml'
static String CHECKSTYLE_SUPPRESSION_CONFIG_FILE_NAME =
'checkstyle-suppressions.xml'
+ static String PMD_DIR_PROPERTY = 'grails.codestyle.dir.pmd'
+ static String PMD_ENABLED_PROPERTY = 'grails.codestyle.enabled.pmd'
+ static String PMD_CONFIG_FILE_NAME = 'pmd.xml'
+
static String CODENARC_DIR_PROPERTY = 'grails.codestyle.dir.codenarc'
+ static String CODENARC_ENABLED_PROPERTY =
'grails.codestyle.enabled.codenarc'
static String CODENARC_CONFIG_FILE_NAME = 'codenarc.groovy'
+ static String CODENARC_FIX_PROPERTY = 'grails.codestyle.codenarc.fix'
+
+ static String SPOTBUGS_ENABLED_PROPERTY =
'grails.codestyle.enabled.spotbugs'
+
+ static String JACOCO_ENABLED_PROPERTY = 'grails.codestyle.enabled.jacoco'
+
+ static String IGNORE_FAILURES_PROPERTY = 'grails.codestyle.ignoreFailures'
+
+ static String TEST_STYLING_PROPERTY = 'grails.codestyle.enabled.tests'
+
static String BASE_RESOURCE_PATH =
'/META-INF/org.apache.grails.buildsrc.codestyle'
@Override
void apply(Project project) {
initExtension(project)
configureCodeStyle(project)
- doNotApplyStylingToTests(project)
+ configureAggregation(project)
+
+ boolean jacocoEnabled = GradleUtils.lookupProperty(project,
JACOCO_ENABLED_PROPERTY, false)
+ if (jacocoEnabled) {
+ configureJacoco(project)
+ if (project == project.rootProject) {
+ project.logger.info("JaCoCo enabled globally, applying to
subprojects")
+ project.subprojects.each { subproject ->
+ subproject.pluginManager.withPlugin('java') {
+ configureJacoco(subproject)
+ }
+ subproject.pluginManager.withPlugin('groovy') {
+ configureJacoco(subproject)
+ }
+ }
+ }
+ }
+ }
+
+ static void configureJacoco(Project project) {
+ project.logger.info("Configuring JaCoCo for project: ${project.name}")
+ project.pluginManager.apply(JacocoPlugin)
+
+ project.extensions.configure(JacocoPluginExtension) {
+ it.toolVersion = "0.8.14"
+ }
+
+ project.tasks.withType(Test).configureEach {
+ it.finalizedBy 'jacocoTestReport'
+ }
+
+ project.tasks.withType(JacocoReport).configureEach {
+ it.dependsOn project.tasks.withType(Test)
+ it.reports {
+ it.xml.required = true
+ it.html.required = true
+ it.csv.required = true
+ }
+ }
+ }
+
+ private static void configureAggregation(Project project) {
+ Project root = project.rootProject
+ if (root.tasks.findByName('aggregateStyleViolations')) {
+ return
+ }
+
+ root.tasks.register('aggregateStyleViolations') { task ->
+ task.group = 'verification'
+ task.description = 'Aggregates all code style violations into
separate reports'
+
+ boolean checkTests = GradleUtils.lookupProperty(project,
TEST_STYLING_PROPERTY, false)
+ boolean jacocoEnabled = GradleUtils.lookupProperty(project,
JACOCO_ENABLED_PROPERTY, false)
+
+ // Dependencies: all check tasks in all subprojects
+ root.subprojects.each { subproject ->
+ // CodeNarc (prod only unless test styling is enabled)
+ task.dependsOn(subproject.tasks.withType(CodeNarc).matching {
t ->
+ checkTests || (!t.name.toLowerCase().contains('test') &&
!t.name.toLowerCase().contains('integrationtest'))
+ })
+
+ // Checkstyle (prod only unless test styling is enabled)
+ task.dependsOn(subproject.tasks.withType(Checkstyle).matching
{ t ->
+ checkTests || (!t.name.toLowerCase().contains('test') &&
!t.name.toLowerCase().contains('integrationtest'))
+ })
+
+ if (GradleUtils.lookupProperty(project, PMD_ENABLED_PROPERTY,
false)) {
+ task.dependsOn(subproject.tasks.withType(Pmd).matching { t
->
+ checkTests || (!t.name.toLowerCase().contains('test')
&& !t.name.toLowerCase().contains('integrationtest'))
+ })
+ }
+
+ if (GradleUtils.lookupProperty(project,
SPOTBUGS_ENABLED_PROPERTY, false)) {
+
task.dependsOn(subproject.tasks.withType(SpotBugsTask).matching { t ->
+ checkTests || (!t.name.toLowerCase().contains('test')
&& !t.name.toLowerCase().contains('integrationtest'))
+ })
+ }
+
+ if (jacocoEnabled) {
+ task.dependsOn(subproject.tasks.withType(JacocoReport))
+ }
+ }
+
+ def reportsDir =
project.extensions.getByType(GrailsCodeStyleExtension).reportsDirectory
+ task.inputs.dir(reportsDir).optional()
+
task.outputs.file(root.layout.projectDirectory.file('CODENARC_VIOLATIONS.md'))
Review Comment:
Addressed — reports are now written to `build/codestyle/checkstyle` and
`build/codestyle/codenarc` (under `buildDirectory`), not the project root.
##########
build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStylePlugin.groovy:
##########
@@ -32,33 +37,405 @@ import org.gradle.api.plugins.quality.CheckstylePlugin
import org.gradle.api.plugins.quality.CodeNarc
import org.gradle.api.plugins.quality.CodeNarcExtension
import org.gradle.api.plugins.quality.CodeNarcPlugin
-
-@CompileStatic
+import org.gradle.api.plugins.quality.Pmd
+import org.gradle.api.plugins.quality.PmdExtension
+import org.gradle.api.plugins.quality.PmdPlugin
+
+import com.github.spotbugs.snom.Confidence
+import com.github.spotbugs.snom.Effort
+import com.github.spotbugs.snom.SpotBugsExtension
+import com.github.spotbugs.snom.SpotBugsPlugin
+import com.github.spotbugs.snom.SpotBugsTask
+import org.gradle.api.tasks.testing.Test
+import org.gradle.testing.jacoco.plugins.JacocoPlugin
+import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
+import org.gradle.testing.jacoco.tasks.JacocoReport
+
+/**
+ * Convention plugin for Grails code style enforcement.
+ */
+@CompileDynamic
class GrailsCodeStylePlugin implements Plugin<Project> {
Review Comment:
Addressed — aggregation logic has been extracted into
`GrailsViolationAggregationPlugin`, and JaCoCo coverage is in
`GrailsJacocoPlugin`. `GrailsCodeStylePlugin` now only handles Checkstyle and
CodeNarc.
##########
plans/aggregate-style-violations.md:
##########
@@ -0,0 +1,65 @@
+<!--
+SPDX-License-Identifier: Apache-2.0
+
+Licensed 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.
+-->
+# Implementation Plan: Aggregate Style Violations
Review Comment:
The `plans/` directory no longer exists in the branch — this plan has been
removed.
##########
grails-test-examples/hibernate7/grails-partitioned-multi-tenancy/src/test/groovy/example/PartitionedMultiTenancySpec.groovy:
##########
@@ -40,6 +41,10 @@ class PartitionedMultiTenancySpec extends HibernateSpec {
)
}
+ def cleanup() {
+ System.setProperty(SystemPropertyTenantResolver.PROPERTY_NAME, "")
Review Comment:
`@RestoreSystemProperties` adopted.
--
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]