From 0755ac23067eefda4f8b57498b23cc90ead029c7 Mon Sep 17 00:00:00 2001 From: Joost Farla Date: Fri, 15 Mar 2024 12:01:35 +0100 Subject: [PATCH] Auto-discover extensions (#187) --- .../imx/orchestrate/ext/spatial/SpatialExtension.java | 2 ++ .../imx/orchestrate/gateway/GatewayConfiguration.java | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ext-spatial/src/main/java/nl/geostandaarden/imx/orchestrate/ext/spatial/SpatialExtension.java b/ext-spatial/src/main/java/nl/geostandaarden/imx/orchestrate/ext/spatial/SpatialExtension.java index ce2a15ce..fcfa097a 100644 --- a/ext-spatial/src/main/java/nl/geostandaarden/imx/orchestrate/ext/spatial/SpatialExtension.java +++ b/ext-spatial/src/main/java/nl/geostandaarden/imx/orchestrate/ext/spatial/SpatialExtension.java @@ -1,10 +1,12 @@ package nl.geostandaarden.imx.orchestrate.ext.spatial; +import com.google.auto.service.AutoService; import java.util.Set; import nl.geostandaarden.imx.orchestrate.ext.spatial.geometry.GeometryTypeFactory; import nl.geostandaarden.imx.orchestrate.model.OrchestrateExtension; import nl.geostandaarden.imx.orchestrate.model.types.ValueTypeFactory; +@AutoService(OrchestrateExtension.class) public final class SpatialExtension implements OrchestrateExtension { @Override diff --git a/gateway/src/main/java/nl/geostandaarden/imx/orchestrate/gateway/GatewayConfiguration.java b/gateway/src/main/java/nl/geostandaarden/imx/orchestrate/gateway/GatewayConfiguration.java index 3ac8ddda..b50e4f70 100644 --- a/gateway/src/main/java/nl/geostandaarden/imx/orchestrate/gateway/GatewayConfiguration.java +++ b/gateway/src/main/java/nl/geostandaarden/imx/orchestrate/gateway/GatewayConfiguration.java @@ -16,10 +16,10 @@ import nl.geostandaarden.imx.orchestrate.engine.OrchestrateEngine; import nl.geostandaarden.imx.orchestrate.engine.source.Source; import nl.geostandaarden.imx.orchestrate.engine.source.SourceType; -import nl.geostandaarden.imx.orchestrate.ext.spatial.SpatialExtension; import nl.geostandaarden.imx.orchestrate.gateway.schema.SchemaFactory; import nl.geostandaarden.imx.orchestrate.model.ComponentRegistry; import nl.geostandaarden.imx.orchestrate.model.Model; +import nl.geostandaarden.imx.orchestrate.model.OrchestrateExtension; import nl.geostandaarden.imx.orchestrate.model.loader.ModelLoader; import nl.geostandaarden.imx.orchestrate.model.loader.ModelLoaderRegistry; import nl.geostandaarden.imx.orchestrate.model.types.ValueTypeFactory; @@ -41,7 +41,7 @@ public class GatewayConfiguration { @Bean public GraphQlSource graphQlSource() throws IOException { - var extensions = Set.of(new SpatialExtension()); + var extensions = resolveExtensions(); var componentRegistry = new ComponentRegistry(); extensions.forEach(extension -> extension.registerComponents(componentRegistry)); @@ -84,6 +84,13 @@ public GraphQLSchema schema() { }; } + private Set resolveExtensions() { + return ServiceLoader.load(OrchestrateExtension.class) + .stream() + .map(ServiceLoader.Provider::get) + .collect(toUnmodifiableSet()); + } + private Set resolveModelLoaders() { return ServiceLoader.load(ModelLoader.class) .stream()