Skip to content

Commit

Permalink
Create two demos modules and remove resteasy-reactive-client dependen…
Browse files Browse the repository at this point in the history
…cy from runtime module
  • Loading branch information
jtama committed Dec 21, 2023
1 parent 5a5351d commit 17a057f
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 27 deletions.
9 changes: 0 additions & 9 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-server-spi-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>configuration-provider</artifactId>
Expand All @@ -32,11 +28,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devservices-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AcmeEnvironmentBuildItem> buildProducer) {
index.getIndex().getAnnotations(ConfigProperty.class)
.stream()
Expand All @@ -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.");


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -40,6 +39,13 @@ class ThisIsNotRestTransformerProcessor {
private static final Predicate<MethodInfo> isPatch = method -> method.hasAnnotation(DotName.createSimple(PATCH.class));
private static final Predicate<MethodInfo> 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(
Expand All @@ -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;
Expand All @@ -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."))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.acme.configurationProvider.it;


import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

Expand Down
85 changes: 85 additions & 0 deletions picocli-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>configuration-provider-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>configuration-provider-picocli-tests</artifactId>
<name>Configuration Provider - Picocli sample application</name>
<properties>
<skipITs>true</skipITs>
</properties>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-picocli</artifactId>
</dependency>
<dependency>
<groupId>org.acme</groupId>
<artifactId>configuration-provider</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner
</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<skipITs>false</skipITs>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -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("*********************************");
}
}
33 changes: 33 additions & 0 deletions picocli-tests/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
































acme.devservices.enabled=false
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
</activation>
<modules>
<module>integration-tests</module>
<module>picocli-tests</module>
</modules>
</profile>
</profiles>
Expand Down
13 changes: 12 additions & 1 deletion runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
<artifactId>quarkus-resteasy-reactive</artifactId>
<optional>true</optional>
</dependency>
<!-- Don't do this, use quarkus extensions when they exists -->
<!-- I've only done it this way for demonstration purposes -->
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> readValue(String content) {
try {
return this.readValue(content, new TypeReference<>() {
});
} catch (IOException ioe) {
throw new CompletionException(ioe);
}
}
}
}

0 comments on commit 17a057f

Please sign in to comment.