diff --git a/deployment/pom.xml b/deployment/pom.xml index 45c17c9..71377e2 100644 --- a/deployment/pom.xml +++ b/deployment/pom.xml @@ -19,10 +19,6 @@ io.quarkus quarkus-resteasy-reactive-server-spi-deployment - - io.quarkus - quarkus-rest-client-reactive-jackson-deployment - org.acme configuration-provider @@ -32,11 +28,6 @@ io.quarkus quarkus-devservices-deployment - - io.quarkus - quarkus-resteasy-reactive - true - io.quarkus quarkus-junit5-internal diff --git a/deployment/src/main/java/org/acme/configurationProvider/deployment/EnvironmentInjectorProcessor.java b/deployment/src/main/java/org/acme/configurationProvider/deployment/EnvironmentInjectorProcessor.java index 6c292c6..60c598d 100644 --- a/deployment/src/main/java/org/acme/configurationProvider/deployment/EnvironmentInjectorProcessor.java +++ b/deployment/src/main/java/org/acme/configurationProvider/deployment/EnvironmentInjectorProcessor.java @@ -16,7 +16,7 @@ public class EnvironmentInjectorProcessor { private static final Logger logger = Logger.getLogger(EnvironmentInjectorProcessor.class); @BuildStep - void askForAppllicationScan(ApplicationIndexBuildItem index, + void askForApplicationScan(ApplicationIndexBuildItem index, BuildProducer buildProducer) { index.getIndex().getAnnotations(ConfigProperty.class) .stream() @@ -34,7 +34,7 @@ void envConfigSourceFactory(AcmeEnvironmentBuildItem acmeEnvironmentBuildItem, runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(AcmeConfigSourceFactoryBuilder.class.getName())); return; } - logger.warn("You shoud not use this extension if you don't need it."); + logger.warn("You should not use this extension if you don't need it."); } diff --git a/deployment/src/main/java/org/acme/configurationProvider/deployment/ThisIsNotRestTransformerProcessor.java b/deployment/src/main/java/org/acme/configurationProvider/deployment/ThisIsNotRestTransformerProcessor.java index 992368c..5bef4e6 100644 --- a/deployment/src/main/java/org/acme/configurationProvider/deployment/ThisIsNotRestTransformerProcessor.java +++ b/deployment/src/main/java/org/acme/configurationProvider/deployment/ThisIsNotRestTransformerProcessor.java @@ -18,7 +18,6 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.MethodInfo; import org.jboss.logging.Logger; -import org.jboss.resteasy.reactive.ResponseHeader; import org.jboss.resteasy.reactive.common.processor.transformation.AnnotationsTransformer; import org.jboss.resteasy.reactive.common.processor.transformation.Transformation; @@ -40,6 +39,13 @@ class ThisIsNotRestTransformerProcessor { private static final Predicate isPatch = method -> method.hasAnnotation(DotName.createSimple(PATCH.class)); private static final Predicate isRestEndpoint = isGet.or(isPut).or(isPost).or(isDelete).or(isPatch); + public static class ReactiveResteasyEnabled implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return QuarkusClassLoader.isClassPresentAtRuntime("org.jboss.resteasy.reactive.ResponseHeader"); + } + } + @BuildStep(onlyIf = ReactiveResteasyEnabled.class) @Record(ExecutionTime.RUNTIME_INIT) public void warn( @@ -60,13 +66,6 @@ public void warn( .toList()); } - public static class ReactiveResteasyEnabled implements BooleanSupplier { - @Override - public boolean getAsBoolean() { - return QuarkusClassLoader.isClassPresentAtRuntime("org.jboss.resteasy.reactive.ResponseHeader"); - } - } - private class RestMethodCorrector implements AnnotationsTransformer { private final boolean mustRecordWarning = true; @@ -89,7 +88,7 @@ public void transform(AnnotationsTransformer.TransformationContext context) { } Transformation transform = context.transform(); - transform.add(DotName.createSimple(ResponseHeader.class), + transform.add(DotName.createSimple(org.jboss.resteasy.reactive.ResponseHeader.class), AnnotationValue.createStringValue("name", "X-ApproximationCorrector"), AnnotationValue.createArrayValue("value", Collections .singletonList(AnnotationValue.createStringValue("", "It's more JSON over http really.")))); diff --git a/integration-tests/src/main/java/org/acme/configurationProvider/it/AcmeResource.java b/integration-tests/src/main/java/org/acme/configurationProvider/it/AcmeResource.java index 88a7c0a..1940fff 100644 --- a/integration-tests/src/main/java/org/acme/configurationProvider/it/AcmeResource.java +++ b/integration-tests/src/main/java/org/acme/configurationProvider/it/AcmeResource.java @@ -4,7 +4,6 @@ import jakarta.ws.rs.Path; import org.eclipse.microprofile.config.inject.ConfigProperty; -import java.util.HashMap; import java.util.Map; @Path("/acme") diff --git a/integration-tests/src/main/java/org/acme/configurationProvider/it/CustomResourceUtils.java b/integration-tests/src/main/java/org/acme/configurationProvider/it/CustomResourceUtils.java index 587d880..985d8d2 100644 --- a/integration-tests/src/main/java/org/acme/configurationProvider/it/CustomResourceUtils.java +++ b/integration-tests/src/main/java/org/acme/configurationProvider/it/CustomResourceUtils.java @@ -16,6 +16,7 @@ */ package org.acme.configurationProvider.it; + import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; diff --git a/picocli-tests/pom.xml b/picocli-tests/pom.xml new file mode 100644 index 0000000..9cdc0c2 --- /dev/null +++ b/picocli-tests/pom.xml @@ -0,0 +1,85 @@ + + + 4.0.0 + + org.acme + configuration-provider-parent + 1.0.0-SNAPSHOT + + configuration-provider-picocli-tests + Configuration Provider - Picocli sample application + + true + + + + io.quarkus + quarkus-picocli + + + org.acme + configuration-provider + ${project.version} + + + + + + io.quarkus + quarkus-maven-plugin + + + + build + + + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + + native-image + + + native + + + + + + maven-surefire-plugin + + ${native.surefire.skip} + + + + + + false + native + + + + diff --git a/picocli-tests/src/main/java/org/acme/configurationProvider/it/Starter.java b/picocli-tests/src/main/java/org/acme/configurationProvider/it/Starter.java new file mode 100644 index 0000000..5649af5 --- /dev/null +++ b/picocli-tests/src/main/java/org/acme/configurationProvider/it/Starter.java @@ -0,0 +1,21 @@ +package org.acme.configurationProvider.it; + +import org.eclipse.microprofile.config.inject.ConfigProperty; +import picocli.CommandLine; + +@CommandLine.Command +public class Starter implements Runnable{ + + + @ConfigProperty(name = "env.snowcamp.title") + String snowcampConfTitle; + @ConfigProperty(name = "env.snowcamp.author") + String snowcampConfAuthor; + + @Override + public void run() { + System.out.println("******** WELCOME ! ********"); + System.out.println("Welcome %s, that will present: \"%s\"%n".formatted(snowcampConfAuthor, snowcampConfTitle)); + System.out.println("*********************************"); + } +} diff --git a/picocli-tests/src/main/resources/application.properties b/picocli-tests/src/main/resources/application.properties new file mode 100644 index 0000000..b502644 --- /dev/null +++ b/picocli-tests/src/main/resources/application.properties @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +acme.devservices.enabled=false \ No newline at end of file diff --git a/pom.xml b/pom.xml index eac39ca..aede1c9 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,7 @@ integration-tests + picocli-tests diff --git a/runtime/pom.xml b/runtime/pom.xml index 19f017f..0382291 100644 --- a/runtime/pom.xml +++ b/runtime/pom.xml @@ -17,7 +17,18 @@ io.quarkus - quarkus-rest-client-reactive-jackson + quarkus-resteasy-reactive + true + + + + + jakarta.ws.rs + jakarta.ws.rs-api + + + com.fasterxml.jackson.core + jackson-databind diff --git a/runtime/src/main/java/org/acme/configurationProvider/runtime/EnvironmentProviderClient.java b/runtime/src/main/java/org/acme/configurationProvider/runtime/EnvironmentProviderClient.java index 86b5694..95367d3 100644 --- a/runtime/src/main/java/org/acme/configurationProvider/runtime/EnvironmentProviderClient.java +++ b/runtime/src/main/java/org/acme/configurationProvider/runtime/EnvironmentProviderClient.java @@ -1,23 +1,55 @@ package org.acme.configurationProvider.runtime; -import jakarta.ws.rs.client.Client; -import jakarta.ws.rs.client.ClientBuilder; +import com.fasterxml.jackson.core.type.TypeReference; import jakarta.ws.rs.core.UriBuilder; +import java.io.IOException; import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.util.Map; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; class EnvironmentProviderClient { - private final Client restClient; + private final HttpClient restClient; private final UriBuilder uriBuilder; + private final UncheckedObjectMapper objectMapper; EnvironmentProviderClient(URI baseUrl) { - restClient = ClientBuilder.newClient(); + restClient = HttpClient.newBuilder().build(); uriBuilder = UriBuilder.fromUri(baseUrl).path("/conferences/{prefix}"); + objectMapper = new UncheckedObjectMapper(); } public Map getEnvironment(String prefix) { - return restClient.target(uriBuilder.build(prefix)).request().get(Map.class); + HttpRequest request = HttpRequest.newBuilder() + .GET() + .uri(uriBuilder.build(prefix)) + .build(); + try { + return restClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()) + .thenApply(HttpResponse::body) + .thenApply(objectMapper::readValue) + .get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } + + static class UncheckedObjectMapper extends com.fasterxml.jackson.databind.ObjectMapper { + /** + * Parses the given JSON string into a Map. + */ + Map readValue(String content) { + try { + return this.readValue(content, new TypeReference<>() { + }); + } catch (IOException ioe) { + throw new CompletionException(ioe); + } + } } }