Skip to content

Commit d280cb6

Browse files
committed
Make BlackStep serializable.
1 parent 15960a8 commit d280cb6

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/src/main/java/com/diffplug/spotless/python/BlackStep.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022 DiffPlug
2+
* Copyright 2020-2023 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.
@@ -56,17 +56,33 @@ public BlackStep withPathToExe(String pathToExe) {
5656
}
5757

5858
public FormatterStep create() {
59-
return FormatterStep.createLazy(name(), this::createState, State::toFunc);
59+
return FormatterStep.createLazy(name(), this::createState, RoundtripState::state, State::toFunc);
6060
}
6161

62-
private State createState() throws IOException, InterruptedException {
62+
private RoundtripState createState() {
6363
String trackingIssue = "\n github issue to handle this better: https://github.com/diffplug/spotless/issues/674";
6464
ForeignExe exeAbsPath = ForeignExe.nameAndVersion("black", version)
6565
.pathToExe(pathToExe)
6666
.versionRegex(Pattern.compile("(?:black, version|black,|version) (\\S*)"))
6767
.fixCantFind("Try running {@code pip install black=={version}}, or else tell Spotless where it is with {@code black().pathToExe('path/to/executable')}" + trackingIssue)
6868
.fixWrongVersion("Try running {@code pip install --force-reinstall black=={version}}, or else specify {@code black('{versionFound}')} to Spotless" + trackingIssue);
69-
return new State(this, exeAbsPath);
69+
return new RoundtripState(version, exeAbsPath);
70+
}
71+
72+
static class RoundtripState implements Serializable {
73+
private static final long serialVersionUID = 1L;
74+
75+
final String version;
76+
final ForeignExe exe;
77+
78+
RoundtripState(String version, ForeignExe exe) {
79+
this.version = version;
80+
this.exe = exe;
81+
}
82+
83+
private State state() {
84+
return new State(version, exe);
85+
}
7086
}
7187

7288
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED")
@@ -78,8 +94,8 @@ static class State implements Serializable {
7894
// used for executing
7995
private transient @Nullable String[] args;
8096

81-
State(BlackStep step, ForeignExe exeAbsPath) {
82-
this.version = step.version;
97+
State(String version, ForeignExe exeAbsPath) {
98+
this.version = version;
8399
this.exe = Objects.requireNonNull(exeAbsPath);
84100
}
85101

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected StepHarnessBase(Formatter formatter) {
4949
supportsRoundTrip = true;
5050
} else if (onlyStepName.equals("fence")) {
5151
supportsRoundTrip = true;
52-
} else if (Set.of("buf", "clang").contains(onlyStepName)) {
52+
} else if (Set.of("black", "buf", "clang").contains(onlyStepName)) {
5353
supportsRoundTrip = true;
5454
}
5555
}

0 commit comments

Comments
 (0)