1
1
/*
2
- * Copyright 2021-2023 DiffPlug
2
+ * Copyright 2021-2024 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package com .diffplug .spotless .gherkin ;
17
17
18
- import java .io .IOException ;
19
18
import java .io .Serializable ;
20
19
import java .lang .reflect .Constructor ;
21
20
import java .lang .reflect .InvocationTargetException ;
25
24
import com .diffplug .spotless .FormatterStep ;
26
25
import com .diffplug .spotless .JarState ;
27
26
import com .diffplug .spotless .Provisioner ;
27
+ import com .diffplug .spotless .RoundedStep ;
28
28
29
- public class GherkinUtilsStep {
29
+ public class GherkinUtilsStep implements RoundedStep {
30
+ private static final long serialVersionUID = 1L ;
30
31
private static final String MAVEN_COORDINATE = "io.cucumber:gherkin-utils:" ;
31
32
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
+ }
32
42
33
43
public static String defaultVersion () {
34
44
return DEFAULT_VERSION ;
@@ -37,7 +47,14 @@ public static String defaultVersion() {
37
47
public static FormatterStep create (GherkinUtilsConfig gherkinSimpleConfig ,
38
48
String formatterVersion , Provisioner provisioner ) {
39
49
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 );
41
58
}
42
59
43
60
private static final class State implements Serializable {
@@ -46,9 +63,9 @@ private static final class State implements Serializable {
46
63
private final GherkinUtilsConfig gherkinSimpleConfig ;
47
64
private final JarState jarState ;
48
65
49
- private State (GherkinUtilsConfig gherkinSimpleConfig , String formatterVersion , Provisioner provisioner ) throws IOException {
66
+ State (JarState jarState , GherkinUtilsConfig gherkinSimpleConfig ) {
67
+ this .jarState = jarState ;
50
68
this .gherkinSimpleConfig = gherkinSimpleConfig ;
51
- this .jarState = JarState .from (MAVEN_COORDINATE + formatterVersion , provisioner );
52
69
}
53
70
54
71
FormatterFunc toFormatter () throws ClassNotFoundException , NoSuchMethodException , InvocationTargetException ,
@@ -58,8 +75,4 @@ FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException
58
75
return (FormatterFunc ) constructor .newInstance (gherkinSimpleConfig );
59
76
}
60
77
}
61
-
62
- private GherkinUtilsStep () {
63
- // cannot be directly instantiated
64
- }
65
78
}
0 commit comments