From 1b01c718f4e7b15bac9e08309eb4ca7b89bfd9d1 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Tue, 11 Jul 2023 14:21:26 -0700 Subject: [PATCH 1/7] Adding spotless plugin to project build.gradle. Signed-off-by: Mitchell Gale Remove commented out spotless changes. Signed-off-by: Mitchell Gale Adding Spotless to DEVELOPER_GUIDE.rst Signed-off-by: Mitchell Gale Added Google Java format to spotless. Signed-off-by: Mitchell Gale Update DEVELOPER_GUIDE.rst Co-authored-by: Yury-Fridlyand --- DEVELOPER_GUIDE.rst | 8 ++++++-- build.gradle | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/DEVELOPER_GUIDE.rst b/DEVELOPER_GUIDE.rst index 923cb459f9..257e3bb8f9 100644 --- a/DEVELOPER_GUIDE.rst +++ b/DEVELOPER_GUIDE.rst @@ -113,8 +113,8 @@ Note that missing license header will be detected by Gradle license plugin and f Making Code Changes =================== -Project Strucure ----------------- +Project Structure +----------------- The plugin codebase is in standard layout of Gradle project:: @@ -226,6 +226,10 @@ Most of the time you just need to run ./gradlew build which will make sure you p - Build plugin by run all tasks above (this takes time). * - ./gradlew pitest - Run PiTest mutation testing (see more info in `#1204 `_) + * - ./gradlew spotlessCheck + - Runs Spotless to check for code style. + * - ./gradlew spotlessApply + - Automatically apply spotless code style changes. For integration test, you can use ``-Dtests.class`` “UT full path” to run a task individually. For example ``./gradlew :integ-test:integTest -Dtests.class="*QueryIT"``. diff --git a/build.gradle b/build.gradle index d7458f722f..6e7dc631e9 100644 --- a/build.gradle +++ b/build.gradle @@ -65,6 +65,7 @@ plugins { id 'checkstyle' id "io.freefair.lombok" version "6.4.0" id 'jacoco' + id 'com.diffplug.spotless' version '6.19.0' } // import versions defined in https://github.com/opensearch-project/OpenSearch/blob/main/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchJavaPlugin.java#L94 @@ -79,6 +80,20 @@ repositories { maven { url 'https://jitpack.io' } } +spotless { + java { + target fileTree('.') { + include '**/*.java' + exclude '**/build/**', '**/build-*/**' + } + importOrder() + removeUnusedImports() + trimTrailingWhitespace() + endWithNewline() + googleJavaFormat() + } +} + allprojects { version = opensearch_version.tokenize('-')[0] + '.0' if (buildVersionQualifier) { From 3d87ab57cf074a30e68a40097916282929fa5812 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Tue, 11 Jul 2023 20:57:21 -0700 Subject: [PATCH 2/7] Added apply false for spotless Signed-off-by: Mitchell Gale --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6e7dc631e9..678df1324d 100644 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,7 @@ plugins { id 'checkstyle' id "io.freefair.lombok" version "6.4.0" id 'jacoco' - id 'com.diffplug.spotless' version '6.19.0' + id 'com.diffplug.spotless' version '6.19.0' apply false } // import versions defined in https://github.com/opensearch-project/OpenSearch/blob/main/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchJavaPlugin.java#L94 From 98479d0aa5873ae3d0c91f4f91570bb54c0abe72 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Wed, 12 Jul 2023 13:00:31 -0700 Subject: [PATCH 3/7] Adding ratchetFrom to build.gradle Signed-off-by: Mitchell Gale --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 678df1324d..852f97d9c9 100644 --- a/build.gradle +++ b/build.gradle @@ -81,6 +81,7 @@ repositories { } spotless { + ratchetFrom java { target fileTree('.') { include '**/*.java' From bf595d3a05dac892fa837db9f6e2bde95190dd0d Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Wed, 12 Jul 2023 15:12:18 -0700 Subject: [PATCH 4/7] Adding license header to build.gradle for spotless. Signed-off-by: Mitchell Gale --- build.gradle | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 852f97d9c9..d18d25dcf7 100644 --- a/build.gradle +++ b/build.gradle @@ -65,7 +65,7 @@ plugins { id 'checkstyle' id "io.freefair.lombok" version "6.4.0" id 'jacoco' - id 'com.diffplug.spotless' version '6.19.0' apply false + id 'com.diffplug.spotless' version '6.19.0' } // import versions defined in https://github.com/opensearch-project/OpenSearch/blob/main/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchJavaPlugin.java#L94 @@ -81,17 +81,20 @@ repositories { } spotless { - ratchetFrom java { target fileTree('.') { include '**/*.java' exclude '**/build/**', '**/build-*/**' } - importOrder() - removeUnusedImports() - trimTrailingWhitespace() - endWithNewline() - googleJavaFormat() +// importOrder() + licenseHeader("/*\n" + + " * Copyright OpenSearch Contributors\n" + + " * SPDX-License-Identifier: Apache-2.0\n" + + " */\n\n\n") +// removeUnusedImports() +// trimTrailingWhitespace() +// endWithNewline() +// googleJavaFormat() } } From b23f84cbcb88bc466a548cd859dc1207032a0ba9 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Wed, 12 Jul 2023 15:16:14 -0700 Subject: [PATCH 5/7] Uncommenting all changes to build.gradle for spotless. Signed-off-by: Mitchell Gale --- build.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index d18d25dcf7..dbc9ac650b 100644 --- a/build.gradle +++ b/build.gradle @@ -86,15 +86,15 @@ spotless { include '**/*.java' exclude '**/build/**', '**/build-*/**' } -// importOrder() + importOrder() licenseHeader("/*\n" + " * Copyright OpenSearch Contributors\n" + " * SPDX-License-Identifier: Apache-2.0\n" + " */\n\n\n") -// removeUnusedImports() -// trimTrailingWhitespace() -// endWithNewline() -// googleJavaFormat() + removeUnusedImports() + trimTrailingWhitespace() + endWithNewline() + googleJavaFormat() } } From 5e15e79d5e1719d266426a7c3ace7afb9092df42 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Wed, 19 Jul 2023 14:29:26 -0700 Subject: [PATCH 6/7] Commented out spotless checks. Signed-off-by: Mitchell Gale --- build.gradle | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index dbc9ac650b..f142dedb48 100644 --- a/build.gradle +++ b/build.gradle @@ -80,21 +80,22 @@ repositories { maven { url 'https://jitpack.io' } } +// Spotless checks will be added as PRs are applied to resolve each style issue is approved. spotless { java { - target fileTree('.') { - include '**/*.java' - exclude '**/build/**', '**/build-*/**' - } - importOrder() - licenseHeader("/*\n" + - " * Copyright OpenSearch Contributors\n" + - " * SPDX-License-Identifier: Apache-2.0\n" + - " */\n\n\n") - removeUnusedImports() - trimTrailingWhitespace() - endWithNewline() - googleJavaFormat() +// target fileTree('.') { +// include '**/*.java' +// exclude '**/build/**', '**/build-*/**' +// } +// importOrder() +// licenseHeader("/*\n" + +// " * Copyright OpenSearch Contributors\n" + +// " * SPDX-License-Identifier: Apache-2.0\n" + +// " */\n\n\n") +// removeUnusedImports() +// trimTrailingWhitespace() +// endWithNewline() +// googleJavaFormat() } } From 18a75bd98fdca34405face2a80562bca1138e841 Mon Sep 17 00:00:00 2001 From: Mitchell Gale Date: Wed, 19 Jul 2023 21:51:58 -0700 Subject: [PATCH 7/7] Add specific version for java format spotless (1.17.0) Signed-off-by: Mitchell Gale --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index f142dedb48..ff29eb7687 100644 --- a/build.gradle +++ b/build.gradle @@ -84,7 +84,7 @@ repositories { spotless { java { // target fileTree('.') { -// include '**/*.java' +// include '**/*.java', 'src/*/java/**/*.java' // exclude '**/build/**', '**/build-*/**' // } // importOrder() @@ -95,7 +95,7 @@ spotless { // removeUnusedImports() // trimTrailingWhitespace() // endWithNewline() -// googleJavaFormat() +// googleJavaFormat('1.17.0').reflowLongStrings().groupArtifact('com.google.googlejavaformat:google-java-format') } }