Skip to content

Fix configuration cache issue with BufStep #1779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/src/main/java/com/diffplug/spotless/protobuf/BufStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;

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

private State createState() throws IOException, InterruptedException {
private State createState() {
String instructions = "https://docs.buf.build/installation";
String exeAbsPath = ForeignExe.nameAndVersion("buf", version)
ForeignExe exeAbsPath = 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')}")
.confirmVersionAndGetAbsolutePath();
.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);
}

Expand All @@ -76,19 +76,23 @@ 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
final transient List<String> args;
private transient @Nullable List<String> args;

State(BufStep step, String exeAbsPath) {
State(BufStep step, ForeignExe exeAbsPath) {
this.version = step.version;
this.args = Arrays.asList(exeAbsPath, "format");
this.exe = Objects.requireNonNull(exeAbsPath);
}

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

FormatterFunc.Closeable toFunc() {
Expand Down
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
* 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))
* 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))
* Fix configuration cache failure when using LineEnding.GIT_ATTRIBUTES ([#1644](https://github.com/diffplug/spotless/issues/1644))
* Fix configuration cache failure when formatting proto files with Buf. ([#1779]https://github.com/diffplug/spotless/pull/1779))
### Changes
* Bump default `eslint` version to latest `8.31.0` -> `8.45.0` ([#1761](https://github.com/diffplug/spotless/pull/1761))
* Bump default `prettier` version to latest (v2) `2.8.1` -> `2.8.8`. ([#1760](https://github.com/diffplug/spotless/pull/1760))
Expand Down