diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 331eaa411d..c750cbde0b 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -22,15 +22,29 @@ jobs: with: script: | try { + // Get username - prioritize sender (the person who triggered the event) + const username = github.event.sender?.login || + github.event.comment?.user?.login; + + if (!username) { + console.log('Could not determine username from event payload'); + console.log(`Event type: ${github.event_name}`); + console.log(`Event payload keys: ${Object.keys(github.event).join(', ')}`); + return false; + } + + console.log(`Checking team membership for user: ${username} (triggered by ${github.event_name} event)`); + const { data } = await github.rest.teams.getMembershipForUserInOrg({ org: 'diffplug', team_slug: 'spotless', - username: github.event.sender.login + username: username }); - console.log(`User ${github.event.sender.login} membership status: ${data.state}`); + console.log(`User ${username} membership status: ${data.state}`); return data.state === 'active'; } catch (error) { - console.log(`User ${github.event.sender.login} is not a member of the Spotless team`); + const username = github.event.sender?.login || github.event.comment?.user?.login || 'unknown user'; + console.log(`User ${username} is not a member of the Spotless team or error occurred: ${error.message}`); return false; } diff --git a/build.gradle b/build.gradle index 0ad34ed577..45233aa12a 100644 --- a/build.gradle +++ b/build.gradle @@ -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') } diff --git a/gradle/rewrite.gradle b/gradle/rewrite.gradle index f520ab77eb..258d5df6d5 100644 --- a/gradle/rewrite.gradle +++ b/gradle/rewrite.gradle @@ -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 } diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java index 2695068e5b..f28eb5a338 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitAttributesLineEndings.java @@ -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 */ diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java index 037d4d847b..c8f5fb68fb 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.java @@ -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. @@ -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 gitRoots = new HashMap<>(); Table rootTreeShaCache = HashBasedTable.create(); diff --git a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java index c02c2f2987..2b05bf93c3 100644 --- a/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java +++ b/lib-extra/src/main/java/com/diffplug/spotless/extra/integration/DiffMessageFormatter.java @@ -251,7 +251,7 @@ public static Map.Entry diff(Path rootDir, Formatter formatter, } private static Map.Entry 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); diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java index 7bfddc8e1c..6b00c0e794 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/groovy/GrEclipseFormatterStepTest.java @@ -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. @@ -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())); diff --git a/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java b/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java index e4a2b7cc0e..2500e611c1 100644 --- a/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java +++ b/lib-extra/src/test/java/com/diffplug/spotless/extra/wtp/EclipseWtpFormatterStepTest.java @@ -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. @@ -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; @@ -33,7 +34,7 @@ import com.diffplug.spotless.extra.eclipse.EclipseResourceHarness; public class EclipseWtpFormatterStepTest { - private final static Jvm.Support JVM_SUPPORT = Jvm. support("Oldest Version").add(8, "4.8.0"); + private static final Jvm.Support JVM_SUPPORT = Jvm. support("Oldest Version").add(8, "4.8.0"); private static class NestedTests extends EclipseResourceHarness { private final String unformatted, formatted; @@ -76,7 +77,7 @@ void multipleConfigurations() throws Exception { private File createPropertyFile(Consumer 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(); diff --git a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java index 0cd8d85849..57c8e9aedf 100644 --- a/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java +++ b/lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java @@ -52,6 +52,7 @@ protected Class inferType(String input) { * @return a {@link JsonFactory}. May be overridden to handle alternative formats. * @see jackson-dataformats-text */ + @Override protected JsonFactory makeJsonFactory() { JsonFactory jsonFactory = new JsonFactoryBuilder().build(); diff --git a/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java b/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java index 00233ef0a8..486fd470dc 100644 --- a/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java +++ b/lib/src/main/java/com/diffplug/spotless/FormatterProperties.java @@ -113,7 +113,7 @@ public static FormatterProperties fromXmlContent(final Iterable 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; } diff --git a/lib/src/main/java/com/diffplug/spotless/GitPrePushHookInstaller.java b/lib/src/main/java/com/diffplug/spotless/GitPrePushHookInstaller.java index f2c6ad8018..40fe2f8c31 100644 --- a/lib/src/main/java/com/diffplug/spotless/GitPrePushHookInstaller.java +++ b/lib/src/main/java/com/diffplug/spotless/GitPrePushHookInstaller.java @@ -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 @@ -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); } diff --git a/lib/src/main/java/com/diffplug/spotless/NoLambda.java b/lib/src/main/java/com/diffplug/spotless/NoLambda.java index f292d1549e..3c6676ee55 100644 --- a/lib/src/main/java/com/diffplug/spotless/NoLambda.java +++ b/lib/src/main/java/com/diffplug/spotless/NoLambda.java @@ -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; diff --git a/lib/src/main/java/com/diffplug/spotless/biome/BiomeSettings.java b/lib/src/main/java/com/diffplug/spotless/biome/BiomeSettings.java index 82194c2a13..6d1db090b3 100644 --- a/lib/src/main/java/com/diffplug/spotless/biome/BiomeSettings.java +++ b/lib/src/main/java/com/diffplug/spotless/biome/BiomeSettings.java @@ -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() {} diff --git a/lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java b/lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java index 9b90964a3f..e64e388aa8 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java @@ -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 params = getParams(tempFile); @@ -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()); } diff --git a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java index 3de76313f7..bfdfc0ba09 100644 --- a/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java +++ b/lib/src/main/java/com/diffplug/spotless/java/FormatAnnotationsStep.java @@ -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. diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java index 865a3e37c4..0f1abf1320 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java @@ -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; diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java index 1b8ec1c58e..941fe8abb5 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeServerLayout.java @@ -96,7 +96,7 @@ public boolean isNodeModulesPrepared() { // check if it is NOT empty return ThrowingEx.get(() -> { try (Stream entries = Files.list(nodeModulesInstallDirPath)) { - return entries.findFirst().isPresent(); + return entries.findAny().isPresent(); } }); } diff --git a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java index 27a1002df5..aa12e64407 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java @@ -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. @@ -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 diff --git a/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java b/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java index 1328ec318f..ef72c20721 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/SimpleRestClient.java @@ -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() {} diff --git a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java index 8ca7246221..bb618d016c 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/StandardNpmProcessFactory.java @@ -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; diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/FormatterToken.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/FormatterToken.java index fd5e3994f9..f608a1686f 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/FormatterToken.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/FormatterToken.java @@ -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. @@ -63,6 +63,7 @@ public int getPos() { return fPos; } + @Override public String toString() { final StringBuilder buf = new StringBuilder(); buf.append(getClass().getName()); diff --git a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/KeywordCase.java b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/KeywordCase.java index 45a7083a80..0ea1a2ff71 100644 --- a/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/KeywordCase.java +++ b/lib/src/main/java/com/diffplug/spotless/sql/dbeaver/KeywordCase.java @@ -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. @@ -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; } diff --git a/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java b/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java index ab7e56ba45..053bed0cab 100644 --- a/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java +++ b/lib/src/scalafmt/java/com/diffplug/spotless/glue/scalafmt/ScalafmtFormatterFunc.java @@ -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; @@ -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(); } diff --git a/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java b/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java index f5abef6614..53a186169f 100644 --- a/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java +++ b/lib/src/sortPom/java/com/diffplug/spotless/glue/pom/SortPomFormatterFunc.java @@ -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. @@ -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; @@ -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); diff --git a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java index 97278f9ffb..9c6d31c5a1 100644 --- a/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java @@ -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; @@ -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)); } } diff --git a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java index faa95c938c..d7128e1d54 100644 --- a/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot49Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot49Dot0AdapterTest.java @@ -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; @@ -59,7 +58,7 @@ private static String loadAndWriteText(Path path, String name) throws IOExceptio try (InputStream is = KtLintCompat0Dot49Dot0AdapterTest.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)); } } diff --git a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java index ccb5e931db..81698b44db 100644 --- a/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint0Dot50Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot50Dot0AdapterTest.java @@ -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; @@ -59,7 +58,7 @@ private static String loadAndWriteText(Path path, String name) throws IOExceptio try (InputStream is = KtLintCompat0Dot50Dot0AdapterTest.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)); } } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index 4792e278d0..6223fcc793 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -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; @@ -59,7 +58,7 @@ private static String loadAndWriteText(Path path, String name) throws IOExceptio try (InputStream is = KtLintCompat1Dot0Dot0AdapterTest.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)); } } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CssExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CssExtension.java index 2491faa04e..fa7af5a3b4 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CssExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/CssExtension.java @@ -43,6 +43,7 @@ protected void setupTask(SpotlessTask task) { * offline, you can specify the path to the Biome executable via * {@code biome().pathToExe(...)}. */ + @Override public BiomeCss biome() { return biome(null); } @@ -54,6 +55,7 @@ public BiomeCss biome() { * {@code biome().pathToExe(...)}. * @param version Biome version to use. */ + @Override public BiomeCss biome(String version) { var biomeConfig = new BiomeCss(version); addStep(biomeConfig.createStep()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java index 8ebdec2c06..cf9fa7cf83 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java @@ -748,7 +748,7 @@ protected void replaceStep() { replaceStep.accept(createStep()); } - abstract protected FormatterStep createStep(); + protected abstract FormatterStep createStep(); } diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/IdeHook.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/IdeHook.java index 8b7253fd8c..6fe6b52a80 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/IdeHook.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/IdeHook.java @@ -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. @@ -47,9 +47,9 @@ static class State extends NoLambda.EqualityBasedOnSerialization { } } - final static String PROPERTY = "spotlessIdeHook"; - final static String USE_STD_IN = "spotlessIdeHookUseStdIn"; - final static String USE_STD_OUT = "spotlessIdeHookUseStdOut"; + static final String PROPERTY = "spotlessIdeHook"; + static final String USE_STD_IN = "spotlessIdeHookUseStdIn"; + static final String USE_STD_OUT = "spotlessIdeHookUseStdOut"; private static void dumpIsClean() { System.err.println("IS CLEAN"); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java index 043fd8237a..894d18017c 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java @@ -58,7 +58,7 @@ public JavascriptEslintConfig eslint(Map devDependencies) { return eslint; } - public static abstract class EslintBaseConfig> + public abstract static class EslintBaseConfig> extends NpmStepConfig> { Map devDependencies = new LinkedHashMap<>(); @@ -100,6 +100,7 @@ public JavascriptEslintConfig(Map devDependencies) { super(getProject(), JavascriptExtension.this::replaceStep, devDependencies); } + @Override public FormatterStep createStep() { final Project project = getProject(); @@ -140,11 +141,13 @@ public PrettierConfig prettier(Map devDependencies) { * offline, you can specify the path to the Biome executable via * {@code biome().pathToExe(...)}. */ + @Override public BiomeJs biome() { return biome(null); } /** Downloads the given Biome version from the network. */ + @Override public BiomeJs biome(String version) { var biomeConfig = new BiomeJs(version); addStep(biomeConfig.createStep()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java index 9d3c111b59..8fc00c65af 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java @@ -63,11 +63,13 @@ public JacksonJsonGradleConfig jackson() { * offline, you can specify the path to the Biome executable via * {@code biome().pathToExe(...)}. */ + @Override public BiomeJson biome() { return biome(null); } /** Downloads the given Biome version from the network. */ + @Override public BiomeJson biome(String version) { var biomeConfig = new BiomeJson(version); addStep(biomeConfig.createStep()); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java index 450a205425..252e418a0b 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskImpl.java @@ -55,6 +55,7 @@ public abstract class SpotlessTaskImpl extends SpotlessTask { abstract Property getIdeHookState(); @Internal + @Override abstract DirectoryProperty getProjectDir(); void init(Provider service) { diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java index b58ff9005a..f1d78c57a9 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/SpotlessTaskService.java @@ -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. @@ -57,8 +57,7 @@ public abstract class SpotlessTaskService implements BuildService source = Collections.synchronizedMap(new HashMap<>()); private final Map provisioner = Collections.synchronizedMap(new HashMap<>()); - @Nullable - GradleProvisioner.DedupingProvisioner predeclaredProvisioner; + @Nullable GradleProvisioner.DedupingProvisioner predeclaredProvisioner; Provisioner provisionerFor(SpotlessExtension spotless) { if (spotless instanceof SpotlessExtensionPredeclare) { @@ -110,7 +109,7 @@ static void usesServiceTolerateTestFailure(DefaultTask task, Provider getSpotlessCleanDirectory(); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java index 1e7c9efc24..af9955aecb 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java @@ -112,6 +112,7 @@ private TypescriptFormatExtension configFile(TsConfigFileType filetype, Object p return this; } + @Override public FormatterStep createStep() { final Project project = getProject(); @@ -207,6 +208,7 @@ public TypescriptEslintConfig tsconfigFile(Object path) { return this; } + @Override public FormatterStep createStep() { final Project project = getProject(); @@ -228,11 +230,13 @@ protected EslintConfig eslintConfig() { * offline, you can specify the path to the Biome executable via * {@code biome().pathToExe(...)}. */ + @Override public BiomeTs biome() { return biome(null); } /** Downloads the given Biome version from the network. */ + @Override public BiomeTs biome(String version) { var biomeConfig = new BiomeTs(version); addStep(biomeConfig.createStep()); diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java index 480178eab2..9aca7333d4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/AbstractSpotlessMojo.java @@ -414,8 +414,7 @@ private List getFormatterFactories() { } private List getFormatterStepFactories() { - return Stream.of(licenseHeader) - .filter(Objects::nonNull) + return Stream.ofNullable(licenseHeader) .collect(toList()); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java index d0c8cb729a..35c8e6d421 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/ArtifactResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 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. @@ -41,7 +41,7 @@ public class ArtifactResolver { - private final static Exclusion EXCLUDE_ALL_TRANSITIVES = new Exclusion("*", "*", "*", "*"); + private static final Exclusion EXCLUDE_ALL_TRANSITIVES = new Exclusion("*", "*", "*", "*"); private final RepositorySystem repositorySystem; private final RepositorySystemSession session; diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java index 40dc84c8c6..c5c734a4d7 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/incremental/UpToDateChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 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. @@ -29,6 +29,7 @@ public interface UpToDateChecker extends AutoCloseable { void setUpToDate(Path file); + @Override void close(); static UpToDateChecker noop(MavenProject project, Path indexFile, Log log) { diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java index 5e795ac93f..e5185e8806 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java @@ -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. @@ -90,6 +90,7 @@ public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) { return eclipseConfig.build(); } + @Override public void init(RepositorySystemSession repositorySystemSession) { this.cacheDirectory = repositorySystemSession.getLocalRepository().getBasedir(); } diff --git a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java index 483d38ae1e..091d58fcc4 100644 --- a/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java +++ b/plugin-maven/src/main/java/com/diffplug/spotless/maven/javascript/EslintJs.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 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. @@ -23,10 +23,12 @@ public class EslintJs extends AbstractEslint { + @Override protected EslintConfig eslintConfig(FormatterStepConfig stepConfig) { return new EslintConfig(this.configFile != null ? stepConfig.getFileLocator().locateFile(this.configFile) : null, this.configJs); } + @Override protected Map createDefaultDependencies() { return this.eslintVersion == null ? EslintFormatterStep.defaultDevDependencies() : EslintFormatterStep.defaultDevDependenciesWithEslint(this.eslintVersion); } diff --git a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java index d81017aa36..5f6b33289b 100644 --- a/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java +++ b/testlib/src/main/java/com/diffplug/spotless/ResourceHarness.java @@ -111,7 +111,7 @@ public String read(String path) throws IOException { } public String read(Path path, Charset encoding) throws IOException { - return new String(Files.readAllBytes(path), encoding); + return Files.readString(path, encoding); } public void replace(String path, String toReplace, String replaceWith) throws IOException { @@ -214,7 +214,7 @@ public void notSameAsResource(String resource) throws IOException { } public void matches(Consumer> conditions) throws IOException { - String content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); + String content = Files.readString(file.toPath()); conditions.accept(assertThat(content)); } } diff --git a/testlib/src/test/java/com/diffplug/spotless/FileSignatureTest.java b/testlib/src/test/java/com/diffplug/spotless/FileSignatureTest.java index ab7c8c277b..88e4175046 100644 --- a/testlib/src/test/java/com/diffplug/spotless/FileSignatureTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/FileSignatureTest.java @@ -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. @@ -31,9 +31,9 @@ import org.junit.jupiter.api.condition.EnabledOnOs; class FileSignatureTest extends ResourceHarness { - private final static String[] inputPaths = {"A", "C", "C", "A", "B"}; - private final static String[] expectedPathList = inputPaths; - private final static String[] expectedPathSet = {"A", "B", "C"}; + private static final String[] inputPaths = {"A", "C", "C", "A", "B"}; + private static final String[] expectedPathList = inputPaths; + private static final String[] expectedPathSet = {"A", "B", "C"}; @Test void testFromList() throws IOException { diff --git a/testlib/src/test/java/com/diffplug/spotless/GitPrePushHookInstallerTest.java b/testlib/src/test/java/com/diffplug/spotless/GitPrePushHookInstallerTest.java index 3c391b9a9b..a5be4ea43c 100644 --- a/testlib/src/test/java/com/diffplug/spotless/GitPrePushHookInstallerTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/GitPrePushHookInstallerTest.java @@ -31,7 +31,7 @@ import com.diffplug.spotless.GitPrePushHookInstaller.GitPreHookLogger; class GitPrePushHookInstallerTest extends ResourceHarness { - private final static String OS = System.getProperty("os.name"); + private static final String OS = System.getProperty("os.name"); private final List logs = new CopyOnWriteArrayList<>(); private final GitPreHookLogger logger = new GitPreHookLogger() { diff --git a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java index 9633e31bab..a05de28411 100644 --- a/testlib/src/test/java/com/diffplug/spotless/JvmTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/JvmTest.java @@ -43,8 +43,8 @@ void initialize() { @Test void supportAdd() { Integer differentVersions[] = {0, 1, 2}; - Arrays.asList(differentVersions).stream().forEach(v -> testSupport.add(v + Jvm.version(), v.toString())); - Arrays.asList(differentVersions).stream().forEach(v -> assertThat(testSupport.toString()).contains("Version %d".formatted(v))); + Arrays.asList(differentVersions).forEach(v -> testSupport.add(v + Jvm.version(), v.toString())); + Arrays.asList(differentVersions).forEach(v -> assertThat(testSupport.toString()).contains("Version %d".formatted(v))); assertThat(testSupport.toString()).contains("%s alternatives".formatted(TEST_NAME)); }