|
25 | 25 | import com.diffplug.spotless.*;
|
26 | 26 |
|
27 | 27 | /** Wraps up <a href="https://github.com/cqfn/diKTat">diktat</a> as a FormatterStep. */
|
28 |
| -public class DiktatStep { |
29 |
| - |
30 |
| - // prevent direct instantiation |
31 |
| - private DiktatStep() {} |
| 28 | +public class DiktatStep extends FormatterStepEqualityOnStateSerialization<DiktatStep.State> { |
| 29 | + private final JarState.Promised jarState; |
| 30 | + private final boolean isScript; |
| 31 | + private final @Nullable FileSignature.RoundTrippable config; |
| 32 | + |
| 33 | + private DiktatStep(JarState.Promised jarState, boolean isScript, @Nullable FileSignature config) { |
| 34 | + this.jarState = jarState; |
| 35 | + this.isScript = isScript; |
| 36 | + this.config = FileSignature.roundTrippableNullable(config); |
| 37 | + } |
32 | 38 |
|
33 | 39 | private static final String MIN_SUPPORTED_VERSION = "1.2.1";
|
34 | 40 |
|
@@ -59,26 +65,35 @@ public static FormatterStep create(String versionDiktat, Provisioner provisioner
|
59 | 65 | }
|
60 | 66 | Objects.requireNonNull(versionDiktat, "versionDiktat");
|
61 | 67 | Objects.requireNonNull(provisioner, "provisioner");
|
62 |
| - return FormatterStep.createLazy(NAME, |
63 |
| - () -> new DiktatStep.State(versionDiktat, provisioner, isScript, config), |
64 |
| - DiktatStep.State::createFormat); |
| 68 | + return new DiktatStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + versionDiktat, provisioner)), isScript, config); |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public String getName() { |
| 73 | + return NAME; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + protected State stateSupplier() throws Exception { |
| 78 | + return new State(jarState.get(), isScript, FileSignature.stripAbsolutePathsNullable(config)); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + protected FormatterFunc stateToFormatter(State state) throws Exception { |
| 83 | + return state.createFormat(); |
65 | 84 | }
|
66 | 85 |
|
67 | 86 | static final class State implements Serializable {
|
68 | 87 |
|
69 | 88 | private static final long serialVersionUID = 1L;
|
70 | 89 |
|
| 90 | + final JarState jar; |
71 | 91 | /** Are the files being linted Kotlin script files. */
|
72 | 92 | private final boolean isScript;
|
73 | 93 | private final @Nullable FileSignature config;
|
74 |
| - final JarState jar; |
75 |
| - |
76 |
| - State(String versionDiktat, Provisioner provisioner, boolean isScript, @Nullable FileSignature config) throws IOException { |
77 |
| - |
78 |
| - HashSet<String> pkgSet = new HashSet<>(); |
79 |
| - pkgSet.add(MAVEN_COORDINATE + versionDiktat); |
80 | 94 |
|
81 |
| - this.jar = JarState.from(pkgSet, provisioner); |
| 95 | + State(JarState jar, boolean isScript, @Nullable FileSignature config) throws IOException { |
| 96 | + this.jar = jar; |
82 | 97 | this.isScript = isScript;
|
83 | 98 | this.config = config;
|
84 | 99 | }
|
|
0 commit comments