Skip to content

Commit 6c0d270

Browse files
committed
Fix CHANGES.MD, Fix JVM_SUPPORT.suggestLaterVersionOnError for NeedsFile management
1 parent 5b9e123 commit 6c0d270

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2828
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
2929
* Bump default `sortpom` version to latest `3.2.1` -> `4.0.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049), [#2078](https://github.com/diffplug/spotless/pull/2078), [#2115](https://github.com/diffplug/spotless/pull/2115))
3030
* Bump default `zjsonpatch` version to latest `0.4.14` -> `0.4.16`. ([#1969](https://github.com/diffplug/spotless/pull/1969))
31-
* Bump default `cleanthat` version to latest `2.17` -> `2.20`. ([#1725](https://github.com/diffplug/spotless/pull/1725))
31+
* Bump default `cleanthat` version to latest `2.16` -> `2.20`. ([#1725](https://github.com/diffplug/spotless/pull/1725))
3232
### Removed
3333
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
3434
* **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954))

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
*/
1616
package com.diffplug.spotless.java;
1717

18+
import java.io.File;
1819
import java.io.Serializable;
1920
import java.lang.reflect.Constructor;
2021
import java.lang.reflect.Method;
2122
import java.util.List;
2223
import java.util.Objects;
2324

25+
import com.diffplug.spotless.Formatter;
2426
import com.diffplug.spotless.FormatterFunc;
2527
import com.diffplug.spotless.FormatterStep;
2628
import com.diffplug.spotless.JarState;
@@ -166,12 +168,28 @@ FormatterFunc createFormat() {
166168
Constructor<?> formatterConstructor = formatterClazz.getConstructor(String.class, List.class, List.class, boolean.class);
167169

168170
formatter = formatterConstructor.newInstance(sourceJdkVersion, included, excluded, includeDraft);
169-
formatterMethod = formatterClazz.getMethod("apply", String.class);
171+
formatterMethod = formatterClazz.getMethod("apply", String.class, File.class);
170172
} catch (ReflectiveOperationException e) {
171173
throw new IllegalStateException("Issue executing the formatter", e);
172174
}
173175

174-
return JVM_SUPPORT.suggestLaterVersionOnError(version, input -> (String) formatterMethod.invoke(formatter, input));
176+
FormatterFunc formatterFunc = new FormatterFunc() {
177+
@Override
178+
public String apply(String input) throws Exception {
179+
return apply(input, Formatter.NO_FILE_SENTINEL);
180+
}
181+
182+
@Override
183+
public String apply(String input, File file) throws Exception {
184+
if (file.isAbsolute()) {
185+
// Cleanthat expects a relative file as input (relative to the root of the repository)
186+
file = new File(".", file.getPath());
187+
}
188+
return (String) formatterMethod.invoke(formatter, input, file);
189+
}
190+
};
191+
192+
return JVM_SUPPORT.suggestLaterVersionOnError(version, formatterFunc);
175193
}
176194
}
177195
}

plugin-gradle/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2323
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
2424
* Bump default `sortpom` version to latest `3.2.1` -> `4.0.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049), [#2078](https://github.com/diffplug/spotless/pull/2078), [#2115](https://github.com/diffplug/spotless/pull/2115))
2525
* Bump default `zjsonpatch` version to latest `0.4.14` -> `0.4.16`. ([#1969](https://github.com/diffplug/spotless/pull/1969))
26+
* Bump default `cleanthat` version to latest `2.16` -> `2.20`. ([#1725](https://github.com/diffplug/spotless/pull/1725))
2627
### Removed
2728
* **BREAKING** Fully removed `Rome`, use `Biome` instead. ([#2119](https://github.com/diffplug/spotless/pull/2119))
2829

plugin-maven/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2121
* Bump default `shfmt` version to latest `3.7.0` -> `3.8.0`. ([#2050](https://github.com/diffplug/spotless/pull/2050))
2222
* Bump default `sortpom` version to latest `3.2.1` -> `4.0.0`. ([#2049](https://github.com/diffplug/spotless/pull/2049), [#2078](https://github.com/diffplug/spotless/pull/2078), [#2115](https://github.com/diffplug/spotless/pull/2115))
2323
* Bump default `zjsonpatch` version to latest `0.4.14` -> `0.4.16`. ([#1969](https://github.com/diffplug/spotless/pull/1969))
24+
* Bump default `cleanthat` version to latest `2.16` -> `2.20`. ([#1725](https://github.com/diffplug/spotless/pull/1725))
2425
### Removed
2526
* **BREAKING** Fully removed `Rome`, use `Biome` instead. ([#2119](https://github.com/diffplug/spotless/pull/2119))
2627

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2016-2024 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.java;
17+
18+
import org.junit.jupiter.api.Test;
19+
20+
import com.diffplug.spotless.FormatterStep;
21+
import com.diffplug.spotless.ResourceHarness;
22+
import com.diffplug.spotless.StepHarnessWithFile;
23+
import com.diffplug.spotless.TestProvisioner;
24+
25+
class CleanthatJavaFormatStepTest extends ResourceHarness {
26+
27+
@Test
28+
void testDefault() {
29+
FormatterStep step = CleanthatJavaStep.create(TestProvisioner.mavenCentral());
30+
try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(this, step)) {
31+
harness.testResource("java/cleanthat/MultipleMutators.dirty.test", "java/cleanthat/MultipleMutators.dirty.test");
32+
}
33+
}
34+
35+
@Test
36+
void test11IncludeDraft() {
37+
FormatterStep step = CleanthatJavaStep.create("io.github.solven-eu.cleanthat:java",
38+
CleanthatJavaStep.defaultVersion(),
39+
"11",
40+
CleanthatJavaStep.defaultMutators(), CleanthatJavaStep.defaultExcludedMutators(), true, TestProvisioner.mavenCentral());
41+
try (StepHarnessWithFile harness = StepHarnessWithFile.forStep(this, step)) {
42+
harness.testResource("java/cleanthat/MultipleMutators.dirty.test", "java/cleanthat/MultipleMutators.clean.onlyOptionalIsPresent.test");
43+
}
44+
}
45+
46+
}

0 commit comments

Comments
 (0)