Skip to content

Commit a3ef63b

Browse files
authored
Don't reuse BufStep args across invocations (#1976)
2 parents c917f3e + d055d4f commit a3ef63b

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1212
## [Unreleased]
1313
### Added
1414
* New static method to `DiffMessageFormatter` which allows to retrieve diffs with their line numbers ([#1960](https://github.com/diffplug/spotless/issues/1960))
15+
### Fixed
16+
* Fix a regression in BufStep where the same arguments were being provided to every `buf` invocation. ([#1976](https://github.com/diffplug/spotless/issues/1976))
1517
### Changes
1618
* Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948))
1719
* Bump default `ktlint` version to latest `1.0.1` -> `1.1.1`. ([#1973](https://github.com/diffplug/spotless/pull/1973))

lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022-2023 DiffPlug
2+
* Copyright 2022-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import java.io.IOException;
2020
import java.io.Serializable;
2121
import java.nio.charset.StandardCharsets;
22-
import java.util.Arrays;
2322
import java.util.List;
2423
import java.util.Objects;
2524
import java.util.regex.Pattern;
@@ -64,34 +63,33 @@ public FormatterStep create() {
6463

6564
private State createState() {
6665
String instructions = "https://docs.buf.build/installation";
67-
ForeignExe exeAbsPath = ForeignExe.nameAndVersion("buf", version)
66+
ForeignExe exe = ForeignExe.nameAndVersion("buf", version)
6867
.pathToExe(pathToExe)
6968
.versionRegex(Pattern.compile("(\\S*)"))
7069
.fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}");
71-
return new State(this, exeAbsPath);
70+
return new State(this, exe);
7271
}
7372

7473
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
7574
static class State implements Serializable {
7675
private static final long serialVersionUID = -1825662356883926318L;
7776
// used for up-to-date checks and caching
7877
final String version;
79-
final transient ForeignExe exe;
78+
8079
// used for executing
81-
private transient @Nullable List<String> args;
80+
private final transient ForeignExe exe;
81+
private transient String exeAbsPath;
8282

83-
State(BufStep step, ForeignExe exeAbsPath) {
83+
State(BufStep step, ForeignExe exe) {
8484
this.version = step.version;
85-
this.exe = Objects.requireNonNull(exeAbsPath);
85+
this.exe = Objects.requireNonNull(exe);
8686
}
8787

8888
String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException {
89-
if (args == null) {
90-
args = Arrays.asList(
91-
exe.confirmVersionAndGetAbsolutePath(),
92-
"format",
93-
file.getAbsolutePath());
89+
if (exeAbsPath == null) {
90+
exeAbsPath = exe.confirmVersionAndGetAbsolutePath();
9491
}
92+
List<String> args = List.of(exeAbsPath, "format", file.getAbsolutePath());
9593
return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8);
9694
}
9795

plugin-gradle/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Fixed
7+
* Fix a regression in BufStep where the same arguments were being provided to every `buf` invocation. ([#1976](https://github.com/diffplug/spotless/issues/1976))
68
### Changes
79
* Use palantir-java-format 2.39.0 on Java 21. ([#1948](https://github.com/diffplug/spotless/pull/1948))
810
* Bump default `ktlint` version to latest `1.0.1` -> `1.1.1`. ([#1973](https://github.com/diffplug/spotless/pull/1973))

0 commit comments

Comments
 (0)