Skip to content
Merged
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
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ concurrency:
cancel-in-progress: true
jobs:
sanityCheck:
name: spotlessCheck assemble testClasses
runs-on: ubuntu-latest
env:
buildcacheuser: ${{ secrets.BUILDCACHE_USER }}
Expand All @@ -31,6 +30,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 +67,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")
}
6 changes: 3 additions & 3 deletions gradle/java-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ model {
from components.java
}

groupId project.group
artifactId project.ext.artifactId
version project.version
groupId = project.group
artifactId = project.ext.artifactId
version = project.version

def projectExtArtifactId = project.ext.artifactId
def projectDescription = project.description
Expand Down
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.UpgradeToJava17")
exportDatatables = true
failOnDryRunResults = true
}
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 Down Expand Up @@ -175,7 +175,7 @@ private static String convertEclipseVersion(String version) {
char lastChar = version.charAt(version.length() - 1);
if ('.' != lastChar && 'a' <= lastChar) {
semanticVersion = version.substring(0, version.length() - 1);
semanticVersion += String.format(".%d", (int) lastChar);
semanticVersion += ".%d".formatted((int) lastChar);
}
}
return semanticVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce
return (String) method.invoke(formatter, input);
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
Exception exception = (throwable instanceof Exception e) ? e : null;
throw (null == exception) ? exceptionWrapper : exception;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static FormatterFunc apply(EquoBasedStepBuilder.State state) throws Exce
return (String) method.invoke(formatter, input);
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
Exception exception = (throwable instanceof Exception e) ? e : null;
throw (null == exception) ? exceptionWrapper : exception;
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2021 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 Down Expand Up @@ -67,7 +67,7 @@ private static FormatterFunc applyWithoutFile(String className, EclipseBasedStep
return (String) method.invoke(formatter, input);
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
Exception exception = (throwable instanceof Exception e) ? e : null;
throw (null == exception) ? exceptionWrapper : exception;
}
};
Expand All @@ -85,7 +85,7 @@ public String applyWithFile(String unix, File file) throws Exception {
return (String) method.invoke(formatter, unix, file.getAbsolutePath());
} catch (InvocationTargetException exceptionWrapper) {
Throwable throwable = exceptionWrapper.getTargetException();
Exception exception = (throwable instanceof Exception) ? (Exception) throwable : null;
Exception exception = (throwable instanceof Exception e) ? e : null;
throw (null == exception) ? exceptionWrapper : exception;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.diffplug.spotless;

import java.io.IOException;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -51,6 +52,7 @@
* to make Spotless work with all of Gradle's cache systems at once.
*/
public class ConfigurationCacheHackList implements java.io.Serializable {
@Serial
private static final long serialVersionUID = 6914178791997323870L;

private boolean optimizeForEquality;
Expand Down Expand Up @@ -108,8 +110,8 @@ public void clear() {

public void addAll(Collection<? extends FormatterStep> c) {
for (FormatterStep step : c) {
if (step instanceof FormatterStepSerializationRoundtrip) {
var clone = ((FormatterStepSerializationRoundtrip) step).hackClone(optimizeForEquality);
if (step instanceof FormatterStepSerializationRoundtrip roundtrip) {
var clone = roundtrip.hackClone(optimizeForEquality);
backingList.add(clone);
} else {
backingList.add(step);
Expand All @@ -120,8 +122,8 @@ public void addAll(Collection<? extends FormatterStep> c) {
public List<FormatterStep> getSteps() {
var result = new ArrayList<FormatterStep>(backingList.size());
for (Object obj : backingList) {
if (obj instanceof FormatterStepSerializationRoundtrip.HackClone) {
result.add(((FormatterStepSerializationRoundtrip.HackClone) obj).rehydrate());
if (obj instanceof FormatterStepSerializationRoundtrip.HackClone clone) {
result.add(clone.rehydrate());
} else {
result.add((FormatterStep) obj);
}
Expand Down
6 changes: 5 additions & 1 deletion lib/src/main/java/com/diffplug/spotless/FileSignature.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 @@ -23,6 +23,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serial;
import java.io.Serializable;
import java.security.MessageDigest;
import java.util.Arrays;
Expand All @@ -38,6 +39,7 @@

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

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

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

@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
private static final class Sig implements Serializable {
@Serial
private static final long serialVersionUID = 6727302747168655222L;

@SuppressWarnings("unused")
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 @@ -16,6 +16,7 @@
package com.diffplug.spotless;

import java.io.File;
import java.io.Serial;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -73,5 +74,6 @@ public int hashCode() {
return Objects.hash(delegateStep, onMatch, contentPattern.pattern());
}

@Serial
private static final long serialVersionUID = 2L;
}
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,6 +16,7 @@
package com.diffplug.spotless;

import java.io.File;
import java.io.Serial;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -69,5 +70,6 @@ public int hashCode() {
return Objects.hash(delegateStep, filter);
}

@Serial
private static final long serialVersionUID = 1L;
}
4 changes: 3 additions & 1 deletion lib/src/main/java/com/diffplug/spotless/ForeignExe.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2024 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 @@ -16,6 +16,7 @@
package com.diffplug.spotless;

import java.io.IOException;
import java.io.Serial;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Objects;
Expand All @@ -33,6 +34,7 @@
* will find grep, confirm that it is version 2.5.7, and then return.
*/
public class ForeignExe implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private @Nullable String pathToExe;
private String versionFlag = "--version";
Expand Down
4 changes: 3 additions & 1 deletion lib/src/main/java/com/diffplug/spotless/Formatter.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 @@ -22,6 +22,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.Serial;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.ArrayList;
Expand All @@ -33,6 +34,7 @@

/** Formatter which performs the full formatting. */
public final class Formatter implements Serializable, AutoCloseable {
@Serial
private static final long serialVersionUID = 1L;

// The name is used for logging purpose. It does not convey any applicative
Expand Down
15 changes: 7 additions & 8 deletions lib/src/main/java/com/diffplug/spotless/FormatterProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public static FormatterProperties fromXmlContent(final Iterable<String> content)
final Properties newSettings = FileParser.XML.executeXmlContent(contentElement);
properties.properties.putAll(newSettings);
} catch (IOException | IllegalArgumentException exception) {
String message = String.format("Failed to add preferences from XML:%n%s%n", contentElement);
String message = "Failed to add preferences from XML:%n%s%n".formatted(contentElement);
final String detailedMessage = exception.getMessage();
if (null != detailedMessage) {
message += String.format(" %s", detailedMessage);
message += " %s".formatted(detailedMessage);
}
throw new IllegalArgumentException(message, exception);
}
Expand All @@ -129,17 +129,17 @@ public static FormatterProperties merge(Properties... properties) {
private void add(final File settingsFile) throws IllegalArgumentException {
Objects.requireNonNull(settingsFile);
if (!(settingsFile.isFile() && settingsFile.canRead())) {
String msg = String.format("Settings file '%s' does not exist or can not be read.", settingsFile);
String msg = "Settings file '%s' does not exist or can not be read.".formatted(settingsFile);
throw new IllegalArgumentException(msg);
}
try {
Properties newSettings = FileParser.parse(settingsFile);
properties.putAll(newSettings);
} catch (IOException | IllegalArgumentException exception) {
String message = String.format("Failed to add properties from '%s' to formatter settings.", settingsFile);
String message = "Failed to add properties from '%s' to formatter settings.".formatted(settingsFile);
String detailedMessage = exception.getMessage();
if (null != detailedMessage) {
message += String.format(" %s", detailedMessage);
message += " %s".formatted(detailedMessage);
}
throw new IllegalArgumentException(message, exception);
}
Expand Down Expand Up @@ -241,8 +241,7 @@ public static Properties parse(final File file) throws IOException, IllegalArgum
return parser.execute(file);
}
}
String msg = String.format(
"The file name extension '%1$s' is not part of the supported file extensions [%2$s].",
String msg = "The file name extension '%1$s' is not part of the supported file extensions [%2$s].".formatted(
fileNameExtension, Arrays.toString(FileParser.values()));
throw new IllegalArgumentException(msg);

Expand Down Expand Up @@ -341,7 +340,7 @@ public static Properties parse(final InputStream is, final Node rootNode)
return parser.execute(is, rootNode);
}
}
String msg = String.format("The XML root node '%1$s' is not part of the supported root nodes [%2$s].",
String msg = "The XML root node '%1$s' is not part of the supported root nodes [%2$s].".formatted(
rootNodeName, Arrays.toString(XmlParser.values()));
throw new IllegalArgumentException(msg);
}
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 @@ -16,6 +16,7 @@
package com.diffplug.spotless;

import java.io.File;
import java.io.Serial;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
Expand All @@ -31,6 +32,7 @@
*/
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
abstract class FormatterStepEqualityOnStateSerialization<State extends Serializable> implements FormatterStep, Serializable {
@Serial
private static final long serialVersionUID = 1L;

protected abstract State stateSupplier() throws Exception;
Expand Down Expand Up @@ -75,8 +77,8 @@ public int hashCode() {

@Override
public void close() {
if (formatter instanceof FormatterFunc.Closeable) {
((FormatterFunc.Closeable) formatter).close();
if (formatter instanceof FormatterFunc.Closeable closeable) {
closeable.close();
formatter = null;
}
}
Expand Down
Loading
Loading