Skip to content

Commit

Permalink
Merge pull request #13147 from dmlloyd/depr-field-outjection
Browse files Browse the repository at this point in the history
Deprecate field- and ctor-based BuildProducers
  • Loading branch information
gsmet authored Nov 6, 2020
2 parents c2fa70a + 5eadb10 commit a3c4231
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public final class ExtensionLoader {
private ExtensionLoader() {
}

private static final Logger loadLog = Logger.getLogger("io.quarkus.deployment");
private static final Logger cfgLog = Logger.getLogger("io.quarkus.configuration");
private static final String CONFIG_ROOTS_LIST = "META-INF/quarkus-config-roots.list";

Expand Down Expand Up @@ -325,6 +326,7 @@ public static Consumer<BuildChainBuilder> loadStepsFrom(Class<?> clazz, BuildTim
stepConfig = stepConfig.andThen(bsb -> bsb.consumes(buildItemClass));
ctorParamFns.add(bc -> bc.consumeMulti(buildItemClass));
} else if (isConsumerOf(parameterType, BuildItem.class)) {
deprecatedProducer(parameter);
final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0)
.asSubclass(BuildItem.class);
if (overridable) {
Expand All @@ -343,6 +345,7 @@ public static Consumer<BuildChainBuilder> loadStepsFrom(Class<?> clazz, BuildTim
}
ctorParamFns.add(bc -> (Consumer<? extends BuildItem>) bc::produce);
} else if (isBuildProducerOf(parameterType, BuildItem.class)) {
deprecatedProducer(parameter);
final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(parameterType, 0)
.asSubclass(BuildItem.class);
if (overridable) {
Expand Down Expand Up @@ -434,6 +437,7 @@ public static Consumer<BuildChainBuilder> loadStepsFrom(Class<?> clazz, BuildTim
stepInstanceSetup = stepInstanceSetup
.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, bc.consumeMulti(buildItemClass)));
} else if (isConsumerOf(fieldType, BuildItem.class)) {
deprecatedProducer(field);
final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(fieldType, 0).asSubclass(BuildItem.class);
if (overridable) {
if (weak) {
Expand All @@ -452,6 +456,7 @@ public static Consumer<BuildChainBuilder> loadStepsFrom(Class<?> clazz, BuildTim
stepInstanceSetup = stepInstanceSetup
.andThen((bc, o) -> ReflectUtil.setFieldVal(field, o, (Consumer<? extends BuildItem>) bc::produce));
} else if (isBuildProducerOf(fieldType, BuildItem.class)) {
deprecatedProducer(field);
final Class<? extends BuildItem> buildItemClass = rawTypeOfParameter(fieldType, 0).asSubclass(BuildItem.class);
if (overridable) {
if (weak) {
Expand Down Expand Up @@ -998,6 +1003,12 @@ public String toString() {
return chainConfig;
}

private static void deprecatedProducer(final Object element) {
loadLog.warnf(
"Producing values from constructors and fields is no longer supported and will be removed in a future release: %s",
element);
}

protected static List<Method> getMethods(Class<?> clazz) {
List<Method> declaredMethods = new ArrayList<>();
if (!clazz.getName().equals(Object.class.getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ public class RegisterForReflectionBuildStep {

private static final Logger log = Logger.getLogger(RegisterForReflectionBuildStep.class);

@Inject
BuildProducer<ReflectiveClassBuildItem> reflectiveClass;

@Inject
CombinedIndexBuildItem combinedIndexBuildItem;

@BuildStep
public void build() {
public void build(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
for (AnnotationInstance i : combinedIndexBuildItem.getIndex()
.getAnnotations(DotName.createSimple(RegisterForReflection.class.getName()))) {

Expand All @@ -40,21 +37,21 @@ public void build() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (targetsValue == null && classNamesValue == null) {
ClassInfo classInfo = i.target().asClass();
registerClass(classLoader, classInfo.name().toString(), methods, fields, ignoreNested);
registerClass(classLoader, classInfo.name().toString(), methods, fields, ignoreNested, reflectiveClass);
continue;
}

if (targetsValue != null) {
Type[] targets = targetsValue.asClassArray();
for (Type type : targets) {
registerClass(classLoader, type.name().toString(), methods, fields, ignoreNested);
registerClass(classLoader, type.name().toString(), methods, fields, ignoreNested, reflectiveClass);
}
}

if (classNamesValue != null) {
String[] classNames = classNamesValue.asStringArray();
for (String className : classNames) {
registerClass(classLoader, className, methods, fields, ignoreNested);
registerClass(classLoader, className, methods, fields, ignoreNested, reflectiveClass);
}
}
}
Expand All @@ -64,7 +61,7 @@ public void build() {
* BFS Recursive Method to register a class and it's inner classes for Reflection.
*/
private void registerClass(ClassLoader classLoader, String className, boolean methods, boolean fields,
boolean ignoreNested) {
boolean ignoreNested, final BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(methods, fields, className));

if (ignoreNested) {
Expand All @@ -74,7 +71,7 @@ private void registerClass(ClassLoader classLoader, String className, boolean me
try {
Class<?>[] declaredClasses = classLoader.loadClass(className).getDeclaredClasses();
for (Class<?> clazz : declaredClasses) {
registerClass(classLoader, clazz.getName(), methods, fields, false);
registerClass(classLoader, clazz.getName(), methods, fields, false, reflectiveClass);
}
} catch (ClassNotFoundException e) {
log.warnf(e, "Failed to load Class %s", className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.function.BooleanSupplier;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
Expand Down Expand Up @@ -81,9 +80,6 @@ public final class TestProcessor {
static DotName TEST_ANNOTATION = DotName.createSimple(TestAnnotation.class.getName());
static DotName TEST_ANNOTATION_SCOPE = DotName.createSimple(ApplicationScoped.class.getName());

@Inject
BuildProducer<NativeImageResourceBuildItem> resource;

TestConfigRoot configRoot;
TestBuildTimeConfig buildTimeConfig;
TestBuildAndRunTimeConfig buildAndRunTimeConfig;
Expand Down Expand Up @@ -125,7 +121,7 @@ LogHandlerBuildItem registerAdditionalLogHandler(final AdditionalLogHandlerValue
}

@BuildStep
void registerNativeImageResources() {
void registerNativeImageResources(BuildProducer<NativeImageResourceBuildItem> resource) {
resource.produce(new NativeImageResourceBuildItem("/DSAPublicKey.encoded"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ public class BeanArchiveProcessor {
@Inject
List<GeneratedBeanBuildItem> generatedBeans;

@Inject
BuildProducer<GeneratedClassBuildItem> generatedClass;

ArcConfig config;

@BuildStep
public BeanArchiveIndexBuildItem build(LiveReloadBuildItem liveReloadBuildItem) throws Exception {
public BeanArchiveIndexBuildItem build(LiveReloadBuildItem liveReloadBuildItem,
BuildProducer<GeneratedClassBuildItem> generatedClass) throws Exception {

// First build an index from application archives
IndexView applicationIndex = buildApplicationIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,22 @@ public class JacksonProcessor {
private static final List<String> MODULES_NAMES_TO_AUTO_REGISTER = Arrays.asList(TIME_MODULE, JDK8_MODULE,
PARAMETER_NAMES_MODULE);

@Inject
BuildProducer<ReflectiveClassBuildItem> reflectiveClass;

@Inject
BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchyClass;

@Inject
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethod;

@Inject
BuildProducer<AdditionalBeanBuildItem> additionalBeans;

@Inject
CombinedIndexBuildItem combinedIndexBuildItem;

@Inject
List<IgnoreJsonDeserializeClassBuildItem> ignoreJsonDeserializeClassBuildItems;

@BuildStep
CapabilityBuildItem register() {
addReflectiveClass(true, false,
"com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector",
"com.fasterxml.jackson.databind.ser.std.SqlDateSerializer",
"com.fasterxml.jackson.databind.ser.std.SqlTimeSerializer");
CapabilityBuildItem register(
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchyClass,
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethod,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
reflectiveClass.produce(
new ReflectiveClassBuildItem(true, false, "com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector",
"com.fasterxml.jackson.databind.ser.std.SqlDateSerializer",
"com.fasterxml.jackson.databind.ser.std.SqlTimeSerializer"));

IndexView index = combinedIndexBuildItem.getIndex();

Expand All @@ -103,14 +95,14 @@ CapabilityBuildItem register() {
if (CLASS.equals(annotationTarget.kind())) {
DotName dotName = annotationTarget.asClass().name();
if (!ignoredDotNames.contains(dotName)) {
addReflectiveHierarchyClass(dotName);
addReflectiveHierarchyClass(dotName, reflectiveHierarchyClass);
}

AnnotationValue annotationValue = deserializeInstance.value("builder");
if (null != annotationValue && AnnotationValue.Kind.CLASS.equals(annotationValue.kind())) {
DotName builderClassName = annotationValue.asClass().name();
if (!BUILDER_VOID.equals(builderClassName)) {
addReflectiveHierarchyClass(builderClassName);
addReflectiveHierarchyClass(builderClassName, reflectiveHierarchyClass);
}
}
}
Expand Down Expand Up @@ -151,18 +143,15 @@ CapabilityBuildItem register() {
return new CapabilityBuildItem(Capability.JACKSON);
}

private void addReflectiveHierarchyClass(DotName className) {
private void addReflectiveHierarchyClass(DotName className,
BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchyClass) {
Type jandexType = Type.create(className, Type.Kind.CLASS);
reflectiveHierarchyClass.produce(new ReflectiveHierarchyBuildItem.Builder()
.type(jandexType)
.source(getClass().getSimpleName() + " > " + jandexType.name().toString())
.build());
}

private void addReflectiveClass(boolean methods, boolean fields, String... className) {
reflectiveClass.produce(new ReflectiveClassBuildItem(methods, fields, className));
}

@BuildStep
void autoRegisterModules(BuildProducer<ClassPathJacksonModuleBuildItem> classPathJacksonModules) {
for (String module : MODULES_NAMES_TO_AUTO_REGISTER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.Optional;

import javax.inject.Inject;

import io.jaegertracing.internal.JaegerTracer;
import io.quarkus.deployment.Capability;
import io.quarkus.deployment.Feature;
Expand All @@ -25,9 +23,6 @@

public class JaegerProcessor {

@Inject
BuildProducer<ExtensionSslNativeSupportBuildItem> extensionSslNativeSupport;

@BuildStep(onlyIf = NativeBuild.class)
@Record(ExecutionTime.STATIC_INIT)
void setVersion(JaegerDeploymentRecorder jdr) {
Expand All @@ -36,12 +31,10 @@ void setVersion(JaegerDeploymentRecorder jdr) {

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
void setupTracer(JaegerDeploymentRecorder jdr, JaegerBuildTimeConfig buildTimeConfig, JaegerConfig jaeger,
ExtensionSslNativeSupportBuildItem setupTracer(JaegerDeploymentRecorder jdr, JaegerBuildTimeConfig buildTimeConfig,
JaegerConfig jaeger,
ApplicationConfig appConfig, Optional<MetricsCapabilityBuildItem> metricsCapability) {

// Indicates that this extension would like the SSL support to be enabled
extensionSslNativeSupport.produce(new ExtensionSslNativeSupportBuildItem(Feature.JAEGER.getName()));

if (buildTimeConfig.enabled) {
if (buildTimeConfig.metricsEnabled && metricsCapability.isPresent()) {
if (metricsCapability.get().metricsSupported(MetricsFactory.MICROMETER)) {
Expand All @@ -53,11 +46,14 @@ void setupTracer(JaegerDeploymentRecorder jdr, JaegerBuildTimeConfig buildTimeCo
jdr.registerTracerWithoutMetrics(jaeger, appConfig);
}
}

// Indicates that this extension would like the SSL support to be enabled
return new ExtensionSslNativeSupportBuildItem(Feature.JAEGER.getName());
}

@BuildStep
public void build(BuildProducer<FeatureBuildItem> feature) {
feature.produce(new FeatureBuildItem(Feature.JAEGER));
public FeatureBuildItem build() {
return new FeatureBuildItem(Feature.JAEGER);
}

@BuildStep
Expand All @@ -69,11 +65,11 @@ public void capability(JaegerBuildTimeConfig buildTimeConfig,
}

@BuildStep
public void reflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
reflectiveClasses.produce(ReflectiveClassBuildItem
public ReflectiveClassBuildItem reflectiveClasses() {
return ReflectiveClassBuildItem
.builder("io.jaegertracing.internal.samplers.http.SamplingStrategyResponse",
"io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy")
.finalFieldsWritable(true)
.build());
.build();
}
}
Loading

0 comments on commit a3c4231

Please sign in to comment.