From d39c3e415374653f65ba974bacc9a3be97118755 Mon Sep 17 00:00:00 2001 From: Lee Dongjin Date: Sat, 27 Mar 2021 22:23:49 +0900 Subject: [PATCH 1/7] Define an Java import order and configure automatic code formatting 1. Define an Java import order: kafka, org.apache.kafka, com, net, org, java, javax, (static imports). 2. Add eclipse formatter and configure automatic code formatting. 3. Suppress import order check for all modules. 4. Separate raft module configurations in suppression.xml. 5. Add storage module configurations in suppression.xml. Define an Java import order and configure automatic code formatting (2) Make server-common's import ordering off --- README.md | 16 ++++++++- build.gradle | 24 +++++++++++++ checkstyle/checkstyle.xml | 7 ++++ checkstyle/suppressions.xml | 69 +++++++++++++++++++++++++++++-------- eclipse-formatter.xml | 52 ++++++++++++++++++++++++++++ 5 files changed, 153 insertions(+), 15 deletions(-) create mode 100644 eclipse-formatter.xml diff --git a/README.md b/README.md index a4fd037ce8824..71e553c50621a 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Please note for this to work you should create/update user maven settings (typic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> - ... + ... ... @@ -207,6 +207,20 @@ You can run checkstyle using: The checkstyle warnings will be found in `reports/checkstyle/reports/main.html` and `reports/checkstyle/reports/test.html` files in the subproject build directories. They are also printed to the console. The build will fail if Checkstyle fails. +As of present, the auto-formatting configuration is working in progress. Auto-formatting is automatically invoked for the modules listed below when the 'checkstyleMain' or 'checkstyleTest' task is run. + +- (No modules specified yet) + +You can also run auto-formatting independently for a single module listed above, like: + + ./gradlew :core:spotlessApply # auto-format *.java files in core module, without running checkstyleMain or checkstyleTest. + +If you are using an IDE, you can use a plugin that provides real-time automatic formatting. For detailed information, refer to the following links: + +- [Eclipse](https://checkstyle.org/eclipse-cs) +- [Intellij](https://plugins.jetbrains.com/plugin/1065-checkstyle-idea) +- [Vscode](https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-checkstyle) + #### Spotbugs #### Spotbugs uses static analysis to look for bugs in the code. You can run spotbugs using: diff --git a/build.gradle b/build.gradle index b589525dff501..290f3d1498346 100644 --- a/build.gradle +++ b/build.gradle @@ -187,6 +187,7 @@ subprojects { apply plugin: 'checkstyle' apply plugin: "com.github.spotbugs" apply plugin: 'org.gradle.test-retry' + apply plugin: 'com.diffplug.spotless' // We use the shadow plugin for the jmh-benchmarks module and the `-all` jar can get pretty large, so // don't publish it @@ -611,6 +612,26 @@ subprojects { } } + spotless { + java { + importOrder('kafka', 'org.apache.kafka', 'com', 'net', 'org', 'java', 'javax', '', '\\#') + + // auto-format specified modules only; the list of auto-format modules will be updated incrementally. + if ([].contains(project.name)) { + target 'src/**/*.java' + } else { + target = project.files([]) + } + + eclipse('4.13.0').configFile("$rootDir/eclipse-formatter.xml") + indentWithSpaces() + trimTrailingWhitespace() + removeUnusedImports() + + licenseHeaderFile file("$rootDir/checkstyle/java.header") + } + } + checkstyle { configFile = new File(rootDir, "checkstyle/checkstyle.xml") configProperties = checkstyleConfigProperties("import-control.xml") @@ -622,6 +643,9 @@ subprojects { description = 'Run checkstyle on all main Java sources' } + checkstyleMain.dependsOn('spotlessApply') + checkstyleTest.dependsOn('spotlessApply') + configure(checkstyleTest) { group = 'Verification' description = 'Run checkstyle on all test Java sources' diff --git a/checkstyle/checkstyle.xml b/checkstyle/checkstyle.xml index 7f912dc428a15..fe6cde0e2ba4a 100644 --- a/checkstyle/checkstyle.xml +++ b/checkstyle/checkstyle.xml @@ -34,6 +34,13 @@ + + + + + + + diff --git a/checkstyle/suppressions.xml b/checkstyle/suppressions.xml index 538feca238cb0..dc0af38b724b7 100644 --- a/checkstyle/suppressions.xml +++ b/checkstyle/suppressions.xml @@ -19,9 +19,15 @@ files="(FieldSpec|MessageDataGenerator).java"/> - - - + + + + + @@ -81,8 +87,10 @@ - + + @@ -135,7 +143,12 @@ - + + + + @@ -150,6 +163,10 @@ + + + @@ -182,13 +199,12 @@ + + - - - @@ -226,10 +242,18 @@ files="TopologyTestDriver.java"/> + + + + + + + + - + - + + + + + + + - diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml new file mode 100644 index 0000000000000..6f8b3f2ebc711 --- /dev/null +++ b/eclipse-formatter.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 2ef5af78ada2496997c8d5e25790a50f2ac3ebec Mon Sep 17 00:00:00 2001 From: Lee Dongjin Date: Wed, 14 Apr 2021 23:39:59 +0900 Subject: [PATCH 2/7] =?UTF-8?q?1.=20Fix=20typo:=20working=20in=20progress?= =?UTF-8?q?=20=E2=86=92=20work=20in=20progress.=202.=20Remove=20Line,=20Br?= =?UTF-8?q?acing=20related=20formatting=20rules.=203.=20Comment=20is=20not?= =?UTF-8?q?=20a=20target=20of=20the=20formatting=20anymore.=204.=20Wrap=20?= =?UTF-8?q?after=20assignment=20operator.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- eclipse-formatter.xml | 22 +++++----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 71e553c50621a..75a1607c08fb0 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ You can run checkstyle using: The checkstyle warnings will be found in `reports/checkstyle/reports/main.html` and `reports/checkstyle/reports/test.html` files in the subproject build directories. They are also printed to the console. The build will fail if Checkstyle fails. -As of present, the auto-formatting configuration is working in progress. Auto-formatting is automatically invoked for the modules listed below when the 'checkstyleMain' or 'checkstyleTest' task is run. +As of present, the auto-formatting configuration is work in progress. Auto-formatting is automatically invoked for the modules listed below when the 'checkstyleMain' or 'checkstyleTest' task is run. - (No modules specified yet) diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml index 6f8b3f2ebc711..76dd39e76b2af 100644 --- a/eclipse-formatter.xml +++ b/eclipse-formatter.xml @@ -6,21 +6,10 @@ - - - - - - - - - - - - - - - + + + + @@ -33,10 +22,9 @@ + - - From 8de2a0f8e097e5645c0a47c858d39d2046b6dfb1 Mon Sep 17 00:00:00 2001 From: Lee Dongjin Date: Tue, 20 Apr 2021 17:16:20 +0900 Subject: [PATCH 3/7] 1. Add license header to eclipse-formatter.xml 2. Re-add line break formatting with 200 characters. 3. Add trogdor to suppressions.xml (Trogdor is separated from tools in fc405d792d) --- checkstyle/suppressions.xml | 4 ++++ eclipse-formatter.xml | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/checkstyle/suppressions.xml b/checkstyle/suppressions.xml index dc0af38b724b7..de9005cdfd2da 100644 --- a/checkstyle/suppressions.xml +++ b/checkstyle/suppressions.xml @@ -281,6 +281,10 @@ + + + diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml index 76dd39e76b2af..2468394619200 100644 --- a/eclipse-formatter.xml +++ b/eclipse-formatter.xml @@ -1,4 +1,20 @@ + @@ -6,6 +22,10 @@ + + + + From 6a86b163ef2f60a263dceadba3c660d702574541 Mon Sep 17 00:00:00 2001 From: Lee Dongjin Date: Thu, 27 May 2021 13:16:07 +0900 Subject: [PATCH 4/7] Update Formatter configuration: 1. remove duplicated entry 'org.eclipse.jdt.core.formatter.indent_empty_lines'. 2. Add 'org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default' entry. (i.e., No space between switch statement's default case and colon.) 3. Remove 'org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration' entry. (i.e., No blank line at the end of the class.) --- eclipse-formatter.xml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml index 2468394619200..8f046e08250c7 100644 --- a/eclipse-formatter.xml +++ b/eclipse-formatter.xml @@ -35,7 +35,6 @@ - @@ -46,6 +45,7 @@ + @@ -53,8 +53,5 @@ - - - - + \ No newline at end of file From a7a2a7ab8c0143a62721580f1b338e862330bba7 Mon Sep 17 00:00:00 2001 From: Lee Dongjin Date: Thu, 3 Jun 2021 20:52:17 +0900 Subject: [PATCH 5/7] Make no blank line at the end of the class (note: it does not remove existing blank lines but just not adding ones.) --- eclipse-formatter.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml index 8f046e08250c7..df5fd356b9247 100644 --- a/eclipse-formatter.xml +++ b/eclipse-formatter.xml @@ -53,5 +53,8 @@ + + + \ No newline at end of file From f7865fbf7e49a4f932a272ba19f7d1ef4def22b4 Mon Sep 17 00:00:00 2001 From: Lee Dongjin Date: Thu, 10 Jun 2021 21:41:15 +0900 Subject: [PATCH 6/7] Remove the formatting section from README.md --- README.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/README.md b/README.md index 75a1607c08fb0..73221b5fd90ff 100644 --- a/README.md +++ b/README.md @@ -207,20 +207,6 @@ You can run checkstyle using: The checkstyle warnings will be found in `reports/checkstyle/reports/main.html` and `reports/checkstyle/reports/test.html` files in the subproject build directories. They are also printed to the console. The build will fail if Checkstyle fails. -As of present, the auto-formatting configuration is work in progress. Auto-formatting is automatically invoked for the modules listed below when the 'checkstyleMain' or 'checkstyleTest' task is run. - -- (No modules specified yet) - -You can also run auto-formatting independently for a single module listed above, like: - - ./gradlew :core:spotlessApply # auto-format *.java files in core module, without running checkstyleMain or checkstyleTest. - -If you are using an IDE, you can use a plugin that provides real-time automatic formatting. For detailed information, refer to the following links: - -- [Eclipse](https://checkstyle.org/eclipse-cs) -- [Intellij](https://plugins.jetbrains.com/plugin/1065-checkstyle-idea) -- [Vscode](https://marketplace.visualstudio.com/items?itemName=shengchen.vscode-checkstyle) - #### Spotbugs #### Spotbugs uses static analysis to look for bugs in the code. You can run spotbugs using: From 5d26cf1af11d40c9b349c58b9050c1a620513993 Mon Sep 17 00:00:00 2001 From: Lee Dongjin Date: Thu, 8 Jul 2021 21:06:49 +0900 Subject: [PATCH 7/7] Suppress storage/api module --- checkstyle/suppressions.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/checkstyle/suppressions.xml b/checkstyle/suppressions.xml index de9005cdfd2da..40e2e8419b549 100644 --- a/checkstyle/suppressions.xml +++ b/checkstyle/suppressions.xml @@ -326,9 +326,9 @@ + files="storage[\\/]api[\\/]src[\\/](main|test)[\\/].+.java$"/> + files="storage[\\/]api[\\/]src[\\/](generated|generated-test)[\\/].+.java$"/>