From 687bace3f3e77bd955a72cc705315debd25d8468 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 9 Feb 2023 10:29:40 +0800 Subject: [PATCH] [Java][native] add spotless gradle/mvn plugin (#14641) * add spotless plugin to java native client * apply spotless * Revert "apply spotless" This reverts commit 485d50bbde417044f8aabaef76dee906afc6798c. --- .../libraries/native/build.gradle.mustache | 27 ++++++++++++ .../Java/libraries/native/pom.mustache | 41 +++++++++++++++++++ .../client/echo_api/java/native/build.gradle | 27 ++++++++++++ samples/client/echo_api/java/native/pom.xml | 41 +++++++++++++++++++ .../petstore/java/native-async/build.gradle | 27 ++++++++++++ .../client/petstore/java/native-async/pom.xml | 41 +++++++++++++++++++ .../petstore/java/native-jakarta/build.gradle | 27 ++++++++++++ .../petstore/java/native-jakarta/pom.xml | 41 +++++++++++++++++++ .../client/petstore/java/native/build.gradle | 27 ++++++++++++ samples/client/petstore/java/native/pom.xml | 41 +++++++++++++++++++ 10 files changed, 340 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache index bbb221864eb..0613829b009 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/build.gradle.mustache @@ -1,5 +1,6 @@ apply plugin: 'idea' apply plugin: 'eclipse' +apply plugin: 'com.diffplug.spotless' group = '{{groupId}}' version = '{{artifactVersion}}' @@ -8,6 +9,9 @@ buildscript { repositories { mavenCentral() } + dependencies { + classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.11.0' + } } repositories { @@ -85,3 +89,26 @@ dependencies { implementation "org.apache.httpcomponents:httpmime:$httpmime_version" testImplementation "junit:junit:$junit_version" } + +// Use spotless plugin to automatically format code, remove unused import, etc +// To apply changes directly to the file, run `gradlew spotlessApply` +// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle +spotless { + // comment out below to run spotless as part of the `check` task + enforceCheck false + format 'misc', { + // define the files (e.g. '*.gradle', '*.md') to apply `misc` to + target '.gitignore' + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() // Takes an integer argument if you don't like 4 + endWithNewline() + } + java { + // don't need to set target, it is inferred from java + // apply a specific flavor of google-java-format + googleJavaFormat('1.8').aosp().reflowLongStrings() + removeUnusedImports() + importOrder() + } +} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache index 7eebfd48026..fc78cca4e02 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache @@ -134,6 +134,46 @@ + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + + .gitignore + + + + + + true + 4 + + + + + + + + + + 1.8 + + true + + + + + + @@ -240,5 +280,6 @@ {{/useJakartaEe}} 4.5.13 4.13.2 + 2.27.2 diff --git a/samples/client/echo_api/java/native/build.gradle b/samples/client/echo_api/java/native/build.gradle index 479c7ef1ffb..4e526cc1e75 100644 --- a/samples/client/echo_api/java/native/build.gradle +++ b/samples/client/echo_api/java/native/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'idea' apply plugin: 'eclipse' +apply plugin: 'com.diffplug.spotless' group = 'org.openapitools' version = '0.1.0' @@ -8,6 +9,9 @@ buildscript { repositories { mavenCentral() } + dependencies { + classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.11.0' + } } repositories { @@ -79,3 +83,26 @@ dependencies { implementation "org.apache.httpcomponents:httpmime:$httpmime_version" testImplementation "junit:junit:$junit_version" } + +// Use spotless plugin to automatically format code, remove unused import, etc +// To apply changes directly to the file, run `gradlew spotlessApply` +// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle +spotless { + // comment out below to run spotless as part of the `check` task + enforceCheck false + format 'misc', { + // define the files (e.g. '*.gradle', '*.md') to apply `misc` to + target '.gitignore' + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() // Takes an integer argument if you don't like 4 + endWithNewline() + } + java { + // don't need to set target, it is inferred from java + // apply a specific flavor of google-java-format + googleJavaFormat('1.8').aosp().reflowLongStrings() + removeUnusedImports() + importOrder() + } +} diff --git a/samples/client/echo_api/java/native/pom.xml b/samples/client/echo_api/java/native/pom.xml index 8e8079eb53a..21f978f406f 100644 --- a/samples/client/echo_api/java/native/pom.xml +++ b/samples/client/echo_api/java/native/pom.xml @@ -127,6 +127,46 @@ + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + + .gitignore + + + + + + true + 4 + + + + + + + + + + 1.8 + + true + + + + + + @@ -218,5 +258,6 @@ 1.3.5 4.5.13 4.13.2 + 2.27.2 diff --git a/samples/client/petstore/java/native-async/build.gradle b/samples/client/petstore/java/native-async/build.gradle index 139a7ae2321..9a13583ffe1 100644 --- a/samples/client/petstore/java/native-async/build.gradle +++ b/samples/client/petstore/java/native-async/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'idea' apply plugin: 'eclipse' +apply plugin: 'com.diffplug.spotless' group = 'org.openapitools' version = '1.0.0' @@ -8,6 +9,9 @@ buildscript { repositories { mavenCentral() } + dependencies { + classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.11.0' + } } repositories { @@ -79,3 +83,26 @@ dependencies { implementation "org.apache.httpcomponents:httpmime:$httpmime_version" testImplementation "junit:junit:$junit_version" } + +// Use spotless plugin to automatically format code, remove unused import, etc +// To apply changes directly to the file, run `gradlew spotlessApply` +// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle +spotless { + // comment out below to run spotless as part of the `check` task + enforceCheck false + format 'misc', { + // define the files (e.g. '*.gradle', '*.md') to apply `misc` to + target '.gitignore' + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() // Takes an integer argument if you don't like 4 + endWithNewline() + } + java { + // don't need to set target, it is inferred from java + // apply a specific flavor of google-java-format + googleJavaFormat('1.8').aosp().reflowLongStrings() + removeUnusedImports() + importOrder() + } +} diff --git a/samples/client/petstore/java/native-async/pom.xml b/samples/client/petstore/java/native-async/pom.xml index 5166589d284..0c11192b050 100644 --- a/samples/client/petstore/java/native-async/pom.xml +++ b/samples/client/petstore/java/native-async/pom.xml @@ -127,6 +127,46 @@ + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + + .gitignore + + + + + + true + 4 + + + + + + + + + + 1.8 + + true + + + + + + @@ -218,5 +258,6 @@ 1.3.5 4.5.13 4.13.2 + 2.27.2 diff --git a/samples/client/petstore/java/native-jakarta/build.gradle b/samples/client/petstore/java/native-jakarta/build.gradle index 5c2571fb4a4..0c8090d61ed 100644 --- a/samples/client/petstore/java/native-jakarta/build.gradle +++ b/samples/client/petstore/java/native-jakarta/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'idea' apply plugin: 'eclipse' +apply plugin: 'com.diffplug.spotless' group = 'org.openapitools' version = '1.0.0' @@ -8,6 +9,9 @@ buildscript { repositories { mavenCentral() } + dependencies { + classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.11.0' + } } repositories { @@ -79,3 +83,26 @@ dependencies { implementation "org.apache.httpcomponents:httpmime:$httpmime_version" testImplementation "junit:junit:$junit_version" } + +// Use spotless plugin to automatically format code, remove unused import, etc +// To apply changes directly to the file, run `gradlew spotlessApply` +// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle +spotless { + // comment out below to run spotless as part of the `check` task + enforceCheck false + format 'misc', { + // define the files (e.g. '*.gradle', '*.md') to apply `misc` to + target '.gitignore' + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() // Takes an integer argument if you don't like 4 + endWithNewline() + } + java { + // don't need to set target, it is inferred from java + // apply a specific flavor of google-java-format + googleJavaFormat('1.8').aosp().reflowLongStrings() + removeUnusedImports() + importOrder() + } +} diff --git a/samples/client/petstore/java/native-jakarta/pom.xml b/samples/client/petstore/java/native-jakarta/pom.xml index 5b48ab268de..6bc82abbcc0 100644 --- a/samples/client/petstore/java/native-jakarta/pom.xml +++ b/samples/client/petstore/java/native-jakarta/pom.xml @@ -127,6 +127,46 @@ + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + + .gitignore + + + + + + true + 4 + + + + + + + + + + 1.8 + + true + + + + + + @@ -218,5 +258,6 @@ 2.1.1 4.5.13 4.13.2 + 2.27.2 diff --git a/samples/client/petstore/java/native/build.gradle b/samples/client/petstore/java/native/build.gradle index 139a7ae2321..9a13583ffe1 100644 --- a/samples/client/petstore/java/native/build.gradle +++ b/samples/client/petstore/java/native/build.gradle @@ -1,5 +1,6 @@ apply plugin: 'idea' apply plugin: 'eclipse' +apply plugin: 'com.diffplug.spotless' group = 'org.openapitools' version = '1.0.0' @@ -8,6 +9,9 @@ buildscript { repositories { mavenCentral() } + dependencies { + classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.11.0' + } } repositories { @@ -79,3 +83,26 @@ dependencies { implementation "org.apache.httpcomponents:httpmime:$httpmime_version" testImplementation "junit:junit:$junit_version" } + +// Use spotless plugin to automatically format code, remove unused import, etc +// To apply changes directly to the file, run `gradlew spotlessApply` +// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle +spotless { + // comment out below to run spotless as part of the `check` task + enforceCheck false + format 'misc', { + // define the files (e.g. '*.gradle', '*.md') to apply `misc` to + target '.gitignore' + // define the steps to apply to those files + trimTrailingWhitespace() + indentWithSpaces() // Takes an integer argument if you don't like 4 + endWithNewline() + } + java { + // don't need to set target, it is inferred from java + // apply a specific flavor of google-java-format + googleJavaFormat('1.8').aosp().reflowLongStrings() + removeUnusedImports() + importOrder() + } +} diff --git a/samples/client/petstore/java/native/pom.xml b/samples/client/petstore/java/native/pom.xml index 5166589d284..0c11192b050 100644 --- a/samples/client/petstore/java/native/pom.xml +++ b/samples/client/petstore/java/native/pom.xml @@ -127,6 +127,46 @@ + + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + + + + + + .gitignore + + + + + + true + 4 + + + + + + + + + + 1.8 + + true + + + + + + @@ -218,5 +258,6 @@ 1.3.5 4.5.13 4.13.2 + 2.27.2