|
23 | 23 | import org.jetbrains.annotations.NotNull; |
24 | 24 | import org.jetbrains.annotations.Nullable; |
25 | 25 |
|
26 | | -import com.diffplug.spotless.cli.steps.SpotlessCLIFormatterStep; |
| 26 | +import com.diffplug.spotless.ThrowingEx; |
27 | 27 |
|
28 | 28 | import picocli.CommandLine; |
29 | 29 |
|
@@ -76,12 +76,25 @@ public SpotlessCLIRunner withStep(@NotNull String stepName) { |
76 | 76 | return this; |
77 | 77 | } |
78 | 78 |
|
79 | | - public SpotlessCLIRunner withStep(@NotNull Class<? extends SpotlessCLIFormatterStep> stepClass) { |
| 79 | + /** |
| 80 | + * Adds a step to the command line arguments. |
| 81 | + * The step class must implement {@link SpotlessCLIFormatterStep}. |
| 82 | + * |
| 83 | + * @param stepClass the class of the step to add |
| 84 | + * @return this instance for method chaining |
| 85 | + * @throws IllegalArgumentException if the step class does not implement {@link SpotlessCLIFormatterStep} |
| 86 | + */ |
| 87 | + public SpotlessCLIRunner withStep(@NotNull Class<?> stepClass) { |
| 88 | + // use reflection to allow having this class in testlib |
| 89 | + if (!ThrowingEx.get(() -> Class.forName("com.diffplug.spotless.cli.steps.SpotlessCLIFormatterStep")) |
| 90 | + .isAssignableFrom(stepClass)) { |
| 91 | + throw new IllegalArgumentException("Step class must implement SpotlessCLIFormatterStep"); |
| 92 | + } |
80 | 93 | String stepName = determineStepName(stepClass); |
81 | 94 | return withStep(stepName); |
82 | 95 | } |
83 | 96 |
|
84 | | - private String determineStepName(Class<? extends SpotlessCLIFormatterStep> stepClass) { |
| 97 | + private String determineStepName(Class<?> stepClass) { |
85 | 98 | CommandLine.Command annotation = stepClass.getAnnotation(CommandLine.Command.class); |
86 | 99 | if (annotation == null) { |
87 | 100 | throw new IllegalArgumentException("Step class must be annotated with @CommandLine.Command"); |
|
0 commit comments