Skip to content

Commit 92045d0

Browse files
committed
Use Spotless and .editorconfig for import order normalization instead of Checkstyle
It makes it much simpler to understand the violations, and it provides automatic fix via ./gradlew spotlessApply
1 parent c493310 commit 92045d0

38 files changed

+147
-51
lines changed

.editorconfig

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
root = true
2+
3+
[*]
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = space
8+
9+
[{*.sh,gradlew}]
10+
end_of_line = lf
11+
12+
[{*.bat,*.cmd}]
13+
end_of_line = crlf
14+
15+
[{*.kts,*.kt}]
16+
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
17+
ij_kotlin_name_count_to_use_star_import = 99
18+
ij_kotlin_name_count_to_use_star_import_for_members = 99
19+
ij_java_use_single_class_imports = true
20+
max_line_length = 100
21+
ij_any_wrap_long_lines = true
22+
23+
[*.java]
24+
# Doc: https://youtrack.jetbrains.com/issue/IDEA-170643#focus=streamItem-27-3708697.0-0
25+
# $ means "static"
26+
ij_java_imports_layout = org.apache.calcite.**,|,org.apache.**,|,au.com.**,|,com.**,|,io.**,|,mondrian.**,|,net.**,|,org.**,|,scala.**,|,java.**,javax.**,|,*,|,$com.**,|,$org.apache.calcite.**,|,$org.apache.**,|,$org.**,|,$java,|,$*
27+
indent_size = 2
28+
tab_width = 2
29+
max_line_length = 100
30+
ij_any_spaces_around_additive_operators = true
31+
ij_any_spaces_around_assignment_operators = true
32+
ij_any_spaces_around_bitwise_operators = true
33+
ij_any_spaces_around_equality_operators = true
34+
ij_any_spaces_around_lambda_arrow = true
35+
ij_any_spaces_around_logical_operators = true
36+
ij_any_spaces_around_multiplicative_operators = true
37+
ij_any_spaces_around_relational_operators = true
38+
ij_any_spaces_around_shift_operators = true
39+
ij_continuation_indent_size = 4
40+
ij_java_if_brace_force = always
41+
ij_java_indent_case_from_switch = false
42+
ij_java_space_after_colon = true
43+
ij_java_space_before_colon = true
44+
ij_java_ternary_operation_signs_on_next_line = true
45+
ij_java_use_single_class_imports = true
46+
ij_java_wrap_long_lines = true
47+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
**/.editorconfig
12
*~
23
/.idea
34
*.iml

build.gradle.kts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ import com.github.vlsi.gradle.properties.dsl.toBool
2727
import com.github.vlsi.gradle.release.RepositoryType
2828
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis
2929
import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApisExtension
30-
import org.apache.tools.ant.DirectoryScanner
3130
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
3231

3332
plugins {
3433
publishing
3534
// Verification
3635
checkstyle
36+
id("com.diffplug.gradle.spotless")
3737
id("org.nosphere.apache.rat")
3838
id("com.github.spotbugs")
3939
id("de.thetaphi.forbiddenapis") apply false
@@ -61,6 +61,7 @@ val lastEditYear by extra(lastEditYear())
6161
// Do not enable spotbugs by default. Execute it only when -Pspotbugs is present
6262
val enableSpotBugs = props.bool("spotbugs", default = false)
6363
val skipCheckstyle by props()
64+
val skipSpotless by props()
6465
val skipJavadoc by props()
6566
val enableMavenLocal by props()
6667
val enableGradleMetadata by props()
@@ -152,10 +153,34 @@ val javadocAggregate by tasks.registering(Javadoc::class) {
152153
setDestinationDir(file("$buildDir/docs/javadocAggregate"))
153154
}
154155

156+
val licenseHeaderFile = file("config/license.header.java")
157+
155158
allprojects {
156159
group = "org.apache.calcite.avatica"
157160
version = buildVersion
158161

162+
if (!skipSpotless) {
163+
apply(plugin = "com.diffplug.gradle.spotless")
164+
spotless {
165+
kotlinGradle {
166+
ktlint()
167+
trimTrailingWhitespace()
168+
endWithNewline()
169+
}
170+
if (project == rootProject) {
171+
// Spotless does not exclude subprojects when using target(...)
172+
// So **/*.md is enough to scan all the md files in the codebase
173+
// See https://github.com/diffplug/spotless/issues/468
174+
format("markdown") {
175+
target("**/*.md")
176+
// Flot is known to have trailing whitespace, so the files
177+
// are kept in their original format (e.g. to simplify diff on library upgrade)
178+
trimTrailingWhitespace()
179+
endWithNewline()
180+
}
181+
}
182+
}
183+
}
159184
if (!skipCheckstyle) {
160185
apply<CheckstylePlugin>()
161186
dependencies {
@@ -257,6 +282,37 @@ allprojects {
257282
}
258283
}
259284

285+
if (!skipSpotless) {
286+
spotless {
287+
java {
288+
// targetExclude(*javaccGeneratedPatterns + "**/test/java/*.java")
289+
licenseHeaderFile(licenseHeaderFile)
290+
importOrder(
291+
"org.apache.calcite.",
292+
"org.apache.",
293+
"au.com.",
294+
"com.",
295+
"io.",
296+
"mondrian.",
297+
"net.",
298+
"org.",
299+
"scala.",
300+
"java",
301+
"",
302+
"static com.",
303+
"static org.apache.calcite.",
304+
"static org.apache.",
305+
"static org.",
306+
"static java",
307+
"static "
308+
)
309+
removeUnusedImports()
310+
trimTrailingWhitespace()
311+
indentWithSpaces(4)
312+
endWithNewline()
313+
}
314+
}
315+
}
260316
if (enableSpotBugs) {
261317
apply(plugin = "com.github.spotbugs")
262318
spotbugs {

config/license.header.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/

core/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
*
1717
*/
1818

19-
import com.google.protobuf.gradle.*
19+
import com.google.protobuf.gradle.generateProtoTasks
20+
import com.google.protobuf.gradle.ofSourceSet
21+
import com.google.protobuf.gradle.proto
22+
import com.google.protobuf.gradle.protobuf
23+
import com.google.protobuf.gradle.protoc
2024

2125
plugins {
2226
`java-library`

core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import java.net.URISyntaxException;
5858
import java.net.URL;
5959
import java.util.Objects;
60-
6160
import javax.net.ssl.HostnameVerifier;
6261
import javax.net.ssl.SSLContext;
6362

core/src/main/java/org/apache/calcite/avatica/remote/ClientKeytabJaasConf.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import java.util.HashMap;
2323
import java.util.Map;
24-
2524
import javax.security.auth.login.AppConfigurationEntry;
2625
import javax.security.auth.login.Configuration;
2726

core/src/main/java/org/apache/calcite/avatica/remote/DoAsAvaticaHttpClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.security.PrivilegedAction;
2020
import java.util.Objects;
21-
2221
import javax.security.auth.Subject;
2322

2423
/**

core/src/main/java/org/apache/calcite/avatica/remote/KerberosConnection.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.util.Objects;
2929
import java.util.Set;
3030
import java.util.concurrent.atomic.AtomicBoolean;
31-
3231
import javax.security.auth.Subject;
3332
import javax.security.auth.kerberos.KerberosPrincipal;
3433
import javax.security.auth.kerberos.KerberosTicket;

core/src/test/java/org/apache/calcite/avatica/remote/KerberosConnectionTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.File;
2525
import java.util.Locale;
2626
import java.util.Map.Entry;
27-
2827
import javax.security.auth.Subject;
2928
import javax.security.auth.login.Configuration;
3029
import javax.security.auth.login.LoginContext;

0 commit comments

Comments
 (0)