1
1
/*
2
- * Copyright 2022-2023 DiffPlug
2
+ * Copyright 2022-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 .json .gson ;
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 GsonStep {
29
+ public class GsonStep implements RoundedStep {
30
+ private static final long serialVersionUID = 1L ;
30
31
private static final String MAVEN_COORDINATES = "com.google.code.gson:gson" ;
31
32
private static final String INCOMPATIBLE_ERROR_MESSAGE = "There was a problem interacting with Gson; maybe you set an incompatible version?" ;
33
+ public static final String NAME = "gson" ;
32
34
33
- @ Deprecated
34
- public static FormatterStep create (int indentSpaces , boolean sortByKeys , boolean escapeHtml , String version , Provisioner provisioner ) {
35
- return create (new GsonConfig (sortByKeys , escapeHtml , indentSpaces , version ), provisioner );
35
+ private final JarState .Promised jarState ;
36
+ private final GsonConfig gsonConfig ;
37
+
38
+ private GsonStep (JarState .Promised jarState , GsonConfig gsonConfig ) {
39
+ this .gsonConfig = gsonConfig ;
40
+ this .jarState = jarState ;
36
41
}
37
42
38
43
public static FormatterStep create (GsonConfig gsonConfig , Provisioner provisioner ) {
39
44
Objects .requireNonNull (provisioner , "provisioner cannot be null" );
40
- return FormatterStep .createLazy ("gson" , () -> new State (gsonConfig , provisioner ), State ::toFormatter );
45
+ return FormatterStep .create (NAME ,
46
+ new GsonStep (JarState .promise (() -> JarState .from (MAVEN_COORDINATES + ":" + gsonConfig .getVersion (), provisioner )), gsonConfig ),
47
+ GsonStep ::equalityState ,
48
+ State ::toFormatter );
49
+ }
50
+
51
+ private State equalityState () {
52
+ return new State (jarState .get (), gsonConfig );
41
53
}
42
54
43
55
private static final class State implements Serializable {
@@ -46,9 +58,9 @@ private static final class State implements Serializable {
46
58
private final JarState jarState ;
47
59
private final GsonConfig gsonConfig ;
48
60
49
- private State (GsonConfig gsonConfig , Provisioner provisioner ) throws IOException {
61
+ private State (JarState jarState , GsonConfig gsonConfig ) {
62
+ this .jarState = jarState ;
50
63
this .gsonConfig = gsonConfig ;
51
- this .jarState = JarState .from (MAVEN_COORDINATES + ":" + gsonConfig .getVersion (), provisioner );
52
64
}
53
65
54
66
FormatterFunc toFormatter () {
@@ -62,5 +74,4 @@ FormatterFunc toFormatter() {
62
74
}
63
75
}
64
76
}
65
-
66
77
}
0 commit comments