Skip to content

Commit b27632e

Browse files
authored
Enable Gradle users to create custom steps that require a provisioner (#1752)
2 parents d245b60 + 9fc857e commit b27632e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

plugin-gradle/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66

7+
### Added
8+
9+
* Add an overload for `FormatExtension.addStep` which provides access to the `FormatExtension`'s `Provisioner`, enabling custom steps to make use of third-party dependencies.
10+
711
### Fixed
812
* Correctly support the syntax
913
```

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Random;
3131
import java.util.TreeMap;
3232
import java.util.function.Consumer;
33+
import java.util.function.Function;
3334

3435
import javax.annotation.Nullable;
3536
import javax.inject.Inject;
@@ -300,6 +301,13 @@ public void addStep(FormatterStep newStep) {
300301
steps.add(newStep);
301302
}
302303

304+
/** Adds a new step that requires a Provisioner. */
305+
public void addStep(Function<Provisioner, FormatterStep> createStepFn) {
306+
requireNonNull(createStepFn);
307+
FormatterStep newStep = createStepFn.apply(provisioner());
308+
addStep(newStep);
309+
}
310+
303311
/** Returns the index of the existing step with the given name, or -1 if no such step exists. */
304312
protected int getExistingStepIdx(String stepName) {
305313
for (int i = 0; i < steps.size(); ++i) {

0 commit comments

Comments
 (0)