From 22acca5034b72b0f121bc0c10bc7a44bc391d23e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 19 Feb 2023 12:24:25 +0400 Subject: [PATCH 1/8] Upgrade Cleanthat. Enable draft --- lib/build.gradle | 4 +-- .../java/JavaCleanthatRefactorerFunc.java | 10 ++++--- .../spotless/java/CleanthatJavaStep.java | 26 ++++++++++++------- plugin-gradle/CHANGES.md | 4 +++ .../gradle/spotless/JavaExtension.java | 10 ++++++- plugin-maven/CHANGES.md | 3 +++ .../spotless/maven/java/CleanthatJava.java | 5 +++- 7 files changed, 45 insertions(+), 17 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index bfa54aaa13..2b9be494c8 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -108,8 +108,8 @@ dependencies { gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.2' - compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.2' + cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.3' + compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.3' } // we'll hold the core lib to a high standard diff --git a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java index c94fd3c7c4..fca3adc02d 100644 --- a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java +++ b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java @@ -42,15 +42,17 @@ public class JavaCleanthatRefactorerFunc implements FormatterFunc { private String jdkVersion; private List included; private List excluded; + private boolean includeDraft; - public JavaCleanthatRefactorerFunc(String jdkVersion, List included, List excluded) { + public JavaCleanthatRefactorerFunc(String jdkVersion, List included, List excluded, boolean includeDraft) { this.jdkVersion = jdkVersion == null ? IJdkVersionConstants.JDK_8 : jdkVersion; this.included = included == null ? Collections.emptyList() : included; this.excluded = excluded == null ? Collections.emptyList() : excluded; + this.includeDraft = includeDraft; } public JavaCleanthatRefactorerFunc() { - this(IJdkVersionConstants.JDK_8, Arrays.asList(JavaRefactorerProperties.WILDCARD), Arrays.asList()); + this(IJdkVersionConstants.JDK_8, Arrays.asList(JavaRefactorerProperties.WILDCARD), Arrays.asList(), false); } @Override @@ -79,9 +81,11 @@ private String doApply(String input) throws InterruptedException, IOException { refactorerProperties.setIncluded(included); refactorerProperties.setExcluded(excluded); + refactorerProperties.setIncludeDraft(includeDraft); + JavaRefactorer refactorer = new JavaRefactorer(engineProperties, refactorerProperties); - LOGGER.debug("Processing sourceJdk={} included={} excluded={}", jdkVersion, included, excluded); + LOGGER.debug("Processing sourceJdk={} included={} excluded={}", jdkVersion, included, excluded, includeDraft); LOGGER.debug("Available mutators: {}", JavaRefactorer.getAllIncluded()); // Spotless calls steps always with LF eol. diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 2ef68f4f85..0f59f903b2 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -40,7 +40,7 @@ public final class CleanthatJavaStep { private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java"; // CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.2"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.3"); // prevent direct instantiation private CleanthatJavaStep() {} @@ -52,7 +52,7 @@ public static FormatterStep create(Provisioner provisioner) { /** Creates a step which apply default CleanThat mutators. */ public static FormatterStep create(String version, Provisioner provisioner) { - return create(MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), provisioner); + return create(MAVEN_COORDINATE, version, defaultSourceJdk(), defaultMutators(), defaultExcludedMutators(), defaultIncludeDraft(), provisioner); } public static String defaultSourceJdk() { @@ -62,16 +62,20 @@ public static String defaultSourceJdk() { return "1.7"; } - public static List defaultExcludedMutators() { - return List.of(); - } - /** - * By default, we include all available rules + * By default, we include only safe and consensual mutators * @return */ public static List defaultMutators() { - return List.of("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeAndConsensualMutators"); + return List.of("SafeAndConsensualMutators"); + } + + public static List defaultExcludedMutators() { + return List.of(); + } + + public static boolean defaultIncludeDraft() { + return false; } /** Creates a step which apply selected CleanThat mutators. */ @@ -80,6 +84,7 @@ public static FormatterStep create(String groupArtifact, String sourceJdkVersion, List excluded, List included, + boolean includeDraft, Provisioner provisioner) { Objects.requireNonNull(groupArtifact, "groupArtifact"); if (groupArtifact.chars().filter(ch -> ch == ':').count() != 1) { @@ -88,7 +93,7 @@ public static FormatterStep create(String groupArtifact, Objects.requireNonNull(version, "version"); Objects.requireNonNull(provisioner, "provisioner"); return FormatterStep.createLazy(NAME, - () -> new JavaRefactorerState(NAME, groupArtifact, version, sourceJdkVersion, excluded, included, provisioner), + () -> new JavaRefactorerState(NAME, groupArtifact, version, sourceJdkVersion, excluded, included, includeDraft, provisioner), JavaRefactorerState::createFormat); } @@ -113,7 +118,7 @@ static final class JavaRefactorerState implements Serializable { final List excluded; JavaRefactorerState(String stepName, String version, Provisioner provisioner) throws IOException { - this(stepName, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), provisioner); + this(stepName, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), defaultIncludeDraft(), provisioner); } JavaRefactorerState(String stepName, @@ -122,6 +127,7 @@ static final class JavaRefactorerState implements Serializable { String sourceJdkVersion, List included, List excluded, + boolean includeDraft, Provisioner provisioner) throws IOException { JVM_SUPPORT.assertFormatterSupported(version); ModuleHelper.doOpenInternalPackagesIfRequired(); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index afba5abdc7..91c1a7192c 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* Add `includeDraft` option, to include draft mutators from composite mutators ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) +### Changes +* Bump default `cleanthat` version to latest `2.2` -> `2.3` ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) ## [6.15.0] - 2023-02-10 diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java index 7ab94ba7e4..f351dd6188 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java @@ -288,6 +288,8 @@ public class CleanthatJavaConfig { private List excludedMutators = new ArrayList<>(CleanthatJavaStep.defaultExcludedMutators()); + private boolean includeDraft = CleanthatJavaStep.defaultIncludeDraft(); + CleanthatJavaConfig() { addStep(createStep()); } @@ -341,11 +343,17 @@ public CleanthatJavaConfig excludeMutator(String mutator) { return this; } + public CleanthatJavaConfig includeDraft(boolean includeDraft) { + this.includeDraft = includeDraft; + replaceStep(createStep()); + return this; + } + private FormatterStep createStep() { return CleanthatJavaStep.create( groupArtifact, version, - sourceJdk, mutators, excludedMutators, provisioner()); + sourceJdk, mutators, excludedMutators, includeDraft, provisioner()); } } diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8d4c67a9b6..b26c664ed1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,7 +3,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* Add `includeDraft` option, to include draft mutators from composite mutators ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) ### Changes +* Bump default `cleanthat` version to latest `2.2` -> `2.3` ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) ## [2.33.0] - 2023-02-10 diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java index d7dd1f2530..4133409919 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/CleanthatJava.java @@ -41,11 +41,14 @@ public class CleanthatJava implements FormatterStepFactory { @Parameter private List excludedMutators = CleanthatJavaStep.defaultExcludedMutators(); + @Parameter + private boolean includeDraft = CleanthatJavaStep.defaultIncludeDraft(); + @Override public FormatterStep newFormatterStep(FormatterStepConfig config) { String groupArtifact = this.groupArtifact != null ? this.groupArtifact : CleanthatJavaStep.defaultGroupArtifact(); String version = this.version != null ? this.version : CleanthatJavaStep.defaultVersion(); - return CleanthatJavaStep.create(groupArtifact, version, sourceJdk, mutators, excludedMutators, config.getProvisioner()); + return CleanthatJavaStep.create(groupArtifact, version, sourceJdk, mutators, excludedMutators, includeDraft, config.getProvisioner()); } } From 0f95eb9a7779ffbc74884d980e5273bd479af8f5 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 19 Feb 2023 12:59:47 +0400 Subject: [PATCH 2/8] Fix glue --- .../spotless/glue/java/JavaCleanthatRefactorerFunc.java | 2 +- .../java/com/diffplug/spotless/java/CleanthatJavaStep.java | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java index fca3adc02d..d7148f8892 100644 --- a/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java +++ b/lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java @@ -52,7 +52,7 @@ public JavaCleanthatRefactorerFunc(String jdkVersion, List included, Lis } public JavaCleanthatRefactorerFunc() { - this(IJdkVersionConstants.JDK_8, Arrays.asList(JavaRefactorerProperties.WILDCARD), Arrays.asList(), false); + this(IJdkVersionConstants.JDK_8, Arrays.asList("SafeAndConsensual"), Arrays.asList(), false); } @Override diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 0f59f903b2..7c43524306 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -116,6 +116,7 @@ static final class JavaRefactorerState implements Serializable { final String sourceJdkVersion; final List included; final List excluded; + final boolean includeDraft; JavaRefactorerState(String stepName, String version, Provisioner provisioner) throws IOException { this(stepName, MAVEN_COORDINATE, version, defaultSourceJdk(), defaultExcludedMutators(), defaultMutators(), defaultIncludeDraft(), provisioner); @@ -138,6 +139,7 @@ static final class JavaRefactorerState implements Serializable { this.sourceJdkVersion = sourceJdkVersion; this.included = included; this.excluded = excluded; + this.includeDraft = includeDraft; } @SuppressWarnings("PMD.UseProperClassLoader") @@ -148,9 +150,9 @@ FormatterFunc createFormat() { Method formatterMethod; try { Class formatterClazz = classLoader.loadClass("com.diffplug.spotless.glue.java.JavaCleanthatRefactorerFunc"); - Constructor formatterConstructor = formatterClazz.getConstructor(String.class, List.class, List.class); + Constructor formatterConstructor = formatterClazz.getConstructor(String.class, List.class, List.class, boolean.class); - formatter = formatterConstructor.newInstance(sourceJdkVersion, included, excluded); + formatter = formatterConstructor.newInstance(sourceJdkVersion, included, excluded, includeDraft); formatterMethod = formatterClazz.getMethod("apply", String.class); } catch (ReflectiveOperationException e) { throw new IllegalStateException("Issue executing the formatter", e); From 0f50f923ce7ae0b031403fa747e988c5362c2a49 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 19 Feb 2023 17:33:36 +0400 Subject: [PATCH 3/8] Upgrade Cleanthat to 2.4 --- lib/build.gradle | 4 ++-- .../java/com/diffplug/spotless/java/CleanthatJavaStep.java | 2 +- plugin-gradle/CHANGES.md | 4 ++-- plugin-maven/CHANGES.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 2b9be494c8..8308eae3c0 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -108,8 +108,8 @@ dependencies { gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.3' - compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.3' + cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.4' + compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.4' } // we'll hold the core lib to a high standard diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 7c43524306..b5093fa680 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -40,7 +40,7 @@ public final class CleanthatJavaStep { private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java"; // CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.3"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.4"); // prevent direct instantiation private CleanthatJavaStep() {} diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 91c1a7192c..1f02827a5e 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,9 +4,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* Add `includeDraft` option, to include draft mutators from composite mutators ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) +* Add `includeDraft` option, to include draft mutators from composite mutators ([#1574](https://github.com/diffplug/spotless/pull/1574)) ### Changes -* Bump default `cleanthat` version to latest `2.2` -> `2.3` ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) +* Bump default `cleanthat` version to latest `2.2` -> `2.4` ([#1574](https://github.com/diffplug/spotless/pull/1574)) * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) ## [6.15.0] - 2023-02-10 diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index b26c664ed1..8cdc1bb1ac 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,7 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add `includeDraft` option, to include draft mutators from composite mutators ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) ### Changes -* Bump default `cleanthat` version to latest `2.2` -> `2.3` ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) +* Bump default `cleanthat` version to latest `2.2` -> `2.4` ([#1574](https://github.com/diffplug/spotless/pull/1574)) * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) ## [2.33.0] - 2023-02-10 From 7db2ce037a95e726935b2dc8b5e539868d58e3d2 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 19 Feb 2023 18:46:34 +0400 Subject: [PATCH 4/8] Revert to hardcoded SafeAndConsensualMutators className, addTest over includeDraft --- .../diffplug/spotless/java/CleanthatJavaStep.java | 3 ++- .../maven/java/CleanthatJavaRefactorerTest.java | 11 +++++++++++ ...ltipleMutators.clean.onlyOptionalIsPresent.java | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index b5093fa680..20aef5d8d2 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -67,7 +67,8 @@ public static String defaultSourceJdk() { * @return */ public static List defaultMutators() { - return List.of("SafeAndConsensualMutators"); + // To be replaced by 'SafeAndConsensual' + return List.of("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeAndConsensualMutators"); } public static List defaultExcludedMutators() { diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index a32ac337e4..cb76ee71a3 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -25,6 +25,17 @@ class CleanthatJavaRefactorerTest extends MavenIntegrationHarness { private static final Logger LOGGER = LoggerFactory.getLogger(CleanthatJavaRefactorerTest.class); + @Test + void testEnableDraft() throws Exception { + writePomWithJavaSteps( + "", + " 11", + " true", + ""); + + runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyOptionalIsPresent.java"); + } + @Test void testLiteralsFirstInComparisons() throws Exception { writePomWithJavaSteps( diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java new file mode 100644 index 0000000000..318e1efa15 --- /dev/null +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java @@ -0,0 +1,14 @@ +package eu.solven.cleanthat.engine.java.refactorer.cases.do_not_format_me; + +import java.util.Optional; + +public class LiteralsFirstInComparisonsCases { + + public boolean isHardcoded(String input) { + return "hardcoded".equals(input); + } + + public boolean isPresent(Optional optional) { + return optional.isPresent(); + } +} From 78fc52a2fb9bfb02d98e29754fc963d523e0864e Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 19 Feb 2023 18:49:49 +0400 Subject: [PATCH 5/8] Fix testCase as LiteralsFirstInComparisons is not applied --- .../cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java index 318e1efa15..0829602dc1 100644 --- a/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java +++ b/testlib/src/main/resources/java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.java @@ -5,7 +5,7 @@ public class LiteralsFirstInComparisonsCases { public boolean isHardcoded(String input) { - return "hardcoded".equals(input); + return input.equals("hardcoded"); } public boolean isPresent(Optional optional) { From 24fb154c34b62dbbea9efc1a123dddfd400d2cb5 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Sun, 19 Feb 2023 22:04:03 +0400 Subject: [PATCH 6/8] Fix style --- .../spotless/maven/java/CleanthatJavaRefactorerTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java index cb76ee71a3..379397f55b 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java @@ -28,10 +28,10 @@ class CleanthatJavaRefactorerTest extends MavenIntegrationHarness { @Test void testEnableDraft() throws Exception { writePomWithJavaSteps( - "", - " 11", - " true", - ""); + "", + " 11", + " true", + ""); runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyOptionalIsPresent.java"); } From 1b73efc828e78acf0f3bb85cb021efbf3b6f8a90 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Wed, 22 Feb 2023 18:36:33 +0400 Subject: [PATCH 7/8] Upgrade to CleanThat 2.6 --- lib/build.gradle | 4 ++-- .../java/com/diffplug/spotless/java/CleanthatJavaStep.java | 6 +++--- plugin-gradle/CHANGES.md | 2 +- plugin-maven/CHANGES.md | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/build.gradle b/lib/build.gradle index 8308eae3c0..f6e0446f73 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -108,8 +108,8 @@ dependencies { gsonCompileOnly 'com.google.code.gson:gson:2.10.1' - cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.4' - compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.4' + cleanthatCompileOnly 'io.github.solven-eu.cleanthat:java:2.6' + compatCleanthat2Dot1CompileAndTestOnly 'io.github.solven-eu.cleanthat:java:2.6' } // we'll hold the core lib to a high standard diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 20aef5d8d2..87461b5efa 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -40,7 +40,7 @@ public final class CleanthatJavaStep { private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java"; // CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD - private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.4"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support(NAME).add(11, "2.6"); // prevent direct instantiation private CleanthatJavaStep() {} @@ -67,8 +67,8 @@ public static String defaultSourceJdk() { * @return */ public static List defaultMutators() { - // To be replaced by 'SafeAndConsensual' - return List.of("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeAndConsensualMutators"); + // see ICleanthatStepParametersProperties.SAFE_AND_CONSENSUAL + return List.of("SafeAndConsensual"); } public static List defaultExcludedMutators() { diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 1f02827a5e..0b2185ba61 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -6,7 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add `includeDraft` option, to include draft mutators from composite mutators ([#1574](https://github.com/diffplug/spotless/pull/1574)) ### Changes -* Bump default `cleanthat` version to latest `2.2` -> `2.4` ([#1574](https://github.com/diffplug/spotless/pull/1574)) +* Bump default `cleanthat` version to latest `2.2` -> `2.6` ([#1574](https://github.com/diffplug/spotless/pull/1574)) * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) ## [6.15.0] - 2023-02-10 diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 8cdc1bb1ac..4912e4ff52 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -6,7 +6,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ### Added * Add `includeDraft` option, to include draft mutators from composite mutators ([#XXX](https://github.com/diffplug/spotless/pull/XXX)) ### Changes -* Bump default `cleanthat` version to latest `2.2` -> `2.4` ([#1574](https://github.com/diffplug/spotless/pull/1574)) +* Bump default `cleanthat` version to latest `2.2` -> `2.6` ([#1574](https://github.com/diffplug/spotless/pull/1574)) * Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569)) ## [2.33.0] - 2023-02-10 From 224be58350e2d4f3fb7e3f82f492eeeed03e1194 Mon Sep 17 00:00:00 2001 From: Benoit Lacelle Date: Thu, 23 Feb 2023 21:22:43 +0400 Subject: [PATCH 8/8] Add workaround for https://github.com/diffplug/spotless/issues/1583 --- .../spotless/java/CleanthatJavaStep.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java index 87461b5efa..c1e5ae1fa4 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java @@ -131,7 +131,10 @@ static final class JavaRefactorerState implements Serializable { List excluded, boolean includeDraft, Provisioner provisioner) throws IOException { - JVM_SUPPORT.assertFormatterSupported(version); + // https://github.com/diffplug/spotless/issues/1583 + if (!version.endsWith("-SNAPSHOT")) { + JVM_SUPPORT.assertFormatterSupported(version); + } ModuleHelper.doOpenInternalPackagesIfRequired(); this.jarState = JarState.from(groupArtifact + ":" + version, provisioner); this.stepName = stepName; @@ -158,9 +161,17 @@ FormatterFunc createFormat() { } catch (ReflectiveOperationException e) { throw new IllegalStateException("Issue executing the formatter", e); } - return JVM_SUPPORT.suggestLaterVersionOnError(version, input -> { - return (String) formatterMethod.invoke(formatter, input); - }); + + // https://github.com/diffplug/spotless/issues/1583 + if (!version.endsWith("-SNAPSHOT")) { + return JVM_SUPPORT.suggestLaterVersionOnError(version, input -> { + return (String) formatterMethod.invoke(formatter, input); + }); + } else { + return input -> { + return (String) formatterMethod.invoke(formatter, input); + }; + } } }