Skip to content

Commit

Permalink
[build] Use Spotless plugin to enforce/update copyright headers (reac…
Browse files Browse the repository at this point in the history
…tor#2729)

This commit introduces the Spotless plugin, which is capable of only
applying checks to files that have changed compared to a given branch
(by default in this PR, 3.3.x).

For now, only java files are considered, excluding JDK stubs.

This allows to enforce license header with up-to-date end year only when
a file get touched (no need for a big bang update of the end year in
all files comes new year).

The year variable in the template is compatible with IntelliJ's own
template format (velocity), although IntelliJ doesn't typically include
the comment characters like in the added template file.
The template includes 2 blank lines at the end so that one blank line
remains after the license header once spotless is applied.

The ratchet (apply spotless only to files that changed between current
commit and the specified branch) is adapted depending on local build,
CI build without any specific parameter and CI build explicitly intended
for spotless (thanks to -PspotlessFrom=branch). The later is necessary
because spotless needs a full checkout, which is typically not done by
default by CI platforms like GitHub Actions.

In Github Actions, `spotlessCheck` is made a separate step in the
"other tests" job.

See reactor/reactor#701
  • Loading branch information
simonbasle authored Jun 30, 2021
1 parent 8da7d59 commit 4f18a4d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-java@v1
with:
java-version: 8
- uses: eskatos/gradle-command-action@v1
name: gradle
name: license header
with:
arguments: check -x :reactor-core:test --no-daemon
arguments: spotlessCheck -PspotlessFrom=origin/${{ github.base_ref }}
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
#the above should exclude jcstress in master, adding a 3rd job below for jcstress
- uses: eskatos/gradle-command-action@v1
name: other tests
with:
arguments: check -x :reactor-core:test --no-daemon
wrapper-cache-enabled: true
dependencies-cache-enabled: true
configuration-cache-enabled: true
22 changes: 22 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ plugins {
id 'biz.aQute.bnd.builder' version '5.0.1' apply false
id 'io.spring.nohttp' version '0.0.5.RELEASE'
id "io.github.reyerizo.gradle.jcstress" version "0.8.11" apply false
id "com.diffplug.spotless" version "5.14.0"
}

apply plugin: "io.reactor.gradle.detect-ci"
Expand Down Expand Up @@ -106,6 +107,27 @@ nohttp {
allowlistFile = project.file('codequality/nohttp/allowlist.lines')
}

spotless {
if (project.hasProperty("spotlessFrom")) {
println "[Spotless] Ratchet from $project.spotlessFrom"
ratchetFrom project.spotlessFrom
}
else if (isCiServer) {
println "[Spotless] CI detected without explicit branch, not enforcing check"
enforceCheck false
}
else {
String spotlessBranch = "origin/3.3.x"
println "[Spotless] Local run detected, ratchet from $spotlessBranch"
ratchetFrom spotlessBranch
}
java {
target '**/*.java'
targetExclude '**/java8stubs/**/*', '**/java9stubs/**/*'
licenseHeaderFile('codequality/spotless/licenseSlashstarStyle.txt')
}
}

configure(subprojects) { p ->
apply plugin: 'java'
apply plugin: 'jacoco'
Expand Down
16 changes: 16 additions & 0 deletions codequality/spotless/licenseSlashstarStyle.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2011-$today.year VMware Inc. or its affiliates, All Rights Reserved.
*
* 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.
*/

0 comments on commit 4f18a4d

Please sign in to comment.