Skip to content

Commit 1f4fb93

Browse files
author
Vincent Potucek
committed
Issue #2634: Add UpgradeToJava17
1 parent 792d0f2 commit 1f4fb93

File tree

149 files changed

+701
-519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+701
-519
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ concurrency:
1313
cancel-in-progress: true
1414
jobs:
1515
sanityCheck:
16-
name: spotlessCheck assemble testClasses
16+
name: spotlessCheck rewriteDryRun assemble testClasses
1717
runs-on: ubuntu-latest
1818
env:
1919
buildcacheuser: ${{ secrets.BUILDCACHE_USER }}
@@ -31,6 +31,8 @@ jobs:
3131
uses: gradle/actions/setup-gradle@v4
3232
- name: spotlessCheck
3333
run: ./gradlew spotlessCheck
34+
- name: rewriteDryRun
35+
run: ./gradlew rewriteDryRun
3436
- name: assemble testClasses
3537
run: ./gradlew assemble testClasses
3638
build:
@@ -66,10 +68,10 @@ jobs:
6668
uses: gradle/actions/setup-gradle@v4
6769
- name: build (maven-only)
6870
if: matrix.kind == 'maven'
69-
run: ./gradlew :plugin-maven:build -x spotlessCheck
71+
run: ./gradlew :plugin-maven:build -x spotlessCheck -x rewriteDryRun
7072
- name: build (everything-but-maven)
7173
if: matrix.kind == 'gradle'
72-
run: ./gradlew build -x spotlessCheck -PSPOTLESS_EXCLUDE_MAVEN=true
74+
run: ./gradlew build -x spotlessCheck -x rewriteDryRun -PSPOTLESS_EXCLUDE_MAVEN=true
7375
- name: test npm
7476
if: matrix.kind == 'npm'
7577
run: ./gradlew testNpm

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2727
### Added
2828
* Add a `lint` mode to `ReplaceRegexStep` ([#2571](https://github.com/diffplug/spotless/pull/2571))
2929
* `LintSuppression` now enforces unix-style paths in its `setPath` and `relativizeAsUnix` methods. ([#2629](https://github.com/diffplug/spotless/pull/2629))
30+
* Add `rewrite` support ([#2588](https://github.com/diffplug/spotless/pull/2588))
3031

3132
## [3.3.1] - 2025-07-21
3233
### Fixed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repositories {
1212
apply from: rootProject.file('gradle/java-publish.gradle')
1313
apply from: rootProject.file('gradle/changelog.gradle')
1414
allprojects {
15+
apply from: rootProject.file('gradle/rewrite.gradle')
1516
apply from: rootProject.file('gradle/spotless.gradle')
1617
}
1718
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
@@ -27,3 +28,8 @@ spotless {
2728
endWithNewline()
2829
}
2930
}
31+
32+
dependencies {
33+
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.14.1"))
34+
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.17.1")
35+
}

gradle/rewrite.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apply plugin: 'org.openrewrite.rewrite'
2+
3+
rewrite {
4+
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17")
5+
exportDatatables = true
6+
failOnDryRunResults = true
7+
}

lib-extra/src/main/java/com/diffplug/spotless/extra/EclipseBasedStepBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 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.
@@ -175,7 +175,7 @@ private static String convertEclipseVersion(String version) {
175175
char lastChar = version.charAt(version.length() - 1);
176176
if ('.' != lastChar && 'a' <= lastChar) {
177177
semanticVersion = version.substring(0, version.length() - 1);
178-
semanticVersion += String.format(".%d", (int) lastChar);
178+
semanticVersion += ".%d".formatted((int) lastChar);
179179
}
180180
}
181181
return semanticVersion;

lib-extra/src/main/java/com/diffplug/spotless/extra/cpp/EclipseCdtFormatterStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce
6969
return (String) method.invoke(formatter, input);
7070
} catch (InvocationTargetException exceptionWrapper) {
7171
Throwable throwable = exceptionWrapper.getTargetException();
72-
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
72+
Exception exception = (throwable instanceof Exception e) ? e : null;
7373
throw (null == exception) ? exceptionWrapper : exception;
7474
}
7575
});

lib-extra/src/main/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce
9797
return (String) method.invoke(formatter, input);
9898
} catch (InvocationTargetException exceptionWrapper) {
9999
Throwable throwable = exceptionWrapper.getTargetException();
100-
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
100+
Exception exception = (throwable instanceof Exception e) ? e : null;
101101
throw (null == exception) ? exceptionWrapper : exception;
102102
}
103103
});

lib-extra/src/main/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStep.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2021 DiffPlug
2+
* Copyright 2016-2025 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.
@@ -67,7 +67,7 @@ private static FormatterFunc applyWithoutFile(String className, EclipseBasedStep
6767
return (String) method.invoke(formatter, input);
6868
} catch (InvocationTargetException exceptionWrapper) {
6969
Throwable throwable = exceptionWrapper.getTargetException();
70-
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
70+
Exception exception = (throwable instanceof Exception e) ? e : null;
7171
throw (null == exception) ? exceptionWrapper : exception;
7272
}
7373
};
@@ -85,7 +85,7 @@ public String applyWithFile(String unix, File file) throws Exception {
8585
return (String) method.invoke(formatter, unix, file.getAbsolutePath());
8686
} catch (InvocationTargetException exceptionWrapper) {
8787
Throwable throwable = exceptionWrapper.getTargetException();
88-
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
88+
Exception exception = (throwable instanceof Exception e) ? e : null;
8989
throw (null == exception) ? exceptionWrapper : exception;
9090
}
9191
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.diffplug.spotless;
1717

1818
import java.io.IOException;
19+
import java.io.Serial;
1920
import java.io.Serializable;
2021
import java.util.ArrayList;
2122
import java.util.Collection;
@@ -51,6 +52,7 @@
5152
* to make Spotless work with all of Gradle's cache systems at once.
5253
*/
5354
public class ConfigurationCacheHackList implements java.io.Serializable {
55+
@Serial
5456
private static final long serialVersionUID = 6914178791997323870L;
5557

5658
private boolean optimizeForEquality;
@@ -108,8 +110,8 @@ public void clear() {
108110

109111
public void addAll(Collection<? extends FormatterStep> c) {
110112
for (FormatterStep step : c) {
111-
if (step instanceof FormatterStepSerializationRoundtrip) {
112-
var clone = ((FormatterStepSerializationRoundtrip) step).hackClone(optimizeForEquality);
113+
if (step instanceof FormatterStepSerializationRoundtrip roundtrip) {
114+
var clone = roundtrip.hackClone(optimizeForEquality);
113115
backingList.add(clone);
114116
} else {
115117
backingList.add(step);
@@ -120,8 +122,8 @@ public void addAll(Collection<? extends FormatterStep> c) {
120122
public List<FormatterStep> getSteps() {
121123
var result = new ArrayList<FormatterStep>(backingList.size());
122124
for (Object obj : backingList) {
123-
if (obj instanceof FormatterStepSerializationRoundtrip.HackClone) {
124-
result.add(((FormatterStepSerializationRoundtrip.HackClone) obj).rehydrate());
125+
if (obj instanceof FormatterStepSerializationRoundtrip.HackClone clone) {
126+
result.add(clone.rehydrate());
125127
} else {
126128
result.add((FormatterStep) obj);
127129
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 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.
@@ -23,6 +23,7 @@
2323
import java.io.FileInputStream;
2424
import java.io.IOException;
2525
import java.io.InputStream;
26+
import java.io.Serial;
2627
import java.io.Serializable;
2728
import java.security.MessageDigest;
2829
import java.util.Arrays;
@@ -38,6 +39,7 @@
3839

3940
/** Computes a signature for any needed files. */
4041
public final class FileSignature implements Serializable {
42+
@Serial
4143
private static final long serialVersionUID = 2L;
4244

4345
/*
@@ -98,6 +100,7 @@ private FileSignature(final List<File> files) throws IOException {
98100

99101
/** A view of `FileSignature` which can be safely roundtripped. */
100102
public static class Promised implements Serializable {
103+
@Serial
101104
private static final long serialVersionUID = 1L;
102105
private final List<File> files;
103106
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
@@ -212,6 +215,7 @@ synchronized Sig sign(File fileInput) throws IOException {
212215

213216
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
214217
private static final class Sig implements Serializable {
218+
@Serial
215219
private static final long serialVersionUID = 6727302747168655222L;
216220

217221
@SuppressWarnings("unused")

0 commit comments

Comments
 (0)