Skip to content

Commit 50429a8

Browse files
committed
Fix round-tripping of NativeCmdStep.
1 parent cffb2f4 commit 50429a8

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

lib/src/main/java/com/diffplug/spotless/generic/NativeCmdStep.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 DiffPlug
2+
* Copyright 2021-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.
@@ -35,24 +35,37 @@ private NativeCmdStep() {}
3535
public static FormatterStep create(String name, File pathToExe, List<String> arguments) {
3636
Objects.requireNonNull(name, "name");
3737
Objects.requireNonNull(pathToExe, "pathToExe");
38-
return FormatterStep.createLazy(name, () -> new State(FileSignature.signAsList(pathToExe), arguments), State::toFunc);
38+
return FormatterStep.createLazy(name, () -> new State(FileSignature.promise(pathToExe), arguments), State::toRuntime, Runtime::toFunc);
3939
}
4040

4141
static class State implements Serializable {
42-
private static final long serialVersionUID = 1L;
42+
private static final long serialVersionUID = 2L;
43+
final FileSignature.Promised pathToExe;
44+
final List<String> arguments;
4345

44-
final FileSignature pathToExe;
46+
State(FileSignature.Promised pathToExe, List<String> arguments) {
47+
this.pathToExe = pathToExe;
48+
this.arguments = arguments;
49+
}
50+
51+
Runtime toRuntime() {
52+
return new Runtime(pathToExe.get().getOnlyFile(), arguments);
53+
}
54+
}
4555

56+
static class Runtime implements Serializable {
57+
private static final long serialVersionUID = 2L;
58+
final File pathToExe;
4659
final List<String> arguments;
4760

48-
State(FileSignature pathToExe, List<String> arguments) {
61+
Runtime(File pathToExe, List<String> arguments) {
4962
this.pathToExe = pathToExe;
5063
this.arguments = arguments;
5164
}
5265

5366
String format(ProcessRunner runner, String input) throws IOException, InterruptedException {
5467
List<String> argumentsWithPathToExe = new ArrayList<>();
55-
argumentsWithPathToExe.add(pathToExe.getOnlyFile().getAbsolutePath());
68+
argumentsWithPathToExe.add(pathToExe.getAbsolutePath());
5669
if (arguments != null) {
5770
argumentsWithPathToExe.addAll(arguments);
5871
}

0 commit comments

Comments
 (0)