Skip to content

Add a new option to supply a custom UuidGenerator when building runtime #3038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.cucumber.core.eventbus.EventBus;
import io.cucumber.core.feature.FeatureParser;
import io.cucumber.core.filter.Filters;
import io.cucumber.core.eventbus.UuidGenerator;
import io.cucumber.core.gherkin.Feature;
import io.cucumber.core.gherkin.Pickle;
import io.cucumber.core.logging.Logger;
Expand Down Expand Up @@ -119,6 +120,7 @@ public static class Builder {
private BackendSupplier backendSupplier;
private FeatureSupplier featureSupplier;
private List<Plugin> additionalPlugins = emptyList();
private UuidGenerator uuidGenerator;

private Builder() {
}
Expand All @@ -142,6 +144,11 @@ public Builder withFeatureSupplier(final FeatureSupplier featureSupplier) {
this.featureSupplier = featureSupplier;
return this;
}

public Builder withFeatureSupplier(final UuidGenerator uuidGenerator) {
this.uuidGenerator = uuidGenerator;
return this;
}

public Builder withAdditionalPlugins(final Plugin... plugins) {
this.additionalPlugins = Arrays.asList(plugins);
Expand Down Expand Up @@ -173,11 +180,15 @@ public Runtime build() {
plugins.addPlugin(exitStatus);

if (this.eventBus == null) {
final UuidGeneratorServiceLoader uuidGeneratorServiceLoader = new UuidGeneratorServiceLoader(
classLoader,
runtimeOptions);
this.eventBus = new TimeServiceEventBus(Clock.systemUTC(),
uuidGeneratorServiceLoader.loadUuidGenerator());
UuidGenerator generator;
if (uuidGenerator == null) {
final UuidGeneratorServiceLoader uuidGeneratorServiceLoader = new UuidGeneratorServiceLoader(
classLoader, runtimeOptions);
generator = uuidGeneratorServiceLoader.loadUuidGenerator();
} else {
generator = uuidGenerator;
}
this.eventBus = new TimeServiceEventBus(Clock.systemUTC(), generator);
}
final EventBus eventBus = synchronize(this.eventBus);

Expand Down
Loading