Skip to content

Commit

Permalink
Merge pull request #29474 from gsmet/2.14.2-backports-3
Browse files Browse the repository at this point in the history
2.14.2 backports 3
  • Loading branch information
gsmet authored Nov 25, 2022
2 parents 7eb24fe + b8f1a8f commit 0e0cd43
Show file tree
Hide file tree
Showing 41 changed files with 871 additions and 76 deletions.
9 changes: 7 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<bouncycastle.fips.version>1.0.2.3</bouncycastle.fips.version>
<bouncycastle.tls.fips.version>1.0.12.3</bouncycastle.tls.fips.version>
<findbugs.version>3.0.2</findbugs.version>
<jandex.version>3.0.3</jandex.version>
<jandex.version>3.0.4</jandex.version>
<resteasy.version>4.7.7.Final</resteasy.version>
<opentracing.version>0.33.0</opentracing.version>
<opentracing-jdbc.version>0.2.4</opentracing-jdbc.version>
Expand Down Expand Up @@ -117,7 +117,7 @@
<cronutils.version>9.2.0</cronutils.version>
<quartz.version>2.3.2</quartz.version>
<h2.version>2.1.214</h2.version>
<postgresql-jdbc.version>42.5.0</postgresql-jdbc.version>
<postgresql-jdbc.version>42.5.1</postgresql-jdbc.version>
<mariadb-jdbc.version>3.0.9</mariadb-jdbc.version>
<mysql-jdbc.version>8.0.30</mysql-jdbc.version>
<mssql-jdbc.version>11.2.0.jre11</mssql-jdbc.version>
Expand Down Expand Up @@ -4252,6 +4252,11 @@
<artifactId>graal-sdk</artifactId>
<version>${graal-sdk.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graal-sdk.version}</version>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<failsafe-plugin.version>${version.surefire.plugin}</failsafe-plugin.version>

<!-- Jandex versions -->
<jandex.version>3.0.3</jandex.version>
<jandex.version>3.0.4</jandex.version>
<jandex-gradle-plugin.version>1.0.0</jandex-gradle-plugin.version>

<asciidoctorj.version>2.5.7</asciidoctorj.version>
Expand Down
5 changes: 3 additions & 2 deletions devtools/maven/src/main/java/io/quarkus/maven/BuildMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.quarkus.bootstrap.app.AugmentResult;
import io.quarkus.bootstrap.app.CuratedApplication;
import io.quarkus.bootstrap.util.IoUtils;
import io.quarkus.maven.dependency.ArtifactCoords;

/**
* Builds the Quarkus application.
Expand Down Expand Up @@ -77,11 +78,11 @@ protected boolean beforeExecute() throws MojoExecutionException {
getLog().info("Skipping Quarkus build");
return false;
}
if (mavenProject().getPackaging().equals("pom")) {
if (mavenProject().getPackaging().equals(ArtifactCoords.TYPE_POM)) {
getLog().info("Type of the artifact is POM, skipping build goal");
return false;
}
if (!mavenProject().getArtifact().getArtifactHandler().getExtension().equals("jar")) {
if (!mavenProject().getArtifact().getArtifactHandler().getExtension().equals(ArtifactCoords.TYPE_JAR)) {
throw new MojoExecutionException(
"The project artifact's extension is '" + mavenProject().getArtifact().getArtifactHandler().getExtension()
+ "' while this goal expects it be 'jar'");
Expand Down
5 changes: 5 additions & 0 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ public void setLog(Log log) {
@Override
public void execute() throws MojoFailureException, MojoExecutionException {

if (project.getPackaging().equals(ArtifactCoords.TYPE_POM)) {
getLog().info("Type of the artifact is POM, skipping dev goal");
return;
}

mavenVersionEnforcer.ensureMavenVersion(getLog(), session);

initToolchain();
Expand Down
7 changes: 6 additions & 1 deletion docs/src/main/asciidoc/rest-client-reactive.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1050,9 +1050,11 @@ Then, in your test you can simply use `@InjectMock` to create and inject a mock:

[source,java]
----
import static org.assertj.core.api.Assertions.assertThat;
package io.quarkus.it.rest.client.main;
import static org.mockito.Mockito.when;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -1063,6 +1065,7 @@ import io.quarkus.test.junit.mockito.InjectMock;
public class InjectMockTest {
@InjectMock
@RestClient
Client mock;
@BeforeEach
Expand All @@ -1082,6 +1085,8 @@ If Mockito doesn't meet your needs, you can create a mock programmatically using

[source,java]
----
package io.quarkus.it.rest.client.main;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public Builder setUnremovable() {
}

/**
* The default scope is only used if there is no scope declared on the bean class.
* The default scope is only used if there is no scope declared on the bean class or added by an annotation transformer
* with priority higher than {@code io.quarkus.arc.processor.BuildExtension.DEFAULT_PRIORITY}
* <p>
* The default scope should be used in cases where a bean class source is not controlled by the extension and the
* scope annotation cannot be declared directly on the class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ public void transform(TransformationContext transformationContext) {
// If it declares a scope no action is needed
return;
}
if (customScopes.isScopeIn(transformationContext.getAnnotations())) {
// if one of annotations (even if added via transformer) is a scope, no action is needed
return;
}
DotName defaultScope = additionalBeanTypes.get(beanClassName);
if (defaultScope != null) {
transformationContext.transform().add(defaultScope).done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;

Expand Down Expand Up @@ -31,6 +32,9 @@ public class LookupConditionsProcessor {
private static final DotName LOOK_UP_UNLESS_PROPERTY_CONTAINER = DotName
.createSimple(LookupUnlessProperty.List.class.getName());

public static final Set<DotName> LOOKUP_BEAN_ANNOTATIONS = Set.of(LOOK_UP_IF_PROPERTY, LOOK_UP_IF_CONTAINER,
LOOK_UP_UNLESS_PROPERTY, LOOK_UP_UNLESS_PROPERTY_CONTAINER);

private static final String NAME = "name";
private static final String STRING_VALUE = "stringValue";
private static final String LOOKUP_IF_MISSING = "lookupIfMissing";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ private FilterClassIntrospector createFilterClassIntrospector() {
return ab.get();
}

// We want to add @Typed to resources and providers so that they can be resolved as CDI bean using purely their
// We want to add @Typed to resources, beanparams and providers so that they can be resolved as CDI bean using purely their
// class as a bean type. This removes any ambiguity that potential subclasses may have.
@BuildStep
public void transformEndpoints(
Expand All @@ -745,6 +745,10 @@ public void transformEndpoints(
allResources.addAll(resourceScanningResultBuildItem.getResult().getScannedResources().keySet());
allResources.addAll(resourceScanningResultBuildItem.getResult().getPossibleSubResources().keySet());

// all found bean params
Set<String> beanParams = resourceScanningResultBuildItem.getResult()
.getBeanParams();

// discovered filters and interceptors
Set<String> filtersAndInterceptors = new HashSet<>();
InterceptorContainer<ReaderInterceptor> readerInterceptors = resourceInterceptorsBuildItem.getResourceInterceptors()
Expand Down Expand Up @@ -789,6 +793,14 @@ public void transform(TransformationContext context) {
&& clazz.declaredAnnotation(ResteasyReactiveDotNames.TYPED) == null) {
// Add @Typed(MyResource.class)
context.transform().add(createTypedAnnotationInstance(clazz, beanArchiveIndexBuildItem)).done();
return;
}
// check if the class is a bean param
if (beanParams.contains(clazz.name().toString())
&& clazz.declaredAnnotation(ResteasyReactiveDotNames.TYPED) == null) {
// Add @Typed(MyBean.class)
context.transform().add(createTypedAnnotationInstance(clazz, beanArchiveIndexBuildItem)).done();
return;
}
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import io.quarkus.arc.deployment.BuildTimeEnabledProcessor;
import io.quarkus.arc.deployment.GeneratedBeanBuildItem;
import io.quarkus.arc.deployment.GeneratedBeanGizmoAdaptor;
import io.quarkus.arc.deployment.LookupConditionsProcessor;
import io.quarkus.arc.processor.DotNames;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
Expand Down Expand Up @@ -81,6 +82,13 @@
*/
public class ResteasyReactiveScanningProcessor {

public static final Set<DotName> CONDITIONAL_BEAN_ANNOTATIONS;

static {
CONDITIONAL_BEAN_ANNOTATIONS = new HashSet<>(BuildTimeEnabledProcessor.BUILD_TIME_ENABLED_BEAN_ANNOTATIONS);
CONDITIONAL_BEAN_ANNOTATIONS.addAll(LookupConditionsProcessor.LOOKUP_BEAN_ANNOTATIONS);
}

@BuildStep
public MethodScannerBuildItem asyncSupport() {
return new MethodScannerBuildItem(new AsyncReturnTypeScanner());
Expand Down Expand Up @@ -313,9 +321,18 @@ public void handleCustomAnnotatedMethods(
List<FilterGeneration.GeneratedFilter> generatedFilters = FilterGeneration.generate(index,
Set.of(HTTP_SERVER_REQUEST, HTTP_SERVER_RESPONSE, ROUTING_CONTEXT), Set.of(Unremovable.class.getName()),
(methodInfo -> {
List<AnnotationInstance> methodAnnotations = methodInfo.annotations();
for (AnnotationInstance methodAnnotation : methodAnnotations) {
if (CONDITIONAL_BEAN_ANNOTATIONS.contains(methodAnnotation.name())) {
throw new RuntimeException("The combination of '@" + methodAnnotation.name().withoutPackagePrefix()
+ "' and '@ServerRequestFilter' or '@ServerResponseFilter' is not allowed. Offending method is '"
+ methodInfo.name() + "' of class '" + methodInfo.declaringClass().name() + "'");
}
}

List<AnnotationInstance> classAnnotations = methodInfo.declaringClass().declaredAnnotations();
for (AnnotationInstance classAnnotation : classAnnotations) {
if (BuildTimeEnabledProcessor.BUILD_TIME_ENABLED_BEAN_ANNOTATIONS.contains(classAnnotation.name())) {
if (CONDITIONAL_BEAN_ANNOTATIONS.contains(classAnnotation.name())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package io.quarkus.resteasy.reactive.server.test.beanparam;

import javax.ws.rs.BeanParam;
import javax.ws.rs.CookieParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

public class BeanParamTest {
@RegisterExtension
static final QuarkusUnitTest TEST = new QuarkusUnitTest()
.setArchiveProducer(() -> {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(MyBeanParamWithFieldsAndProperties.class, Top.class);
});

@Test
void shouldDeployWithoutIssues() {
// we only need to check that it deploys
}

public static class Top {
@PathParam("pathParam")
private String pathParam = "pathParam";

public String getPathParam() {
return pathParam;
}

public void setPathParam(String pathParam) {
this.pathParam = pathParam;
}
}

public static class MyBeanParamWithFieldsAndProperties extends Top {
@HeaderParam("headerParam")
private String headerParam = "headerParam";
@CookieParam("cookieParam")
private String cookieParam = "cookieParam";
@FormParam("formParam")
private String formParam = "formParam";
@QueryParam("queryParam")
private String queryParam = "queryParam";

// FIXME: Matrix not supported

public String getHeaderParam() {
return headerParam;
}

public void setHeaderParam(String headerParam) {
this.headerParam = headerParam;
}

public String getCookieParam() {
return cookieParam;
}

public void setCookieParam(String cookieParam) {
this.cookieParam = cookieParam;
}

public String getFormParam() {
return formParam;
}

public void setFormParam(String formParam) {
this.formParam = formParam;
}

public String getQueryParam() {
return queryParam;
}

public void setQueryParam(String queryParam) {
this.queryParam = queryParam;
}
}

@Path("/")
public static class Resource {
@Path("/a/{restPathDefault}/{restPath_Overridden}/{pathParam}")
@POST
public String beanParamWithFields(@BeanParam MyBeanParamWithFieldsAndProperties p) {
return null;
}

@Path("/b/{pathParam}")
@POST
public String beanParamWithFields(@BeanParam Top p) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.lookup.LookupIfProperty;
import io.quarkus.arc.lookup.LookupUnlessProperty;
import io.quarkus.arc.profile.IfBuildProfile;
import io.quarkus.arc.properties.IfBuildProperty;
import io.quarkus.test.QuarkusUnitTest;
Expand All @@ -49,14 +51,14 @@ public JavaArchive get() {
public void testExpectedFilters() {
List<String> responseFiltersValues = get("/test/filters")
.then().statusCode(200)
.body(Matchers.is("void-on,response-on,uni-on,always"))
.body(Matchers.is("void-on,response-on,uni-on,void-lookup-on,always"))
.extract()
.headers()
.getList("response-filters")
.stream()
.map(Header::getValue)
.collect(Collectors.toList());
assertThat(responseFiltersValues).containsOnly("always", "void-on", "uni-on");
assertThat(responseFiltersValues).containsOnly("always", "void-lookup-on", "void-on", "uni-on");
}

@Path("test")
Expand Down Expand Up @@ -135,6 +137,34 @@ public Uni<Void> uniResponseFilter(ContainerResponseContext ctx) {
}
}

@LookupIfProperty(name = "notexistingproperty", stringValue = "true")
public static class WontBeEnabledLookupPropertyFilter {

@ServerRequestFilter(priority = Priorities.USER + 10)
public void voidRequestFilter(ContainerRequestContext requestContext) {
requestContext.getHeaders().add("request-filters", "void-lookup-off");
}

@ServerResponseFilter
public void voidResponseFilter(ContainerResponseContext ctx) {
assertFalse(true);
}
}

@LookupUnlessProperty(name = "notexistingproperty", stringValue = "true", lookupIfMissing = true)
public static class WillBeEnabledLookupPropertyFilter {

@ServerRequestFilter(priority = Priorities.USER + 20)
public void voidRequestFilter(ContainerRequestContext requestContext) {
requestContext.getHeaders().add("request-filters", "void-lookup-on");
}

@ServerResponseFilter(priority = Priorities.USER + 20)
public void voidResponseFilter(ContainerResponseContext ctx) {
ctx.getHeaders().add("response-filters", "void-lookup-on");
}
}

@Singleton
public static class AlwaysEnabledFilter {

Expand Down
Loading

0 comments on commit 0e0cd43

Please sign in to comment.