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/06/01 20:12:08 UTC
(grails-core) branch feat/grails-code-analysis-plugin updated: chore: address review feedback on code style and analysis configuration
This is an automated email from the ASF dual-hosted git repository.
borinquenkid pushed a commit to branch feat/grails-code-analysis-plugin
in repository https://gitbox.apache.org/repos/asf/grails-core.git
The following commit(s) were added to refs/heads/feat/grails-code-analysis-plugin by this push:
new fc63cd05c5 chore: address review feedback on code style and analysis configuration
fc63cd05c5 is described below
commit fc63cd05c59135b03fc665fbf443f69433972a6c
Author: Walter Duque de Estrada <wb...@mac.com>
AuthorDate: Mon Jun 1 14:59:47 2026 -0500
chore: address review feedback on code style and analysis configuration
- Replace deprecated buildDir with layout.buildDirectory in analysis plugin
- Rename codestyle properties and directories to code-style for consistency
- Extract duplicate secure XML slurper and report writer logic into helpers
- Simplify TaskOutcome references and remove explicit closure parameter
- Fix build directory exclusion check for Windows platform compatibility
- Revert unintended IntelliJ project code style configuration changes
---
.agents/skills/violation-fixer/SKILL.md | 32 ++--
.idea/codeStyles/Project.xml | 198 +++++++++++----------
.idea/codeStyles/codeStyleConfig.xml | 22 ++-
.../org/apache/grails/buildsrc/GradleUtils.groovy | 2 +-
.../buildsrc/GrailsCodeAnalysisPlugin.groovy | 20 +--
.../buildsrc/GrailsCodeStyleExtension.groovy | 12 +-
.../grails/buildsrc/GrailsCodeStylePlugin.groovy | 30 ++--
.../GrailsViolationAggregationPlugin.groovy | 140 ++++++---------
.../buildsrc/GrailsCodeStylePluginSpec.groovy | 13 +-
grails-forge/gradle.properties | 2 +-
10 files changed, 233 insertions(+), 238 deletions(-)
diff --git a/.agents/skills/violation-fixer/SKILL.md b/.agents/skills/violation-fixer/SKILL.md
index adf1b764e3..d8742d1964 100644
--- a/.agents/skills/violation-fixer/SKILL.md
+++ b/.agents/skills/violation-fixer/SKILL.md
@@ -30,7 +30,7 @@ Activate this skill when:
| Plugin | Applied to | Responsibility |
|--------|-----------|----------------|
-| `org.apache.grails.gradle.grails-code-style` | Every subproject | Applies Checkstyle and CodeNarc; registers per-project `codeStyle` task; redirects XML reports to root `build/reports/codestyle/` |
+| `org.apache.grails.gradle.grails-code-style` | Every subproject | Applies Checkstyle and CodeNarc; registers per-project `codeStyle` task; redirects XML reports to root `build/reports/code-style/` |
| `org.apache.grails.gradle.grails-code-analysis` | Every subproject | Applies PMD and SpotBugs (both opt-in); registers per-project `codeAnalysis` task; redirects XML reports to root `build/reports/code-analysis/` |
| `org.apache.grails.gradle.grails-jacoco` | Every subproject | Applies JaCoCo; wires `jacocoTestReport` to run after each `test` task |
| `org.apache.grails.gradle.grails-violation-aggregation` | **Root project only** | Registers `aggregateViolations` and `aggregateJacocoCoverage` tasks; writes Markdown summaries to `build/reports/violations/` |
@@ -60,13 +60,13 @@ Activate this skill when:
./gradlew aggregateViolations
# Include test sources in style checks
-./gradlew aggregateViolations -Pgrails.codestyle.enabled.tests=true
+./gradlew aggregateViolations -Pgrails.code-style.enabled.tests=true
# Include test sources in analysis
./gradlew aggregateViolations -Pgrails.code-analysis.enabled.tests=true
# Ignore failures (collect reports without failing the build)
-./gradlew aggregateViolations -Pgrails.codestyle.ignoreFailures=true -Pgrails.code-analysis.ignoreFailures=true
+./gradlew aggregateViolations -Pgrails.code-style.ignoreFailures=true -Pgrails.code-analysis.ignoreFailures=true
# Auto-fix some CodeNarc violations before running checks
./gradlew codenarcFix codeStyle
@@ -104,7 +104,7 @@ Each file is a Markdown table grouped by module, with columns: **Class**, **Tool
### CodeNarc (Groovy — always enabled)
-Rule file: `build/codestyle/codenarc/codenarc.groovy` (generated by the plugin during setup; not intended to be edited directly).
+Rule file: `build/code-style/codenarc/codenarc.groovy` (generated by the plugin during setup; not intended to be edited directly).
Most common violations and how to fix them:
@@ -126,7 +126,7 @@ Auto-fixable via `codenarcFix`: `ClassStartsWithBlankLine`, `SpaceAroundMapEntry
### Checkstyle (Java — always enabled)
-Rule file: `build/codestyle/checkstyle/checkstyle.xml`.
+Rule file: `build/code-style/checkstyle/checkstyle.xml`.
Common violations:
@@ -154,7 +154,7 @@ Runs at `Effort.MAX` / `Confidence.HIGH`. Only high-confidence bugs are reported
### Spotless (Java auto-formatting — opt-in)
-Enable: `-Pgrails.codestyle.enabled.spotless=true`
+Enable: `-Pgrails.code-style.enabled.spotless=true`
Uses Palantir Java Format. Can auto-fix by running:
```bash
@@ -171,14 +171,14 @@ All properties can be set in `gradle.properties` or passed as `-P` flags:
| Property | Default | Description |
|----------|---------|-------------|
-| `grails.codestyle.enabled.checkstyle` | `true` | Enable Checkstyle |
-| `grails.codestyle.enabled.codenarc` | `true` | Enable CodeNarc |
-| `grails.codestyle.enabled.spotless` | `false` | Enable Spotless |
-| `grails.codestyle.enabled.tests` | `false` | Also check test source sets |
-| `grails.codestyle.ignoreFailures` | `false` | Collect reports without failing build |
-| `grails.codestyle.codenarc.fix` | `false` | Run `codenarcFix` before CodeNarc tasks |
-| `grails.codestyle.dir.checkstyle` | (auto) | Custom path to Checkstyle config dir |
-| `grails.codestyle.dir.codenarc` | (auto) | Custom path to CodeNarc config dir |
+| `grails.code-style.enabled.checkstyle` | `true` | Enable Checkstyle |
+| `grails.code-style.enabled.codenarc` | `true` | Enable CodeNarc |
+| `grails.code-style.enabled.spotless` | `false` | Enable Spotless |
+| `grails.code-style.enabled.tests` | `false` | Also check test source sets |
+| `grails.code-style.ignoreFailures` | `false` | Collect reports without failing build |
+| `grails.code-style.codenarc.fix` | `false` | Run `codenarcFix` before CodeNarc tasks |
+| `grails.code-style.dir.checkstyle` | (auto) | Custom path to Checkstyle config dir |
+| `grails.code-style.dir.codenarc` | (auto) | Custom path to CodeNarc config dir |
| `skipCodeStyle` | unset | If present, all style tasks are skipped |
### `grails-code-analysis` plugin (PMD + SpotBugs)
@@ -196,7 +196,7 @@ All properties can be set in `gradle.properties` or passed as `-P` flags:
## Fixing Violations Workflow
-1. Run `./gradlew aggregateViolations -Pgrails.codestyle.ignoreFailures=true -Pgrails.code-analysis.ignoreFailures=true`
+1. Run `./gradlew aggregateViolations -Pgrails.code-style.ignoreFailures=true -Pgrails.code-analysis.ignoreFailures=true`
2. Open `build/reports/violations/CODENARC_VIOLATIONS.md` and `build/reports/violations/CHECKSTYLE_VIOLATIONS.md` to see all issues by module
3. For CodeNarc, run `./gradlew codenarcFix` to auto-fix what it can
4. Fix remaining violations manually using the table above
@@ -209,7 +209,7 @@ All properties can be set in `gradle.properties` or passed as `-P` flags:
All XML reports are consolidated at:
```
-build/reports/codestyle/ ← XML inputs for style aggregation
+build/reports/code-style/ ← XML inputs for style aggregation
├── checkstyle/
│ ├── grails-core-checkstyleMain.xml
│ ├── grails-web-mvc-checkstyleMain.xml
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 898ed70de8..ab13aa909a 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -1,97 +1,105 @@
+<!--
+
+ 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.
+
+-->
<component name="ProjectCodeStyleConfiguration">
- <code_scheme name="Project" version="173">
- <option name="AUTODETECT_INDENTS" value="false" />
- <GroovyCodeStyleSettings>
- <option name="ENABLE_GROOVYDOC_FORMATTING" value="false" />
- <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
- <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
- <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
- <value />
- </option>
- <option name="IMPORT_LAYOUT_TABLE">
- <value>
- <package name="java" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="javax" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="groovy" withSubpackages="true" static="false" />
- <package name="org.apache.groovy" withSubpackages="true" static="false" />
- <package name="org.codehaus.groovy" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="jakarta" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="io.spring" withSubpackages="true" static="false" />
- <package name="org.springframework" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="grails" withSubpackages="true" static="false" />
- <package name="org.apache.grails" withSubpackages="true" static="false" />
- <package name="org.grails" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="" withSubpackages="true" static="true" />
- </value>
- </option>
- </GroovyCodeStyleSettings>
- <JavaCodeStyleSettings>
- <option name="SPACE_INSIDE_ONE_LINE_ENUM_BRACES" value="true" />
- <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
- <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
- <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
- <value />
- </option>
- <option name="IMPORT_LAYOUT_TABLE">
- <value>
- <package name="java" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="javax" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="groovy" withSubpackages="true" static="false" />
- <package name="org.apache.groovy" withSubpackages="true" static="false" />
- <package name="org.codehaus.groovy" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="jakarta" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="io.spring" withSubpackages="true" static="false" />
- <package name="org.springframework" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="grails" withSubpackages="true" static="false" />
- <package name="org.apache.grails" withSubpackages="true" static="false" />
- <package name="org.grails" withSubpackages="true" static="false" />
- <emptyLine />
- <package name="" withSubpackages="true" static="true" />
- </value>
- </option>
- <option name="ENABLE_JAVADOC_FORMATTING" value="false" />
- </JavaCodeStyleSettings>
- <editorconfig>
- <option name="ENABLED" value="false" />
- </editorconfig>
- <codeStyleSettings language="Cookie">
- <indentOptions>
- <option name="USE_TAB_CHARACTER" value="false" />
- </indentOptions>
- </codeStyleSettings>
- <codeStyleSettings language="Groovy">
- <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
- </codeStyleSettings>
- <codeStyleSettings language="JAVA">
- <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
- <option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
- <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
- <option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
- <option name="ARRAY_INITIALIZER_WRAP" value="1" />
- <option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
- <indentOptions>
- <option name="CONTINUATION_INDENT_SIZE" value="4" />
- </indentOptions>
- </codeStyleSettings>
- <codeStyleSettings language="csv">
- <indentOptions>
- <option name="USE_TAB_CHARACTER" value="false" />
- </indentOptions>
- </codeStyleSettings>
- </code_scheme>
+ <code_scheme name="Project" version="173">
+ <option name="AUTODETECT_INDENTS" value="false"/>
+ <GroovyCodeStyleSettings>
+ <option name="ENABLE_GROOVYDOC_FORMATTING" value="false"/>
+ <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999"/>
+ <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999"/>
+ <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
+ <value/>
+ </option>
+ <option name="IMPORT_LAYOUT_TABLE">
+ <value>
+ <package name="java" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="javax" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="groovy" withSubpackages="true" static="false"/>
+ <package name="org.apache.groovy" withSubpackages="true" static="false"/>
+ <package name="org.codehaus.groovy" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="jakarta" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="io.spring" withSubpackages="true" static="false"/>
+ <package name="org.springframework" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="grails" withSubpackages="true" static="false"/>
+ <package name="org.apache.grails" withSubpackages="true" static="false"/>
+ <package name="org.grails" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="" withSubpackages="true" static="true"/>
+ </value>
+ </option>
+ </GroovyCodeStyleSettings>
+ <JavaCodeStyleSettings>
+ <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999"/>
+ <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999"/>
+ <option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
+ <value/>
+ </option>
+ <option name="IMPORT_LAYOUT_TABLE">
+ <value>
+ <package name="java" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="javax" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="groovy" withSubpackages="true" static="false"/>
+ <package name="org.apache.groovy" withSubpackages="true" static="false"/>
+ <package name="org.codehaus.groovy" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="jakarta" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="io.spring" withSubpackages="true" static="false"/>
+ <package name="org.springframework" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="grails" withSubpackages="true" static="false"/>
+ <package name="org.apache.grails" withSubpackages="true" static="false"/>
+ <package name="org.grails" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="" withSubpackages="true" static="true"/>
+ </value>
+ </option>
+ <option name="ENABLE_JAVADOC_FORMATTING" value="false"/>
+ </JavaCodeStyleSettings>
+ <editorconfig>
+ <option name="ENABLED" value="false"/>
+ </editorconfig>
+ <codeStyleSettings language="Groovy">
+ <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1"/>
+ </codeStyleSettings>
+ <codeStyleSettings language="JAVA">
+ <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1"/>
+ <option name="KEEP_BLANK_LINES_IN_CODE" value="1"/>
+ <option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1"/>
+ <option name="ARRAY_INITIALIZER_WRAP" value="1"/>
+ <option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true"/>
+ <indentOptions>
+ <option name="CONTINUATION_INDENT_SIZE" value="4"/>
+ </indentOptions>
+ </codeStyleSettings>
+ </code_scheme>
</component>
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
index f23d524925..52768fe1ae 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,25 @@
+<!--
+
+ 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.
+
+-->
<component name="ProjectCodeStyleConfiguration">
<state>
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default copy" />
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
\ No newline at end of file
diff --git a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GradleUtils.groovy b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GradleUtils.groovy
index 924958d439..906740662a 100644
--- a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GradleUtils.groovy
+++ b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GradleUtils.groovy
@@ -40,7 +40,7 @@ class GradleUtils {
static Provider<Boolean> booleanProvider(Project project, String name, boolean defaultValue = false) {
project.providers.gradleProperty(name)
- .map { String it -> it.trim().toBoolean() }
+ .map { it.trim().toBoolean() }
.orElse(defaultValue)
}
diff --git a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeAnalysisPlugin.groovy b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeAnalysisPlugin.groovy
index dae4b7495f..6b88166d90 100644
--- a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeAnalysisPlugin.groovy
+++ b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeAnalysisPlugin.groovy
@@ -94,7 +94,7 @@ class GrailsCodeAnalysisPlugin implements Plugin<Project> {
}
private static void createOrLoad(Path expectedPath, String defaultResource, Project project) {
- boolean defaultPath = expectedPath.startsWith(project.rootProject.buildDir.toPath())
+ def defaultPath = expectedPath.startsWith(project.rootProject.layout.buildDirectory.get().asFile.toPath())
if (!Files.exists(expectedPath) || expectedPath.size() == 0 || defaultPath) {
def defaultValue = GrailsCodeAnalysisPlugin.getResourceAsStream(defaultResource)
if (!defaultValue) {
@@ -106,15 +106,15 @@ class GrailsCodeAnalysisPlugin implements Plugin<Project> {
}
static void configurePmd(Project project) {
- Provider<Boolean> pmdEnabled = GradleUtils.booleanProvider(project, PMD_ENABLED_PROPERTY)
+ def pmdEnabled = GradleUtils.booleanProvider(project, PMD_ENABLED_PROPERTY)
if (!pmdEnabled.get()) {
return
}
project.pluginManager.apply(PmdPlugin)
- Provider<Boolean> ignoreFailures = GradleUtils.booleanProvider(project, IGNORE_FAILURES_PROPERTY)
- Provider<Boolean> testStylingEnabled = GradleUtils.booleanProvider(project, TEST_ANALYSIS_PROPERTY)
+ def ignoreFailures = GradleUtils.booleanProvider(project, IGNORE_FAILURES_PROPERTY)
+ def testStylingEnabled = GradleUtils.booleanProvider(project, TEST_ANALYSIS_PROPERTY)
project.extensions.configure(PmdExtension) {
it.ruleSetFiles = project.files(project.extensions.getByType(GrailsCodeAnalysisExtension).pmdDirectory.file(PMD_CONFIG_FILE_NAME))
@@ -144,15 +144,15 @@ class GrailsCodeAnalysisPlugin implements Plugin<Project> {
}
static void configureSpotbugs(Project project) {
- Provider<Boolean> spotbugsEnabled = GradleUtils.booleanProvider(project, SPOTBUGS_ENABLED_PROPERTY)
+ def spotbugsEnabled = GradleUtils.booleanProvider(project, SPOTBUGS_ENABLED_PROPERTY)
if (!spotbugsEnabled.get()) {
return
}
project.pluginManager.apply(SpotBugsPlugin)
- Provider<Boolean> ignoreFailures = GradleUtils.booleanProvider(project, IGNORE_FAILURES_PROPERTY)
- Provider<Boolean> testStylingEnabled = GradleUtils.booleanProvider(project, TEST_ANALYSIS_PROPERTY)
+ def ignoreFailures = GradleUtils.booleanProvider(project, IGNORE_FAILURES_PROPERTY)
+ def testStylingEnabled = GradleUtils.booleanProvider(project, TEST_ANALYSIS_PROPERTY)
project.extensions.configure(SpotBugsExtension) {
it.effort.set(Effort.valueOf('MAX'))
@@ -162,10 +162,10 @@ class GrailsCodeAnalysisPlugin implements Plugin<Project> {
project.tasks.withType(SpotBugsTask).configureEach { SpotBugsTask task ->
task.group = 'verification'
- NamedDomainObjectContainer<SpotBugsReport> spotBugsReports = task.reports
- SpotBugsReport htmlReport = spotBugsReports.maybeCreate('html')
+ def spotBugsReports = task.reports
+ def htmlReport = spotBugsReports.maybeCreate('html')
htmlReport.required.set(true)
- SpotBugsReport xmlReport = spotBugsReports.maybeCreate('xml')
+ def xmlReport = spotBugsReports.maybeCreate('xml')
xmlReport.required.set(true)
xmlReport.outputLocation.set(
project.extensions.getByType(GrailsCodeAnalysisExtension)
diff --git a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStyleExtension.groovy b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStyleExtension.groovy
index 599e9c5ca3..b52965ed7f 100644
--- a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStyleExtension.groovy
+++ b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStyleExtension.groovy
@@ -30,19 +30,19 @@ import org.gradle.api.model.ObjectFactory
class GrailsCodeStyleExtension {
/**
- * Defaults to project.rootProject.buildDir/codestyle/checkstyle.
+ * Defaults to rootProject.layout.buildDirectory/code-style/checkstyle.
* Default checkstyle files will be written here and used from this location.
*/
final DirectoryProperty checkstyleDirectory
/**
- * Defaults to project.rootProject.buildDir/codestyle/codenarc.
+ * Defaults to rootProject.layout.buildDirectory/code-style/codenarc.
* Default codenarc files will be written here and used from this location.
*/
final DirectoryProperty codenarcDirectory
/**
- * Defaults to rootProject.buildDir/reports/codestyle.
+ * Defaults to rootProject.layout.buildDirectory/reports/code-style.
* All Checkstyle and Codenarc reports will be written here.
*/
final DirectoryProperty reportsDirectory
@@ -50,13 +50,13 @@ class GrailsCodeStyleExtension {
@Inject
GrailsCodeStyleExtension(ObjectFactory objects, Project project) {
checkstyleDirectory = objects.directoryProperty().convention(
- project.rootProject.layout.buildDirectory.dir('codestyle/checkstyle')
+ project.rootProject.layout.buildDirectory.dir('code-style/checkstyle')
)
codenarcDirectory = objects.directoryProperty().convention(
- project.rootProject.layout.buildDirectory.dir('codestyle/codenarc')
+ project.rootProject.layout.buildDirectory.dir('code-style/codenarc')
)
reportsDirectory = objects.directoryProperty().convention(
- project.rootProject.layout.buildDirectory.dir('reports/codestyle')
+ project.rootProject.layout.buildDirectory.dir('reports/code-style')
)
}
}
diff --git a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStylePlugin.groovy b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStylePlugin.groovy
index 0941c0b0ed..1b6e8e7fab 100644
--- a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStylePlugin.groovy
+++ b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsCodeStylePlugin.groovy
@@ -40,20 +40,20 @@ import org.gradle.api.provider.Provider
@CompileStatic
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_DIR_PROPERTY = 'grails.code-style.dir.checkstyle'
+ static String CHECKSTYLE_ENABLED_PROPERTY = 'grails.code-style.enabled.checkstyle'
static String CHECKSTYLE_CONFIG_FILE_NAME = 'checkstyle.xml'
static String CHECKSTYLE_SUPPRESSION_CONFIG_FILE_NAME = 'checkstyle-suppressions.xml'
- static String CODENARC_DIR_PROPERTY = 'grails.codestyle.dir.codenarc'
- static String CODENARC_ENABLED_PROPERTY = 'grails.codestyle.enabled.codenarc'
+ static String CODENARC_DIR_PROPERTY = 'grails.code-style.dir.codenarc'
+ static String CODENARC_ENABLED_PROPERTY = 'grails.code-style.enabled.codenarc'
static String CODENARC_CONFIG_FILE_NAME = 'codenarc.groovy'
- static String CODENARC_FIX_PROPERTY = 'grails.codestyle.codenarc.fix'
+ static String CODENARC_FIX_PROPERTY = 'grails.code-style.codenarc.fix'
- static String IGNORE_FAILURES_PROPERTY = 'grails.codestyle.ignoreFailures'
+ static String IGNORE_FAILURES_PROPERTY = 'grails.code-style.ignoreFailures'
- static String TEST_STYLING_PROPERTY = 'grails.codestyle.enabled.tests'
+ static String TEST_STYLING_PROPERTY = 'grails.code-style.enabled.tests'
static String BASE_RESOURCE_PATH = '/META-INF/org.apache.grails.buildsrc.grails-code-style'
@@ -71,7 +71,7 @@ class GrailsCodeStylePlugin implements Plugin<Project> {
gce.checkstyleDirectory.set(project.provider {
def directory = project.hasProperty(CHECKSTYLE_DIR_PROPERTY) ?
project.rootProject.layout.projectDirectory.dir(project.property(CHECKSTYLE_DIR_PROPERTY) as String) :
- project.rootProject.layout.buildDirectory.get().dir('codestyle').dir('checkstyle')
+ project.rootProject.layout.buildDirectory.get().dir('code-style').dir('checkstyle')
def toCreate = directory.asFile.toPath()
Files.createDirectories(toCreate)
@@ -91,7 +91,7 @@ class GrailsCodeStylePlugin implements Plugin<Project> {
gce.codenarcDirectory.set(project.provider {
def directory = project.hasProperty(CODENARC_DIR_PROPERTY) ?
project.rootProject.layout.projectDirectory.dir(project.property(CODENARC_DIR_PROPERTY) as String) :
- project.rootProject.layout.buildDirectory.get().dir('codestyle').dir('codenarc')
+ project.rootProject.layout.buildDirectory.get().dir('code-style').dir('codenarc')
def toCreate = directory.asFile.toPath()
Files.createDirectories(toCreate)
@@ -134,11 +134,11 @@ class GrailsCodeStylePlugin implements Plugin<Project> {
static void configureCheckstyle(Project project) {
project.pluginManager.apply(CheckstylePlugin)
- Provider<Boolean> ignoreFailures = GradleUtils.booleanProvider(project, IGNORE_FAILURES_PROPERTY)
+ def ignoreFailures = GradleUtils.booleanProvider(project, IGNORE_FAILURES_PROPERTY)
project.extensions.configure(CheckstyleExtension) {
// Explicit `it` is required in extension configuration
- it.getConfigDirectory().set(project.extensions.getByType(GrailsCodeStyleExtension).checkstyleDirectory)
+ it.configDirectory.set(project.extensions.getByType(GrailsCodeStyleExtension).checkstyleDirectory)
it.maxWarnings = 0
it.showViolations = true
it.ignoreFailures = ignoreFailures.get()
@@ -154,8 +154,10 @@ class GrailsCodeStylePlugin implements Plugin<Project> {
task.enabled = false
}
+ // Exclude build directory from Checkstyle task sources to ignore generated sources (e.g. for grails-forge)
+ // Checked via absolute path to ensure platform-independent separator handling
task.exclude { org.gradle.api.file.FileTreeElement element ->
- element.getFile().getAbsolutePath().contains("/build/")
+ element.file.absolutePath.contains(File.separator + 'build' + File.separator)
}
// Redirect XML report output to a single directory to consolidate
@@ -174,8 +176,8 @@ class GrailsCodeStylePlugin implements Plugin<Project> {
registerCodenarcFixTask(project)
- Provider<Boolean> ignoreFailures = GradleUtils.booleanProvider(project, IGNORE_FAILURES_PROPERTY)
- Provider<Boolean> codenarcFix = GradleUtils.booleanProvider(project, CODENARC_FIX_PROPERTY)
+ def ignoreFailures = GradleUtils.booleanProvider(project, IGNORE_FAILURES_PROPERTY)
+ def codenarcFix = GradleUtils.booleanProvider(project, CODENARC_FIX_PROPERTY)
project.extensions.configure(CodeNarcExtension) {
it.configFile = project.extensions.getByType(GrailsCodeStyleExtension)
diff --git a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy
index 7e634d64ec..f02a71310a 100644
--- a/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy
+++ b/build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/GrailsViolationAggregationPlugin.groovy
@@ -21,8 +21,10 @@ package org.apache.grails.buildsrc
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
+import com.github.spotbugs.snom.SpotBugsTask
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
+import groovy.xml.XmlSlurper
import org.gradle.api.GradleException
import org.gradle.api.Plugin
@@ -40,9 +42,6 @@ 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/.
@@ -84,9 +83,9 @@ class GrailsViolationAggregationPlugin implements Plugin<Project> {
)
}
- 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/code-analysis')
+ def violationsDir = project.layout.buildDirectory.dir('reports/violations')
+ def styleXmlDir = project.layout.buildDirectory.dir('reports/code-style')
+ def analysisXmlDir = project.layout.buildDirectory.dir('reports/code-analysis')
TaskProvider<Task> styleTask = registerStyleAggregation(project, styleXmlDir, violationsDir)
TaskProvider<Task> analysisTask = registerAnalysisAggregation(project, analysisXmlDir, violationsDir)
@@ -195,24 +194,57 @@ class GrailsViolationAggregationPlugin implements Plugin<Project> {
}
}
- @CompileDynamic
- private static void parseStyleViolations(Directory styleXmlDir, Directory violationsDir,
- boolean checkStyleTests, boolean codenarcEnabled, boolean checkstyleEnabled) {
+ private static XmlSlurper createSecureSlurper() {
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)
+ return slurper
+ }
- def getModule = { String fileName ->
- def lastDash = fileName.lastIndexOf('-')
- lastDash != -1 ? fileName.substring(0, lastDash) : fileName
- }
+ private static String getModule(String fileName) {
+ def lastDash = fileName.lastIndexOf('-')
+ lastDash != -1 ? fileName.substring(0, lastDash) : fileName
+ }
+
+ private static boolean isTestFile(String fileName) {
+ fileName.toLowerCase().contains('test') || fileName.toLowerCase().contains('integrationtest')
+ }
+
+ @CompileDynamic
+ private static void writeReport(Directory violationsDir, String fileName, List violations, String title) {
+ def outDir = violationsDir.asFile
+ outDir.mkdirs()
+ def reportFile = new File(outDir, fileName)
+ def out = new StringBuilder()
+ out.append("# ${title}\n")
+ out.append("Generated on: ${LocalDateTime.now().format(DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm:ss'))}\n\n")
- def isTestFile = { String fileName ->
- fileName.toLowerCase().contains('test') || fileName.toLowerCase().contains('integrationtest')
+ if (violations.isEmpty()) {
+ out.append('No violations found! 🎉\n')
+ } else {
+ def uniqueViolations = violations.unique().sort { v -> "${v.module}:${v.className}:${v.line}" }
+ def groupedByModule = uniqueViolations.groupBy { it.module }.sort()
+ groupedByModule.each { module, modViolations ->
+ out.append("## Module: ${module}\n")
+ out.append('| Class | Tool | Violation | Line | Message |\n')
+ out.append('| :--- | :--- | :--- | :--- | :--- |\n')
+ modViolations.each { v ->
+ out.append("| ${v.className} | ${v.tool} | ${v.type} | ${v.line} | ${v.message.replaceAll(/\|/, '\\|')} |\n")
+ }
+ out.append('\n')
+ }
}
+ reportFile.text = out.toString()
+ LOGGER.lifecycle("Aggregated report generated: ${reportFile.absolutePath}")
+ }
+
+ @CompileDynamic
+ private static void parseStyleViolations(Directory styleXmlDir, Directory violationsDir,
+ boolean checkStyleTests, boolean codenarcEnabled, boolean checkstyleEnabled) {
+ def slurper = createSecureSlurper()
def shouldSkipClass = { boolean includeTests, String className, String filePath = null ->
if (includeTests) {
@@ -224,33 +256,6 @@ class GrailsViolationAggregationPlugin implements Plugin<Project> {
!filePath && (className.contains('Spec') || className.contains('Test') || className.contains('Tests'))
}
- def writeReport = { String fileName, List violations, String title ->
- def outDir = violationsDir.asFile
- outDir.mkdirs()
- def reportFile = new File(outDir, fileName)
- def out = new StringBuilder()
- out.append("# ${title}\n")
- out.append("Generated on: ${LocalDateTime.now().format(DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm:ss'))}\n\n")
-
- if (violations.isEmpty()) {
- out.append('No violations found! 🎉\n')
- } else {
- def uniqueViolations = violations.unique().sort { v -> "${v.module}:${v.className}:${v.line}" }
- def groupedByModule = uniqueViolations.groupBy { it.module }.sort()
- groupedByModule.each { module, modViolations ->
- out.append("## Module: ${module}\n")
- out.append('| Class | Tool | Violation | Line | Message |\n')
- out.append('| :--- | :--- | :--- | :--- | :--- |\n')
- modViolations.each { v ->
- out.append("| ${v.className} | ${v.tool} | ${v.type} | ${v.line} | ${v.message.replaceAll(/\|/, '\\|')} |\n")
- }
- out.append('\n')
- }
- }
- reportFile.text = out.toString()
- LOGGER.lifecycle("Aggregated report generated: ${reportFile.absolutePath}")
- }
-
// CodeNarc
def codenarcViolations = []
def codenarcDir = styleXmlDir.dir('codenarc').asFile
@@ -284,7 +289,7 @@ class GrailsViolationAggregationPlugin implements Plugin<Project> {
}
}
}
- writeReport('CODENARC_VIOLATIONS.md', codenarcViolations, 'CodeNarc Violations Summary')
+ writeReport(violationsDir, 'CODENARC_VIOLATIONS.md', codenarcViolations, 'CodeNarc Violations Summary')
// Checkstyle
def checkstyleViolations = []
@@ -320,27 +325,13 @@ class GrailsViolationAggregationPlugin implements Plugin<Project> {
}
}
}
- writeReport('CHECKSTYLE_VIOLATIONS.md', checkstyleViolations, 'Checkstyle Violations Summary')
+ writeReport(violationsDir, 'CHECKSTYLE_VIOLATIONS.md', checkstyleViolations, 'Checkstyle Violations Summary')
}
@CompileDynamic
private static void parseAnalysisViolations(Directory analysisXmlDir, Directory violationsDir,
boolean checkAnalysisTests, boolean pmdEnabled, boolean spotbugsEnabled) {
- 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 slurper = createSecureSlurper()
def shouldSkipClass = { boolean includeTests, String className ->
if (includeTests) {
@@ -349,33 +340,6 @@ class GrailsViolationAggregationPlugin implements Plugin<Project> {
className.contains('Spec') || className.contains('Test') || className.contains('Tests')
}
- def writeReport = { String fileName, List violations, String title ->
- def outDir = violationsDir.asFile
- outDir.mkdirs()
- def reportFile = new File(outDir, fileName)
- def out = new StringBuilder()
- out.append("# ${title}\n")
- out.append("Generated on: ${LocalDateTime.now().format(DateTimeFormatter.ofPattern('yyyy-MM-dd HH:mm:ss'))}\n\n")
-
- if (violations.isEmpty()) {
- out.append('No violations found! 🎉\n')
- } else {
- def uniqueViolations = violations.unique().sort { v -> "${v.module}:${v.className}:${v.line}" }
- def groupedByModule = uniqueViolations.groupBy { it.module }.sort()
- groupedByModule.each { module, modViolations ->
- out.append("## Module: ${module}\n")
- out.append('| Class | Tool | Violation | Line | Message |\n')
- out.append('| :--- | :--- | :--- | :--- | :--- |\n')
- modViolations.each { v ->
- out.append("| ${v.className} | ${v.tool} | ${v.type} | ${v.line} | ${v.message.replaceAll(/\|/, '\\|')} |\n")
- }
- out.append('\n')
- }
- }
- reportFile.text = out.toString()
- LOGGER.lifecycle("Aggregated report generated: ${reportFile.absolutePath}")
- }
-
// PMD
def pmdViolations = []
def pmdDir = analysisXmlDir.dir('pmd').asFile
@@ -404,7 +368,7 @@ class GrailsViolationAggregationPlugin implements Plugin<Project> {
}
}
}
- writeReport('PMD_VIOLATIONS.md', pmdViolations, 'PMD Violations Summary')
+ writeReport(violationsDir, 'PMD_VIOLATIONS.md', pmdViolations, 'PMD Violations Summary')
// SpotBugs
def spotbugsViolations = []
@@ -432,7 +396,7 @@ class GrailsViolationAggregationPlugin implements Plugin<Project> {
}
}
}
- writeReport('SPOTBUGS_VIOLATIONS.md', spotbugsViolations, 'SpotBugs Violations Summary')
+ writeReport(violationsDir, 'SPOTBUGS_VIOLATIONS.md', spotbugsViolations, 'SpotBugs Violations Summary')
}
@CompileDynamic
diff --git a/build-logic/plugins/src/test/groovy/org/apache/grails/buildsrc/GrailsCodeStylePluginSpec.groovy b/build-logic/plugins/src/test/groovy/org/apache/grails/buildsrc/GrailsCodeStylePluginSpec.groovy
index 3620c119c1..46c9246992 100644
--- a/build-logic/plugins/src/test/groovy/org/apache/grails/buildsrc/GrailsCodeStylePluginSpec.groovy
+++ b/build-logic/plugins/src/test/groovy/org/apache/grails/buildsrc/GrailsCodeStylePluginSpec.groovy
@@ -19,6 +19,7 @@
package org.apache.grails.buildsrc
import org.gradle.testkit.runner.GradleRunner
+import org.gradle.testkit.runner.TaskOutcome
import spock.lang.Specification
import spock.lang.TempDir
import java.nio.file.Path
@@ -70,7 +71,7 @@ class Test{
.build()
then: "task finished successfully"
- result.task(':codenarcFix').outcome == org.gradle.testkit.runner.TaskOutcome.SUCCESS
+ result.task(':codenarcFix').outcome == TaskOutcome.SUCCESS
and: "violations are fixed"
def fixedContent = groovyFile.text
@@ -101,7 +102,7 @@ class Test {
.build()
then: "task finished successfully"
- result.task(':codenarcFix').outcome == org.gradle.testkit.runner.TaskOutcome.SUCCESS
+ result.task(':codenarcFix').outcome == TaskOutcome.SUCCESS
and: "strings with single quotes are NOT changed to single quotes (which would break them)"
def content = groovyFile.text
@@ -127,7 +128,7 @@ class Test {
.build()
then: "task finished successfully"
- result.task(':codenarcFix').outcome == org.gradle.testkit.runner.TaskOutcome.SUCCESS
+ result.task(':codenarcFix').outcome == TaskOutcome.SUCCESS
and: "escaped quotes are NOT broken"
groovyFile.text.contains('"\\"\\$it\\""')
@@ -153,7 +154,7 @@ class Test {
.build()
then: "task finished successfully"
- result.task(':codenarcFix').outcome == org.gradle.testkit.runner.TaskOutcome.SUCCESS
+ result.task(':codenarcFix').outcome == TaskOutcome.SUCCESS
and: "method references are NOT broken"
def content = groovyFile.text
@@ -184,7 +185,7 @@ class Test {
.build()
then: "task finished successfully"
- result.task(':codenarcFix').outcome == org.gradle.testkit.runner.TaskOutcome.SUCCESS
+ result.task(':codenarcFix').outcome == TaskOutcome.SUCCESS
and: "adjacent GString boundaries are NOT fused"
def content = groovyFile.text
@@ -212,7 +213,7 @@ class Test {
.build()
then: "task finished successfully"
- result.task(':codenarcFix').outcome == org.gradle.testkit.runner.TaskOutcome.SUCCESS
+ result.task(':codenarcFix').outcome == TaskOutcome.SUCCESS
and: "double quotes inside single-quoted strings are NOT changed"
def content = groovyFile.text
diff --git a/grails-forge/gradle.properties b/grails-forge/gradle.properties
index 0a3e6f6690..7e7d48df5f 100644
--- a/grails-forge/gradle.properties
+++ b/grails-forge/gradle.properties
@@ -60,7 +60,7 @@ testRetryVersion=1.6.2
typesafeConfigVersion=1.4.3
# custom checkstyle configuration for forge
-grails.codestyle.dir.checkstyle=config/checkstyle
+grails.code-style.dir.checkstyle=config/checkstyle
org.gradle.parallel=true
org.gradle.caching=true