@@ -40,7 +40,7 @@ public final class CleanthatJavaStep {
40
40
private static final String MAVEN_COORDINATE = "io.github.solven-eu.cleanthat:java" ;
41
41
42
42
// CleanThat changelog is available at https://github.com/solven-eu/cleanthat/blob/master/CHANGES.MD
43
- private static final Jvm .Support <String > JVM_SUPPORT = Jvm .<String > support (NAME ).add (11 , "2.2 " );
43
+ private static final Jvm .Support <String > JVM_SUPPORT = Jvm .<String > support (NAME ).add (11 , "2.6 " );
44
44
45
45
// prevent direct instantiation
46
46
private CleanthatJavaStep () {}
@@ -52,7 +52,7 @@ public static FormatterStep create(Provisioner provisioner) {
52
52
53
53
/** Creates a step which apply default CleanThat mutators. */
54
54
public static FormatterStep create (String version , Provisioner provisioner ) {
55
- return create (MAVEN_COORDINATE , version , defaultSourceJdk (), defaultExcludedMutators (), defaultMutators (), provisioner );
55
+ return create (MAVEN_COORDINATE , version , defaultSourceJdk (), defaultMutators (), defaultExcludedMutators (), defaultIncludeDraft (), provisioner );
56
56
}
57
57
58
58
public static String defaultSourceJdk () {
@@ -62,16 +62,21 @@ public static String defaultSourceJdk() {
62
62
return "1.7" ;
63
63
}
64
64
65
- public static List <String > defaultExcludedMutators () {
66
- return List .of ();
67
- }
68
-
69
65
/**
70
- * By default, we include all available rules
66
+ * By default, we include only safe and consensual mutators
71
67
* @return
72
68
*/
73
69
public static List <String > defaultMutators () {
74
- return List .of ("eu.solven.cleanthat.engine.java.refactorer.mutators.composite.SafeAndConsensualMutators" );
70
+ // see ICleanthatStepParametersProperties.SAFE_AND_CONSENSUAL
71
+ return List .of ("SafeAndConsensual" );
72
+ }
73
+
74
+ public static List <String > defaultExcludedMutators () {
75
+ return List .of ();
76
+ }
77
+
78
+ public static boolean defaultIncludeDraft () {
79
+ return false ;
75
80
}
76
81
77
82
/** Creates a step which apply selected CleanThat mutators. */
@@ -80,6 +85,7 @@ public static FormatterStep create(String groupArtifact,
80
85
String sourceJdkVersion ,
81
86
List <String > excluded ,
82
87
List <String > included ,
88
+ boolean includeDraft ,
83
89
Provisioner provisioner ) {
84
90
Objects .requireNonNull (groupArtifact , "groupArtifact" );
85
91
if (groupArtifact .chars ().filter (ch -> ch == ':' ).count () != 1 ) {
@@ -88,7 +94,7 @@ public static FormatterStep create(String groupArtifact,
88
94
Objects .requireNonNull (version , "version" );
89
95
Objects .requireNonNull (provisioner , "provisioner" );
90
96
return FormatterStep .createLazy (NAME ,
91
- () -> new JavaRefactorerState (NAME , groupArtifact , version , sourceJdkVersion , excluded , included , provisioner ),
97
+ () -> new JavaRefactorerState (NAME , groupArtifact , version , sourceJdkVersion , excluded , included , includeDraft , provisioner ),
92
98
JavaRefactorerState ::createFormat );
93
99
}
94
100
@@ -111,9 +117,10 @@ static final class JavaRefactorerState implements Serializable {
111
117
final String sourceJdkVersion ;
112
118
final List <String > included ;
113
119
final List <String > excluded ;
120
+ final boolean includeDraft ;
114
121
115
122
JavaRefactorerState (String stepName , String version , Provisioner provisioner ) throws IOException {
116
- this (stepName , MAVEN_COORDINATE , version , defaultSourceJdk (), defaultExcludedMutators (), defaultMutators (), provisioner );
123
+ this (stepName , MAVEN_COORDINATE , version , defaultSourceJdk (), defaultExcludedMutators (), defaultMutators (), defaultIncludeDraft (), provisioner );
117
124
}
118
125
119
126
JavaRefactorerState (String stepName ,
@@ -122,8 +129,12 @@ static final class JavaRefactorerState implements Serializable {
122
129
String sourceJdkVersion ,
123
130
List <String > included ,
124
131
List <String > excluded ,
132
+ boolean includeDraft ,
125
133
Provisioner provisioner ) throws IOException {
126
- JVM_SUPPORT .assertFormatterSupported (version );
134
+ // https://github.com/diffplug/spotless/issues/1583
135
+ if (!version .endsWith ("-SNAPSHOT" )) {
136
+ JVM_SUPPORT .assertFormatterSupported (version );
137
+ }
127
138
ModuleHelper .doOpenInternalPackagesIfRequired ();
128
139
this .jarState = JarState .from (groupArtifact + ":" + version , provisioner );
129
140
this .stepName = stepName ;
@@ -132,6 +143,7 @@ static final class JavaRefactorerState implements Serializable {
132
143
this .sourceJdkVersion = sourceJdkVersion ;
133
144
this .included = included ;
134
145
this .excluded = excluded ;
146
+ this .includeDraft = includeDraft ;
135
147
}
136
148
137
149
@ SuppressWarnings ("PMD.UseProperClassLoader" )
@@ -142,16 +154,24 @@ FormatterFunc createFormat() {
142
154
Method formatterMethod ;
143
155
try {
144
156
Class <?> formatterClazz = classLoader .loadClass ("com.diffplug.spotless.glue.java.JavaCleanthatRefactorerFunc" );
145
- Constructor <?> formatterConstructor = formatterClazz .getConstructor (String .class , List .class , List .class );
157
+ Constructor <?> formatterConstructor = formatterClazz .getConstructor (String .class , List .class , List .class , boolean . class );
146
158
147
- formatter = formatterConstructor .newInstance (sourceJdkVersion , included , excluded );
159
+ formatter = formatterConstructor .newInstance (sourceJdkVersion , included , excluded , includeDraft );
148
160
formatterMethod = formatterClazz .getMethod ("apply" , String .class );
149
161
} catch (ReflectiveOperationException e ) {
150
162
throw new IllegalStateException ("Issue executing the formatter" , e );
151
163
}
152
- return JVM_SUPPORT .suggestLaterVersionOnError (version , input -> {
153
- return (String ) formatterMethod .invoke (formatter , input );
154
- });
164
+
165
+ // https://github.com/diffplug/spotless/issues/1583
166
+ if (!version .endsWith ("-SNAPSHOT" )) {
167
+ return JVM_SUPPORT .suggestLaterVersionOnError (version , input -> {
168
+ return (String ) formatterMethod .invoke (formatter , input );
169
+ });
170
+ } else {
171
+ return input -> {
172
+ return (String ) formatterMethod .invoke (formatter , input );
173
+ };
174
+ }
155
175
}
156
176
157
177
}
0 commit comments