Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
cancel-in-progress: true
jobs:
sanityCheck:
name: spotlessCheck assemble testClasses
name: spotlessCheck rewriteDryRun assemble testClasses
runs-on: ubuntu-latest
env:
buildcacheuser: ${{ secrets.BUILDCACHE_USER }}
Expand All @@ -31,6 +31,8 @@ jobs:
uses: gradle/actions/setup-gradle@v4
- name: spotlessCheck
run: ./gradlew spotlessCheck
- name: rewriteDryRun
run: ./gradlew rewriteDryRun
- name: assemble testClasses
run: ./gradlew assemble testClasses
build:
Expand Down Expand Up @@ -66,10 +68,10 @@ jobs:
uses: gradle/actions/setup-gradle@v4
- name: build (maven-only)
if: matrix.kind == 'maven'
run: ./gradlew :plugin-maven:build -x spotlessCheck
run: ./gradlew :plugin-maven:build -x spotlessCheck -x rewriteDryRun
- name: build (everything-but-maven)
if: matrix.kind == 'gradle'
run: ./gradlew build -x spotlessCheck -PSPOTLESS_EXCLUDE_MAVEN=true
run: ./gradlew build -x spotlessCheck -x rewriteDryRun -PSPOTLESS_EXCLUDE_MAVEN=true
- name: test npm
if: matrix.kind == 'npm'
run: ./gradlew testNpm
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Added
* Add a `lint` mode to `ReplaceRegexStep` ([#2571](https://github.com/diffplug/spotless/pull/2571))
* `LintSuppression` now enforces unix-style paths in its `setPath` and `relativizeAsUnix` methods. ([#2629](https://github.com/diffplug/spotless/pull/2629))
* Add `rewrite` support ([#2588](https://github.com/diffplug/spotless/pull/2588))

## [3.3.1] - 2025-07-21
### Fixed
Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repositories {
apply from: rootProject.file('gradle/java-publish.gradle')
apply from: rootProject.file('gradle/changelog.gradle')
allprojects {
apply from: rootProject.file('gradle/rewrite.gradle')
apply from: rootProject.file('gradle/spotless.gradle')
}
apply from: rootProject.file('gradle/spotless-freshmark.gradle')
Expand All @@ -27,3 +28,8 @@ spotless {
endWithNewline()
}
}

dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.14.1"))
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.17.1")
}
7 changes: 7 additions & 0 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apply plugin: 'org.openrewrite.rewrite'

rewrite {
activeRecipe("org.openrewrite.java.migrate.Java8toJava11")
exportDatatables = true
failOnDryRunResults = true
}
9 changes: 4 additions & 5 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -161,7 +160,7 @@ private static String defaultVersion() {
* @param filePath Path to the file to make executable.
*/
private static void makeExecutable(String filePath) {
var exePath = Paths.get(filePath);
var exePath = Path.of(filePath);
attemptToAddPosixPermission(exePath, PosixFilePermission.GROUP_EXECUTE);
attemptToAddPosixPermission(exePath, PosixFilePermission.OTHERS_EXECUTE);
attemptToAddPosixPermission(exePath, PosixFilePermission.OWNER_EXECUTE);
Expand Down Expand Up @@ -199,7 +198,7 @@ private static void validateBiomeConfigPath(String configPath, String version) {
return;
}
var atLeastV2 = BiomeSettings.versionHigherThanOrEqualTo(version, 2, 0, 0);
var path = Paths.get(configPath);
var path = Path.of(configPath);
var configFile = Files.isRegularFile(path) && atLeastV2 ? path : path.resolve(BiomeSettings.configName());
if (!Files.exists(path)) {
throw new IllegalArgumentException("Biome config directory does not exist: " + path);
Expand Down Expand Up @@ -323,13 +322,13 @@ private State createState() throws IOException, InterruptedException {
private String resolveExe() throws IOException, InterruptedException {
new ForeignExe();
if (pathToExe != null) {
if (Paths.get(pathToExe).getNameCount() == 1) {
if (Path.of(pathToExe).getNameCount() == 1) {
return resolveNameAgainstPath(pathToExe);
} else {
return pathToExe;
}
} else {
var downloader = new BiomeExecutableDownloader(Paths.get(downloadDir));
var downloader = new BiomeExecutableDownloader(Path.of(downloadDir));
var downloaded = downloader.ensureDownloaded(version).toString();
makeExecutable(downloaded);
return downloaded;
Expand Down
12 changes: 10 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/java/ImportSorterImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,15 @@
package com.diffplug.spotless.java;

import java.io.Serializable;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down
10 changes: 7 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2024 DiffPlug
* Copyright 2021-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,11 +18,15 @@
import java.io.File;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.*;
import java.util.Objects;

import javax.annotation.Nullable;

import com.diffplug.spotless.*;
import com.diffplug.spotless.FileSignature;
import com.diffplug.spotless.FormatterFunc;
import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.JarState;
import com.diffplug.spotless.Provisioner;

/** Wraps up <a href="https://github.com/cqfn/diKTat">diktat</a> as a FormatterStep. */
public class DiktatStep implements Serializable {
Expand Down
10 changes: 6 additions & 4 deletions lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 DiffPlug
* Copyright 2020-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,10 @@
import static java.util.Objects.requireNonNull;

import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand All @@ -43,8 +46,7 @@ Optional<File> tryFind() {
return fileCandidateFinders
.stream()
.map(Supplier::get)
.filter(Optional::isPresent)
.map(Optional::get)
.flatMap(Optional::stream)
.findFirst();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/
package com.diffplug.spotless.npm;

import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.MessageDigest;
import java.time.Duration;
Expand Down Expand Up @@ -130,7 +133,7 @@ static File copyFileToDirAtSubpath(File file, File targetDir, String relativePat
Objects.requireNonNull(relativePath);
try {
// create file pointing to relativePath in targetDir
final Path relativeTargetFile = Paths.get(targetDir.getAbsolutePath(), relativePath);
final Path relativeTargetFile = Path.of(targetDir.getAbsolutePath(), relativePath);
assertDirectoryExists(relativeTargetFile.getParent().toFile());

Files.copy(file.toPath(), relativeTargetFile, StandardCopyOption.REPLACE_EXISTING);
Expand Down
7 changes: 3 additions & 4 deletions lib/src/main/java/com/diffplug/spotless/npm/ShadowCopy.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 DiffPlug
* Copyright 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,6 @@
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
Expand Down Expand Up @@ -108,11 +107,11 @@ public File getEntry(String key, String fileName) {
}

private File entry(String key, String origName) {
return Paths.get(shadowCopyRoot().getAbsolutePath(), key, origName).toFile();
return Path.of(shadowCopyRoot().getAbsolutePath(), key, origName).toFile();
}

public File copyEntryInto(String key, String origName, File targetParentFolder) {
File target = Paths.get(targetParentFolder.getAbsolutePath(), origName).toFile();
File target = Path.of(targetParentFolder.getAbsolutePath(), origName).toFile();
if (target.exists()) {
logger.warn("Shadow copy destination already exists, deleting! {}: {}", key, target);
ThrowingEx.run(() -> Files.walkFileTree(target.toPath(), new DeleteDirectoryRecursively()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2024 DiffPlug
* Copyright 2016-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,9 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -68,8 +70,7 @@ public static class State extends NpmFormatterStepStateBase implements Serializa

private final File buildDir;

@Nullable
private final TypedTsFmtConfigFile configFile;
@Nullable private final TypedTsFmtConfigFile configFile;

public State(String stepName, Map<String, String> versions, File projectDir, File buildDir, File cacheDir, NpmPathResolver npmPathResolver, @Nullable TypedTsFmtConfigFile configFile, @Nullable Map<String, Object> inlineTsFmtSettings) throws IOException {
super(stepName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 DiffPlug
* Copyright 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -34,7 +33,7 @@ public class KtLintCompat0Dot48Dot0AdapterTest {
public void testDefaults(@TempDir Path path) throws IOException {
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
var content = loadAndWriteText(path, "empty_class_body.kt");
final Path filePath = Paths.get(path.toString(), "empty_class_body.kt");
final Path filePath = Path.of(path.toString(), "empty_class_body.kt");

Map<String, Object> editorConfigOverrideMap = new HashMap<>();

Expand All @@ -46,7 +45,7 @@ public void testDefaults(@TempDir Path path) throws IOException {
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
var content = loadAndWriteText(path, "fails_no_semicolons.kt");
final Path filePath = Paths.get(path.toString(), "fails_no_semicolons.kt");
final Path filePath = Path.of(path.toString(), "fails_no_semicolons.kt");

Map<String, Object> editorConfigOverrideMap = new HashMap<>();
editorConfigOverrideMap.put("indent_style", "tab");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 DiffPlug
* Copyright 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -34,7 +33,7 @@ public class KtLintCompat0Dot49Dot0AdapterTest {
public void testDefaults(@TempDir Path path) throws IOException {
KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter();
var content = loadAndWriteText(path, "EmptyClassBody.kt");
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
final Path filePath = Path.of(path.toString(), "EmptyClassBody.kt");

Map<String, Object> editorConfigOverrideMap = new HashMap<>();

Expand All @@ -46,7 +45,7 @@ public void testDefaults(@TempDir Path path) throws IOException {
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
KtLintCompat0Dot49Dot0Adapter ktLintCompat0Dot49Dot0Adapter = new KtLintCompat0Dot49Dot0Adapter();
var content = loadAndWriteText(path, "FailsNoSemicolons.kt");
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
final Path filePath = Path.of(path.toString(), "FailsNoSemicolons.kt");

Map<String, Object> editorConfigOverrideMap = new HashMap<>();
editorConfigOverrideMap.put("indent_style", "tab");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 DiffPlug
* Copyright 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -34,7 +33,7 @@ public class KtLintCompat0Dot50Dot0AdapterTest {
public void testDefaults(@TempDir Path path) throws IOException {
KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter();
var content = loadAndWriteText(path, "EmptyClassBody.kt");
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
final Path filePath = Path.of(path.toString(), "EmptyClassBody.kt");

Map<String, Object> editorConfigOverrideMap = new HashMap<>();

Expand All @@ -46,7 +45,7 @@ public void testDefaults(@TempDir Path path) throws IOException {
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
KtLintCompat0Dot50Dot0Adapter KtLintCompat0Dot50Dot0Adapter = new KtLintCompat0Dot50Dot0Adapter();
var content = loadAndWriteText(path, "FailsNoSemicolons.kt");
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
final Path filePath = Path.of(path.toString(), "FailsNoSemicolons.kt");

Map<String, Object> editorConfigOverrideMap = new HashMap<>();
editorConfigOverrideMap.put("indent_style", "tab");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 DiffPlug
* Copyright 2023-2025 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -34,7 +33,7 @@ public class KtLintCompat1Dot0Dot0AdapterTest {
public void testDefaults(@TempDir Path path) throws IOException {
KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter();
var content = loadAndWriteText(path, "EmptyClassBody.kt");
final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt");
final Path filePath = Path.of(path.toString(), "EmptyClassBody.kt");

Map<String, Object> editorConfigOverrideMap = new HashMap<>();

Expand All @@ -46,7 +45,7 @@ public void testDefaults(@TempDir Path path) throws IOException {
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter();
var content = loadAndWriteText(path, "FailsNoSemicolons.kt");
final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt");
final Path filePath = Path.of(path.toString(), "FailsNoSemicolons.kt");

Map<String, Object> editorConfigOverrideMap = new HashMap<>();
editorConfigOverrideMap.put("indent_style", "tab");
Expand Down
Loading
Loading