You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CHANGES.md
+4
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,10 @@ This document is intended for Spotless developers.
10
10
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
11
11
12
12
## [Unreleased]
13
+
### Added
14
+
*`FileSignature.Promised` and `JarState.Promised` to facilitate round-trip serialization for the Gradle configuration cache. ([#1945](https://github.com/diffplug/spotless/pull/1945))
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+22-1
Original file line number
Diff line number
Diff line change
@@ -94,10 +94,31 @@ Here's a checklist for creating a new step for Spotless:
94
94
95
95
-[ ] Class name ends in Step, `SomeNewStep`.
96
96
-[ ] Class has a public static method named `create` that returns a `FormatterStep`.
97
-
-[ ] Has a test class named `SomeNewStepTest`.
97
+
-[ ] Has a test class named `SomeNewStepTest` that uses `StepHarness` or `StepHarnessWithFile` to test the step.
98
+
-[ ] Start with `StepHarness.forStep(myStep).supportsRoundTrip(false)`, and then add round trip support as described in the next section.
98
99
-[ ] Test class has test methods to verify behavior.
99
100
-[ ] Test class has a test method `equality()` which tests equality using `StepEqualityTester` (see existing methods for examples).
100
101
102
+
### Serialization roundtrip
103
+
104
+
In order to support Gradle's configuration cache, all `FormatterStep` must be round-trip serializable. This is a bit tricky because step equality is based on the serialized form of the state, and `transient` is used to take absolute paths out of the equality check. To make this work, roundtrip compatible steps actually have *two* states:
105
+
106
+
-`RoundtripState` which must be roundtrip serializable but has no equality constraints
107
+
-`FileSignature.Promised` for settings files and `JarState.Promised` for the classpath
108
+
-`EqualityState` which will never be reserialized and its serialized form is used for equality / hashCode checks
109
+
-`FileSignature` for settings files and `JarState` for the classpath
### Third-party dependencies via reflection or compile-only source sets
102
123
103
124
Most formatters are going to use some kind of third-party jar. Spotless integrates with many formatters, some of which have incompatible transitive dependencies. To address this, we resolve third-party dependencies using [`JarState`](https://github.com/diffplug/spotless/blob/b26f0972b185995d7c6a7aefa726c146d24d9a82/lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java#L118). To call methods on the classes in that `JarState`, you can either use reflection or a compile-only source set. See [#524](https://github.com/diffplug/spotless/issues/524) for examples of both approaches.
0 commit comments