|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2022 DiffPlug |
| 2 | + * Copyright 2016-2023 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.
|
|
34 | 34 | import com.diffplug.spotless.extra.EclipseBasedStepBuilder;
|
35 | 35 | import com.diffplug.spotless.extra.java.EclipseJdtFormatterStep;
|
36 | 36 | import com.diffplug.spotless.generic.LicenseHeaderStep;
|
| 37 | +import com.diffplug.spotless.java.CleanthatJavaStep; |
37 | 38 | import com.diffplug.spotless.java.FormatAnnotationsStep;
|
38 | 39 | import com.diffplug.spotless.java.GoogleJavaFormatStep;
|
39 | 40 | import com.diffplug.spotless.java.ImportOrderStep;
|
@@ -270,6 +271,77 @@ private FormatterStep createStep() {
|
270 | 271 | }
|
271 | 272 | }
|
272 | 273 |
|
| 274 | + /** Apply CleanThat refactoring rules. */ |
| 275 | + public CleanthatJavaConfig cleanthat() { |
| 276 | + return new CleanthatJavaConfig(); |
| 277 | + } |
| 278 | + |
| 279 | + public class CleanthatJavaConfig { |
| 280 | + private String groupArtifact = CleanthatJavaStep.defaultGroupArtifact(); |
| 281 | + |
| 282 | + private String version = CleanthatJavaStep.defaultVersion(); |
| 283 | + |
| 284 | + private String sourceJdk = CleanthatJavaStep.defaultJdkVersion(); |
| 285 | + |
| 286 | + private List<String> mutators = CleanthatJavaStep.defaultMutators(); |
| 287 | + |
| 288 | + private List<String> excludedMutators = CleanthatJavaStep.defaultExcludedMutators(); |
| 289 | + |
| 290 | + CleanthatJavaConfig() { |
| 291 | + addStep(createStep()); |
| 292 | + } |
| 293 | + |
| 294 | + public CleanthatJavaConfig groupArtifact(String groupArtifact) { |
| 295 | + Objects.requireNonNull(groupArtifact); |
| 296 | + this.groupArtifact = groupArtifact; |
| 297 | + replaceStep(createStep()); |
| 298 | + return this; |
| 299 | + } |
| 300 | + |
| 301 | + public CleanthatJavaConfig version(String version) { |
| 302 | + Objects.requireNonNull(version); |
| 303 | + this.version = version; |
| 304 | + replaceStep(createStep()); |
| 305 | + return this; |
| 306 | + } |
| 307 | + |
| 308 | + public CleanthatJavaConfig sourceJdk(String sourceJdk) { |
| 309 | + Objects.requireNonNull(sourceJdk); |
| 310 | + this.sourceJdk = sourceJdk; |
| 311 | + replaceStep(createStep()); |
| 312 | + return this; |
| 313 | + } |
| 314 | + |
| 315 | + // Especially useful to clear default mutators |
| 316 | + public CleanthatJavaConfig clearMutators() { |
| 317 | + this.mutators.clear(); |
| 318 | + replaceStep(createStep()); |
| 319 | + return this; |
| 320 | + } |
| 321 | + |
| 322 | + // The fully qualified name of a class implementing eu.solven.cleanthat.engine.java.refactorer.meta.IMutator |
| 323 | + // or '*' to include all default mutators |
| 324 | + public CleanthatJavaConfig addMutator(String mutator) { |
| 325 | + this.mutators.add(mutator); |
| 326 | + replaceStep(createStep()); |
| 327 | + return this; |
| 328 | + } |
| 329 | + |
| 330 | + // useful to exclude a mutator amongst the default list of mutators |
| 331 | + public CleanthatJavaConfig excludeMutator(String mutator) { |
| 332 | + this.excludedMutators.add(mutator); |
| 333 | + replaceStep(createStep()); |
| 334 | + return this; |
| 335 | + } |
| 336 | + |
| 337 | + private FormatterStep createStep() { |
| 338 | + return CleanthatJavaStep.create( |
| 339 | + groupArtifact, |
| 340 | + version, |
| 341 | + sourceJdk, mutators, excludedMutators, provisioner()); |
| 342 | + } |
| 343 | + } |
| 344 | + |
273 | 345 | /** If the user hasn't specified the files yet, we'll assume he/she means all of the java files. */
|
274 | 346 | @Override
|
275 | 347 | protected void setupTask(SpotlessTask task) {
|
|
0 commit comments