From 459708539308161e9f9f91de99a453053535dfb1 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 19 Nov 2023 01:55:53 +0800 Subject: [PATCH 1/2] Reuse configs for KotlinExtension and KotlinGradleExtension --- .../diffplug/spotless/kotlin/DiktatStep.java | 4 - .../diffplug/spotless/kotlin/KtLintStep.java | 17 -- .../gradle/spotless/BaseKotlinExtension.java | 209 ++++++++++++++++++ .../gradle/spotless/KotlinExtension.java | 183 +-------------- .../spotless/KotlinGradleExtension.java | 189 +--------------- 5 files changed, 217 insertions(+), 385 deletions(-) create mode 100644 plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java index fefda39784..a2650e31fc 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java @@ -53,10 +53,6 @@ public static FormatterStep create(String versionDiktat, Provisioner provisioner return create(versionDiktat, provisioner, false, config); } - public static FormatterStep createForScript(String versionDiktat, Provisioner provisioner, @Nullable FileSignature config) { - return create(versionDiktat, provisioner, true, config); - } - public static FormatterStep create(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) { if (BadSemver.version(versionDiktat) < BadSemver.version(MIN_SUPPORTED_VERSION)) { throw new IllegalStateException("Minimum required Diktat version is " + MIN_SUPPORTED_VERSION + ", you tried " + versionDiktat + " which is too old"); diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 4aca4da02e..13fba97c57 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -54,23 +54,6 @@ public static FormatterStep create(String version, Provisioner provisioner, return create(version, provisioner, false, null, userData, editorConfigOverride); } - public static FormatterStep createForScript(String version, Provisioner provisioner) { - return create(version, provisioner, true, null, Collections.emptyMap(), Collections.emptyMap()); - } - - public static FormatterStep createForScript(String version, - Provisioner provisioner, - @Nullable FileSignature editorConfigPath, - Map userData, - Map editorConfigOverride) { - return create(version, - provisioner, - true, - editorConfigPath, - userData, - editorConfigOverride); - } - public static FormatterStep create(String version, Provisioner provisioner, boolean isScript, diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java new file mode 100644 index 0000000000..5ced54a94e --- /dev/null +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -0,0 +1,209 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.gradle.spotless; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; +import java.util.function.Consumer; + +import javax.annotation.Nullable; + +import com.diffplug.common.collect.ImmutableSortedMap; +import com.diffplug.spotless.FileSignature; +import com.diffplug.spotless.FormatterStep; +import com.diffplug.spotless.kotlin.DiktatStep; +import com.diffplug.spotless.kotlin.KtLintStep; +import com.diffplug.spotless.kotlin.KtfmtStep; + +public abstract class BaseKotlinExtension extends FormatExtension { + public BaseKotlinExtension(SpotlessExtension spotless) { + super(spotless); + } + + public DiktatConfig diktat() { + return diktat(DiktatStep.defaultVersionDiktat()); + } + + /** Adds the specified version of diktat. */ + public DiktatConfig diktat(String version) { + return new DiktatConfig(version); + } + + public KtlintConfig ktlint() throws IOException { + return ktlint(KtLintStep.defaultVersion()); + } + + /** Adds the specified version of ktlint. */ + public KtlintConfig ktlint(String version) throws IOException { + return new KtlintConfig(version, Collections.emptyMap(), Collections.emptyMap()); + } + + /** Uses the ktfmt jar to format source code. */ + public KtfmtConfig ktfmt() { + return ktfmt(KtfmtStep.defaultVersion()); + } + + /** + * Uses the given version of ktfmt and applies the dropbox style + * option to format source code. + */ + public KtfmtConfig ktfmt(String version) { + return new KtfmtConfig(version); + } + + protected abstract boolean isScript(); + + public class DiktatConfig { + + private final String version; + private FileSignature config; + + DiktatConfig(String version) { + Objects.requireNonNull(version, "version"); + this.version = version; + addStep(createStep()); + } + + public DiktatConfig configFile(Object file) throws IOException { + // Specify the path to the configuration file + if (file == null) { + this.config = null; + } else { + this.config = FileSignature.signAsList(getProject().file(file)); + } + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return DiktatStep.create(version, provisioner(), isScript(), config); + } + } + + public class KtfmtConfig { + final String version; + KtfmtStep.Style style; + KtfmtStep.KtfmtFormattingOptions options; + + private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); + + KtfmtConfig(String version) { + Objects.requireNonNull(version); + this.version = Objects.requireNonNull(version); + addStep(createStep()); + } + + private ConfigurableStyle style(KtfmtStep.Style style) { + this.style = style; + replaceStep(createStep()); + return configurableStyle; + } + + public ConfigurableStyle dropboxStyle() { + return style(KtfmtStep.Style.DROPBOX); + } + + public ConfigurableStyle googleStyle() { + return style(KtfmtStep.Style.GOOGLE); + } + + public ConfigurableStyle kotlinlangStyle() { + return style(KtfmtStep.Style.KOTLINLANG); + } + + public void configure(Consumer optionsConfiguration) { + this.configurableStyle.configure(optionsConfiguration); + } + + private FormatterStep createStep() { + return KtfmtStep.create(version, provisioner(), style, options); + } + + public class ConfigurableStyle { + + public void configure(Consumer optionsConfiguration) { + KtfmtStep.KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtStep.KtfmtFormattingOptions(); + optionsConfiguration.accept(ktfmtFormattingOptions); + options = ktfmtFormattingOptions; + replaceStep(createStep()); + } + } + } + + public class KtlintConfig { + + private final String version; + @Nullable + private FileSignature editorConfigPath; + private Map userData; + private Map editorConfigOverride; + + KtlintConfig(String version, Map config, + Map editorConfigOverride) throws IOException { + Objects.requireNonNull(version); + File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); + FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; + this.version = version; + this.editorConfigPath = editorConfigPath; + this.userData = config; + this.editorConfigOverride = editorConfigOverride; + addStep(createStep()); + } + + public KtlintConfig setEditorConfigPath(Object editorConfigPath) throws IOException { + if (editorConfigPath == null) { + this.editorConfigPath = null; + } else { + File editorConfigFile = getProject().file(editorConfigPath); + if (!editorConfigFile.exists()) { + throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile); + } + this.editorConfigPath = FileSignature.signAsList(editorConfigFile); + } + replaceStep(createStep()); + return this; + } + + public KtlintConfig userData(Map userData) { + // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized + // representation. + this.userData = ImmutableSortedMap.copyOf(userData); + replaceStep(createStep()); + return this; + } + + public KtlintConfig editorConfigOverride(Map editorConfigOverride) { + // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized + // representation. + this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); + replaceStep(createStep()); + return this; + } + + private FormatterStep createStep() { + return KtLintStep.create( + version, + provisioner(), + isScript(), + editorConfigPath, + userData, + editorConfigOverride); + } + } +} 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 27d93717f4..21ccb8dd0f 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 @@ -17,28 +17,11 @@ import static com.diffplug.spotless.kotlin.KotlinConstants.LICENSE_HEADER_DELIMITER; -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.function.Consumer; - -import javax.annotation.Nullable; import javax.inject.Inject; import org.gradle.api.tasks.SourceSet; -import com.diffplug.common.collect.ImmutableSortedMap; -import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.kotlin.DiktatStep; -import com.diffplug.spotless.kotlin.KtLintStep; -import com.diffplug.spotless.kotlin.KtfmtStep; -import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; -import com.diffplug.spotless.kotlin.KtfmtStep.Style; - -public class KotlinExtension extends FormatExtension implements HasBuiltinDelimiterForLicense, JvmLang { +public class KotlinExtension extends BaseKotlinExtension implements HasBuiltinDelimiterForLicense, JvmLang { static final String NAME = "kotlin"; @Inject @@ -56,167 +39,9 @@ public LicenseHeaderConfig licenseHeaderFile(Object licenseHeaderFile) { return licenseHeaderFile(licenseHeaderFile, LICENSE_HEADER_DELIMITER); } - /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) throws IOException { - Objects.requireNonNull(version); - File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; - return new KotlinFormatExtension(version, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); - } - - public KotlinFormatExtension ktlint() throws IOException { - return ktlint(KtLintStep.defaultVersion()); - } - - public class KotlinFormatExtension { - - private final String version; - @Nullable - private FileSignature editorConfigPath; - private Map userData; - private Map editorConfigOverride; - - KotlinFormatExtension(String version, @Nullable FileSignature editorConfigPath, Map config, - Map editorConfigOverride) { - this.version = version; - this.editorConfigPath = editorConfigPath; - this.userData = config; - this.editorConfigOverride = editorConfigOverride; - addStep(createStep()); - } - - public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { - if (editorConfigPath == null) { - this.editorConfigPath = null; - } else { - File editorConfigFile = getProject().file(editorConfigPath); - if (!editorConfigFile.exists()) { - throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile); - } - this.editorConfigPath = FileSignature.signAsList(editorConfigFile); - } - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension userData(Map userData) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.userData = ImmutableSortedMap.copyOf(userData); - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension editorConfigOverride(Map editorConfigOverride) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return KtLintStep.create(version, provisioner(), false, editorConfigPath, userData, editorConfigOverride); - } - } - - /** Uses the ktfmt jar to format source code. */ - public KtfmtConfig ktfmt() { - return ktfmt(KtfmtStep.defaultVersion()); - } - - /** - * Uses the given version of ktfmt and applies the dropbox style - * option to format source code. - */ - public KtfmtConfig ktfmt(String version) { - Objects.requireNonNull(version); - return new KtfmtConfig(version); - } - - public class KtfmtConfig { - final String version; - Style style; - KtfmtFormattingOptions options; - - private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); - - KtfmtConfig(String version) { - this.version = Objects.requireNonNull(version); - addStep(createStep()); - } - - private ConfigurableStyle style(Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - - public ConfigurableStyle dropboxStyle() { - return style(Style.DROPBOX); - } - - public ConfigurableStyle googleStyle() { - return style(Style.GOOGLE); - } - - public ConfigurableStyle kotlinlangStyle() { - return style(Style.KOTLINLANG); - } - - public void configure(Consumer optionsConfiguration) { - this.configurableStyle.configure(optionsConfiguration); - } - - private FormatterStep createStep() { - return KtfmtStep.create(version, provisioner(), style, options); - } - - public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { - KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); - optionsConfiguration.accept(ktfmtFormattingOptions); - options = ktfmtFormattingOptions; - replaceStep(createStep()); - } - } - } - - /** Adds the specified version of diktat. */ - public DiktatFormatExtension diktat(String version) { - Objects.requireNonNull(version); - return new DiktatFormatExtension(version); - } - - public DiktatFormatExtension diktat() { - return diktat(DiktatStep.defaultVersionDiktat()); - } - - public class DiktatFormatExtension { - - private final String version; - private FileSignature config; - - DiktatFormatExtension(String version) { - this.version = version; - addStep(createStep()); - } - - public DiktatFormatExtension configFile(Object file) throws IOException { - // Specify the path to the configuration file - if (file == null) { - this.config = null; - } else { - this.config = FileSignature.signAsList(getProject().file(file)); - } - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return DiktatStep.create(version, provisioner(), config); - } + @Override + protected boolean isScript() { + return false; } /** If the user hasn't specified the files yet, we'll assume he/she means all of the kotlin files. */ diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java index 751b649491..5cf2847d62 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/KotlinGradleExtension.java @@ -15,26 +15,9 @@ */ package com.diffplug.gradle.spotless; -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.function.Consumer; - -import javax.annotation.Nullable; import javax.inject.Inject; -import com.diffplug.common.collect.ImmutableSortedMap; -import com.diffplug.spotless.FileSignature; -import com.diffplug.spotless.FormatterStep; -import com.diffplug.spotless.kotlin.DiktatStep; -import com.diffplug.spotless.kotlin.KtLintStep; -import com.diffplug.spotless.kotlin.KtfmtStep; -import com.diffplug.spotless.kotlin.KtfmtStep.KtfmtFormattingOptions; -import com.diffplug.spotless.kotlin.KtfmtStep.Style; - -public class KotlinGradleExtension extends FormatExtension { +public class KotlinGradleExtension extends BaseKotlinExtension { private static final String GRADLE_KOTLIN_DSL_FILE_EXTENSION = "*.gradle.kts"; static final String NAME = "kotlinGradle"; @@ -44,173 +27,9 @@ public KotlinGradleExtension(SpotlessExtension spotless) { super(spotless); } - /** Adds the specified version of ktlint. */ - public KotlinFormatExtension ktlint(String version) throws IOException { - Objects.requireNonNull(version, "version"); - File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); - FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; - return new KotlinFormatExtension(version, editorConfigPath, Collections.emptyMap(), Collections.emptyMap()); - } - - public KotlinFormatExtension ktlint() throws IOException { - return ktlint(KtLintStep.defaultVersion()); - } - - public class KotlinFormatExtension { - - private final String version; - @Nullable - private FileSignature editorConfigPath; - private Map userData; - private Map editorConfigOverride; - - KotlinFormatExtension(String version, FileSignature editorConfigPath, Map config, - Map editorConfigOverride) { - this.version = version; - this.editorConfigPath = editorConfigPath; - this.userData = config; - this.editorConfigOverride = editorConfigOverride; - addStep(createStep()); - } - - public KotlinFormatExtension setEditorConfigPath(Object editorConfigPath) throws IOException { - if (editorConfigPath == null) { - this.editorConfigPath = null; - } else { - File editorConfigFile = getProject().file(editorConfigPath); - if (!editorConfigFile.exists()) { - throw new IllegalArgumentException("EditorConfig file does not exist: " + editorConfigFile); - } - this.editorConfigPath = FileSignature.signAsList(editorConfigFile); - } - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension userData(Map userData) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.userData = ImmutableSortedMap.copyOf(userData); - replaceStep(createStep()); - return this; - } - - public KotlinFormatExtension editorConfigOverride(Map editorConfigOverride) { - // Copy the map to a sorted map because up-to-date checking is based on binary-equals of the serialized - // representation. - this.editorConfigOverride = ImmutableSortedMap.copyOf(editorConfigOverride); - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return KtLintStep.createForScript( - version, - provisioner(), - editorConfigPath, - userData, - editorConfigOverride); - } - } - - /** Uses the ktfmt jar to format source code. */ - public KtfmtConfig ktfmt() { - return ktfmt(KtfmtStep.defaultVersion()); - } - - /** - * Uses the given version of ktfmt to format source - * code. - */ - public KtfmtConfig ktfmt(String version) { - Objects.requireNonNull(version); - return new KtfmtConfig(version); - } - - public class KtfmtConfig { - final String version; - Style style; - KtfmtFormattingOptions options; - - private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); - - KtfmtConfig(String version) { - this.version = Objects.requireNonNull(version); - this.style = Style.DEFAULT; - addStep(createStep()); - } - - private ConfigurableStyle style(Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - - public ConfigurableStyle dropboxStyle() { - return style(Style.DROPBOX); - } - - public ConfigurableStyle googleStyle() { - return style(Style.GOOGLE); - } - - public ConfigurableStyle kotlinlangStyle() { - return style(Style.KOTLINLANG); - } - - public void configure(Consumer optionsConfiguration) { - this.configurableStyle.configure(optionsConfiguration); - } - - private FormatterStep createStep() { - return KtfmtStep.create(version, provisioner(), style, options); - } - - public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { - KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtFormattingOptions(); - optionsConfiguration.accept(ktfmtFormattingOptions); - options = ktfmtFormattingOptions; - replaceStep(createStep()); - } - } - } - - /** Adds the specified version of diktat. */ - public DiktatFormatExtension diktat(String version) { - Objects.requireNonNull(version, "version"); - return new DiktatFormatExtension(version); - } - - public DiktatFormatExtension diktat() { - return diktat(DiktatStep.defaultVersionDiktat()); - } - - public class DiktatFormatExtension { - - private final String version; - private FileSignature config; - - DiktatFormatExtension(String version) { - this.version = version; - addStep(createStep()); - } - - public DiktatFormatExtension configFile(Object file) throws IOException { - // Specify the path to the configuration file - if (file == null) { - this.config = null; - } else { - this.config = FileSignature.signAsList(getProject().file(file)); - } - replaceStep(createStep()); - return this; - } - - private FormatterStep createStep() { - return DiktatStep.createForScript(version, provisioner(), config); - } + @Override + protected boolean isScript() { + return true; } @Override From a392c72e4383952faa564b892e38357666986cf9 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 19 Nov 2023 18:22:11 +0800 Subject: [PATCH 2/2] Clean up BaseKotlinExtension --- .../gradle/spotless/BaseKotlinExtension.java | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java index 5ced54a94e..69de375800 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/BaseKotlinExtension.java @@ -31,8 +31,8 @@ import com.diffplug.spotless.kotlin.KtLintStep; import com.diffplug.spotless.kotlin.KtfmtStep; -public abstract class BaseKotlinExtension extends FormatExtension { - public BaseKotlinExtension(SpotlessExtension spotless) { +abstract class BaseKotlinExtension extends FormatExtension { + protected BaseKotlinExtension(SpotlessExtension spotless) { super(spotless); } @@ -70,11 +70,10 @@ public KtfmtConfig ktfmt(String version) { protected abstract boolean isScript(); public class DiktatConfig { - private final String version; private FileSignature config; - DiktatConfig(String version) { + private DiktatConfig(String version) { Objects.requireNonNull(version, "version"); this.version = version; addStep(createStep()); @@ -97,24 +96,17 @@ private FormatterStep createStep() { } public class KtfmtConfig { - final String version; - KtfmtStep.Style style; - KtfmtStep.KtfmtFormattingOptions options; - + private final String version; private final ConfigurableStyle configurableStyle = new ConfigurableStyle(); + private KtfmtStep.Style style; + private KtfmtStep.KtfmtFormattingOptions options; - KtfmtConfig(String version) { + private KtfmtConfig(String version) { Objects.requireNonNull(version); this.version = Objects.requireNonNull(version); addStep(createStep()); } - private ConfigurableStyle style(KtfmtStep.Style style) { - this.style = style; - replaceStep(createStep()); - return configurableStyle; - } - public ConfigurableStyle dropboxStyle() { return style(KtfmtStep.Style.DROPBOX); } @@ -131,13 +123,18 @@ public void configure(Consumer optionsConfigur this.configurableStyle.configure(optionsConfiguration); } + private ConfigurableStyle style(KtfmtStep.Style style) { + this.style = style; + replaceStep(createStep()); + return configurableStyle; + } + private FormatterStep createStep() { return KtfmtStep.create(version, provisioner(), style, options); } public class ConfigurableStyle { - - public void configure(Consumer optionsConfiguration) { + private void configure(Consumer optionsConfiguration) { KtfmtStep.KtfmtFormattingOptions ktfmtFormattingOptions = new KtfmtStep.KtfmtFormattingOptions(); optionsConfiguration.accept(ktfmtFormattingOptions); options = ktfmtFormattingOptions; @@ -147,26 +144,26 @@ public void configure(Consumer optionsConfigur } public class KtlintConfig { - private final String version; - @Nullable private FileSignature editorConfigPath; private Map userData; private Map editorConfigOverride; - KtlintConfig(String version, Map config, + private KtlintConfig( + String version, + Map userData, Map editorConfigOverride) throws IOException { Objects.requireNonNull(version); File defaultEditorConfig = getProject().getRootProject().file(".editorconfig"); FileSignature editorConfigPath = defaultEditorConfig.exists() ? FileSignature.signAsList(defaultEditorConfig) : null; this.version = version; this.editorConfigPath = editorConfigPath; - this.userData = config; + this.userData = userData; this.editorConfigOverride = editorConfigOverride; addStep(createStep()); } - public KtlintConfig setEditorConfigPath(Object editorConfigPath) throws IOException { + public KtlintConfig setEditorConfigPath(@Nullable Object editorConfigPath) throws IOException { if (editorConfigPath == null) { this.editorConfigPath = null; } else {