use of io.cucumber.core.backend.DefaultObjectFactory in project cucumber-jvm by cucumber.
the class ObjectFactoryServiceLoader method loadSingleObjectFactoryOrDefault.
private static ObjectFactory loadSingleObjectFactoryOrDefault(ServiceLoader<ObjectFactory> loader) {
Iterator<ObjectFactory> objectFactories = loader.iterator();
// Find the first non-default object factory,
// or the default as a side effect.
ObjectFactory objectFactory = null;
while (objectFactories.hasNext()) {
objectFactory = objectFactories.next();
if (!(objectFactory instanceof DefaultObjectFactory)) {
break;
}
}
if (objectFactory == null) {
throw new CucumberException("" + "Could not find any object factory.\n" + "\n" + "Cucumber uses SPI to discover object factory implementations.\n" + "This typically happens when using shaded jars. Make sure\n" + "to merge all SPI definitions in META-INF/services correctly");
}
// Check if there are no other non-default object factories
while (objectFactories.hasNext()) {
ObjectFactory extraObjectFactory = objectFactories.next();
if (extraObjectFactory instanceof DefaultObjectFactory) {
continue;
}
throw new CucumberException(getMultipleObjectFactoryLogMessage(objectFactory, extraObjectFactory));
}
return objectFactory;
}
Aggregations