Skip to content

Commit 54c6333

Browse files
authored
Fix configuration cache issue with BufStep (#1779)
2 parents b99ec3d + 19f68d6 commit 54c6333

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Diff for: lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java

+15-11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.nio.charset.StandardCharsets;
2222
import java.util.Arrays;
2323
import java.util.List;
24+
import java.util.Objects;
2425
import java.util.regex.Pattern;
2526

2627
import javax.annotation.Nullable;
@@ -61,13 +62,12 @@ public FormatterStep create() {
6162
return FormatterStep.createLazy(name(), this::createState, State::toFunc);
6263
}
6364

64-
private State createState() throws IOException, InterruptedException {
65+
private State createState() {
6566
String instructions = "https://docs.buf.build/installation";
66-
String exeAbsPath = ForeignExe.nameAndVersion("buf", version)
67+
ForeignExe exeAbsPath = ForeignExe.nameAndVersion("buf", version)
6768
.pathToExe(pathToExe)
6869
.versionRegex(Pattern.compile("(\\S*)"))
69-
.fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}")
70-
.confirmVersionAndGetAbsolutePath();
70+
.fixCantFind("Try following the instructions at " + instructions + ", or else tell Spotless where it is with {@code buf().pathToExe('path/to/executable')}");
7171
return new State(this, exeAbsPath);
7272
}
7373

@@ -76,19 +76,23 @@ static class State implements Serializable {
7676
private static final long serialVersionUID = -1825662356883926318L;
7777
// used for up-to-date checks and caching
7878
final String version;
79+
final transient ForeignExe exe;
7980
// used for executing
80-
final transient List<String> args;
81+
private transient @Nullable List<String> args;
8182

82-
State(BufStep step, String exeAbsPath) {
83+
State(BufStep step, ForeignExe exeAbsPath) {
8384
this.version = step.version;
84-
this.args = Arrays.asList(exeAbsPath, "format");
85+
this.exe = Objects.requireNonNull(exeAbsPath);
8586
}
8687

8788
String format(ProcessRunner runner, String input, File file) throws IOException, InterruptedException {
88-
String[] processArgs = args.toArray(new String[args.size() + 1]);
89-
// add an argument to the end
90-
processArgs[args.size()] = file.getAbsolutePath();
91-
return runner.exec(input.getBytes(StandardCharsets.UTF_8), processArgs).assertExitZero(StandardCharsets.UTF_8);
89+
if (args == null) {
90+
args = Arrays.asList(
91+
exe.confirmVersionAndGetAbsolutePath(),
92+
"format",
93+
file.getAbsolutePath());
94+
}
95+
return runner.exec(input.getBytes(StandardCharsets.UTF_8), args).assertExitZero(StandardCharsets.UTF_8);
9296
}
9397

9498
FormatterFunc.Closeable toFunc() {

Diff for: plugin-gradle/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
99
* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
1010
* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
1111
* Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644))
12+
* Fix configuration cache failure when formatting proto files with Buf. ([#1779]https://github.com/diffplug/spotless/pull/1779))
1213
### Changes
1314
* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
1415
* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))

0 commit comments

Comments
 (0)