Skip to content

Commit fec005d

Browse files
committed
Make GherkinUtilsStep round-trippable
1 parent 3261a13 commit fec005d

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

lib/src/main/java/com/diffplug/spotless/gherkin/GherkinUtilsStep.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 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.
@@ -15,7 +15,6 @@
1515
*/
1616
package com.diffplug.spotless.gherkin;
1717

18-
import java.io.IOException;
1918
import java.io.Serializable;
2019
import java.lang.reflect.Constructor;
2120
import java.lang.reflect.InvocationTargetException;
@@ -25,10 +24,21 @@
2524
import com.diffplug.spotless.FormatterStep;
2625
import com.diffplug.spotless.JarState;
2726
import com.diffplug.spotless.Provisioner;
27+
import com.diffplug.spotless.RoundedStep;
2828

29-
public class GherkinUtilsStep {
29+
public class GherkinUtilsStep implements RoundedStep {
30+
private static final long serialVersionUID = 1L;
3031
private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-utils:";
3132
private static final String DEFAULT_VERSION = "8.0.2";
33+
public static final String NAME = "gherkinUtils";
34+
35+
private final JarState.Promised jarState;
36+
private final GherkinUtilsConfig gherkinSimpleConfig;
37+
38+
private GherkinUtilsStep(JarState.Promised jarState, GherkinUtilsConfig gherkinSimpleConfig) {
39+
this.jarState = jarState;
40+
this.gherkinSimpleConfig = gherkinSimpleConfig;
41+
}
3242

3343
public static String defaultVersion() {
3444
return DEFAULT_VERSION;
@@ -37,7 +47,14 @@ public static String defaultVersion() {
3747
public static FormatterStep create(GherkinUtilsConfig gherkinSimpleConfig,
3848
String formatterVersion, Provisioner provisioner) {
3949
Objects.requireNonNull(provisioner, "provisioner cannot be null");
40-
return FormatterStep.createLazy("gherkin", () -> new GherkinUtilsStep.State(gherkinSimpleConfig, formatterVersion, provisioner), GherkinUtilsStep.State::toFormatter);
50+
return FormatterStep.create(NAME,
51+
new GherkinUtilsStep(JarState.promise(() -> JarState.from(MAVEN_COORDINATE + formatterVersion, provisioner)), gherkinSimpleConfig),
52+
GherkinUtilsStep::equalityState,
53+
GherkinUtilsStep.State::toFormatter);
54+
}
55+
56+
private State equalityState() {
57+
return new State(jarState.get(), gherkinSimpleConfig);
4158
}
4259

4360
private static final class State implements Serializable {
@@ -46,9 +63,9 @@ private static final class State implements Serializable {
4663
private final GherkinUtilsConfig gherkinSimpleConfig;
4764
private final JarState jarState;
4865

49-
private State(GherkinUtilsConfig gherkinSimpleConfig, String formatterVersion, Provisioner provisioner) throws IOException {
66+
State(JarState jarState, GherkinUtilsConfig gherkinSimpleConfig) {
67+
this.jarState = jarState;
5068
this.gherkinSimpleConfig = gherkinSimpleConfig;
51-
this.jarState = JarState.from(MAVEN_COORDINATE + formatterVersion, provisioner);
5269
}
5370

5471
FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
@@ -58,8 +75,4 @@ FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException
5875
return (FormatterFunc) constructor.newInstance(gherkinSimpleConfig);
5976
}
6077
}
61-
62-
private GherkinUtilsStep() {
63-
// cannot be directly instantiated
64-
}
6578
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected StepHarnessBase(Formatter formatter) {
5151
supportsRoundTrip = true;
5252
} else if (Set.of("black", "buf", "clang", "ktlint", "ktfmt", "scalafmt", "palantir-java-format", "google-java-format",
5353
"removeUnusedImports", "cleanthat", "No line break between type annotation and type",
54-
"gson", "jacksonJson", "apply-json-patch", "jsonSimple", "sortPom", "jacksonYaml",
54+
"gson", "jacksonJson", "apply-json-patch", "jsonSimple", "sortPom", "jacksonYaml", "gherkinUtils",
5555
"importOrder", "Remove unnecessary semicolons").contains(onlyStepName)) {
5656
supportsRoundTrip = true;
5757
}

0 commit comments

Comments
 (0)