Skip to content

Commit 5b9e123

Browse files
committed
Upgrade Spotless, and provide File to Cleanthat for better error logging
1 parent 1e8fc34 commit 5b9e123

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +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))
3132
### Removed
3233
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))
3334
* **BREAKING** Replace `PipeStepPair` with `FenceStep`. ([#1954](https://github.com/diffplug/spotless/pull/1954))

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ dependencies {
8080

8181
// GLUE CODE (alphabetic order please)
8282
// cleanthat
83-
String VER_CLEANTHAT='2.17'
83+
String VER_CLEANTHAT='2.20'
8484
cleanthatCompileOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT"
8585
compatCleanthat2Dot1CompileAndTestOnly "io.github.solven-eu.cleanthat:java:$VER_CLEANTHAT"
8686
// diktat old supported version 1.x

lib/src/cleanthat/java/com/diffplug/spotless/glue/java/JavaCleanthatRefactorerFunc.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 DiffPlug
2+
* Copyright 2023-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
1515
*/
1616
package com.diffplug.spotless.glue.java;
1717

18+
import java.io.File;
1819
import java.io.IOException;
1920
import java.util.Arrays;
2021
import java.util.Collections;
@@ -31,12 +32,13 @@
3132
import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorer;
3233
import eu.solven.cleanthat.engine.java.refactorer.JavaRefactorerProperties;
3334
import eu.solven.cleanthat.formatter.LineEnding;
35+
import eu.solven.cleanthat.formatter.PathAndContent;
3436

3537
/**
3638
* The glue for CleanThat: it is build over the version in build.gradle, but at runtime it will be executed over
3739
* the version loaded in JarState, which is by default defined in com.diffplug.spotless.java.CleanthatJavaStep#JVM_SUPPORT
3840
*/
39-
public class JavaCleanthatRefactorerFunc implements FormatterFunc {
41+
public class JavaCleanthatRefactorerFunc implements FormatterFunc.NeedsFile {
4042
private static final Logger LOGGER = LoggerFactory.getLogger(JavaCleanthatRefactorerFunc.class);
4143

4244
private String jdkVersion;
@@ -56,20 +58,20 @@ public JavaCleanthatRefactorerFunc() {
5658
}
5759

5860
@Override
59-
public String apply(String input) throws Exception {
61+
public String applyWithFile(String unix, File file) throws Exception {
6062
// https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader
6163
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
6264
try {
6365
// Ensure CleanThat main Thread has its custom classLoader while executing its refactoring
6466
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
65-
return doApply(input);
67+
return doApply(unix, file);
6668
} finally {
6769
// Restore the originalClassLoader
6870
Thread.currentThread().setContextClassLoader(originalClassLoader);
6971
}
7072
}
7173

72-
private String doApply(String input) throws InterruptedException, IOException {
74+
private String doApply(String input, File file) throws IOException {
7375
// call some API that uses reflection without taking ClassLoader param
7476
CleanthatEngineProperties engineProperties = CleanthatEngineProperties.builder().engineVersion(jdkVersion).build();
7577

@@ -88,7 +90,9 @@ private String doApply(String input) throws InterruptedException, IOException {
8890
LOGGER.debug("Processing sourceJdk={} included={} excluded={}", jdkVersion, included, excluded, includeDraft);
8991
LOGGER.debug("Available mutators: {}", JavaRefactorer.getAllIncluded());
9092

91-
return refactorer.doFormat(input);
93+
PathAndContent pathAndContent = new PathAndContent(file.toPath(), input);
94+
95+
return refactorer.doFormat(pathAndContent);
9296
}
9397

9498
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class CleanthatJavaStep implements java.io.Serializable {
4040
/**
4141
* CleanThat changelog is available at <a href="https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD">here</a>.
4242
*/
43-
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.16");
43+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.20");
4444

4545
private final JarState.Promised jarState;
4646
private final String version;

0 commit comments

Comments
 (0)