diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java index 74c2e9f840639..4812b57c2f46e 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/deployment/src/main/java/io/quarkus/resteasy/reactive/common/deployment/ResteasyReactiveCommonProcessor.java @@ -327,7 +327,7 @@ void deprioritizeLegacyProviders(BuildProducer getExcludedClasses(List buildTimeConditions) { + public static Set getExcludedClasses(List buildTimeConditions) { return buildTimeConditions.stream() .filter(item -> !item.isEnabled()) .map(BuildTimeConditionBuildItem::getTarget) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java index cb06597935f48..5548d55c5ab86 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/java/io/quarkus/resteasy/reactive/server/deployment/ResteasyReactiveProcessor.java @@ -756,7 +756,7 @@ public void setupDeployment(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem, BeanFactory initClassFactory = recorder.factory(QUARKUS_INIT_CLASS, beanContainerBuildItem.getValue()); - String applicationPath = determineApplicationPath(index, getAppPath(serverConfig.path)); + String applicationPath = determineApplicationPath(appResult, getAppPath(serverConfig.path)); // spec allows the path contain encoded characters if ((applicationPath != null) && applicationPath.contains("%")) { applicationPath = Encode.decodePath(applicationPath); @@ -981,32 +981,19 @@ private Optional getAppPath(Optional newPropertyValue) { return newPropertyValue; } - private String determineApplicationPath(IndexView index, Optional defaultPath) { - Collection applicationPaths = index.getAnnotations(ResteasyReactiveDotNames.APPLICATION_PATH); - if (applicationPaths.isEmpty()) { + private String determineApplicationPath(ApplicationScanningResult appResult, + Optional defaultPath) { + if (appResult.getSelectedAppClass() == null) { return defaultPath.orElse("/"); } - // currently we only examine the first class that is annotated with @ApplicationPath so best - // fail if the user code has multiple such annotations instead of surprising the user - // at runtime - if (applicationPaths.size() > 1) { - StringBuilder sb = new StringBuilder(); - boolean first = true; - for (AnnotationInstance annotationInstance : applicationPaths) { - if (first) { - first = false; - } else { - sb.append(","); - } - sb.append(annotationInstance.target().asClass().name().toString()); - } - throw new RuntimeException("Multiple classes ( " + sb.toString() - + ") have been annotated with @ApplicationPath which is currently not supported"); + AnnotationInstance applicationPathValue = appResult.getSelectedAppClass() + .classAnnotation(ResteasyReactiveDotNames.APPLICATION_PATH); + if (applicationPathValue == null) { + return defaultPath.orElse("/"); } String applicationPath = null; - AnnotationValue applicationPathValue = applicationPaths.iterator().next().value(); - if ((applicationPathValue != null)) { - applicationPath = applicationPathValue.asString(); + if ((applicationPathValue.value() != null)) { + applicationPath = applicationPathValue.value().asString(); } return applicationPath; } diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/MultipleApplicationClassesWithBuildProfileTest.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/MultipleApplicationClassesWithBuildProfileTest.java new file mode 100644 index 0000000000000..3db55b97b2326 --- /dev/null +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/MultipleApplicationClassesWithBuildProfileTest.java @@ -0,0 +1,52 @@ +package io.quarkus.resteasy.reactive.server.test; + +import static io.restassured.RestAssured.get; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Application; + +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.arc.properties.IfBuildProperty; +import io.quarkus.test.QuarkusUnitTest; + +class MultipleApplicationClassesWithBuildProfileTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClasses( + Application1.class, Application2.class, TestResource.class)); + + @Test + public void testNoAnnotation() { + get("/1/test") + .then() + .statusCode(200) + .body(Matchers.equalTo("test")); + } + + @ApplicationPath("1") + public static class Application1 extends Application { + + } + + @ApplicationPath("2") + @IfBuildProperty(name = "some.prop2", stringValue = "v2") + public static class Application2 extends Application { + + } + + @Path("test") + public static class TestResource { + + @GET + public String get() { + return "test"; + } + } +} diff --git a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java index a3ac1781dbad2..cefc3375a9f7c 100644 --- a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java +++ b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveScanner.java @@ -80,6 +80,9 @@ public static ApplicationScanningResult scanForApplicationClass(IndexView index, if (Modifier.isAbstract(applicationClassInfo.flags())) { continue; } + if (excludedClasses.contains(applicationClassInfo.name().toString())) { + continue; + } if (selectedAppClass != null) { throw new RuntimeException("More than one Application class: " + applications); }