From 46c8f55b144e59eba7247c81aacae655fb9551f4 Mon Sep 17 00:00:00 2001 From: theminecoder Date: Thu, 31 Dec 2020 18:05:13 +1100 Subject: [PATCH 1/7] Support ktfmt dropbox style in maven plugin --- .../main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java index a5d99f81f4..f91941bf79 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java @@ -19,6 +19,7 @@ import com.diffplug.spotless.FormatterStep; import com.diffplug.spotless.kotlin.KtfmtStep; +import com.diffplug.spotless.kotlin.KtfmtStep.Style; import com.diffplug.spotless.maven.FormatterStepConfig; import com.diffplug.spotless.maven.FormatterStepFactory; @@ -26,10 +27,13 @@ public class Ktfmt implements FormatterStepFactory { @Parameter private String version; + + @Parameter + private boolean dropboxStyle; @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String version = this.version != null ? this.version : KtfmtStep.defaultVersion(); - return KtfmtStep.create(version, config.getProvisioner()); + return KtfmtStep.create(version, config.getProvisioner(), dropboxStyle ? Style.DROPBOX : Style.DEFAULT); } } From a0f62e689061e99955b7ac69545c89b291f5693d Mon Sep 17 00:00:00 2001 From: theminecoder Date: Thu, 31 Dec 2020 18:10:50 +1100 Subject: [PATCH 2/7] Update CHANGES.md --- plugin-maven/CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 38fd3ac767..950d0f0fd0 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,6 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added support for eclipse-cdt 4.18.0. * Added support for eclipse-jdt 4.18.0. * Added support for eclipse-wtp 4.18.0. +* Added ability to specify dropbox style for ktfmt `true` ### Changed * Updated default eclipse-jdt from 4.17.0 to 4.18.0. * Updated default eclipse-wtp from 4.17.0 to 4.18.0. From de49bfece9f8818daf6bd3bf5d44860e6863e000 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 1 Jan 2021 20:29:36 -0800 Subject: [PATCH 3/7] FIxup formatting. --- .../main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java index f91941bf79..4cf276f24d 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 DiffPlug + * Copyright 2016-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ public class Ktfmt implements FormatterStepFactory { @Parameter private String version; - + @Parameter private boolean dropboxStyle; From b9b07b22d6102a9fe1f4afd160130b0b67323c1c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 2 Jan 2021 15:23:38 -0800 Subject: [PATCH 4/7] Add a "style" parameter to match the GJF step, and also a test. --- .../com/diffplug/spotless/kotlin/KtfmtStep.java | 4 ++++ .../com/diffplug/spotless/maven/kotlin/Ktfmt.java | 5 +++-- .../diffplug/spotless/maven/kotlin/KtfmtTest.java | 14 +++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index 1f1c14a5e2..aa69837947 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -79,6 +79,10 @@ public static String defaultVersion() { return DEFAULT_VERSION; } + public static String defaultStyle() { + return Style.DEFAULT.name(); + } + static final class State implements Serializable { private static final long serialVersionUID = 1L; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java index 4cf276f24d..c1258a15fe 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/kotlin/Ktfmt.java @@ -29,11 +29,12 @@ public class Ktfmt implements FormatterStepFactory { private String version; @Parameter - private boolean dropboxStyle; + private String style; @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String version = this.version != null ? this.version : KtfmtStep.defaultVersion(); - return KtfmtStep.create(version, config.getProvisioner(), dropboxStyle ? Style.DROPBOX : Style.DEFAULT); + String style = this.style != null ? this.style : KtfmtStep.defaultStyle(); + return KtfmtStep.create(version, config.getProvisioner(), Style.valueOf(style)); } } diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java index 53a0d336b9..774dbf0733 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtfmtTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,4 +39,16 @@ public void testKtfmt() throws Exception { assertFile(path1).sameAsResource("kotlin/ktfmt/basic.clean"); assertFile(path2).sameAsResource("kotlin/ktfmt/basic.clean"); } + + @Test + public void testKtfmtStyle() throws Exception { + // ktfmt's dependency, google-java-format 1.8 requires a minimum of JRE 11+. + JreVersion.assume11OrGreater(); + + writePomWithKotlinSteps(""); + + setFile("src/main/kotlin/main.kt").toResource("kotlin/ktfmt/basic.dirty"); + mavenRunner().withArguments("spotless:apply").runNoError(); + assertFile("src/main/kotlin/main.kt").sameAsResource("kotlin/ktfmt/basic-dropboxstyle.clean"); + } } From 3e7800bae16ae2ef975b89c2b4a7e970a7d6df49 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 2 Jan 2021 15:26:06 -0800 Subject: [PATCH 5/7] Add a generic "style" parameter into the gradle ktfmt support for consistency. --- .../com/diffplug/gradle/spotless/KotlinExtension.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java index e58129f5ac..0c1f0c44c8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinExtension.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 DiffPlug + * Copyright 2016-2021 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,7 +109,11 @@ public class KtfmtConfig { } public void dropboxStyle() { - style = Style.DROPBOX; + style(Style.DROPBOX); + } + + public void style(Style style) { + this.style = style; replaceStep(createStep()); } From 57f5cc2055e1bd371d108110367ef530f3c2eecd Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 2 Jan 2021 15:26:18 -0800 Subject: [PATCH 6/7] Update maven docs. --- plugin-maven/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 69473075a4..de6bb61002 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -306,7 +306,8 @@ Groovy-Eclipse formatting errors/warnings lead per default to a build failure. T ```xml - 0.13 + 0.18 + ``` From 3f48d2c83c57746fe8fe34d36330b77460a5b8a6 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sat, 2 Jan 2021 15:28:27 -0800 Subject: [PATCH 7/7] Update changelog. --- plugin-maven/CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 08725cca93..fdc7a530c3 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -7,7 +7,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( * Added support for eclipse-cdt 4.18.0. * Added support for eclipse-jdt 4.18.0. * Added support for eclipse-wtp 4.18.0. -* Added ability to specify dropbox style for ktfmt `true` +* Added ability to specify dropbox style for ktfmt `` ([#764](https://github.com/diffplug/spotless/pull/764)) ### Changed * Updated default eclipse-jdt from 4.17.0 to 4.18.0. * Updated default eclipse-wtp from 4.17.0 to 4.18.0.