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.
28
28
import com .diffplug .spotless .FormatterStep ;
29
29
import com .diffplug .spotless .JarState ;
30
30
import com .diffplug .spotless .Provisioner ;
31
+ import com .diffplug .spotless .RoundedStep ;
31
32
32
33
/** Wraps up <a href="https://github.com/scalameta/scalafmt">scalafmt</a> as a FormatterStep. */
33
- public class ScalaFmtStep {
34
- // prevent direct instantiation
35
- private ScalaFmtStep () {}
34
+ public class ScalaFmtStep implements RoundedStep {
35
+ private static final long serialVersionUID = 1L ;
36
36
37
37
static final String DEFAULT_VERSION = "3.7.3" ;
38
38
39
39
private static final String DEFAULT_SCALA_MAJOR_VERSION = "2.13" ;
40
- static final String NAME = "scalafmt" ;
41
- static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_" ;
40
+ private static final String NAME = "scalafmt" ;
41
+ private static final String MAVEN_COORDINATE = "org.scalameta:scalafmt-core_" ;
42
+
43
+ private final JarState .Promised jarState ;
44
+ @ Nullable
45
+ private final File configFile ;
46
+
47
+ private ScalaFmtStep (JarState .Promised jarState , @ Nullable File configFile ) {
48
+ this .jarState = jarState ;
49
+ this .configFile = configFile ;
50
+ }
42
51
43
52
public static FormatterStep create (Provisioner provisioner ) {
44
53
return create (defaultVersion (), defaultScalaMajorVersion (), provisioner , null );
@@ -51,8 +60,9 @@ public static FormatterStep create(String version, Provisioner provisioner, @Nul
51
60
public static FormatterStep create (String version , @ Nullable String scalaMajorVersion , Provisioner provisioner , @ Nullable File configFile ) {
52
61
String finalScalaMajorVersion = scalaMajorVersion == null ? DEFAULT_SCALA_MAJOR_VERSION : scalaMajorVersion ;
53
62
54
- return FormatterStep .createLazy (NAME ,
55
- () -> new State (JarState .from (MAVEN_COORDINATE + finalScalaMajorVersion + ":" + version , provisioner ), configFile ),
63
+ return FormatterStep .create (NAME ,
64
+ new ScalaFmtStep (JarState .promise (() -> JarState .from (MAVEN_COORDINATE + finalScalaMajorVersion + ":" + version , provisioner )), configFile ),
65
+ ScalaFmtStep ::equalityState ,
56
66
State ::createFormat );
57
67
}
58
68
@@ -64,11 +74,15 @@ public static String defaultScalaMajorVersion() {
64
74
return DEFAULT_SCALA_MAJOR_VERSION ;
65
75
}
66
76
67
- static final class State implements Serializable {
77
+ private State equalityState () throws IOException {
78
+ return new State (jarState .get (), configFile );
79
+ }
80
+
81
+ private static final class State implements Serializable {
68
82
private static final long serialVersionUID = 1L ;
69
83
70
- final JarState jarState ;
71
- final FileSignature configSignature ;
84
+ private final JarState jarState ;
85
+ private final FileSignature configSignature ;
72
86
73
87
State (JarState jarState , @ Nullable File configFile ) throws IOException {
74
88
this .jarState = jarState ;
0 commit comments