Skip to content

Commit

Permalink
Merge pull request #21829 from gsmet/2.5.1-backports-3
Browse files Browse the repository at this point in the history
2.5.1 backports 3
  • Loading branch information
gsmet authored Dec 1, 2021
2 parents 2bf1db4 + ee0685e commit f7747a4
Show file tree
Hide file tree
Showing 26 changed files with 317 additions and 68 deletions.
4 changes: 2 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<smallrye-config.version>2.6.1</smallrye-config.version>
<smallrye-health.version>3.1.2</smallrye-health.version>
<smallrye-metrics.version>3.0.4</smallrye-metrics.version>
<smallrye-open-api.version>2.1.15</smallrye-open-api.version>
<smallrye-open-api.version>2.1.16</smallrye-open-api.version>
<smallrye-graphql.version>1.3.5</smallrye-graphql.version>
<smallrye-opentracing.version>2.0.1</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>5.2.1</smallrye-fault-tolerance.version>
Expand Down Expand Up @@ -83,7 +83,7 @@
<plexus-component-annotations.version>2.1.0</plexus-component-annotations.version>
<!-- What we actually depend on for the annotations, as latest Graal is not available in Maven fast enough: -->
<graal-sdk.version>21.3.0</graal-sdk.version>
<gizmo.version>1.0.9.Final</gizmo.version>
<gizmo.version>1.0.10.Final</gizmo.version>
<jackson.version>2.12.5</jackson.version>
<commons-logging-jboss-logging.version>1.0.0.Final</commons-logging-jboss-logging.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
final class GraalVM {
static final class Version implements Comparable<Version> {
private static final Pattern PATTERN = Pattern.compile(
"(GraalVM|native-image)( Version)? (?<version>[1-9][0-9]*(\\.[0-9]+)+(-dev\\p{XDigit}*)?)(?<distro>[^\n$]*)(Java Version (?<javaVersion>[^)]+))?\\s*");
"(GraalVM|native-image)( Version)? (?<version>[1-9][0-9]*(\\.[0-9]+)+(-dev\\p{XDigit}*)?)(?<distro>.*?)?(\\(Java Version (?<javaVersion>[^)]+)\\))?$");

static final Version UNVERSIONED = new Version("Undefined", "snapshot", Distribution.ORACLE);
static final Version VERSION_21_2 = new Version("GraalVM 21.2", "21.2", Distribution.ORACLE);
Expand Down Expand Up @@ -100,6 +100,7 @@ private static boolean isMandrel(String s) {
public String toString() {
return "Version{" +
"version=" + version +
", fullVersion=" + fullVersion +
", distribution=" + distribution +
", javaVersion=" + javaVersion +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,17 @@ static void assertNewerThan(String version, String other) {
assertThat(Version.of(Stream.of(version)).isNewerThan(Version.of(Stream.of(other)))).isTrue();
}

@Test
public void testGraalVMVersionIsJava17() {
Version graalVM21_3_11 = Version.of(Stream.of("GraalVM 21.3.0 Java 11 CE (Java Version 11.0.13+7-jvmci-21.3-b05)"));
assertThat(graalVM21_3_11.isJava17()).isFalse();
Version graalVM21_3_17 = Version.of(Stream.of("GraalVM 21.3.0 Java 17 CE (Java Version 17.0.1+12-jvmci-21.3-b05)"));
assertThat(graalVM21_3_17.isJava17()).isTrue();
Version mandrel21_3_11 = Version
.of(Stream.of("native-image 21.3.0.0-Final Mandrel Distribution (Java Version 11.0.13+8)"));
assertThat(mandrel21_3_11.isJava17()).isFalse();
Version mandrel21_3_17 = Version
.of(Stream.of("native-image 21.3.0.0-Final Mandrel Distribution (Java Version 17.0.1+12)"));
assertThat(mandrel21_3_17.isJava17()).isTrue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void handleHttpRequests(RoutingContext ctx) {
if (body != null) {
String ct = ctx.request().getHeader("content-type");
if (ct == null || isBinary(ct)) {
String encoded = Base64.getMimeEncoder().encodeToString(body.getBytes());
String encoded = Base64.getEncoder().encodeToString(body.getBytes());
event.setBody(encoded);
event.setIsBase64Encoded(true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void handleHttpRequests(RoutingContext ctx) {
if (body != null) {
String ct = ctx.request().getHeader("content-type");
if (ct == null || isBinary(ct)) {
String encoded = Base64.getMimeEncoder().encodeToString(body.getBytes());
String encoded = Base64.getEncoder().encodeToString(body.getBytes());
event.setBody(encoded);
event.setIsBase64Encoded(true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -150,17 +151,20 @@ private Uni<TenantConfigContext> createTenantContext(Vertx vertx, OidcTenantConf
if (!oidcConfig.discoveryEnabled) {
if (!isServiceApp(oidcConfig)) {
if (!oidcConfig.authorizationPath.isPresent() || !oidcConfig.tokenPath.isPresent()) {
throw new OIDCException("'web-app' applications must have 'authorization-path' and 'token-path' properties "
+ "set when the discovery is disabled.");
throw new ConfigurationException(
"'web-app' applications must have 'authorization-path' and 'token-path' properties "
+ "set when the discovery is disabled.",
Set.of("quarkus.oidc.authorization-path", "quarkus.oidc.token-path"));
}
}
// JWK and introspection endpoints have to be set for both 'web-app' and 'service' applications
if (!oidcConfig.jwksPath.isPresent() && !oidcConfig.introspectionPath.isPresent()) {
if (!oidcConfig.authentication.isIdTokenRequired() && oidcConfig.authentication.isUserInfoRequired()) {
LOG.debugf("tenant %s supports only UserInfo", oidcConfig.tenantId.get());
} else {
throw new OIDCException(
"Either 'jwks-path' or 'introspection-path' properties must be set when the discovery is disabled.");
throw new ConfigurationException(
"Either 'jwks-path' or 'introspection-path' properties must be set when the discovery is disabled.",
Set.of("quarkus.oidc.jwks-path", "quarkus.oidc.introspection-path"));
}
}
}
Expand Down Expand Up @@ -253,6 +257,7 @@ protected static Uni<JsonWebKeySet> getJsonWebSetUni(OidcProviderClient client,
.withBackOff(OidcCommonUtils.CONNECTION_BACKOFF_DURATION, OidcCommonUtils.CONNECTION_BACKOFF_DURATION)
.expireIn(connectionDelayInMillisecs)
.onFailure()
.transform(t -> toOidcException(t, oidcConfig.authServerUrl.get()))
.invoke(client::close);
} else {
return client.getJsonWebKeySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import io.quarkus.qute.generator.ExtensionMethodGenerator;
import io.quarkus.qute.generator.ExtensionMethodGenerator.NamespaceResolverCreator;
import io.quarkus.qute.generator.ExtensionMethodGenerator.NamespaceResolverCreator.ResolveCreator;
import io.quarkus.qute.generator.ExtensionMethodGenerator.Param;
import io.quarkus.qute.generator.ValueResolverGenerator;
import io.quarkus.qute.runtime.ContentTypes;
import io.quarkus.qute.runtime.EngineProducer;
Expand Down Expand Up @@ -1729,40 +1730,34 @@ private static TemplateExtensionMethodBuildItem findTemplateExtensionMethod(Info
// Name does not match
continue;
}
List<Type> parameters = extensionMethod.getMethod().parameters();
int realParamSize = parameters.size();
if (!extensionMethod.hasNamespace()) {
realParamSize -= 1;
}
if (TemplateExtension.ANY.equals(extensionMethod.getMatchName())) {
realParamSize -= 1;
}
if (realParamSize > 0 && !info.isVirtualMethod()) {

List<Param> evaluatedParams = extensionMethod.getParams().evaluated();
if (evaluatedParams.size() > 0 && !info.isVirtualMethod()) {
// If method accepts additional params the info must be a virtual method
continue;
}
if (info.isVirtualMethod()) {
// For virtual method validate the number of params and attempt to validate the parameter types if available
VirtualMethodPart virtualMethod = info.part.asVirtualMethod();

boolean isVarArgs = ValueResolverGenerator.isVarArgs(extensionMethod.getMethod());
int lastParamIdx = parameters.size() - 1;
int lastParamIdx = evaluatedParams.size() - 1;

if (isVarArgs) {
// For varargs methods match the minimal number of params
if ((realParamSize - 1) > virtualMethod.getParameters().size()) {
if ((evaluatedParams.size() - 1) > virtualMethod.getParameters().size()) {
continue;
}
} else {
if (virtualMethod.getParameters().size() != realParamSize) {
if (virtualMethod.getParameters().size() != evaluatedParams.size()) {
// Check number of parameters; some of params of the extension method must be ignored
continue;
}
}

// Check parameter types if available
boolean matches = true;
// Skip base and name param if needed
int idx = parameters.size() - realParamSize;
int idx = 0;

for (Expression param : virtualMethod.getParameters()) {

Expand All @@ -1772,9 +1767,9 @@ private static TemplateExtensionMethodBuildItem findTemplateExtensionMethod(Info
Type paramType;
if (isVarArgs && (idx >= lastParamIdx)) {
// Replace the type for varargs methods
paramType = parameters.get(lastParamIdx).asArrayType().component();
paramType = evaluatedParams.get(lastParamIdx).type.asArrayType().component();
} else {
paramType = parameters.get(idx);
paramType = evaluatedParams.get(idx).type;
}
if (!Types.isAssignableFrom(paramType,
result.type, index)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.qute.Namespaces;
import io.quarkus.qute.TemplateExtension;
import io.quarkus.qute.generator.ExtensionMethodGenerator;
import io.quarkus.qute.generator.ExtensionMethodGenerator.Parameters;

/**
* Represents a template extension method.
Expand All @@ -24,6 +26,7 @@ public final class TemplateExtensionMethodBuildItem extends MultiBuildItem {
private final Type matchType;
private final int priority;
private final String namespace;
private final Parameters params;

public TemplateExtensionMethodBuildItem(MethodInfo method, String matchName, String matchRegex, Type matchType,
int priority, String namespace) {
Expand All @@ -34,6 +37,7 @@ public TemplateExtensionMethodBuildItem(MethodInfo method, String matchName, Str
this.priority = priority;
this.namespace = (namespace != null && !namespace.isEmpty()) ? Namespaces.requireValid(namespace) : namespace;
this.matchPattern = (matchRegex == null || matchRegex.isEmpty()) ? null : Pattern.compile(matchRegex);
this.params = new ExtensionMethodGenerator.Parameters(method, matchPattern != null || matchesAny(), hasNamespace());
}

public MethodInfo getMethod() {
Expand Down Expand Up @@ -68,11 +72,19 @@ boolean matchesName(String name) {
if (matchPattern != null) {
return matchPattern.matcher(name).matches();
}
return TemplateExtension.ANY.equals(matchName) ? true : matchName.equals(name);
return matchesAny() ? true : matchName.equals(name);
}

boolean hasNamespace() {
boolean matchesAny() {
return TemplateExtension.ANY.equals(matchName);
}

public boolean hasNamespace() {
return namespace != null && !namespace.isEmpty();
}

public Parameters getParams() {
return params;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import javax.inject.Inject;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -19,6 +20,9 @@ public class TemplateExtensionAttributeTest {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addAsResource(
new StringAsset("{ping:transform('Foo')}"),
"templates/foo.txt")
.addClasses(Extensions.class));

@Inject
Expand All @@ -34,6 +38,8 @@ public void testTemplateExtensions() {
engine.parse("{foo.myAttr}").render());
assertEquals("OK",
engine.parse("{attr:ping}").instance().setAttribute("myAttribute", "OK").render());
assertEquals("foo::cs",
engine.getTemplate("foo").instance().setAttribute("locale", "cs").render());
}

@TemplateExtension
Expand All @@ -54,4 +60,13 @@ static String ping(@TemplateAttribute Object myAttribute) {

}

@TemplateExtension(namespace = "ping")
public static class NamespaceExtensions {

static String transform(@TemplateAttribute("locale") Object loc, String val) {
return val.toLowerCase() + "::" + loc.toString();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,21 @@ void addRestClientBeans(Capabilities capabilities,
ClassInfo jaxrsInterface = registerRestClient.target().asClass();
// for each interface annotated with @RegisterRestClient, generate a $$CDIWrapper CDI bean that can be injected
if (Modifier.isAbstract(jaxrsInterface.flags())) {
List<MethodInfo> restMethods = new ArrayList<>();

// search this class and its super interfaces for jaxrs methods
searchForJaxRsMethods(restMethods, jaxrsInterface, index);
if (restMethods.isEmpty()) {
List<MethodInfo> methodsToImplement = new ArrayList<>();

// search this interface and its super interfaces for jaxrs methods
searchForJaxRsMethods(methodsToImplement, jaxrsInterface, index);
// search this interface for default methods
// we could search for default methods in super interfaces too,
// but emitting the correct invokespecial instruction would become convoluted
// (as invokespecial may only reference a method from a _direct_ super interface)
for (MethodInfo method : jaxrsInterface.methods()) {
boolean isDefault = !Modifier.isAbstract(method.flags());
if (isDefault) {
methodsToImplement.add(method);
}
}
if (methodsToImplement.isEmpty()) {
continue;
}

Expand Down Expand Up @@ -384,11 +394,16 @@ void addRestClientBeans(Capabilities capabilities,
constructor.returnValue(null);

// METHODS:
for (MethodInfo method : restMethods) {
for (MethodInfo method : methodsToImplement) {
// for each method that corresponds to making a rest call, create a method like:
// public JsonArray get() {
// return ((InterfaceClass)this.getDelegate()).get();
// }
//
// for each default method, create a method like:
// public JsonArray get() {
// return InterfaceClass.super.get();
// }
MethodCreator methodCreator = classCreator.getMethodCreator(MethodDescriptor.of(method));
methodCreator.setSignature(AsmUtil.getSignatureIfRequired(method));

Expand All @@ -401,22 +416,25 @@ void addRestClientBeans(Capabilities capabilities,
}
}

ResultHandle delegate = methodCreator.invokeVirtualMethod(
MethodDescriptor.ofMethod(RestClientReactiveCDIWrapperBase.class, "getDelegate",
Object.class),
methodCreator.getThis());
ResultHandle result;

int parameterCount = method.parameters().size();
ResultHandle result;
if (parameterCount == 0) {
result = methodCreator.invokeInterfaceMethod(method, delegate);
} else {
ResultHandle[] params = new ResultHandle[parameterCount];
for (int i = 0; i < parameterCount; i++) {
params[i] = methodCreator.getMethodParam(i);
}
ResultHandle[] params = new ResultHandle[parameterCount];
for (int i = 0; i < parameterCount; i++) {
params[i] = methodCreator.getMethodParam(i);
}

if (Modifier.isAbstract(method.flags())) { // RestClient method
ResultHandle delegate = methodCreator.invokeVirtualMethod(
MethodDescriptor.ofMethod(RestClientReactiveCDIWrapperBase.class, "getDelegate",
Object.class),
methodCreator.getThis());

result = methodCreator.invokeInterfaceMethod(method, delegate, params);
} else { // default method
result = methodCreator.invokeSpecialInterfaceMethod(method, methodCreator.getThis(), params);
}

methodCreator.returnValue(result);
}
}
Expand Down
Loading

0 comments on commit f7747a4

Please sign in to comment.