forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotless.gradle
110 lines (100 loc) · 4.69 KB
/
spotless.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* 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
*
* http://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.
*/
subprojects {
apply plugin: "com.diffplug.gradle.spotless"
spotless {
lineEndings = 'unix'
java {
target project.fileTree(project.projectDir) {
include '**/*.java'
exclude '**/generated-src/**'
exclude '**/build/**'
}
// As the method name suggests, bump this number if any of the below "custom" rules change.
// Spotless will not run on unchanged files unless this number changes.
bumpThisNumberIfACustomStepChanges(3)
removeUnusedImports()
custom 'Remove commented-out import statements', {
it.replaceAll(/\n\/\/ import .*?;.*/, '')
}
custom 'Refuse wildcard imports', {
// Wildcard imports can't be resolved by spotless itself.
// This will require the developer themselves to adhere to best practices.
if (it =~ /\nimport .*\*;/) {
throw new AssertionError("Do not use wildcard imports. 'spotlessApply' cannot resolve this issue.");
}
}
importOrderFile "${project(':geode-core').projectDir}/../etc/eclipseOrganizeImports.importorder"
custom 'Remove unhelpful javadoc stubs', {
// e.g., remove the following lines:
// "* @param paramName"
// "* @throws ExceptionType"
// "* @return returnType"'
// Multiline to allow anchors on newlines
it.replaceAll(/(?m)^ *\* *@(?:param|throws|return) *\w* *\n/, '')
}
custom 'Remove any empty Javadocs and block comments', {
// Matches any /** [...] */ or /* [...] */ that contains:
// (a) only whitespace
// (b) trivial information, such as "@param paramName" or @throws ExceptionType
// without any additional information. This information is implicit in the signature.
it.replaceAll(/\/\*+\s*\n(\s*\*\s*\n)*\s*\*+\/\s*\n/, '')
}
// Enforce style modifier order
custom 'Modifier ordering', {
def modifierRanking = [
public : 1,
protected : 2,
private : 3,
abstract : 4,
default : 5,
static : 6,
final : 7,
transient : 8,
volatile : 9,
synchronized: 10,
native : 11,
strictfp : 12]
// Find any instance of multiple modifiers. Lead with a non-word character to avoid
// accidental matching against for instance, "an alternative default value"
it.replaceAll(/\W(?:public |protected |private |abstract |default |static |final |transient |volatile |synchronized |native |strictfp ){2,}/, {
// Do not replace the leading non-word character. Identify the modifiers
it.replaceAll(/(?:public |protected |private |abstract |default |static |final |transient |volatile |synchronized |native |strictfp ){2,}/, {
// Sort the modifiers according to the ranking above
it.split().sort({ modifierRanking[it] }).join(' ') + ' '
}
)
}
)
}
// Notes on eclipse formatter version:
// 4.6.3 is consistent with existing / previous behavior.
// 4.7.1 works, but had different default whitespace rules, notably with mid-ternary linebreak.
// 4.7.2 exists but is currently incompatible with our style file, raising NPEs.
// The format file is relative to geode-core and not the root project as the root project would change
// if Geode and submodules are included as part of a different gradle project.
eclipse('4.6.3').configFile "${project(':geode-core').projectDir}/../etc/eclipse-java-google-style.xml"
trimTrailingWhitespace()
endWithNewline()
}
}
// If we add more languages to Spotless, add them to 'compileXYZ' trigger below
afterEvaluate {
project.tasks['compileJava'].mustRunAfter(spotlessCheck)
project.tasks['compileJava'].mustRunAfter(spotlessApply)
}
}