From 67b6ea2b80f433b9e5a0192bda68cee14aa30dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 7 Aug 2025 14:18:35 +0200 Subject: [PATCH] Add a new option to supply a custom UuidGenerator when building runtime Currently the UuidGenerator is looked up by SPI when creating the event bus. This requires the UuidGenerator to be part of the classloader what might not always be the case. This now adds an option to set an actual instance for the UuidGenerator and uses that in case it is specified. --- .../io/cucumber/core/runtime/Runtime.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java b/cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java index 1a17276692..81b189fc1a 100644 --- a/cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java +++ b/cucumber-core/src/main/java/io/cucumber/core/runtime/Runtime.java @@ -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; @@ -119,6 +120,7 @@ public static class Builder { private BackendSupplier backendSupplier; private FeatureSupplier featureSupplier; private List additionalPlugins = emptyList(); + private UuidGenerator uuidGenerator; private Builder() { } @@ -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); @@ -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);