use of org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem in project camel-quarkus by apache.
the class InjectionPointsProcessor method injectedComponents.
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
void injectedComponents(CombinedIndexBuildItem index, InjectionPointsRecorder recorder, BeanRegistrationPhaseBuildItem beanRegistrationPhase, BuildProducer<SyntheticBeanBuildItem> syntheticBeans, BuildProducer<CamelRuntimeTaskBuildItem> runtimeTasks, BuildProducer<BeanRegistrationPhaseBuildItem.BeanConfiguratorBuildItem> beanConfigurator) {
final Collection<ClassInfo> components = index.getIndex().getAllKnownImplementors(INTERFACE_NAME_COMPONENT);
final Set<String> created = new HashSet<>();
for (InjectionPointInfo injectionPoint : beanRegistrationPhase.getContext().get(BuildExtension.Key.INJECTION_POINTS)) {
if (injectionPoint.getTarget().kind() == AnnotationTarget.Kind.FIELD) {
FieldInfo target = injectionPoint.getTarget().asField();
if (!created.add(target.type().name().toString())) {
continue;
}
if (components.stream().anyMatch(ci -> Objects.equals(ci.name(), target.type().name()))) {
final AnnotationInstance named = target.annotation(ANNOTATION_NAME_NAMED);
final String componentName = named == null ? target.name() : named.value().asString();
final Supplier<?> creator = recorder.componentSupplier(componentName, target.type().toString());
LOGGER.debugf("Creating synthetic component bean [name=%s, type=%s]", componentName, target.type().name());
syntheticBeans.produce(syntheticBean(target.type().name(), creator));
}
}
if (injectionPoint.getTarget().kind() == AnnotationTarget.Kind.METHOD) {
final MethodInfo target = injectionPoint.getTarget().asMethod();
final List<Type> types = target.parameters();
for (int i = 0; i < types.size(); i++) {
Type type = types.get(0);
if (!created.add(type.name().toString())) {
continue;
}
if (components.stream().anyMatch(ci -> Objects.equals(ci.name(), type.name()))) {
final AnnotationInstance named = target.annotation(ANNOTATION_NAME_NAMED);
final String componentName = named == null ? target.parameterName(i) : named.value().asString();
final Supplier<?> creator = recorder.componentSupplier(componentName, type.toString());
LOGGER.debugf("Creating synthetic component bean [name=%s, type=%s]", componentName, type.name());
syntheticBeans.produce(syntheticBean(type.name(), creator));
}
}
}
}
// Ensure the task is executed before the runtime is assembled
runtimeTasks.produce(new CamelRuntimeTaskBuildItem("components-injection"));
// Methods using BeanRegistrationPhaseBuildItem should return/produce a BeanConfiguratorBuildItem
// otherwise the build step may be processed at the wrong time.
//
// See BeanRegistrationPhaseBuildItem javadoc
beanConfigurator.produce(new BeanRegistrationPhaseBuildItem.BeanConfiguratorBuildItem());
}
Aggregations