Skip to content

Commit bf0d73a

Browse files
committed
Make BufStep serializable.
1 parent 0fe5d42 commit bf0d73a

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,32 @@ public BufStep withPathToExe(String pathToExe) {
5959
}
6060

6161
public FormatterStep create() {
62-
return FormatterStep.createLazy(name(), this::createState, State::toFunc);
62+
return FormatterStep.createLazy(name(), this::createRoundtrip, RoundtripState::state, State::toFunc);
6363
}
6464

65-
private State createState() {
65+
private RoundtripState createRoundtrip() {
6666
String instructions = "https://docs.buf.build/installation";
6767
ForeignExe exeAbsPath = ForeignExe.nameAndVersion("buf", version)
6868
.pathToExe(pathToExe)
6969
.versionRegex(Pattern.compile("(\\S*)"))
7070
.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);
71+
return new RoundtripState(version, exeAbsPath);
72+
}
73+
74+
private static class RoundtripState implements Serializable {
75+
private static final long serialVersionUID = 1L;
76+
77+
final String version;
78+
final ForeignExe exe;
79+
80+
RoundtripState(String version, ForeignExe exe) {
81+
this.version = version;
82+
this.exe = exe;
83+
}
84+
85+
private State state() {
86+
return new State(version, exe);
87+
}
7288
}
7389

7490
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
@@ -80,8 +96,8 @@ static class State implements Serializable {
8096
// used for executing
8197
private transient @Nullable List<String> args;
8298

83-
State(BufStep step, ForeignExe exeAbsPath) {
84-
this.version = step.version;
99+
State(String version, ForeignExe exeAbsPath) {
100+
this.version = version;
85101
this.exe = Objects.requireNonNull(exeAbsPath);
86102
}
87103

testlib/src/main/java/com/diffplug/spotless/StepHarnessBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ protected StepHarnessBase(Formatter formatter) {
4848
supportsRoundTrip = true;
4949
} else if (onlyStepName.equals("fence")) {
5050
supportsRoundTrip = true;
51+
} else if (onlyStepName.equals("buf")) {
52+
supportsRoundTrip = true;
5153
}
5254
}
5355
}

0 commit comments

Comments
 (0)