Skip to content

Commit

Permalink
Update Cleanthat to 2.2. Tests workaround lack of OptionalNotEmpty (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Feb 13, 2023
2 parents 6cde625 + bf9b811 commit 74b3443
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.1");
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.2");

// prevent direct instantiation
private CleanthatJavaStep() {}
Expand Down Expand Up @@ -71,8 +71,7 @@ public static List<String> defaultExcludedMutators() {
* @return
*/
public static List<String> defaultMutators() {
// see JavaRefactorerProperties.WILDCARD
return List.of("*");
return List.of("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeAndConsensualMutators");
}

/** Creates a step which apply selected CleanThat mutators. */
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).

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

## [6.15.0] - 2023-02-10
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -283,9 +284,9 @@ public class CleanthatJavaConfig {

private String sourceJdk = CleanthatJavaStep.defaultSourceJdk();

private List<String> mutators = CleanthatJavaStep.defaultMutators();
private List<String> mutators = new ArrayList<>(CleanthatJavaStep.defaultMutators());

private List<String> excludedMutators = CleanthatJavaStep.defaultExcludedMutators();
private List<String> excludedMutators = new ArrayList<>(CleanthatJavaStep.defaultExcludedMutators());

CleanthatJavaConfig() {
addStep(createStep());
Expand Down Expand Up @@ -319,14 +320,20 @@ public CleanthatJavaConfig clearMutators() {
return this;
}

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

public CleanthatJavaConfig addMutators(Collection<String> mutators) {
this.mutators.addAll(mutators);
replaceStep(createStep());
return this;
}

// useful to exclude a mutator amongst the default list of mutators
public CleanthatJavaConfig excludeMutator(String mutator) {
this.excludedMutators.add(mutator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ void integration() throws IOException {
"spotless {",
" java {",
" target file('test.java')",
" cleanthat().sourceCompatibility('11')",
" cleanthat()",
" .sourceCompatibility('11')",
" .addMutators(['LiteralsFirstInComparisons', 'OptionalNotEmpty'])",
" }",
"}");

Expand Down
2 changes: 2 additions & 0 deletions plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).

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

## [2.33.0] - 2023-02-10
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,23 @@ class CleanthatJavaRefactorerTest extends MavenIntegrationHarness {
void testLiteralsFirstInComparisons() throws Exception {
writePomWithJavaSteps(
"<cleanthat>",
" <mutators>",
" <mutator>LiteralsFirstInComparisons</mutator>",
" </mutators>",
"</cleanthat>");

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

@Test
void testMultipleMutators_defaultIsJdk7() throws Exception {
// OptionalNotEmpty will be excluded as it is not compatible with JDK7
writePomWithJavaSteps(
"<cleanthat>",
" <mutators>",
" <mutator>LiteralsFirstInComparisons</mutator>",
" <mutator>OptionalNotEmpty</mutator>",
" </mutators>",
"</cleanthat>");

runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.onlyLiteralsFirst.java");
Expand All @@ -47,7 +55,11 @@ void testMultipleMutators_defaultIsJdk7() throws Exception {
void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception {
writePomWithJavaSteps(
"<cleanthat>",
"<sourceJdk>11</sourceJdk>",
" <sourceJdk>11</sourceJdk>",
" <mutators>",
" <mutator>LiteralsFirstInComparisons</mutator>",
" <mutator>OptionalNotEmpty</mutator>",
" </mutators>",
"</cleanthat>");

runTest("MultipleMutators.dirty.java", "MultipleMutators.clean.java");
Expand All @@ -57,6 +69,10 @@ void testMultipleMutators_Jdk11IntroducedOptionalisPresent() throws Exception {
void testExcludeOptionalNotEmpty() throws Exception {
writePomWithJavaSteps(
"<cleanthat>",
" <mutators>",
" <mutator>LiteralsFirstInComparisons</mutator>",
" <mutator>OptionalNotEmpty</mutator>",
" </mutators>",
" <excludedMutators>",
" <excludedMutator>OptionalNotEmpty</excludedMutator>",
" </excludedMutators>",
Expand Down

0 comments on commit 74b3443

Please sign in to comment.