Skip to content

Spotless / Checkstyle & Code Reformatting #14903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 7.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Enhancement suggestions are tracked as [GitHub issues](https://github.com/apache
#### Environment Setup

##### 1. Forking the Code
One of the benefits of [GitHub](http://github.com) is the way that you can easily contribute to a project by [forking the repository](https://help.github.com/articles/fork-a-repo/) and [sending pull requests](https://help.github.com/articles/creating-a-pull-request/) with your changes. Please see GitHub's guides on how to create a fork and submit that fork. For easier illustration, the remainder of this document will use the `grails` repositories, but when working locally you should use your own fork.
One of the benefits of [GitHub](https://github.com) is the way that you can easily contribute to a project by [forking the repository](https://help.github.com/articles/fork-a-repo/) and [sending pull requests](https://help.github.com/articles/creating-a-pull-request/) with your changes. Please see GitHub's guides on how to create a fork and submit that fork. For easier illustration, the remainder of this document will use the `grails` repositories, but when working locally you should use your own fork.

##### 2. Tool Setup

Expand All @@ -148,7 +148,7 @@ If you're interested in contributing fixes and features to any part of grails, y
* A container runtime

Once you have the pre-requisite packages installed, the next step is to download the Apache Grails source code, which is
hosted at [GitHub](http://github.com/apache/grails-core). This is a simple case of cloning the repository you're
hosted at [GitHub](https://github.com/apache/grails-core). This is a simple case of cloning the repository you're
interested in. For example, to get the core framework run:

git clone http://github.com/apache/grails-core.git
Expand Down Expand Up @@ -202,7 +202,7 @@ There are many aspects to [Grail's documentation](https://docs.grails.org/)

<!-- omit in toc -->
#### <u>Improving the User Guide</u>
The user guide is written using [Asciidoctor](http://asciidoctor.org/docs/user-manual/). The simplest way to contribute fixes is to simply click on the "Improve this doc" link that is to the right of each section of the documentation.
The user guide is written using [Asciidoctor](https://asciidoctor.org/docs/user-manual/). The simplest way to contribute fixes is to simply click on the "Improve this doc" link that is to the right of each section of the documentation.

This will link to the GitHub edit screen where you can make changes, preview them and create a pull request.

Expand Down
2 changes: 2 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ dependencies {
implementation 'io.github.gradle-nexus:publish-plugin'
implementation 'org.apache.grails:grails-docs-core'
implementation 'org.apache.grails:grails-gradle-plugins'
implementation "com.diffplug.spotless:spotless-plugin-gradle:${gradleProperties.spotlessVersion}"
implementation "io.spring.nohttp:nohttp-gradle:${gradleProperties.nohttpGradleVersion}"
implementation 'org.asciidoctor:asciidoctor-gradle-jvm'
implementation 'org.springframework.boot:spring-boot-gradle-plugin'
implementation 'org.nosphere.apache.rat:org.nosphere.apache.rat.gradle.plugin:0.8.1'
Expand Down
2 changes: 1 addition & 1 deletion etc/bin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
</module>

<module name="TreeWalker">
<module name="AvoidStarImport"/>

<!-- Needed for SuppressWarningsFilter -->
<module name="SuppressWarningsHolder"/>
Expand All @@ -114,6 +115,8 @@
<property name="allowMissingReturnTag" value="true"/>
</module>
<module name="JavadocType">
<!-- https://github.com/checkstyle/checkstyle/issues/14581 -->
<property name="allowMissingParamTags" value="true"/>
</module>

<module name="JavadocStyle">
Expand Down Expand Up @@ -175,7 +178,9 @@
<!-- Checks for blocks. You know, those {}'s -->
<!-- See http://checkstyle.sf.net/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="EmptyBlock">
<property name="option" value="text"/>
</module>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
Expand Down Expand Up @@ -226,6 +231,8 @@
<module name="TodoComment">
<property name="severity" value="warning"/>
</module>

<module name="SuppressionCommentFilter"/>
</module>

</module>
31 changes: 31 additions & 0 deletions etc/config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!--
~ 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.
-->
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://checkstyle.sourceforge.net/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress checks="FileLength"
files="GrailsDomainBinder.java|AbstractHibernateCriteriaBuilder.java|StreamCharBuffer.java"/>
<!-- Ignore until we decide what to do with these files -->
<!-- maybe replace with https://github.com/openjson/openjson -->
<suppress files=".*[\\/]grails-web-common[\\/]src[\\/]main[\\/]groovy[\\/]org[\\/]grails[\\/]web[\\/]json[\\/].*" checks=".*"/>
<suppress files=".*[\\/]grails-wrapper[\\/]src[\\/]main[\\/]java[\\/]grails[\\/]init[\\/]GrailsVersion.*" checks=".*"/>
<suppress files=".*[\\/]grails-wrapper[\\/]src[\\/]main[\\/]java[\\/]grails[\\/]init[\\/]GrailsWrapperHome.*" checks=".*"/>
</suppressions>
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# 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,
Expand Down Expand Up @@ -40,6 +40,8 @@ yakworksHibernateGroovyProxyVersion=1.1
picocliVersion=4.7.6
liquibaseHibernate5Version=4.27.0
hibernate5Version=5.6.15.Final
spotlessVersion=6.25.0
nohttpGradleVersion=0.0.11

githubSlug=apache/grails-core
githubBranch=7.0.x
Expand Down
88 changes: 88 additions & 0 deletions gradle/style-enforcement-config.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import io.spring.nohttp.gradle.NoHttpExtension

/*
* 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.
*/

apply plugin: 'checkstyle'
apply plugin: 'com.diffplug.spotless'
apply plugin: 'io.spring.nohttp' // enforce https everywhere

extensions.configure(SpotlessExtension) {
// Explicit `it` required in extension configuration
it.java {
licenseHeaderFile(rootProject.layout.projectDirectory.file('etc/config/spotless/license.java'))
target(
'grails-app/**/*.java',
'src/main/groovy/**/*.java',
'src/main/java/**/*.java'
)
}
it.groovy {
licenseHeaderFile(rootProject.layout.projectDirectory.file('etc/config/spotless/license.java'))
target(
'grails-app/**/*.groovy',
'src/main/groovy/**/*.groovy'
)
}
it.format('javaMisc') {
licenseHeaderFile(rootProject.layout.projectDirectory.file('etc/config/spotless/license.java'), '\\/\\*\\*')
target(
'src/main/**/module-info.java',
'src/main/**/package-info.java'
)
}
}

extensions.configure(CheckstyleExtension) {
// Explicit `it` required in extension configuration
it.configFile = rootProject.layout.projectDirectory.file('etc/config/checkstyle/checkstyle.xml').asFile
it.configDirectory = project.rootProject.layout.projectDirectory.dir('etc/config/checkstyle').asFile
it.maxErrors = 1
it.maxWarnings = 10
it.showViolations = true
}

extensions.configure(NoHttpExtension) {
// Explicit `it` required in extension configuration
// TODO: xsd, xml, & doc files need looked at; this will at least make sure our POMs are correct
it.source.exclude(
'build/**',
'src/test/**',
'LICENSE', '**/LICENSE', 'NOTICE', '**/NOTICE', 'licenses/**', 'INSTALL',
'**/*.xsd', '**/*.xml', '**/*.dtd',
'**/test/**',
'**/@[email protected]',
'**/grails-doc/**' // TODO: the grails doc still has a lot of work to do to remove https
)
}

if (tasks.names.contains('checkstyleTest')) {
tasks.named('checkstyleTest').configure {
it.group = 'verification'
it.enabled = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment why we have chosen to disable checkstyleTest?

}
}

if (tasks.names.contains('checkstyleMain')) {
tasks.named('checkstyleMain').configure {
it.group = 'verification'
it.dependsOn('spotlessCheck')
}
}
1 change: 1 addition & 0 deletions grails-async/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ apply {
from rootProject.layout.projectDirectory.file('gradle/docs-config.gradle')
from rootProject.layout.projectDirectory.file('gradle/publish-config.gradle')
from rootProject.layout.projectDirectory.file('gradle/test-config.gradle')
from rootProject.layout.projectDirectory.file('gradle/style-enforcement-config.gradle')
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
*/
package grails.async

import org.codehaus.groovy.transform.GroovyASTTransformationClass

import java.lang.annotation.Documented
import java.lang.annotation.ElementType
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import java.lang.annotation.Target

import org.codehaus.groovy.transform.GroovyASTTransformationClass

/**
* An AST transformation that takes each method in the given class and adds a delegate method that returns a {@link grails.async.Promise} and executes the method asynchronously.
* For example given the following class:
Expand Down Expand Up @@ -65,5 +65,6 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass
@Target([ElementType.TYPE, ElementType.FIELD])
@GroovyASTTransformationClass("org.grails.async.transform.internal.DelegateAsyncTransformation")
@interface DelegateAsync {

Class value() default DelegateAsync
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ interface PromiseFactory {
/**
* Creates a promise with a value pre-bound to it
* @param value The value
* @param <T> The type of the value
* @param <T> The type of the value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... what formatting rule adding this whitespace?

* @return A Promise
*/
<T> Promise<T> createBoundPromise(T value)

/**
* Creates an unfulfilled promise that returns the given type
* @param returnType The return type
* @param <T> The type of the class
* @param <T> The type of the class
* @return The unfulfilled promise
*/
<T> Promise<T> createPromise(Class<T> returnType)
Expand All @@ -76,23 +76,23 @@ interface PromiseFactory {
* @param map The map
* @return A promise
*/
<K,V> Promise<Map<K,V>> createPromise(Map<K, V> map)
<K, V> Promise<Map<K, V>> createPromise(Map<K, V> map)

/**
* Creates a promise from the given map where the values of the map are either closures or Promise instances
*
* @param map The map
* @return A promise
*/
<K,V> Promise<Map<K,V>> createPromise(Map<K, V> map, List<PromiseDecorator> decorators)
<K, V> Promise<Map<K, V>> createPromise(Map<K, V> map, List<PromiseDecorator> decorators)

/**
* Creates a promise from one or more other promises
*
* @param promises The promises
* @return The promise
*/
<T> Promise<List<T>> createPromise(Promise<T>...promises)
<T> Promise<List<T>> createPromise(Promise<T>... promises)

/**
* Creates a promise from one or many closures
Expand Down Expand Up @@ -132,7 +132,7 @@ interface PromiseFactory {
* @param promises The promises
* @return The list of bound values
*/
<T> List<T> waitAll(Promise<T>...promises)
<T> List<T> waitAll(Promise<T>... promises)
/**
* Synchronously waits for all promises to complete returning a list of values
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class PromiseList<T> implements Promise<List<T>> {

@Override
boolean isDone() {
return promises.every {promise -> promise.isDone() }
return promises.every { promise -> promise.isDone() }
}

@Override
Expand Down
Loading
Loading