Skip to content

Commit

Permalink
Merge branch 'quarkusio:main' into azure-functions-native-support
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusfcf committed May 29, 2023
2 parents 75967b8 + 3e5167e commit f3dd56e
Show file tree
Hide file tree
Showing 27 changed files with 469 additions and 158 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<slf4j-jboss-logmanager.version>2.0.0.Final</slf4j-jboss-logmanager.version>
<wildfly-common.version>1.5.4.Final-format-001</wildfly-common.version>
<wildfly-client-config.version>1.0.1.Final</wildfly-client-config.version>
<wildfly-elytron.version>2.1.0.Final</wildfly-elytron.version>
<wildfly-elytron.version>2.2.0.Final</wildfly-elytron.version>
<jboss-threads.version>3.5.0.Final</jboss-threads.version>
<vertx.version>4.4.2</vertx.version>
<httpclient.version>4.5.14</httpclient.version>
Expand Down
2 changes: 1 addition & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<commonmark.version>0.21.0</commonmark.version>

<!-- Arquillian BOM -->
<arquillian.version>1.7.0.Alpha13</arquillian.version>
<arquillian.version>1.7.0.Final</arquillian.version>

<!-- Enable APT by default for Eclipse -->
<m2e.apt.activation>jdt_apt</m2e.apt.activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public static class QuiltFlowerConfig {
public String version;

/**
* The directory into which to save the fernflower tool if it doesn't exist
* The directory into which to save the Quiltflower tool if it doesn't exist
*/
@ConfigItem(defaultValue = "${user.home}/.quarkus")
public String jarDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,76 +1571,6 @@ public Context(String versionStr, Path jarLocation, Path decompiledOutputDir) {

}

class FernflowerDecompiler implements Decompiler {

private Context context;
private Path decompilerJar;

@Override
public void init(Context context) {
this.context = context;
this.decompilerJar = context.jarLocation.resolve(String.format("fernflower-%s.jar", context.versionStr));
}

@Override
public boolean downloadIfNecessary() {
if (Files.exists(decompilerJar)) {
return true;
}
String downloadURL = String.format("https://jitpack.io/com/github/fesh0r/fernflower/%s/fernflower-%s.jar",
context.versionStr, context.versionStr);
try (BufferedInputStream in = new BufferedInputStream(new URL(downloadURL).openStream());
FileOutputStream fileOutputStream = new FileOutputStream(decompilerJar.toFile())) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
return true;
} catch (IOException e) {
log.error("Unable to download Fernflower from " + downloadURL, e);
return false;
}
}

@Override
public boolean decompile(Path jarToDecompile) {
int exitCode;
try {
ProcessBuilder processBuilder = new ProcessBuilder(
Arrays.asList("java", "-jar", decompilerJar.toAbsolutePath().toString(),
jarToDecompile.toAbsolutePath().toString(),
context.decompiledOutputDir.toAbsolutePath().toString()));
if (log.isDebugEnabled()) {
processBuilder.inheritIO();
} else {
processBuilder.redirectError(ProcessBuilder.Redirect.DISCARD.file())
.redirectOutput(ProcessBuilder.Redirect.DISCARD.file());
}
exitCode = processBuilder.start().waitFor();
} catch (Exception e) {
log.error("Failed to launch decompiler.", e);
return false;
}

if (exitCode != 0) {
log.errorf("Fernflower decompiler exited with error code: %d.", exitCode);
return false;
}

String jarFileName = jarToDecompile.getFileName().toString();
Path decompiledJar = context.decompiledOutputDir.resolve(jarFileName);
try {
ZipUtils.unzip(decompiledJar, context.decompiledOutputDir.resolve(jarFileName.replace(DOT_JAR, "")));
Files.deleteIfExists(decompiledJar);
} catch (IOException ignored) {
// it doesn't really matter if we can't unzip the jar as we do it merely for user convenience
}

return true;
}
}

class QuiltflowerDecompiler implements Decompiler {

private Context context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.grpc.ServerServiceDefinition;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.quarkus.grpc.runtime.config.Enabled;
import io.quarkus.grpc.runtime.config.GrpcClientConfiguration;
import io.quarkus.grpc.runtime.config.GrpcServerConfiguration;
import io.quarkus.grpc.spi.GrpcBuilderProvider;
Expand All @@ -24,7 +25,7 @@
public class InProcessGrpcServerBuilderProvider implements GrpcBuilderProvider<InProcessServerBuilder> {
@Override
public boolean providesServer(GrpcServerConfiguration configuration) {
return configuration.inProcess.enabled;
return Enabled.isEnabled(configuration.inProcess);
}

@Override
Expand Down Expand Up @@ -69,7 +70,7 @@ public String serverInfo(String host, int port, GrpcServerConfiguration configur

@Override
public boolean providesChannel(GrpcClientConfiguration configuration) {
return configuration.inProcess.enabled;
return Enabled.isEnabled(configuration.inProcess);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkus.grpc.runtime.config;

public interface Enabled {
boolean isEnabled();

static boolean isEnabled(Enabled enabled) {
return enabled != null && enabled.isEnabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.IgnoreProperty;

/**
* In-process config
* * <a href="https://grpc.github.io/grpc-java/javadoc/io/grpc/inprocess/InProcessServerBuilder.html">in-process usage</a>
*/
@ConfigGroup
public class InProcess {
public class InProcess implements Enabled {

@Override
@IgnoreProperty
public boolean isEnabled() {
return enabled;
}

/**
* Explicitly enable use of in-process.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.IgnoreProperty;

/**
* XDS config
* * <a href="https://github.com/grpc/grpc-java/tree/master/examples/example-xds">XDS usage</a>
*/
@ConfigGroup
public class Xds {
public class Xds implements Enabled {

@Override
@IgnoreProperty
public boolean isEnabled() {
return enabled;
}

/**
* Explicitly enable use of XDS.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.grpc.xds.XdsServerBuilder;
import io.grpc.xds.XdsServerCredentials;
import io.quarkus.grpc.runtime.config.ClientXds;
import io.quarkus.grpc.runtime.config.Enabled;
import io.quarkus.grpc.runtime.config.GrpcClientConfiguration;
import io.quarkus.grpc.runtime.config.GrpcServerConfiguration;
import io.quarkus.grpc.runtime.config.Xds;
Expand All @@ -37,8 +38,7 @@
public class XdsGrpcServerBuilderProvider implements GrpcBuilderProvider<XdsServerBuilder> {
@Override
public boolean providesServer(GrpcServerConfiguration configuration) {
Xds xds = configuration.xds;
return xds != null && xds.enabled;
return Enabled.isEnabled(configuration.xds);
}

@Override
Expand Down Expand Up @@ -96,12 +96,7 @@ public String serverInfo(String host, int port, GrpcServerConfiguration configur

@Override
public boolean providesChannel(GrpcClientConfiguration configuration) {
Xds xds = configuration.xds;
if (xds != null) {
return xds.enabled || XDS.equalsIgnoreCase(configuration.nameResolver);
} else {
return false;
}
return Enabled.isEnabled(configuration.xds) || XDS.equalsIgnoreCase(configuration.nameResolver);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion independent-projects/arc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<version.kotlin-coroutines>1.6.4</version.kotlin-coroutines>
<version.mockito>5.3.1</version.mockito>
<!-- TCK versions -->
<version.arquillian>1.7.0.Alpha14</version.arquillian>
<version.arquillian>1.7.0.Final</version.arquillian>
<version.atinject-tck>2.0.1</version.atinject-tck>
<version.cdi-tck>4.0.9</version.cdi-tck>
<version.junit4>4.13.2</version.junit4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public class BeanDeployment {

private final Set<BeanInfo> removedBeans;

private final Set<BeanInfo> beansWithRuntimeDeferredUnproxyableError;

private final Map<ScopeInfo, Function<MethodCreator, ResultHandle>> customContexts;

private final Map<DotName, BeanDefiningAnnotation> beanDefiningAnnotations;
Expand Down Expand Up @@ -149,6 +151,7 @@ public class BeanDeployment {
this.removeUnusedBeans = builder.removeUnusedBeans;
this.unusedExclusions = removeUnusedBeans ? new ArrayList<>(builder.removalExclusions) : null;
this.removedBeans = removeUnusedBeans ? new CopyOnWriteArraySet<>() : Collections.emptySet();
this.beansWithRuntimeDeferredUnproxyableError = Collections.newSetFromMap(new ConcurrentHashMap<>());
this.customContexts = new ConcurrentHashMap<>();

this.excludeTypes = builder.excludeTypes != null ? new ArrayList<>(builder.excludeTypes) : Collections.emptyList();
Expand Down Expand Up @@ -506,6 +509,14 @@ public Collection<BeanInfo> getRemovedBeans() {
return Collections.unmodifiableSet(removedBeans);
}

boolean hasRuntimeDeferredUnproxyableError(BeanInfo bean) {
return beansWithRuntimeDeferredUnproxyableError.contains(bean);
}

void deferUnproxyableErrorToRuntime(BeanInfo bean) {
beansWithRuntimeDeferredUnproxyableError.add(bean);
}

public Collection<ClassInfo> getQualifiers() {
return Collections.unmodifiableCollection(qualifiers.values());
}
Expand Down Expand Up @@ -1522,6 +1533,17 @@ private void validateBeans(List<Throwable> errors, Consumer<BytecodeTransformer>
Map<String, List<BeanInfo>> namedBeans = new HashMap<>();
Set<DotName> classesReceivingNoArgsCtor = new HashSet<>();

// this set is only used in strict compatible mode (see `Beans.validateBean()`),
// so no need to initialize it otherwise
Set<BeanInfo> injectedBeans = new HashSet<>();
if (strictCompatibility) {
for (InjectionPointInfo injectionPoint : this.injectionPoints) {
if (injectionPoint.hasResolvedBean()) {
injectedBeans.add(injectionPoint.getResolvedBean());
}
}
}

for (BeanInfo bean : beans) {
if (bean.getName() != null) {
List<BeanInfo> named = namedBeans.get(bean.getName());
Expand All @@ -1532,7 +1554,7 @@ private void validateBeans(List<Throwable> errors, Consumer<BytecodeTransformer>
named.add(bean);
findNamespaces(bean, namespaces);
}
bean.validate(errors, bytecodeTransformerConsumer, classesReceivingNoArgsCtor);
bean.validate(errors, bytecodeTransformerConsumer, classesReceivingNoArgsCtor, injectedBeans);
}

if (!namedBeans.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.CreationException;
import jakarta.enterprise.inject.IllegalProductException;
import jakarta.enterprise.inject.UnproxyableResolutionException;
import jakarta.enterprise.inject.literal.InjectLiteral;
import jakarta.enterprise.inject.spi.InterceptionType;
import jakarta.interceptor.InvocationContext;
Expand Down Expand Up @@ -1927,7 +1928,10 @@ protected void implementGet(BeanInfo bean, ClassCreator beanCreator, ProviderTyp
MethodCreator get = beanCreator.getMethodCreator("get", providerType.descriptorName(), CreationalContext.class)
.setModifiers(ACC_PUBLIC);

if (BuiltinScope.DEPENDENT.is(bean.getScope())) {
if (bean.getDeployment().hasRuntimeDeferredUnproxyableError(bean)) {
get.throwException(UnproxyableResolutionException.class, "Bean not proxyable: " + bean);
get.returnValue(get.loadNull());
} else if (BuiltinScope.DEPENDENT.is(bean.getScope())) {
// @Dependent pseudo-scope
// Foo instance = create(ctx)
ResultHandle instance = get.invokeVirtualMethod(
Expand Down Expand Up @@ -2214,6 +2218,10 @@ private ResultHandle wrapCurrentInjectionPoint(BeanInfo bean,
}

private void initializeProxy(BeanInfo bean, String baseName, ClassCreator beanCreator) {
if (bean.getDeployment().hasRuntimeDeferredUnproxyableError(bean)) {
return;
}

// Add proxy volatile field
String proxyTypeName = getProxyTypeName(bean, baseName);
beanCreator.getFieldCreator(FIELD_NAME_PROXY, proxyTypeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ public String getClientProxyPackageName() {
}

void validate(List<Throwable> errors, Consumer<BytecodeTransformer> bytecodeTransformerConsumer,
Set<DotName> classesReceivingNoArgsCtor) {
Beans.validateBean(this, errors, bytecodeTransformerConsumer, classesReceivingNoArgsCtor);
Set<DotName> classesReceivingNoArgsCtor, Set<BeanInfo> injectedBeans) {
Beans.validateBean(this, errors, bytecodeTransformerConsumer, classesReceivingNoArgsCtor, injectedBeans);
}

void validateInterceptorDecorator(List<Throwable> errors, Consumer<BytecodeTransformer> bytecodeTransformerConsumer) {
Expand Down Expand Up @@ -797,7 +797,7 @@ private void putLifecycleInterceptors(Map<InterceptionType, InterceptionInfo> li

private void addClassLevelBindings(ClassInfo targetClass, Collection<AnnotationInstance> bindings) {
List<AnnotationInstance> classLevelBindings = new ArrayList<>();
doAddClassLevelBindings(targetClass, classLevelBindings, Set.of());
doAddClassLevelBindings(targetClass, classLevelBindings, Set.of(), false);
bindings.addAll(classLevelBindings);
if (!stereotypes.isEmpty()) {
// interceptor binding declared on a bean class replaces an interceptor binding of the same type
Expand All @@ -808,22 +808,27 @@ private void addClassLevelBindings(ClassInfo targetClass, Collection<AnnotationI
}
for (StereotypeInfo stereotype : Beans.stereotypesWithTransitive(stereotypes,
beanDeployment.getStereotypesMap())) {
doAddClassLevelBindings(stereotype.getTarget(), bindings, skip);
doAddClassLevelBindings(stereotype.getTarget(), bindings, skip, false);
}
}
}

// bindings whose class name is present in `skip` are ignored (this is used to ignore bindings on stereotypes
// when the original class has a binding of the same type)
private void doAddClassLevelBindings(ClassInfo classInfo, Collection<AnnotationInstance> bindings, Set<DotName> skip) {
private void doAddClassLevelBindings(ClassInfo classInfo, Collection<AnnotationInstance> bindings, Set<DotName> skip,
boolean onlyInherited) {
beanDeployment.getAnnotations(classInfo).stream()
.filter(a -> beanDeployment.getInterceptorBinding(a.name()) != null)
.filter(a -> !skip.contains(a.name()))
.filter(a -> !onlyInherited
|| beanDeployment.hasAnnotation(beanDeployment.getInterceptorBinding(a.name()), DotNames.INHERITED))
.forEach(bindings::add);
if (classInfo.superClassType() != null && !classInfo.superClassType().name().equals(DotNames.OBJECT)) {
ClassInfo superClass = getClassByName(beanDeployment.getBeanArchiveIndex(), classInfo.superName());
if (superClass != null) {
doAddClassLevelBindings(superClass, bindings, skip);
// proper interceptor binding inheritance only in strict mode, due to Quarkus expecting security
// annotations (such as `@RolesAllowed`) to be inherited, even though they are not `@Inherited`
doAddClassLevelBindings(superClass, bindings, skip, beanDeployment.strictCompatibility);
}
}
}
Expand Down

0 comments on commit f3dd56e

Please sign in to comment.