Skip to content

Commit 3443c3b

Browse files
committed
Merge branch 'main' into feat/kill-never-up-to-date-step
2 parents 386874c + 6fe56b6 commit 3443c3b

File tree

14 files changed

+112
-28
lines changed

14 files changed

+112
-28
lines changed

.github/workflows/codeql-analysis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
# Initializes the CodeQL tools for scanning.
5252
- name: Initialize CodeQL
53-
uses: github/codeql-action/init@v2
53+
uses: github/codeql-action/init@v3
5454
with:
5555
languages: ${{ matrix.language }}
5656
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -61,7 +61,7 @@ jobs:
6161
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
6262
# If this step fails, then you should remove it and run the build manually (see below)
6363
- name: Autobuild
64-
uses: github/codeql-action/autobuild@v2
64+
uses: github/codeql-action/autobuild@v3
6565

6666
# ℹ️ Command-line programs to run using the OS shell.
6767
# 📚 https://git.io/JvXDl
@@ -75,4 +75,4 @@ jobs:
7575
# make release
7676

7777
- name: Perform CodeQL Analysis
78-
uses: github/codeql-action/analyze@v2
78+
uses: github/codeql-action/analyze@v3

.github/workflows/gradle-wrapper-validation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v4
23-
- uses: gradle/wrapper-validation-action@v1
23+
- uses: gradle/wrapper-validation-action@v3

CHANGES.md

+1
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.16` -> `2.20`. ([#1725](https://github.com/diffplug/spotless/pull/1725))
3132
### Removed
3233
* **BREAKING** Remove `FormatterStep.createNeverUpToDate` methods, they are available only in `testlib`. ([#2145](https://github.com/diffplug/spotless/pull/2145))
3334
* **BREAKING** Remove `JarState.getMavenCoordinate(String prefix)`. ([#1945](https://github.com/diffplug/spotless/pull/1945))

gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ VER_SLF4J=[1.6,2.0[
3030
VER_DURIAN=1.2.0
3131
VER_JGIT=6.7.0.202309050840-r
3232
VER_JUNIT=5.10.2
33-
VER_ASSERTJ=3.25.3
34-
VER_MOCKITO=5.8.0
33+
VER_ASSERTJ=3.26.0
34+
VER_MOCKITO=5.12.0

gradle/wrapper/gradle-wrapper.jar

-9 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew.bat

+10-10
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
4343
%JAVA_EXE% -version >NUL 2>&1
4444
if %ERRORLEVEL% equ 0 goto execute
4545

46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
46+
echo. 1>&2
47+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48+
echo. 1>&2
49+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50+
echo location of your Java installation. 1>&2
5151

5252
goto fail
5353

@@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5757

5858
if exist "%JAVA_EXE%" goto execute
5959

60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
60+
echo. 1>&2
61+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62+
echo. 1>&2
63+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64+
echo location of your Java installation. 1>&2
6565

6666
goto fail
6767

lib/build.gradle

+1-1
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

+10-6
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

+34-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
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;
22+
import java.nio.file.Path;
2123
import java.util.List;
2224
import java.util.Objects;
2325

26+
import com.diffplug.spotless.Formatter;
2427
import com.diffplug.spotless.FormatterFunc;
2528
import com.diffplug.spotless.FormatterStep;
2629
import com.diffplug.spotless.JarState;
@@ -40,7 +43,7 @@ public final class CleanthatJavaStep implements java.io.Serializable {
4043
/**
4144
* CleanThat changelog is available at <a href="https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD">here</a>.
4245
*/
43-
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.16");
46+
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support(NAME).add(11, "2.20");
4447

4548
private final JarState.Promised jarState;
4649
private final String version;
@@ -156,6 +159,32 @@ private static final class State implements Serializable {
156159
this.includeDraft = includeDraft;
157160
}
158161

162+
private static class JvmSupportFormatterFunc implements FormatterFunc {
163+
164+
final Object formatter;
165+
final Method formatterMethod;
166+
167+
private JvmSupportFormatterFunc(Object formatter, Method formatterMethod) {
168+
this.formatter = formatter;
169+
this.formatterMethod = formatterMethod;
170+
}
171+
172+
@Override
173+
public String apply(String input) throws Exception {
174+
return apply(input, Formatter.NO_FILE_SENTINEL);
175+
}
176+
177+
@Override
178+
public String apply(String input, File file) throws Exception {
179+
if (file.isAbsolute()) {
180+
// Cleanthat expects a relative file as input (relative to the root of the repository)
181+
Path absolutePath = file.toPath();
182+
file = absolutePath.subpath(1, absolutePath.getNameCount()).toFile();
183+
}
184+
return (String) formatterMethod.invoke(formatter, input, file);
185+
}
186+
}
187+
159188
FormatterFunc createFormat() {
160189
ClassLoader classLoader = jarState.getClassLoader();
161190

@@ -166,12 +195,14 @@ FormatterFunc createFormat() {
166195
Constructor<?> formatterConstructor = formatterClazz.getConstructor(String.class, List.class, List.class, boolean.class);
167196

168197
formatter = formatterConstructor.newInstance(sourceJdkVersion, included, excluded, includeDraft);
169-
formatterMethod = formatterClazz.getMethod("apply", String.class);
198+
formatterMethod = formatterClazz.getMethod("apply", String.class, File.class);
170199
} catch (ReflectiveOperationException e) {
171200
throw new IllegalStateException("Issue executing the formatter", e);
172201
}
173202

174-
return JVM_SUPPORT.suggestLaterVersionOnError(version, input -> (String) formatterMethod.invoke(formatter, input));
203+
FormatterFunc formatterFunc = new JvmSupportFormatterFunc(formatter, formatterMethod);
204+
205+
return JVM_SUPPORT.suggestLaterVersionOnError(version, formatterFunc);
175206
}
176207
}
177208
}

plugin-gradle/CHANGES.md

+1
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

+1
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

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pluginManagement {
66
}
77

88
plugins {
9-
id 'com.diffplug.spotless' version '6.23.3' apply false
9+
id 'com.diffplug.spotless' version '6.25.0' apply false
1010
// https://plugins.gradle.org/plugin/com.gradle.plugin-publish
1111
id 'com.gradle.plugin-publish' version '1.2.1' apply false
1212
// https://github.com/gradle-nexus/publish-plugin/releases
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)