1
1
/*
2
- * Copyright 2016-2023 DiffPlug
2
+ * Copyright 2016-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.
35
35
import com .diffplug .spotless .JarState ;
36
36
import com .diffplug .spotless .Jvm ;
37
37
import com .diffplug .spotless .Provisioner ;
38
- import com .diffplug .spotless .ThrowingEx . Supplier ;
38
+ import com .diffplug .spotless .RoundedStep ;
39
39
40
40
/** A step for <a href="https://github.com/diffplug/freshmark">FreshMark</a>. */
41
- public class FreshMarkStep {
42
- // prevent direct instantiation
43
- private FreshMarkStep () {}
41
+ public class FreshMarkStep implements RoundedStep {
42
+ private static final long serialVersionUID = 1L ;
44
43
45
44
private static final String DEFAULT_VERSION = "1.3.1" ;
46
45
private static final String NAME = "freshmark" ;
@@ -52,13 +51,21 @@ private FreshMarkStep() {}
52
51
private static final String FORMATTER_CLASS = "com.diffplug.freshmark.FreshMark" ;
53
52
private static final String FORMATTER_METHOD = "compile" ;
54
53
54
+ private final JarState .Promised jarState ;
55
+ private final Map <String , ?> properties ;
56
+
57
+ private FreshMarkStep (JarState .Promised jarState , Map <String , ?> properties ) {
58
+ this .jarState = jarState ;
59
+ this .properties = properties ;
60
+ }
61
+
55
62
/** Creates a formatter step for the given version and settings file. */
56
- public static FormatterStep create (Supplier < Map <String , ?> > properties , Provisioner provisioner ) {
63
+ public static FormatterStep create (Map <String , ?> properties , Provisioner provisioner ) {
57
64
return create (defaultVersion (), properties , provisioner );
58
65
}
59
66
60
67
/** Creates a formatter step for the given version and settings file. */
61
- public static FormatterStep create (String version , Supplier < Map <String , ?> > properties , Provisioner provisioner ) {
68
+ public static FormatterStep create (String version , Map <String , ?> properties , Provisioner provisioner ) {
62
69
Objects .requireNonNull (version , "version" );
63
70
Objects .requireNonNull (properties , "properties" );
64
71
Objects .requireNonNull (provisioner , "provisioner" );
@@ -70,21 +77,25 @@ public static FormatterStep create(String version, Supplier<Map<String, ?>> prop
70
77
mavenCoordinates .add (NASHORN_MAVEN_COORDINATE + NASHORN_VERSION );
71
78
}
72
79
73
- return FormatterStep .createLazy (NAME ,
74
- () -> new State (JarState .from (mavenCoordinates , provisioner ), properties .get ()),
80
+ return FormatterStep .create (NAME ,
81
+ new FreshMarkStep (JarState .promise (() -> JarState .from (mavenCoordinates , provisioner )), properties ),
82
+ FreshMarkStep ::equalityState ,
75
83
State ::createFormat );
76
84
}
77
85
78
86
public static String defaultVersion () {
79
87
return DEFAULT_VERSION ;
80
88
}
81
89
90
+ private State equalityState () throws Exception {
91
+ return new State (jarState .get (), properties );
92
+ }
93
+
82
94
private static class State implements Serializable {
83
95
private static final long serialVersionUID = 1L ;
84
96
85
- /** The jar that contains the formatter. */
86
- final JarState jarState ;
87
- final NavigableMap <String , ?> properties ;
97
+ private final JarState jarState ;
98
+ private final NavigableMap <String , ?> properties ;
88
99
89
100
State (JarState jarState , Map <String , ?> properties ) {
90
101
this .jarState = jarState ;
0 commit comments