Skip to content

Commit

Permalink
Avoid issues with lazy providers that create steps with side effects …
Browse files Browse the repository at this point in the history
…being ran twice
  • Loading branch information
lukebemish committed Jan 8, 2025
1 parent 8ea1d03 commit aedacde
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ public void custom(String name, UnaryOperator<String> customAction) {
}

public <T extends FormattingStep> void step(String name, Class<T> type, Action<? super T> action) {
steps.addLater(getProject().provider(() -> {
Property<FormattingStep> property = getObjects().property(FormattingStep.class);
property.set(getProject().provider(() -> {
T step = createStep(type, name);
action.execute(step);
return step;
}));
steps.addLater(property);
}

public <T extends FormattingStep> void step(String name, Class<T> type) {
Expand All @@ -137,6 +139,9 @@ public FormattingWorkflow() {

@SuppressWarnings("unchecked")
private <T extends FormattingStep> T createStep(Class<T> clazz, String name) {
if (steps.findByName(name) != null) {
throw new IllegalArgumentException("Step with name "+name+" already exists");
}
NamedDomainObjectFactory<T> factory = (NamedDomainObjectFactory<T>) factories.get(clazz);
if (factory == null) {
throw new IllegalArgumentException("No factory for step type "+clazz);
Expand Down

0 comments on commit aedacde

Please sign in to comment.