From 5bcabf854fdf790ea09755e6420feb1b75f4e6f1 Mon Sep 17 00:00:00 2001 From: Vincent Potucek Date: Mon, 20 Oct 2025 13:20:08 +0200 Subject: [PATCH] [prone] Apply `UseTextBlocks` --- .../diffplug/spotless/generic/IdeaStep.java | 10 ++++++---- .../diffplug/spotless/go/GofmtFormatStep.java | 6 ++++-- .../spotless/rdf/ReflectionHelper.java | 5 +++-- .../gradle/spotless/GradleProvisioner.java | 5 +++-- .../TargetExcludeIfContentContainsTest.java | 5 ++++- .../maven/MavenIntegrationHarness.java | 15 +++++++-------- rewrite.yml | 18 ++---------------- 7 files changed, 29 insertions(+), 35 deletions(-) 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 5766e93b05..ebc48211e1 100644 --- a/lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java +++ b/lib/src/main/java/com/diffplug/spotless/generic/IdeaStep.java @@ -158,10 +158,12 @@ private static String resolveFullBinaryPathAndCheckVersion(String binaryPath) { .pathToExe(pathToExe(binaryPath)) .versionRegex(Pattern.compile("(IntelliJ IDEA) .*")) .fixCantFind( - "IDEA executable cannot be found on your machine, " - + "please install it and put idea binary to PATH, provide a valid path to the executable or report the problem") - .fixWrongVersion("Provided binary is not IDEA, " - + "please check it and fix the problem; or report the problem"); + """ + IDEA executable cannot be found on your machine, \ + please install it and put idea binary to PATH, provide a valid path to the executable or report the problem""") + .fixWrongVersion(""" + Provided binary is not IDEA, \ + please check it and fix the problem; or report the problem"""); try { return exe.confirmVersionAndGetAbsolutePath(); } catch (IOException e) { diff --git a/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java b/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java index a4354e89d2..55e5d79061 100644 --- a/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java +++ b/lib/src/main/java/com/diffplug/spotless/go/GofmtFormatStep.java @@ -67,8 +67,10 @@ public FormatterStep create() { } private RoundtripState createRountrip() throws IOException, InterruptedException { - String howToInstall = "gofmt is a part of standard go distribution. If spotless can't discover it automatically, " - + "you can point Spotless to the go binary with {@code pathToExe('/path/to/go')}"; + String howToInstall = """ + gofmt is a part of standard go distribution. If spotless can't discover it automatically, \ + you can point Spotless to the go binary with {@code pathToExe('/path/to/go')}\ + """; final ForeignExe exe = ForeignExe.nameAndVersion("go", version) .pathToExe(pathToExe) .versionFlag("version") diff --git a/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java b/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java index 51f2aff90d..871419f873 100644 --- a/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java +++ b/lib/src/main/java/com/diffplug/spotless/rdf/ReflectionHelper.java @@ -205,8 +205,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl logger.warn("{}({},{}): {}", this.filePath, line, col, message); } else { if ("warning".equals(severity)) { - logger.error("Formatter fails because of a parser warning. To make the formatter succeed in" - + "the presence of warnings, set the configuration parameter 'failOnWarning' to 'false' (default: 'true')"); + logger.error(""" + Formatter fails because of a parser warning. To make the formatter succeed in\ + the presence of warnings, set the configuration parameter 'failOnWarning' to 'false' (default: 'true')"""); } throw new RuntimeException( "line %d, col %d: %s (severity: %s)".formatted(line, col, message, severity)); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index d6b6369bf8..e6facb61d8 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -135,8 +135,9 @@ private static Provisioner forConfigurationContainer(Project project, Configurat projName = projName + "/"; } throw new GradleException(String.format( - "You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.%n" - + "E.g.: 'repositories { mavenCentral() }'", + """ + You need to add a repository containing the '%s' artifact in '%sbuild.gradle'.%n\ + E.g.: 'repositories { mavenCentral() }'""", mavenCoords, projName), e); } }; diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java index 5acfa305be..d2737b6d61 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/TargetExcludeIfContentContainsTest.java @@ -60,7 +60,10 @@ void targetExcludeIfContentContainsWithMultipleSteps() throws IOException { " target '**/*.md'", " targetExcludeIfContentContains '// Generated by Mr. Roboto'", " custom 'lowercase', { str -> str.toLowerCase() }", - " licenseHeader('" + "// My CopyRights header" + "', '--')", + """ + licenseHeader('\ + // My CopyRights header\ + ', '--')""", " }", "}"); String generatedContent = """ diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java index 5e3eb0f46b..6443de6510 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/MavenIntegrationHarness.java @@ -93,14 +93,13 @@ void gitAttributes() throws IOException { if (Jvm.version() >= 16) { // for GJF https://github.com/diffplug/spotless/issues/834 setFile(".mvn/jvm.config").toContent( - "--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED" - + " --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED" - + " --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED" - + " --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED" - + " --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED" - // this last line is for Detekt - + // this last line is for Detekt - " --add-opens java.base/java.lang=ALL-UNNAMED"); + """ + --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED\ + --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED\ + --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED\ + --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED\ + --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED\ + --add-opens java.base/java.lang=ALL-UNNAMED"""); } // copy the mvnw resources copy("mvnw").setExecutable(true); diff --git a/rewrite.yml b/rewrite.yml index a7f4e4654d..1777cc1c4a 100644 --- a/rewrite.yml +++ b/rewrite.yml @@ -17,6 +17,7 @@ recipeList: - org.openrewrite.java.format.NormalizeLineBreaks - org.openrewrite.java.format.RemoveTrailingWhitespace - org.openrewrite.java.migrate.UpgradeToJava17 + - org.openrewrite.java.migrate.lang.UseTextBlocks - org.openrewrite.java.migrate.util.JavaUtilAPIs - org.openrewrite.java.migrate.util.MigrateInflaterDeflaterToClose - org.openrewrite.java.migrate.util.ReplaceStreamCollectWithToList @@ -68,22 +69,7 @@ styleConfigs: - org.openrewrite.java.style.ImportLayoutStyle: classCountToUseStarImport: 999 nameCountToUseStarImport: 999 - # bug https://github.com/openrewrite/rewrite/issues/6107 - # layout: - # - import java.* - # - - # - import javax.* - # - - # - import org.* - # - - # - import com.* - # - - # - import com.diffplug.* - # - - # - import static all other imports - # - - # - import all other imports - # - + # no layout needed, we use spotless - org.openrewrite.java.style.TabsAndIndentsStyle: useTabCharacter: true tabSize: 4