Skip to content

Commit 74b3443

Browse files
authored
Update Cleanthat to 2.2. Tests workaround lack of OptionalNotEmpty (#1569)
2 parents 6cde625 + bf9b811 commit 74b3443

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

lib/src/main/java/com/diffplug/spotless/java/CleanthatJavaStep.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class CleanthatJavaStep {
4040
private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java";
4141

4242
// CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD
43-
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.1");
43+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.2");
4444

4545
// prevent direct instantiation
4646
private CleanthatJavaStep() {}
@@ -71,8 +71,7 @@ public static List<String> defaultExcludedMutators() {
7171
* @return
7272
*/
7373
public static List<String> defaultMutators() {
74-
// see JavaRefactorerProperties.WILDCARD
75-
return List.of("*");
74+
return List.of("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeAndConsensualMutators");
7675
}
7776

7877
/** Creates a step which apply selected CleanThat mutators. */

plugin-gradle/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
* Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569))
67

78
## [6.15.0] - 2023-02-10
89
### Added

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavaExtension.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.File;
2121
import java.util.ArrayList;
22+
import java.util.Collection;
2223
import java.util.List;
2324
import java.util.Objects;
2425

@@ -283,9 +284,9 @@ public class CleanthatJavaConfig {
283284

284285
private String sourceJdk = CleanthatJavaStep.defaultSourceJdk();
285286

286-
private List<String> mutators = CleanthatJavaStep.defaultMutators();
287+
private List<String> mutators = new ArrayList<>(CleanthatJavaStep.defaultMutators());
287288

288-
private List<String> excludedMutators = CleanthatJavaStep.defaultExcludedMutators();
289+
private List<String> excludedMutators = new ArrayList<>(CleanthatJavaStep.defaultExcludedMutators());
289290

290291
CleanthatJavaConfig() {
291292
addStep(createStep());
@@ -319,14 +320,20 @@ public CleanthatJavaConfig clearMutators() {
319320
return this;
320321
}
321322

322-
// The fully qualified name of a class implementing eu.solven.cleanthat.engine.java.refactorer.meta.IMutator
323-
// or '*' to include all default mutators
323+
// An id of a mutator (see IMutator.getIds()) or
324+
// tThe fully qualified name of a class implementing eu.solven.cleanthat.engine.java.refactorer.meta.IMutator
324325
public CleanthatJavaConfig addMutator(String mutator) {
325326
this.mutators.add(mutator);
326327
replaceStep(createStep());
327328
return this;
328329
}
329330

331+
public CleanthatJavaConfig addMutators(Collection<String> mutators) {
332+
this.mutators.addAll(mutators);
333+
replaceStep(createStep());
334+
return this;
335+
}
336+
330337
// useful to exclude a mutator amongst the default list of mutators
331338
public CleanthatJavaConfig excludeMutator(String mutator) {
332339
this.excludedMutators.add(mutator);

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/CleanthatJavaIntegrationTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ void integration() throws IOException {
3131
"spotless {",
3232
" java {",
3333
" target file('test.java')",
34-
" cleanthat().sourceCompatibility('11')",
34+
" cleanthat()",
35+
" .sourceCompatibility('11')",
36+
" .addMutators(['LiteralsFirstInComparisons', 'OptionalNotEmpty'])",
3537
" }",
3638
"}");
3739

plugin-maven/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
44

55
## [Unreleased]
6+
### Changes
7+
* Bump default `cleanthat` version to latest `2.1` -> `2.2` ([#1569](https://github.com/diffplug/spotless/pull/1569))
68

79
## [2.33.0] - 2023-02-10
810
### Added

plugin-maven/src/test/java/com/diffplug/spotless/maven/java/CleanthatJavaRefactorerTest.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,23 @@ class CleanthatJavaRefactorerTest extends MavenIntegrationHarness {
2929
void testLiteralsFirstInComparisons() throws Exception {
3030
writePomWithJavaSteps(
3131
"<cleanthat>",
32+
" <mutators>",
33+
" <mutator>LiteralsFirstInComparisons</mutator>",
34+
" </mutators>",
3235
"</cleanthat>");
3336

3437
runTest("LiteralsFirstInComparisons.dirty.java", "LiteralsFirstInComparisons.clean.java");
3538
}
3639

3740
@Test
3841
void testMultipleMutators_defaultIsJdk7() throws Exception {
42+
// OptionalNotEmpty will be excluded as it is not compatible with JDK7
3943
writePomWithJavaSteps(
4044
"<cleanthat>",
45+
" <mutators>",
46+
" <mutator>LiteralsFirstInComparisons</mutator>",
47+
" <mutator>OptionalNotEmpty</mutator>",
48+
" </mutators>",
4149
"</cleanthat>");
4250

4351
runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java");
@@ -47,7 +55,11 @@ void testMultipleMutators_defaultIsJdk7() throws Exception {
4755
void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception {
4856
writePomWithJavaSteps(
4957
"<cleanthat>",
50-
"<sourceJdk>11</sourceJdk>",
58+
" <sourceJdk>11</sourceJdk>",
59+
" <mutators>",
60+
" <mutator>LiteralsFirstInComparisons</mutator>",
61+
" <mutator>OptionalNotEmpty</mutator>",
62+
" </mutators>",
5163
"</cleanthat>");
5264

5365
runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java");
@@ -57,6 +69,10 @@ void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception {
5769
void testExcludeOptionalNotEmpty() throws Exception {
5870
writePomWithJavaSteps(
5971
"<cleanthat>",
72+
" <mutators>",
73+
" <mutator>LiteralsFirstInComparisons</mutator>",
74+
" <mutator>OptionalNotEmpty</mutator>",
75+
" </mutators>",
6076
" <excludedMutators>",
6177
" <excludedMutator>OptionalNotEmpty</excludedMutator>",
6278
" </excludedMutators>",

0 commit comments

Comments
 (0)