Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ spotless {
dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.14.1"))
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.18.0")
rewrite('org.openrewrite.recipe:rewrite-static-analysis:2.17.0')
rewrite('org.openrewrite.recipe:rewrite-third-party:0.27.0')
}
35 changes: 34 additions & 1 deletion gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
apply plugin: 'org.openrewrite.rewrite'

rewrite {
activeRecipe("org.openrewrite.java.migrate.UpgradeToJava17")
activeRecipe(
'org.openrewrite.gradle.GradleBestPractices',
'org.openrewrite.java.RemoveUnusedImports',
'org.openrewrite.java.migrate.UpgradeToJava17',
'org.openrewrite.staticanalysis.LowercasePackage',
'org.openrewrite.staticanalysis.MissingOverrideAnnotation',
'org.openrewrite.staticanalysis.ModifierOrder',
'org.openrewrite.staticanalysis.NoFinalizer',
'org.openrewrite.staticanalysis.RemoveUnusedLocalVariables',
'org.openrewrite.staticanalysis.RemoveUnusedPrivateFields',
'org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods',
'tech.picnic.errorprone.refasterrules.BigDecimalRulesRecipes',
'tech.picnic.errorprone.refasterrules.CharSequenceRulesRecipes',
'tech.picnic.errorprone.refasterrules.ClassRulesRecipes',
'tech.picnic.errorprone.refasterrules.CollectionRulesRecipes',
'tech.picnic.errorprone.refasterrules.ComparatorRulesRecipes',
'tech.picnic.errorprone.refasterrules.FileRulesRecipes',
'tech.picnic.errorprone.refasterrules.MicrometerRulesRecipes',
'tech.picnic.errorprone.refasterrules.PatternRulesRecipes',
'tech.picnic.errorprone.refasterrules.PreconditionsRulesRecipes',
'tech.picnic.errorprone.refasterrules.PrimitiveRulesRecipes',
'tech.picnic.errorprone.refasterrules.StreamRulesRecipes',
'tech.picnic.errorprone.refasterrules.TimeRulesRecipes'
)
exclusions.addAll(
'**_gradle_node_plugin_example_**',
'**gradle/changelog.gradle',
'**gradle/java-publish.gradle',
'**lib-extra/build.gradle',
'**lib/build.gradle',
'**package-info.java',
'**plugin-maven/build.gradle',
'**settings.gradle'
)
exportDatatables = true
failOnDryRunResults = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static class CachedEndings implements Serializable {
private static final long serialVersionUID = -2534772773057900619L;

/** this is transient, to simulate PathSensitive.RELATIVE */
transient final String rootDir;
final transient String rootDir;
/** the line ending used for most files */
final String defaultEnding;
/** any exceptions to that default, in terms of relative path from rootDir */
Expand Down
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 Down Expand Up @@ -132,9 +132,9 @@ private static boolean worktreeIsCleanCheckout(TreeWalk treeWalk) {
return treeWalk.idEqual(TREE, WORKDIR);
}

private final static int TREE = 0;
private final static int INDEX = 1;
private final static int WORKDIR = 2;
private static final int TREE = 0;
private static final int INDEX = 1;
private static final int WORKDIR = 2;

Map<File, Repository> gitRoots = new HashMap<>();
Table<Repository, String, ObjectId> rootTreeShaCache = HashBasedTable.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public static Map.Entry<Integer, String> diff(Path rootDir, Formatter formatter,
}

private static Map.Entry<Integer, String> diff(CleanProvider formatter, File file) throws IOException {
String raw = new String(Files.readAllBytes(file.toPath()), formatter.getEncoding());
String raw = Files.readString(file.toPath(), formatter.getEncoding());
String rawUnix = LineEnding.toUnix(raw);
String formatted = formatter.getFormatted(file, rawUnix);
String formattedUnix = LineEnding.toUnix(formatted);
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 @@ -24,8 +24,8 @@
import com.diffplug.spotless.extra.eclipse.EquoResourceHarness;

public class GrEclipseFormatterStepTest extends EquoResourceHarness {
private final static String INPUT = "class F{ def m(){} }";
private final static String EXPECTED = "class F{\n\tdef m(){}\n}";
private static final String INPUT = "class F{ def m(){} }";
private static final String EXPECTED = "class F{\n\tdef m(){}\n}";

public GrEclipseFormatterStepTest() {
super(GrEclipseFormatterStep.createBuilder(TestProvisioner.mavenCentral()));
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 @@ -19,6 +19,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.Properties;
import java.util.function.Consumer;
import java.util.stream.Stream;
Expand All @@ -33,7 +34,7 @@
import com.diffplug.spotless.extra.eclipse.EclipseResourceHarness;

public class EclipseWtpFormatterStepTest {
private final static Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support("Oldest Version").add(8, "4.8.0");
private static final Jvm.Support<String> JVM_SUPPORT = Jvm.<String> support("Oldest Version").add(8, "4.8.0");

private static class NestedTests extends EclipseResourceHarness {
private final String unformatted, formatted;
Expand Down Expand Up @@ -76,7 +77,7 @@ void multipleConfigurations() throws Exception {
private File createPropertyFile(Consumer<Properties> config) throws IOException {
Properties configProps = new Properties();
config.accept(configProps);
File tempFile = File.createTempFile("EclipseWtpFormatterStepTest-", ".properties");
File tempFile = Files.createTempFile("EclipseWtpFormatterStepTest-", ".properties").toFile();
OutputStream tempOut = new FileOutputStream(tempFile);
configProps.store(tempOut, "test properties");
tempOut.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected Class<?> inferType(String input) {
* @return a {@link JsonFactory}. May be overridden to handle alternative formats.
* @see <a href="https://github.com/FasterXML/jackson-dataformats-text">jackson-dataformats-text</a>
*/
@Override
protected JsonFactory makeJsonFactory() {
JsonFactory jsonFactory = new JsonFactoryBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static FormatterProperties fromXmlContent(final Iterable<String> content)

public static FormatterProperties merge(Properties... properties) {
FormatterProperties merged = new FormatterProperties();
List.of(properties).stream().forEach((source) -> merged.properties.putAll(source));
List.of(properties).forEach((source) -> merged.properties.putAll(source));
return merged;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void doInstall() throws Exception {
* such as file reading or writing errors
*/
private void uninstall(File gitHookFile) throws Exception {
final var hook = Files.readString(gitHookFile.toPath(), UTF_8);
final var hook = Files.readString(gitHookFile.toPath());
final int hookStart = hook.indexOf(HOOK_HEADER);
final int hookEnd = hook.indexOf(HOOK_FOOTER) + HOOK_FOOTER.length(); // hookEnd exclusive, so must be last symbol \n

Expand Down Expand Up @@ -323,7 +323,7 @@ private boolean isGitInstalled() {
* @throws Exception if an error occurs when reading the file.
*/
private boolean isGitHookInstalled(File gitHookFile) throws Exception {
final var hook = Files.readString(gitHookFile.toPath(), UTF_8);
final var hook = Files.readString(gitHookFile.toPath());
return hook.contains(HOOK_HEADER) && hook.contains(HOOK_FOOTER);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/java/com/diffplug/spotless/NoLambda.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface NoLambda extends Serializable {
public byte[] toBytes();

/** An implementation of NoLambda in which equality is based on the serialized representation of itself. */
public static abstract class EqualityBasedOnSerialization implements NoLambda {
public abstract static class EqualityBasedOnSerialization implements NoLambda {
@Serial
private static final long serialVersionUID = 1733798699224768949L;

Expand Down
12 changes: 6 additions & 6 deletions lib/src/main/java/com/diffplug/spotless/biome/BiomeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
public final class BiomeSettings {
private static final Logger logger = LoggerFactory.getLogger(BiomeSettings.class);

private final static String CONFIG_NAME = "biome.json";
private final static String DEFAULT_VERSION = "1.2.0";
private final static String DOWNLOAD_FILE_PATTERN = "biome-%s-%s-%s";
private final static String SHORT_NAME = "biome";
private final static String URL_PATTERN_1X = "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s";
private final static String URL_PATTERN_2X = "https://github.com/biomejs/biome/releases/download/%%40biomejs%%2Fbiome%%40%s/biome-%s";
private static final String CONFIG_NAME = "biome.json";
private static final String DEFAULT_VERSION = "1.2.0";
private static final String DOWNLOAD_FILE_PATTERN = "biome-%s-%s-%s";
private static final String SHORT_NAME = "biome";
private static final String URL_PATTERN_1X = "https://github.com/biomejs/biome/releases/download/cli%%2Fv%s/biome-%s";
private static final String URL_PATTERN_2X = "https://github.com/biomejs/biome/releases/download/%%40biomejs%%2Fbiome%%40%s/biome-%s";

private BiomeSettings() {}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static boolean isMacOs() {

private String format(IdeaStepFormatterCleanupResources ideaStepFormatterCleanupResources, String unix, File file) throws Exception {
// since we cannot directly work with the file, we need to write the unix string to a temporary file
File tempFile = File.createTempFile("spotless", file.getName());
File tempFile = Files.createTempFile("spotless", file.getName()).toFile();
try {
Files.write(tempFile.toPath(), unix.getBytes(StandardCharsets.UTF_8));
List<String> params = getParams(tempFile);
Expand All @@ -224,7 +224,7 @@ private String format(IdeaStepFormatterCleanupResources ideaStepFormatterCleanup
LOGGER.debug("command finished with exit code: {}", result.exitCode());
LOGGER.debug("command finished with stdout: {}",
result.assertExitZero(StandardCharsets.UTF_8));
return Files.readString(tempFile.toPath(), StandardCharsets.UTF_8);
return Files.readString(tempFile.toPath());
} finally {
Files.delete(tempFile.toPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ private static final class State implements Serializable {

// group 1 is the basename of the annotation.
private static final String annoNoArgRegex = "@(?:[A-Za-z_][A-Za-z0-9_.]*\\.)?([A-Za-z_][A-Za-z0-9_]*)";
private static final Pattern annoNoArgPattern = Pattern.compile(annoNoArgRegex);
// 3 non-empty cases: () (".*") (.*)
private static final String annoArgRegex = "(?:\\(\\)|\\(\"[^\"]*\"\\)|\\([^\")][^)]*\\))?";
// group 1 is the basename of the annotation.
Expand Down
6 changes: 3 additions & 3 deletions lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public enum Style {
;
// @formatter:on

final private String format;
final private String since;
final private @Nullable String until;
private final String format;
private final String since;
private final @Nullable String until;

Style(String format, String since) {
this.format = format;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public boolean isNodeModulesPrepared() {
// check if it is NOT empty
return ThrowingEx.get(() -> {
try (Stream<Path> entries = Files.list(nodeModulesInstallDirPath)) {
return entries.findFirst().isPresent();
return entries.findAny().isPresent();
}
});
}
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 Down Expand Up @@ -137,7 +137,7 @@ private String assertFilepathInConfigOptions(File file) {
return prettierConfigOptions;
}
// if the file has no name, we cannot use it
if (file.getName().trim().length() == 0) {
if (file.getName().trim().isEmpty()) {
return prettierConfigOptions;
}
// if it is not there, we add it at the beginning of the Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private String readInputStream(InputStream inputStream) throws IOException {
}
}

static abstract class SimpleRestException extends RuntimeException {
abstract static class SimpleRestException extends RuntimeException {
private static final long serialVersionUID = -8260821395756603787L;

public SimpleRestException() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public NpmLongRunningProcess createNpmServeProcess(NodeServerLayout nodeServerLa
return new NpmServe(nodeServerLayout.nodeModulesDir(), formatterStepLocations, nodeServerInstanceId);
}

private static abstract class AbstractStandardNpmProcess {
private abstract static class AbstractStandardNpmProcess {
protected final ProcessRunner processRunner = ProcessRunner.usingRingBuffersOfCapacity(100 * 1024); // 100kB

protected final File workingDir;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 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 @@ -63,6 +63,7 @@ public int getPos() {
return fPos;
}

@Override
public String toString() {
final StringBuilder buf = new StringBuilder();
buf.append(getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 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,16 +22,19 @@
*/
enum KeywordCase {
UPPER {
@Override
public String transform(String value) {
return value.toUpperCase(Locale.ENGLISH);
}
},
LOWER {
@Override
public String transform(String value) {
return value.toLowerCase(Locale.ENGLISH);
}
},
ORIGINAL {
@Override
public String transform(String value) {
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.io.File;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.scalafmt.Scalafmt;
Expand All @@ -43,7 +42,7 @@ public ScalafmtFormatterFunc(FileSignature configSignature) throws Exception {
config = (ScalafmtConfig) method.invoke(ScalafmtConfig$.MODULE$);
} else {
File file = configSignature.getOnlyFile();
String configStr = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
String configStr = Files.readString(file.toPath());
config = Scalafmt.parseHoconConfig(configStr).get();
}

Expand Down
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 @@ -15,7 +15,9 @@
*/
package com.diffplug.spotless.glue.pom;

import java.io.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.file.Files;
Expand All @@ -41,7 +43,7 @@ public SortPomFormatterFunc(SortPomCfg cfg) {
@Override
public String apply(String input) throws Exception {
// SortPom expects a file to sort, so we write the input into a temporary file
File pom = File.createTempFile("pom", ".xml");
File pom = Files.createTempFile("pom", ".xml").toFile();
pom.deleteOnExit();
try (BufferedWriter writer = new BufferedWriter(new FileWriter(pom, Charset.forName(cfg.encoding)))) {
writer.write(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
Expand Down Expand Up @@ -61,7 +60,7 @@ private static String loadAndWriteText(Path path, String name) throws IOExceptio
try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/" + name)) {
Files.copy(is, path.resolve(name));
}
return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8);
return Files.readString(path.resolve(name));
}

}
Loading
Loading