Skip to content

Commit 24ef800

Browse files
committed
Rename formatter config and switch to an opt-out list
Backport of elastic#54276. Move and rename formatter config file, so that it is easier for Eclipse users to import. Also switch to an opt-out list for formatting. Instead of explcitly listing projects that should be formatted, instead list projects that should not be formatted. This means that any new projects will automatically be formatted and checked.
1 parent f7ea794 commit 24ef800

File tree

3 files changed

+199
-40
lines changed

3 files changed

+199
-40
lines changed

build.gradle

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ apply from: 'gradle/build-scan.gradle'
4545
apply from: 'gradle/build-complete.gradle'
4646
apply from: 'gradle/runtime-jdk-provision.gradle'
4747
apply from: 'gradle/ide.gradle'
48+
apply from: 'gradle/formatting.gradle'
4849

4950
// common maven publishing configuration
5051
allprojects {
@@ -104,46 +105,6 @@ subprojects {
104105
plugins.withType(BuildPlugin).whenPluginAdded {
105106
project.licenseFile = project.rootProject.file('licenses/APACHE-LICENSE-2.0.txt')
106107
project.noticeFile = project.rootProject.file('NOTICE.txt')
107-
108-
// Projects that should be formatted and checked with Spotless are
109-
// listed here, by project path. Once the number of formatted projects
110-
// is greater than the number of unformatted projects, this can be
111-
// switched to an exclude list, and eventually removed completely.
112-
def projectPathsToFormat = [
113-
':benchmarks',
114-
':build-tools',
115-
':distribution:tools:java-version-checker',
116-
':distribution:tools:launchers',
117-
':distribution:tools:plugin-cli',
118-
':qa:os',
119-
':qa:wildfly',
120-
':x-pack:plugin:autoscaling',
121-
':x-pack:plugin:enrich',
122-
':x-pack:plugin:logstash'
123-
]
124-
125-
if (projectPathsToFormat.contains(project.path)) {
126-
project.apply plugin: "com.diffplug.gradle.spotless"
127-
128-
spotless {
129-
java {
130-
// Normally this isn't necessary, but we have Java sources in
131-
// non-standard places
132-
target '**/*.java'
133-
134-
removeUnusedImports()
135-
eclipse().configFile rootProject.file('.eclipseformat.xml')
136-
trimTrailingWhitespace()
137-
138-
// See CONTRIBUTING.md for details of when to enabled this.
139-
if (System.getProperty('spotless.paddedcell') != null) {
140-
paddedCell()
141-
}
142-
}
143-
}
144-
145-
precommit.dependsOn 'spotlessJavaCheck'
146-
}
147108
}
148109
}
149110

File renamed without changes.

gradle/formatting.gradle

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.elasticsearch.gradle.BuildPlugin
21+
22+
/*
23+
* This script plugin configures formatting for Java source using Spotless
24+
* for Gradle. Since the act of formatting existing source can interfere
25+
* with developers' workflows, we don't automatically format all code
26+
* (yet). Instead, we maintain a list of projects that are excluded from
27+
* formatting, until we reach a point where we can comfortably format them
28+
* in one go without too much disruption.
29+
*
30+
* Any new sub-projects must not be added to the exclusions list!
31+
*
32+
* To perform a reformat, run:
33+
*
34+
* ./gradlew spotlessApply
35+
*
36+
* To check the current format, run:
37+
*
38+
* ./gradlew spotlessJavaCheck
39+
*
40+
* This is also carried out by the `precommit` task.
41+
*
42+
* For more about Spotless, see:
43+
*
44+
* https://github.com/diffplug/spotless/tree/master/plugin-gradle
45+
*/
46+
47+
// Do not add new sub-projects here!
48+
def projectPathsToExclude = [
49+
':client:benchmark',
50+
':client:client-benchmark-noop-api-plugin',
51+
':client:rest',
52+
':client:rest-high-level',
53+
':client:sniffer',
54+
':client:test',
55+
':client:transport',
56+
':example-plugins:custom-settings',
57+
':example-plugins:custom-significance-heuristic',
58+
':example-plugins:custom-suggester',
59+
':example-plugins:painless-whitelist',
60+
':example-plugins:rescore',
61+
':example-plugins:rest-handler',
62+
':example-plugins:script-expert-scoring',
63+
':example-plugins:security-authorization-engine',
64+
':libs:elasticsearch-cli',
65+
':libs:elasticsearch-core',
66+
':libs:elasticsearch-dissect',
67+
':libs:elasticsearch-geo',
68+
':libs:elasticsearch-grok',
69+
':libs:elasticsearch-nio',
70+
':libs:elasticsearch-plugin-classloader',
71+
':libs:elasticsearch-secure-sm',
72+
':libs:elasticsearch-ssl-config',
73+
':libs:elasticsearch-x-content',
74+
':modules:aggs-matrix-stats',
75+
':modules:analysis-common',
76+
':modules:ingest-common',
77+
':modules:ingest-geoip',
78+
':modules:ingest-user-agent',
79+
':modules:lang-expression',
80+
':modules:lang-mustache',
81+
':modules:lang-painless',
82+
':modules:lang-painless:spi',
83+
':modules:mapper-extras',
84+
':modules:parent-join',
85+
':modules:percolator',
86+
':modules:rank-eval',
87+
':modules:reindex',
88+
':modules:repository-url',
89+
':modules:systemd',
90+
':modules:tasks',
91+
':modules:transport-netty4',
92+
':plugins:analysis-icu',
93+
':plugins:analysis-kuromoji',
94+
':plugins:analysis-nori',
95+
':plugins:analysis-phonetic',
96+
':plugins:analysis-smartcn',
97+
':plugins:analysis-stempel',
98+
':plugins:analysis-ukrainian',
99+
':plugins:discovery-azure-classic',
100+
':plugins:discovery-ec2',
101+
':plugins:discovery-gce',
102+
':plugins:ingest-attachment',
103+
':plugins:mapper-annotated-text',
104+
':plugins:mapper-murmur3',
105+
':plugins:mapper-size',
106+
':plugins:repository-azure',
107+
':plugins:repository-gcs',
108+
':plugins:repository-hdfs',
109+
':plugins:repository-s3',
110+
':plugins:store-smb',
111+
':plugins:transport-nio',
112+
':qa:die-with-dignity',
113+
':rest-api-spec',
114+
':server',
115+
':test:fixtures:azure-fixture',
116+
':test:fixtures:gcs-fixture',
117+
':test:fixtures:hdfs-fixture',
118+
':test:fixtures:krb5kdc-fixture',
119+
':test:fixtures:minio-fixture',
120+
':test:fixtures:old-elasticsearch',
121+
':test:fixtures:s3-fixture',
122+
':test:framework',
123+
':test:logger-usage',
124+
':x-pack:license-tools',
125+
':x-pack:plugin:analytics',
126+
':x-pack:plugin:async-search',
127+
':x-pack:plugin:async-search:qa',
128+
':x-pack:plugin:ccr',
129+
':x-pack:plugin:ccr:qa',
130+
':x-pack:plugin:core',
131+
':x-pack:plugin:deprecation',
132+
':x-pack:plugin:eql',
133+
':x-pack:plugin:eql:qa',
134+
':x-pack:plugin:eql:qa:common',
135+
':x-pack:plugin:frozen-indices',
136+
':x-pack:plugin:graph',
137+
':x-pack:plugin:identity-provider',
138+
':x-pack:plugin:ilm',
139+
':x-pack:plugin:mapper-constant-keyword',
140+
':x-pack:plugin:mapper-flattened',
141+
':x-pack:plugin:ml',
142+
':x-pack:plugin:monitoring',
143+
':x-pack:plugin:ql',
144+
':x-pack:plugin:rollup',
145+
':x-pack:plugin:search-business-rules',
146+
':x-pack:plugin:security',
147+
':x-pack:plugin:security:cli',
148+
':x-pack:plugin:spatial',
149+
':x-pack:plugin:sql',
150+
':x-pack:plugin:sql:jdbc',
151+
':x-pack:plugin:sql:qa',
152+
':x-pack:plugin:sql:qa:security',
153+
':x-pack:plugin:sql:sql-action',
154+
':x-pack:plugin:sql:sql-cli',
155+
':x-pack:plugin:sql:sql-client',
156+
':x-pack:plugin:sql:sql-proto',
157+
':x-pack:plugin:transform',
158+
':x-pack:plugin:vectors',
159+
':x-pack:plugin:voting-only-node',
160+
':x-pack:plugin:watcher',
161+
':x-pack:plugin:wildcard',
162+
':x-pack:qa',
163+
':x-pack:qa:security-example-spi-extension',
164+
':x-pack:snapshot-tool',
165+
':x-pack:snapshot-tool:qa:google-cloud-storage',
166+
':x-pack:snapshot-tool:qa:s3',
167+
':x-pack:test:feature-aware',
168+
':x-pack:test:idp-fixture',
169+
':x-pack:test:smb-fixture',
170+
':x-pack:transport-client'
171+
]
172+
173+
subprojects {
174+
plugins.withType(BuildPlugin).whenPluginAdded {
175+
if (projectPathsToExclude.contains(project.path) == false) {
176+
project.apply plugin: "com.diffplug.gradle.spotless"
177+
178+
spotless {
179+
java {
180+
// Normally this isn't necessary, but we have Java sources in
181+
// non-standard places
182+
target '**/*.java'
183+
184+
removeUnusedImports()
185+
eclipse().configFile rootProject.file('buildSrc/formatterConfig.xml')
186+
trimTrailingWhitespace()
187+
188+
// See CONTRIBUTING.md for details of when to enabled this.
189+
if (System.getProperty('spotless.paddedcell') != null) {
190+
paddedCell()
191+
}
192+
}
193+
}
194+
195+
precommit.dependsOn 'spotlessJavaCheck'
196+
}
197+
}
198+
}

0 commit comments

Comments
 (0)