Skip to content

Commit 4733c6d

Browse files
author
Vincent Potucek
committed
Issue #2634: Add Java8toJava11
1 parent 792d0f2 commit 4733c6d

File tree

33 files changed

+122
-96
lines changed

33 files changed

+122
-96
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.Java8toJava11")
5+
exportDatatables = true
6+
failOnDryRunResults = true
7+
}

lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.nio.charset.StandardCharsets;
2323
import java.nio.file.Files;
2424
import java.nio.file.Path;
25-
import java.nio.file.Paths;
2625
import java.nio.file.attribute.PosixFilePermission;
2726
import java.util.ArrayList;
2827
import java.util.Collections;
@@ -161,7 +160,7 @@ private static String defaultVersion() {
161160
* @param filePath Path to the file to make executable.
162161
*/
163162
private static void makeExecutable(String filePath) {
164-
var exePath = Paths.get(filePath);
163+
var exePath = Path.of(filePath);
165164
attemptToAddPosixPermission(exePath, PosixFilePermission.GROUP_EXECUTE);
166165
attemptToAddPosixPermission(exePath, PosixFilePermission.OTHERS_EXECUTE);
167166
attemptToAddPosixPermission(exePath, PosixFilePermission.OWNER_EXECUTE);
@@ -199,7 +198,7 @@ private static void validateBiomeConfigPath(String configPath, String version) {
199198
return;
200199
}
201200
var atLeastV2 = BiomeSettings.versionHigherThanOrEqualTo(version, 2, 0, 0);
202-
var path = Paths.get(configPath);
201+
var path = Path.of(configPath);
203202
var configFile = Files.isRegularFile(path) && atLeastV2 ? path : path.resolve(BiomeSettings.configName());
204203
if (!Files.exists(path)) {
205204
throw new IllegalArgumentException("Biome config directory does not exist: " + path);
@@ -323,13 +322,13 @@ private State createState() throws IOException, InterruptedException {
323322
private String resolveExe() throws IOException, InterruptedException {
324323
new ForeignExe();
325324
if (pathToExe != null) {
326-
if (Paths.get(pathToExe).getNameCount() == 1) {
325+
if (Path.of(pathToExe).getNameCount() == 1) {
327326
return resolveNameAgainstPath(pathToExe);
328327
} else {
329328
return pathToExe;
330329
}
331330
} else {
332-
var downloader = new BiomeExecutableDownloader(Paths.get(downloadDir));
331+
var downloader = new BiomeExecutableDownloader(Path.of(downloadDir));
333332
var downloaded = downloader.ensureDownloaded(version).toString();
334333
makeExecutable(downloaded);
335334
return downloaded;

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

Lines changed: 10 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.
@@ -16,7 +16,15 @@
1616
package com.diffplug.spotless.java;
1717

1818
import java.io.Serializable;
19-
import java.util.*;
19+
import java.util.ArrayList;
20+
import java.util.Collection;
21+
import java.util.Comparator;
22+
import java.util.HashMap;
23+
import java.util.HashSet;
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Objects;
27+
import java.util.Set;
2028
import java.util.stream.Collectors;
2129
import java.util.stream.Stream;
2230

lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2024 DiffPlug
2+
* Copyright 2021-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.
@@ -18,11 +18,15 @@
1818
import java.io.File;
1919
import java.io.Serializable;
2020
import java.lang.reflect.Constructor;
21-
import java.util.*;
21+
import java.util.Objects;
2222

2323
import javax.annotation.Nullable;
2424

25-
import com.diffplug.spotless.*;
25+
import com.diffplug.spotless.FileSignature;
26+
import com.diffplug.spotless.FormatterFunc;
27+
import com.diffplug.spotless.FormatterStep;
28+
import com.diffplug.spotless.JarState;
29+
import com.diffplug.spotless.Provisioner;
2630

2731
/** Wraps up <a href="https://github.com/cqfn/diKTat">diktat</a> as a FormatterStep. */
2832
public class DiktatStep implements Serializable {

lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 DiffPlug
2+
* Copyright 2020-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.
@@ -18,7 +18,10 @@
1818
import static java.util.Objects.requireNonNull;
1919

2020
import java.io.File;
21-
import java.util.*;
21+
import java.util.ArrayList;
22+
import java.util.Arrays;
23+
import java.util.List;
24+
import java.util.Optional;
2225
import java.util.function.Function;
2326
import java.util.function.Predicate;
2427
import java.util.function.Supplier;
@@ -43,8 +46,7 @@ Optional<File> tryFind() {
4346
return fileCandidateFinders
4447
.stream()
4548
.map(Supplier::get)
46-
.filter(Optional::isPresent)
47-
.map(Optional::get)
49+
.flatMap(Optional::stream)
4850
.findFirst();
4951
}
5052

lib/src/main/java/com/diffplug/spotless/npm/NpmResourceHelper.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
*/
1616
package com.diffplug.spotless.npm;
1717

18-
import java.io.*;
18+
import java.io.ByteArrayOutputStream;
19+
import java.io.File;
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.io.OutputStream;
1923
import java.nio.charset.StandardCharsets;
2024
import java.nio.file.Files;
2125
import java.nio.file.Path;
22-
import java.nio.file.Paths;
2326
import java.nio.file.StandardCopyOption;
2427
import java.security.MessageDigest;
2528
import java.time.Duration;
@@ -130,7 +133,7 @@ static File copyFileToDirAtSubpath(File file, File targetDir, String relativePat
130133
Objects.requireNonNull(relativePath);
131134
try {
132135
// create file pointing to relativePath in targetDir
133-
final Path relativeTargetFile = Paths.get(targetDir.getAbsolutePath(), relativePath);
136+
final Path relativeTargetFile = Path.of(targetDir.getAbsolutePath(), relativePath);
134137
assertDirectoryExists(relativeTargetFile.getParent().toFile());
135138

136139
Files.copy(file.toPath(), relativeTargetFile, StandardCopyOption.REPLACE_EXISTING);

lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 DiffPlug
2+
* Copyright 2023-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.
@@ -24,7 +24,6 @@
2424
import java.nio.file.FileVisitResult;
2525
import java.nio.file.Files;
2626
import java.nio.file.Path;
27-
import java.nio.file.Paths;
2827
import java.nio.file.SimpleFileVisitor;
2928
import java.nio.file.StandardCopyOption;
3029
import java.nio.file.attribute.BasicFileAttributes;
@@ -108,11 +107,11 @@ public File getEntry(String key, String fileName) {
108107
}
109108

110109
private File entry(String key, String origName) {
111-
return Paths.get(shadowCopyRoot().getAbsolutePath(), key, origName).toFile();
110+
return Path.of(shadowCopyRoot().getAbsolutePath(), key, origName).toFile();
112111
}
113112

114113
public File copyEntryInto(String key, String origName, File targetParentFolder) {
115-
File target = Paths.get(targetParentFolder.getAbsolutePath(), origName).toFile();
114+
File target = Path.of(targetParentFolder.getAbsolutePath(), origName).toFile();
116115
if (target.exists()) {
117116
logger.warn("Shadow copy destination already exists, deleting! {}: {}", key, target);
118117
ThrowingEx.run(() -> Files.walkFileTree(target.toPath(), new DeleteDirectoryRecursively()));

0 commit comments

Comments
 (0)