From 0e6b460c090e7d58ce05648388f9840c05dc5667 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Sun, 24 Dec 2023 11:07:08 -0500 Subject: [PATCH 1/6] don't reuse buf step args between calls --- .../diffplug/spotless/protobuf/BufStep.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java index a5a6a6cdef..88a87ffd99 100644 --- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java @@ -64,11 +64,11 @@ public FormatterStep create() { private State createState() { String instructions = "https://docs.buf.build/installation"; - ForeignExe exeAbsPath = ForeignExe.nameAndVersion("buf", version) + ForeignExe exe = ForeignExe.nameAndVersion("buf", version) .pathToExe(pathToExe) .versionRegex(Pattern.compile("(\\S*)")) .fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}"); - return new State(this, exeAbsPath); + return new State(this, exe); } @SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") @@ -77,22 +77,21 @@ static class State implements Serializable { // used for up-to-date checks and caching final String version; final transient ForeignExe exe; - // used for executing - private transient @Nullable List args; - State(BufStep step, ForeignExe exeAbsPath) { + State(BufStep step, ForeignExe exe) { this.version = step.version; - this.exe = Objects.requireNonNull(exeAbsPath); + this.exe = Objects.requireNonNull(exe); } String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { - if (args == null) { - args = Arrays.asList( - exe.confirmVersionAndGetAbsolutePath(), - "format", - file.getAbsolutePath()); - } - return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8); + return runner.exec( + input.getBytes(StandardCharsets.UTF_8), + List.of( + exe.confirmVersionAndGetAbsolutePath(), + "format", + file.getAbsolutePath() + ) + ).assertExitZero(StandardCharsets.UTF_8); } FormatterFunc.Closeable toFunc() { From cb36c8bd9d0a49dc2e8ebd68adf81c73968490e7 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Sun, 24 Dec 2023 11:11:22 -0500 Subject: [PATCH 2/6] run spotless --- .../com/diffplug/spotless/protobuf/BufStep.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java index 88a87ffd99..7e0d44ba0c 100644 --- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java @@ -19,7 +19,6 @@ import java.io.IOException; import java.io.Serializable; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.regex.Pattern; @@ -78,20 +77,14 @@ static class State implements Serializable { final String version; final transient ForeignExe exe; - State(BufStep step, ForeignExe exe) { + State(BufStep step, ForeignExe exe) { this.version = step.version; this.exe = Objects.requireNonNull(exe); } String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { - return runner.exec( - input.getBytes(StandardCharsets.UTF_8), - List.of( - exe.confirmVersionAndGetAbsolutePath(), - "format", - file.getAbsolutePath() - ) - ).assertExitZero(StandardCharsets.UTF_8); + List args = List.of(exe.confirmVersionAndGetAbsolutePath(), "format", file.getAbsolutePath()); + return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8); } FormatterFunc.Closeable toFunc() { From 5dc52d721a71a1f49a82306c3b423f331862d677 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Sun, 24 Dec 2023 11:15:53 -0500 Subject: [PATCH 3/6] changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index dc040c9aa2..60069ebb25 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added * New static method to `DiffMessageFormatter` which allows to retrieve diffs with their line numbers ([#1960](https://github.com/diffplug/spotless/issues/1960)) +### Fixed +* Fix a regression in BufStep where the same arguments were being provided to every `buf` invocation. ([#1976](https://github.com/diffplug/spotless/issues/1976)) ### Changes * Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948)) From 1a9bea7c90d9122d95e34c5cc01c10aab4780933 Mon Sep 17 00:00:00 2001 From: Andrew Parmet Date: Sun, 24 Dec 2023 11:37:35 -0500 Subject: [PATCH 4/6] only confirm version once --- .../java/com/diffplug/spotless/protobuf/BufStep.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java index 7e0d44ba0c..e7b39747b9 100644 --- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java @@ -75,7 +75,10 @@ static class State implements Serializable { private static final long serialVersionUID = -1825662356883926318L; // used for up-to-date checks and caching final String version; - final transient ForeignExe exe; + + // used for executing + private final transient ForeignExe exe; + private transient String exeAbsPath; State(BufStep step, ForeignExe exe) { this.version = step.version; @@ -83,7 +86,10 @@ static class State implements Serializable { } String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException { - List args = List.of(exe.confirmVersionAndGetAbsolutePath(), "format", file.getAbsolutePath()); + if (exeAbsPath == null) { + exeAbsPath = exe.confirmVersionAndGetAbsolutePath(); + } + List args = List.of(exeAbsPath, "format", file.getAbsolutePath()); return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8); } From 48ef7caf3ce88137d4360668a8e5a9d3fa5fd80c Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 14 Jan 2024 15:38:57 -0800 Subject: [PATCH 5/6] Update changelog. --- plugin-gradle/CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 1369889ad5..267927fe0f 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +* Fix a regression in BufStep where the same arguments were being provided to every `buf` invocation. ([#1976](https://github.com/diffplug/spotless/issues/1976)) ### Changes * Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948)) * Bump default `ktlint` version to latest `1.0.1` -> `1.1.1`. ([#1973](https://github.com/diffplug/spotless/pull/1973)) From d055d4f8a7ec561fa7636a28d6d1b5342f088ce9 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Sun, 14 Jan 2024 15:48:34 -0800 Subject: [PATCH 6/6] spotlessApply --- lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java index e7b39747b9..ac39eac935 100644 --- a/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java +++ b/lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 DiffPlug + * Copyright 2022-2024 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.