From 3f6a6209cf1d67cc2fed430858a99453f88dac51 Mon Sep 17 00:00:00 2001 From: Marek Skacelik Date: Wed, 28 Aug 2024 16:25:30 +0200 Subject: [PATCH] Added new subsystem for client, where via CDI extension it registers ClientModels bean --- client-subsystem/pom.xml | 138 ++++++++++++++++++ .../graphql/client/ClientModelsExtension.java | 40 +++++ .../MicroProfileGraphQLClientExtension.java | 74 ++++++++++ .../MicroProfileGraphQLClientParser_1_0.java | 22 +++ ...ofileGraphQLClientSubsystemDefinition.java | 92 ++++++++++++ .../MicroProfileGraphQLClientLogger.java | 53 +++++++ ...ofileGraphQLClientDependencyProcessor.java | 54 +++++++ ...ofileGraphQLClientDeploymentProcessor.java | 81 ++++++++++ .../jakarta.enterprise.inject.spi.Extension | 1 + .../org.jboss.as.controller.Extension | 17 +++ .../client/LocalDescriptions.properties | 19 +++ ...croprofile-graphql-client-smallrye_1_0.xsd | 27 ++++ feature-pack/pom.xml | 16 ++ .../feature_groups/graphql-client.xml | 20 +++ .../microprofile-graphql/layer-spec.xml | 2 + .../graphql/client/common/main/module.xml | 4 + .../graphql/client/vertx/main/module.xml | 1 + .../graphql-client-smallrye/main/module.xml | 40 +++++ feature-pack/wildfly-feature-pack-build.xml | 1 + pom.xml | 36 +++++ quickstart/pom.xml | 2 +- ...icroProfileGraphQLDependencyProcessor.java | 2 +- .../TypesafeClientOutsideVMTestCase.java | 2 +- 23 files changed, 741 insertions(+), 3 deletions(-) create mode 100644 client-subsystem/pom.xml create mode 100644 client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/ClientModelsExtension.java create mode 100644 client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientExtension.java create mode 100644 client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientParser_1_0.java create mode 100644 client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientSubsystemDefinition.java create mode 100644 client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/_private/MicroProfileGraphQLClientLogger.java create mode 100644 client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/deployment/MicroProfileGraphQLClientDependencyProcessor.java create mode 100644 client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/deployment/MicroProfileGraphQLClientDeploymentProcessor.java create mode 100644 client-subsystem/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension create mode 100644 client-subsystem/src/main/resources/META-INF/services/org.jboss.as.controller.Extension create mode 100644 client-subsystem/src/main/resources/org/wildfly/extension/microprofile/graphql/client/LocalDescriptions.properties create mode 100644 client-subsystem/src/main/resources/schema/wildfly-microprofile-graphql-client-smallrye_1_0.xsd create mode 100644 feature-pack/src/main/resources/feature_groups/graphql-client.xml create mode 100644 feature-pack/src/main/resources/modules/system/layers/base/org/wildfly/extension/microprofile/graphql-client-smallrye/main/module.xml diff --git a/client-subsystem/pom.xml b/client-subsystem/pom.xml new file mode 100644 index 0000000..cec051d --- /dev/null +++ b/client-subsystem/pom.xml @@ -0,0 +1,138 @@ + + + + + + wildfly-microprofile-graphql-parent + org.wildfly.extras.graphql + 2.4.2.Final-SNAPSHOT + + 2.4.2.Final-SNAPSHOT + 4.0.0 + + wildfly-microprofile-graphql-client + WildFly MicroProfile GraphQL - Client Subsystem + + + + io.smallrye + smallrye-graphql-servlet + + + io.smallrye + smallrye-graphql-cdi + + + io.smallrye + smallrye-graphql-schema-builder + + + io.smallrye + smallrye-graphql-schema-model + + + io.smallrye + smallrye-graphql-client-model + + + io.smallrye + smallrye-graphql-client-model-builder + + + io.smallrye + smallrye-graphql-client + + + com.graphql-java + graphql-java + + + org.jboss.logging + jboss-logging-annotations + + + org.jboss.logging + jboss-logging-processor + + provided + true + + + org.wildfly.core + wildfly-controller + + + org.wildfly.core + wildfly-server + + + org.wildfly + wildfly-ee + + + org.jboss.metadata + jboss-metadata-web + + + org.wildfly + wildfly-web-common + + + org.wildfly + wildfly-weld + + + org.wildfly + wildfly-undertow + + + + io.smallrye + smallrye-graphql + + + jakarta.json.bind + jakarta.json.bind-api + + + jakarta.websocket + jakarta.websocket-api + + + jakarta.websocket + jakarta.websocket-client-api + + + + org.wildfly.core + wildfly-subsystem-test + pom + test + + + junit + junit + test + + + + diff --git a/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/ClientModelsExtension.java b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/ClientModelsExtension.java new file mode 100644 index 0000000..4fd51c1 --- /dev/null +++ b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/ClientModelsExtension.java @@ -0,0 +1,40 @@ +package org.wildfly.extension.microprofile.graphql.client; + +import io.smallrye.graphql.client.model.ClientModels; +import jakarta.enterprise.event.Observes; +import jakarta.enterprise.inject.Any; +import jakarta.enterprise.inject.Default; +import jakarta.enterprise.inject.spi.AfterBeanDiscovery; +import jakarta.enterprise.inject.spi.BeanManager; +import jakarta.enterprise.inject.spi.Extension; +import jakarta.enterprise.util.AnnotationLiteral; +import jakarta.inject.Singleton; + +/** + * CDI extension that registers the {@link ClientModels} instance computed by the deployment processor as a singleton bean. + * This allows the {@link ClientModels} instance to be injected into other CDI beans. + * + * @author mskacelik + */ +public class ClientModelsExtension implements Extension { + + private final ClientModels clientModels; + + public ClientModelsExtension() { + this(null); + } + + public ClientModelsExtension(ClientModels clientModels) { + this.clientModels = clientModels; + } + + void registerClientModelsBean(@Observes AfterBeanDiscovery afterBeanDiscoveryEvent, + BeanManager beanManager) { + afterBeanDiscoveryEvent.addBean() + .types(ClientModels.class) + .qualifiers(new AnnotationLiteral() {}, new AnnotationLiteral() {}) + .scope(Singleton.class) + .beanClass(ClientModels.class) + .createWith(creationalContext -> clientModels); + } +} diff --git a/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientExtension.java b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientExtension.java new file mode 100644 index 0000000..c861fcb --- /dev/null +++ b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientExtension.java @@ -0,0 +1,74 @@ +/* + * Copyright 2020 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wildfly.extension.microprofile.graphql.client; + +import org.jboss.as.controller.ExtensionContext; +import org.jboss.as.controller.ModelVersion; +import org.jboss.as.controller.PathElement; +import org.jboss.as.controller.SubsystemRegistration; +import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; +import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; +import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; +import org.jboss.as.controller.parsing.ExtensionParsingContext; +import org.jboss.as.controller.registry.ManagementResourceRegistration; + +import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; + +public class MicroProfileGraphQLClientExtension implements org.jboss.as.controller.Extension { + + public static final String SUBSYSTEM_NAME = "microprofile-graphql-client-smallrye"; + protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME); + + protected static final ModelVersion VERSION_1_0_0 = ModelVersion.create(1, 0, 0); + private static final ModelVersion CURRENT_MODEL_VERSION = VERSION_1_0_0; + + private static final MicroProfileGraphQLClientParser_1_0 CURRENT_PARSER = new MicroProfileGraphQLClientParser_1_0(); + + static final String WELD_CAPABILITY_NAME = "org.wildfly.weld"; + static final String CONFIG_CAPABILITY_NAME = "org.wildfly.microprofile.config"; + + private static final String RESOURCE_NAME = MicroProfileGraphQLClientExtension.class.getPackage().getName() + ".LocalDescriptions"; + + @Override + public void initialize(ExtensionContext extensionContext) { + final SubsystemRegistration sr = extensionContext.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION); + sr.registerXMLElementWriter(CURRENT_PARSER); + final ManagementResourceRegistration root = sr.registerSubsystemModel(new MicroProfileGraphQLClientSubsystemDefinition()); + root.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE, false); + } + + @Override + public void initializeParsers(ExtensionParsingContext extensionParsingContext) { + extensionParsingContext.setSubsystemXmlMapping(SUBSYSTEM_NAME, MicroProfileGraphQLClientParser_1_0.NAMESPACE, CURRENT_PARSER); + } + + static ResourceDescriptionResolver getResourceDescriptionResolver(final String... keyPrefix) { + return getResourceDescriptionResolver(true, keyPrefix); + } + + static ResourceDescriptionResolver getResourceDescriptionResolver(final boolean useUnprefixedChildTypes, final String... keyPrefix) { + StringBuilder prefix = new StringBuilder(); + for (String kp : keyPrefix) { + if (prefix.length() > 0){ + prefix.append('.'); + } + prefix.append(kp); + } + return new StandardResourceDescriptionResolver(prefix.toString(), RESOURCE_NAME, MicroProfileGraphQLClientExtension.class.getClassLoader(), true, useUnprefixedChildTypes); + } + +} diff --git a/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientParser_1_0.java b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientParser_1_0.java new file mode 100644 index 0000000..d35ce94 --- /dev/null +++ b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientParser_1_0.java @@ -0,0 +1,22 @@ +package org.wildfly.extension.microprofile.graphql.client; + +import org.jboss.as.controller.PersistentResourceXMLDescription; +import org.jboss.as.controller.PersistentResourceXMLParser; + +public class MicroProfileGraphQLClientParser_1_0 extends PersistentResourceXMLParser { + + public static final String NAMESPACE = "urn:wildfly:microprofile-graphql-client-smallrye:1.0"; + + private static final PersistentResourceXMLDescription xmlDescription; + + static { + xmlDescription = org.jboss.as.controller.PersistentResourceXMLDescription.builder(MicroProfileGraphQLClientExtension.SUBSYSTEM_PATH, NAMESPACE) + .build(); + } + + @Override + public PersistentResourceXMLDescription getParserDescription() { + return xmlDescription; + } + +} diff --git a/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientSubsystemDefinition.java b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientSubsystemDefinition.java new file mode 100644 index 0000000..68bf0d9 --- /dev/null +++ b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/MicroProfileGraphQLClientSubsystemDefinition.java @@ -0,0 +1,92 @@ +/* + * Copyright 2019 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wildfly.extension.microprofile.graphql.client; + +import org.jboss.as.controller.AbstractBoottimeAddStepHandler; +import org.jboss.as.controller.AttributeDefinition; +import org.jboss.as.controller.ModelOnlyRemoveStepHandler; +import org.jboss.as.controller.OperationContext; +import org.jboss.as.controller.OperationFailedException; +import org.jboss.as.controller.PersistentResourceDefinition; +import org.jboss.as.controller.capability.RuntimeCapability; +import org.jboss.as.server.AbstractDeploymentChainStep; +import org.jboss.as.server.DeploymentProcessorTarget; +import org.jboss.as.server.deployment.Phase; +import org.jboss.dmr.ModelNode; +import org.wildfly.extension.microprofile.graphql.client._private.MicroProfileGraphQLClientLogger; +import org.wildfly.extension.microprofile.graphql.client.deployment.MicroProfileGraphQLClientDependencyProcessor; +import org.wildfly.extension.microprofile.graphql.client.deployment.MicroProfileGraphQLClientDeploymentProcessor; + +import java.util.Collection; +import java.util.Collections; + +import static org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension.CONFIG_CAPABILITY_NAME; +import static org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension.SUBSYSTEM_NAME; +import static org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension.SUBSYSTEM_PATH; +import static org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension.WELD_CAPABILITY_NAME; + +public class MicroProfileGraphQLClientSubsystemDefinition extends PersistentResourceDefinition { + + private static final String GRAPHQL_CAPABILITY_NAME = "org.wildfly.microprofile.graphql.client"; + + private static final RuntimeCapability GRAPHQL_CAPABILITY = RuntimeCapability.Builder + .of(GRAPHQL_CAPABILITY_NAME) + .addRequirements(WELD_CAPABILITY_NAME) + .addRequirements(CONFIG_CAPABILITY_NAME) + .build(); + + public MicroProfileGraphQLClientSubsystemDefinition() { + super( + new Parameters( + SUBSYSTEM_PATH, + MicroProfileGraphQLClientExtension.getResourceDescriptionResolver(SUBSYSTEM_NAME)) + .setAddHandler(AddHandler.INSTANCE) + .setRemoveHandler(new ModelOnlyRemoveStepHandler()) + .setCapabilities(GRAPHQL_CAPABILITY) + ); + } + + @Override + public Collection getAttributes() { + return Collections.emptyList(); + } + + static class AddHandler extends AbstractBoottimeAddStepHandler { + + static AddHandler INSTANCE = new AddHandler(); + + private AddHandler() { + super(Collections.emptyList()); + } + + @Override + protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { + super.performBoottime(context, operation, model); + + context.addStep(new AbstractDeploymentChainStep() { + public void execute(DeploymentProcessorTarget processorTarget) { + final int DEPENDENCIES_MICROPROFILE_GRAPHQL = 6288; + processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, Phase.DEPENDENCIES, DEPENDENCIES_MICROPROFILE_GRAPHQL, new MicroProfileGraphQLClientDependencyProcessor()); + final int POST_MODULE_MICROPROFILE_GRAPHQL = 14241; + processorTarget.addDeploymentProcessor(SUBSYSTEM_NAME, Phase.POST_MODULE, POST_MODULE_MICROPROFILE_GRAPHQL, new MicroProfileGraphQLClientDeploymentProcessor()); + } + }, OperationContext.Stage.RUNTIME); + + MicroProfileGraphQLClientLogger.LOGGER.activatingSubsystem(); + } + } +} diff --git a/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/_private/MicroProfileGraphQLClientLogger.java b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/_private/MicroProfileGraphQLClientLogger.java new file mode 100644 index 0000000..0f1367f --- /dev/null +++ b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/_private/MicroProfileGraphQLClientLogger.java @@ -0,0 +1,53 @@ +/* + * Copyright 2019 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wildfly.extension.microprofile.graphql.client._private; + +import org.jboss.as.server.deployment.DeploymentUnitProcessingException; +import org.jboss.logging.BasicLogger; +import org.jboss.logging.Logger; +import org.jboss.logging.annotations.LogMessage; +import org.jboss.logging.annotations.Message; +import org.jboss.logging.annotations.MessageLogger; + +import static org.jboss.logging.Logger.Level.INFO; +import static org.jboss.logging.Logger.Level.WARN; + +@MessageLogger(projectCode = "WFLYGRAPHQLCLIENT", length = 5) +public interface MicroProfileGraphQLClientLogger extends BasicLogger { + + MicroProfileGraphQLClientLogger LOGGER = Logger.getMessageLogger(MicroProfileGraphQLClientLogger.class, "org.wildfly.extension.microprofile.graphql.client.smallrye"); + + @LogMessage(level = INFO) + @Message(id = 1, value = "Activating Eclipse MicroProfile GraphQL Client Subsystem") + void activatingSubsystem(); + + @LogMessage(level = INFO) + @Message(id = 2, value = "Activating GraphQL Client for deployment %s") + void activatingGraphQLForDeployment(String deployment); + + @LogMessage(level = INFO) + @Message(id = 3, value = "Found %s queries and %s mutations in the API") + void foundOperations(int queries, int mutations); + + @LogMessage(level = WARN) + @Message(id = 4, value = "Could not update %s because the contents are not as expected") + void couldNotUpdateRenderJs(String path); + + @Message(id = 100, value = "Multiple GraphQLClientApi annotations were found") + DeploymentUnitProcessingException multipleGraphQLApiAnnotations(); + +} diff --git a/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/deployment/MicroProfileGraphQLClientDependencyProcessor.java b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/deployment/MicroProfileGraphQLClientDependencyProcessor.java new file mode 100644 index 0000000..092f452 --- /dev/null +++ b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/deployment/MicroProfileGraphQLClientDependencyProcessor.java @@ -0,0 +1,54 @@ +/* + * Copyright 2020 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wildfly.extension.microprofile.graphql.client.deployment; + +import org.jboss.as.server.deployment.Attachments; +import org.jboss.as.server.deployment.DeploymentPhaseContext; +import org.jboss.as.server.deployment.DeploymentUnit; +import org.jboss.as.server.deployment.DeploymentUnitProcessingException; +import org.jboss.as.server.deployment.DeploymentUnitProcessor; +import org.jboss.as.server.deployment.annotation.CompositeIndex; +import org.jboss.as.server.deployment.module.ModuleDependency; +import org.jboss.as.server.deployment.module.ModuleSpecification; +import org.jboss.modules.ModuleLoader; +import org.jboss.modules.Module; +import org.wildfly.extension.microprofile.graphql.client._private.MicroProfileGraphQLClientLogger; + +import static org.wildfly.extension.microprofile.graphql.client.deployment.MicroProfileGraphQLClientDeploymentProcessor.GRAPHQL_CLIENT_API; + +public class MicroProfileGraphQLClientDependencyProcessor implements DeploymentUnitProcessor { + + @Override + public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { + final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); + final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); + if(!compositeIndex.getAnnotations(GRAPHQL_CLIENT_API).isEmpty()) { + MicroProfileGraphQLClientLogger.LOGGER.multipleGraphQLApiAnnotations(); + final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION); + final ModuleLoader moduleLoader = Module.getBootModuleLoader(); + ModuleDependency dependency = new ModuleDependency(moduleLoader, "org.wildfly.extension.microprofile.graphql-client-smallrye", false, false, true, false); + // this is an equivalent of meta-inf="import" in jboss-deployment-structure.xml and is needed to be able to see CDI beans from the module + dependency.addImportFilter(s -> s.startsWith("META-INF"), true); + moduleSpecification.addSystemDependency(dependency); + } + } + + @Override + public void undeploy(DeploymentUnit context) { + + } +} diff --git a/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/deployment/MicroProfileGraphQLClientDeploymentProcessor.java b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/deployment/MicroProfileGraphQLClientDeploymentProcessor.java new file mode 100644 index 0000000..2f0f32c --- /dev/null +++ b/client-subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/client/deployment/MicroProfileGraphQLClientDeploymentProcessor.java @@ -0,0 +1,81 @@ +/* + * Copyright 2020 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wildfly.extension.microprofile.graphql.client.deployment; + +import io.smallrye.graphql.client.model.ClientModelBuilder; +import io.smallrye.graphql.client.model.ClientModels; +import org.jboss.as.controller.capability.CapabilityServiceSupport; +import org.jboss.as.ee.structure.DeploymentType; +import org.jboss.as.ee.structure.DeploymentTypeMarker; +import org.jboss.as.server.deployment.Attachments; +import org.jboss.as.server.deployment.DeploymentPhaseContext; +import org.jboss.as.server.deployment.DeploymentUnit; +import org.jboss.as.server.deployment.DeploymentUnitProcessingException; +import org.jboss.as.server.deployment.DeploymentUnitProcessor; +import org.jboss.as.weld.WeldCapability; +import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; +import org.wildfly.extension.microprofile.graphql.client.ClientModelsExtension; +import org.wildfly.extension.microprofile.graphql.client._private.MicroProfileGraphQLClientLogger; + +import java.util.Collection; +import java.util.stream.Collectors; + +public class MicroProfileGraphQLClientDeploymentProcessor implements DeploymentUnitProcessor { + + static final DotName GRAPHQL_CLIENT_API = DotName + .createSimple("io.smallrye.graphql.client.typesafe.api.GraphQLClientApi"); + + private static ClientModels clientModels; + + @Override + public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { + + final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); + if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) { + return; + } + // see whether this deployment contains GraphQL annotations + final org.jboss.as.server.deployment.annotation.CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); + // final IndexView index = deploymentUnit.getAttachment(Attachments.ANNOTATION_INDEX); + if (compositeIndex.getAnnotations(GRAPHQL_CLIENT_API).isEmpty()) { + return; + } + final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); + final WeldCapability weldCapability; + MicroProfileGraphQLClientLogger.LOGGER.activatingGraphQLForDeployment(deploymentUnit.getName()); + Collection indexViews = compositeIndex.getIndexes().stream() + .map(index -> (IndexView) index) // Assuming Index has an asIndexView() method + .collect(Collectors.toList()); + + try { + weldCapability = support.getCapabilityRuntimeAPI(org.jboss.as.weld.Capabilities.WELD_CAPABILITY_NAME, WeldCapability.class); + } catch (CapabilityServiceSupport.NoSuchCapabilityException e) { + //We should not be here since the subsystem depends on weld capability. Just in case ... + throw new RuntimeException("todo"); + } + + if (weldCapability.isPartOfWeldDeployment(deploymentUnit)) { + final ClientModels clientModels = ClientModelBuilder.build(org.jboss.jandex.CompositeIndex.create(indexViews)); + weldCapability.registerExtensionInstance(new ClientModelsExtension(clientModels), deploymentUnit); + } + + } + @Override + public void undeploy(DeploymentUnit deploymentUnit) { + } +} diff --git a/client-subsystem/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension b/client-subsystem/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension new file mode 100644 index 0000000..4126bdc --- /dev/null +++ b/client-subsystem/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension @@ -0,0 +1 @@ +org.wildfly.extension.microprofile.graphql.client.ClientModelsExtension \ No newline at end of file diff --git a/client-subsystem/src/main/resources/META-INF/services/org.jboss.as.controller.Extension b/client-subsystem/src/main/resources/META-INF/services/org.jboss.as.controller.Extension new file mode 100644 index 0000000..c37b046 --- /dev/null +++ b/client-subsystem/src/main/resources/META-INF/services/org.jboss.as.controller.Extension @@ -0,0 +1,17 @@ +# +# Copyright 2019 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +org.wildfly.extension.microprofile.graphql.client.MicroProfileGraphQLClientExtension \ No newline at end of file diff --git a/client-subsystem/src/main/resources/org/wildfly/extension/microprofile/graphql/client/LocalDescriptions.properties b/client-subsystem/src/main/resources/org/wildfly/extension/microprofile/graphql/client/LocalDescriptions.properties new file mode 100644 index 0000000..ec40e9e --- /dev/null +++ b/client-subsystem/src/main/resources/org/wildfly/extension/microprofile/graphql/client/LocalDescriptions.properties @@ -0,0 +1,19 @@ +# +# Copyright 2019 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +microprofile-graphql-client-smallrye=The Microprofile GraphQL Client subsystem implemented by SmallRye +microprofile-graphql-client-smallrye.add=Adds the Microprofile GraphQL Client subsystem +microprofile-graphql-client-smallrye.remove=Removes the Microprofile GraphQL Client subsystem \ No newline at end of file diff --git a/client-subsystem/src/main/resources/schema/wildfly-microprofile-graphql-client-smallrye_1_0.xsd b/client-subsystem/src/main/resources/schema/wildfly-microprofile-graphql-client-smallrye_1_0.xsd new file mode 100644 index 0000000..16e58bf --- /dev/null +++ b/client-subsystem/src/main/resources/schema/wildfly-microprofile-graphql-client-smallrye_1_0.xsd @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file diff --git a/feature-pack/pom.xml b/feature-pack/pom.xml index a88343d..8499d48 100644 --- a/feature-pack/pom.xml +++ b/feature-pack/pom.xml @@ -138,6 +138,12 @@ provided + + wildfly-microprofile-graphql-client + ${project.groupId} + 2.4.1.Final-SNAPSHOT + provided + io.smallrye @@ -184,6 +190,16 @@ smallrye-graphql-client-implementation-vertx provided + + io.smallrye + smallrye-graphql-client-model + provided + + + io.smallrye + smallrye-graphql-client-model-builder + provided + io.vertx vertx-web-client diff --git a/feature-pack/src/main/resources/feature_groups/graphql-client.xml b/feature-pack/src/main/resources/feature_groups/graphql-client.xml new file mode 100644 index 0000000..2974011 --- /dev/null +++ b/feature-pack/src/main/resources/feature_groups/graphql-client.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/feature-pack/src/main/resources/layers/standalone/microprofile-graphql/layer-spec.xml b/feature-pack/src/main/resources/layers/standalone/microprofile-graphql/layer-spec.xml index 6175261..614690d 100644 --- a/feature-pack/src/main/resources/layers/standalone/microprofile-graphql/layer-spec.xml +++ b/feature-pack/src/main/resources/layers/standalone/microprofile-graphql/layer-spec.xml @@ -26,9 +26,11 @@ + + diff --git a/feature-pack/src/main/resources/modules/system/layers/base/io/smallrye/graphql/client/common/main/module.xml b/feature-pack/src/main/resources/modules/system/layers/base/io/smallrye/graphql/client/common/main/module.xml index 08a4c1b..d6a6d1b 100644 --- a/feature-pack/src/main/resources/modules/system/layers/base/io/smallrye/graphql/client/common/main/module.xml +++ b/feature-pack/src/main/resources/modules/system/layers/base/io/smallrye/graphql/client/common/main/module.xml @@ -18,6 +18,8 @@ + + @@ -29,6 +31,8 @@ + + diff --git a/feature-pack/src/main/resources/modules/system/layers/base/io/smallrye/graphql/client/vertx/main/module.xml b/feature-pack/src/main/resources/modules/system/layers/base/io/smallrye/graphql/client/vertx/main/module.xml index 9eadc6e..b096f3e 100644 --- a/feature-pack/src/main/resources/modules/system/layers/base/io/smallrye/graphql/client/vertx/main/module.xml +++ b/feature-pack/src/main/resources/modules/system/layers/base/io/smallrye/graphql/client/vertx/main/module.xml @@ -32,6 +32,7 @@ + diff --git a/feature-pack/src/main/resources/modules/system/layers/base/org/wildfly/extension/microprofile/graphql-client-smallrye/main/module.xml b/feature-pack/src/main/resources/modules/system/layers/base/org/wildfly/extension/microprofile/graphql-client-smallrye/main/module.xml new file mode 100644 index 0000000..294ee5c --- /dev/null +++ b/feature-pack/src/main/resources/modules/system/layers/base/org/wildfly/extension/microprofile/graphql-client-smallrye/main/module.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/feature-pack/wildfly-feature-pack-build.xml b/feature-pack/wildfly-feature-pack-build.xml index 83ac96c..984e80d 100644 --- a/feature-pack/wildfly-feature-pack-build.xml +++ b/feature-pack/wildfly-feature-pack-build.xml @@ -51,6 +51,7 @@ org.wildfly.extension.microprofile.graphql-smallrye + org.wildfly.extension.microprofile.graphql-client-smallrye diff --git a/pom.xml b/pom.xml index 89fdf67..8665387 100644 --- a/pom.xml +++ b/pom.xml @@ -292,6 +292,28 @@ + + io.smallrye + smallrye-graphql-client-model-builder + ${version.io.smallrye.graphql} + + + * + * + + + + + io.smallrye + smallrye-graphql-client-model + ${version.io.smallrye.graphql} + + + * + * + + + io.smallrye.reactive mutiny @@ -456,6 +478,17 @@ + + ${project.groupId} + wildfly-microprofile-graphql-client + ${project.version} + + + * + * + + + ${project.groupId} wildfly-microprofile-graphql-feature-pack @@ -685,6 +718,9 @@ build testsuite quickstart + quickstart-client + client-subsystem + diff --git a/quickstart/pom.xml b/quickstart/pom.xml index 02931c5..e322667 100644 --- a/quickstart/pom.xml +++ b/quickstart/pom.xml @@ -38,7 +38,7 @@ - 127.0.0.2 + 127.0.0.1 diff --git a/subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/deployment/MicroProfileGraphQLDependencyProcessor.java b/subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/deployment/MicroProfileGraphQLDependencyProcessor.java index 4a59e1c..961829a 100644 --- a/subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/deployment/MicroProfileGraphQLDependencyProcessor.java +++ b/subsystem/src/main/java/org/wildfly/extension/microprofile/graphql/deployment/MicroProfileGraphQLDependencyProcessor.java @@ -40,7 +40,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro final ModuleLoader moduleLoader = Module.getBootModuleLoader(); ModuleDependency dependency = new ModuleDependency(moduleLoader, "io.smallrye.graphql", false, false, true, false); // this is an equivalent of meta-inf="import" in jboss-deployment-structure.xml and is needed to be able to see CDI beans from the module - dependency.addImportFilter(s -> s.equals("META-INF"), true); + dependency.addImportFilter(s -> s.startsWith("META-INF"), true); moduleSpecification.addSystemDependency(dependency); } } diff --git a/testsuite/client-vertx/src/test/java/org/wildfly/extras/graphql/test/client/vertx/typesafe/TypesafeClientOutsideVMTestCase.java b/testsuite/client-vertx/src/test/java/org/wildfly/extras/graphql/test/client/vertx/typesafe/TypesafeClientOutsideVMTestCase.java index c944afb..a0ef432 100644 --- a/testsuite/client-vertx/src/test/java/org/wildfly/extras/graphql/test/client/vertx/typesafe/TypesafeClientOutsideVMTestCase.java +++ b/testsuite/client-vertx/src/test/java/org/wildfly/extras/graphql/test/client/vertx/typesafe/TypesafeClientOutsideVMTestCase.java @@ -26,7 +26,7 @@ public class TypesafeClientOutsideVMTestCase { @Deployment(testable = false) public static WebArchive deployment() { WebArchive war = ShrinkWrap.create(WebArchive.class, "funny.war") - .addClasses(Funny.class, FunnyApi.class, FunnyApiImpl.class) + .addClasses(Funny.class, FunnyApiImpl.class) .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); return war; }