Search in sources :

Example 1 with CamelSupport

use of org.apache.camel.quarkus.core.deployment.util.CamelSupport in project camel-quarkus by apache.

the class MicroProfileHealthProcessor method camelHealthDiscovery.

@BuildStep(onlyIf = HealthEnabled.class)
List<CamelBeanBuildItem> camelHealthDiscovery(CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    List<CamelBeanBuildItem> buildItems = new ArrayList<>();
    Collection<ClassInfo> healthChecks = index.getAllKnownImplementors(CAMEL_HEALTH_CHECK_DOTNAME);
    Collection<ClassInfo> healthCheckRepositories = index.getAllKnownImplementors(CAMEL_HEALTH_CHECK_REPOSITORY_DOTNAME);
    Config config = ConfigProvider.getConfig();
    Predicate<ClassInfo> healthCheckFilter = classInfo -> {
        String className = classInfo.name().toString();
        if (className.equals(HealthCheckRegistryRepository.class.getName())) {
            // HealthCheckRegistryRepository is created internally by Camel
            return false;
        }
        if (className.equals(ContextHealthCheck.class.getName())) {
            return config.getOptionalValue("camel.health.contextEnabled", boolean.class).orElse(true);
        }
        if (className.equals(RoutesHealthCheckRepository.class.getName())) {
            return config.getOptionalValue("camel.health.routesEnabled", boolean.class).orElse(true);
        }
        if (className.equals(ConsumersHealthCheckRepository.class.getName())) {
            return config.getOptionalValue("camel.health.consumersEnabled", boolean.class).orElse(true);
        }
        return true;
    };
    // Create CamelBeanBuildItem to bind instances of HealthCheck to the camel registry
    healthChecks.stream().filter(CamelSupport::isConcrete).filter(CamelSupport::isPublic).filter(ClassInfo::hasNoArgsConstructor).filter(healthCheckFilter).map(this::createHealthCamelBeanBuildItem).forEach(buildItems::add);
    // Create CamelBeanBuildItem to bind instances of HealthCheckRepository to the camel registry
    healthCheckRepositories.stream().filter(CamelSupport::isConcrete).filter(CamelSupport::isPublic).filter(ClassInfo::hasNoArgsConstructor).filter(healthCheckFilter).map(this::createHealthCamelBeanBuildItem).forEach(buildItems::add);
    return buildItems;
}
Also used : Record(io.quarkus.deployment.annotations.Record) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) HealthCheckRepository(org.apache.camel.health.HealthCheckRepository) DotName(org.jboss.jandex.DotName) CamelServicePatternBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) HealthCheckRegistry(org.apache.camel.health.HealthCheckRegistry) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) BuildStep(io.quarkus.deployment.annotations.BuildStep) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) CamelServiceDestination(org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination) CamelMicroProfileHealthConfig(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthConfig) HealthCheckRegistryRepository(org.apache.camel.impl.health.HealthCheckRegistryRepository) HealthCheck(org.apache.camel.health.HealthCheck) IndexView(org.jboss.jandex.IndexView) CamelMicroProfileHealthRecorder(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthRecorder) ConsumersHealthCheckRepository(org.apache.camel.impl.health.ConsumersHealthCheckRepository) CamelContextCustomizerBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) ContextHealthCheck(org.apache.camel.impl.health.ContextHealthCheck) Config(org.eclipse.microprofile.config.Config) HealthBuildTimeConfig(io.quarkus.smallrye.health.deployment.HealthBuildTimeConfig) List(java.util.List) RoutesHealthCheckRepository(org.apache.camel.impl.health.RoutesHealthCheckRepository) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ObjectHelper(org.apache.camel.util.ObjectHelper) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) IndexView(org.jboss.jandex.IndexView) CamelMicroProfileHealthConfig(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthConfig) Config(org.eclipse.microprofile.config.Config) HealthBuildTimeConfig(io.quarkus.smallrye.health.deployment.HealthBuildTimeConfig) ArrayList(java.util.ArrayList) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with CamelSupport

use of org.apache.camel.quarkus.core.deployment.util.CamelSupport in project camel-quarkus by apache.

the class Hl7Processor method registerForReflection.

@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    // Register hapi model types for reflection
    String[] hapiStructureClasses = index.getAllKnownImplementors(DotName.createSimple(Structure.class.getName())).stream().map(classInfo -> classInfo.name().toString()).toArray(String[]::new);
    String[] hapiTypeClasses = index.getAllKnownImplementors(DotName.createSimple(Type.class.getName())).stream().map(classInfo -> classInfo.name().toString()).toArray(String[]::new);
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, hapiStructureClasses));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, hapiTypeClasses));
    // Beans that have the Hl7Terser annotation require reflective access
    String[] terserBeans = index.getAnnotations(DotName.createSimple(Hl7Terser.class.getName())).stream().map(AnnotationInstance::target).map(annotationTarget -> {
        if (annotationTarget.kind().equals(AnnotationTarget.Kind.FIELD)) {
            return annotationTarget.asType().asClass();
        } else if (annotationTarget.kind().equals(AnnotationTarget.Kind.METHOD)) {
            return annotationTarget.asMethod().declaringClass();
        } else if (annotationTarget.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) {
            return annotationTarget.asMethodParameter().method().declaringClass();
        }
        return null;
    }).filter(CamelSupport::isConcrete).map(classInfo -> classInfo.name().toString()).toArray(String[]::new);
    reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, terserBeans));
}
Also used : IndexView(org.jboss.jandex.IndexView) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) Hl7Terser(org.apache.camel.component.hl7.Hl7Terser) DotName(org.jboss.jandex.DotName) Structure(ca.uhn.hl7v2.model.Structure) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) IndexDependencyBuildItem(io.quarkus.deployment.builditem.IndexDependencyBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) AnnotationInstance(org.jboss.jandex.AnnotationInstance) AnnotationTarget(org.jboss.jandex.AnnotationTarget) Type(ca.uhn.hl7v2.model.Type) Type(ca.uhn.hl7v2.model.Type) IndexView(org.jboss.jandex.IndexView) Structure(ca.uhn.hl7v2.model.Structure) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) AnnotationInstance(org.jboss.jandex.AnnotationInstance) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with CamelSupport

use of org.apache.camel.quarkus.core.deployment.util.CamelSupport in project camel-quarkus by apache.

the class ZendeskProcessor method registerForReflection.

@BuildStep
ReflectiveClassBuildItem registerForReflection(CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    String[] zendeskModelClasses = index.getKnownClasses().stream().filter(CamelSupport::isConcrete).map(classInfo -> classInfo.name().toString()).filter(className -> className.startsWith("org.zendesk.client.v2.model")).toArray(String[]::new);
    return new ReflectiveClassBuildItem(true, false, zendeskModelClasses);
}
Also used : IndexView(org.jboss.jandex.IndexView) BuildStep(io.quarkus.deployment.annotations.BuildStep) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) AdditionalApplicationArchiveMarkerBuildItem(io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) IndexView(org.jboss.jandex.IndexView) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 4 with CamelSupport

use of org.apache.camel.quarkus.core.deployment.util.CamelSupport in project camel-quarkus by apache.

the class CamelNativeImageProcessor method reflectiveItems.

@BuildStep
void reflectiveItems(CombinedIndexBuildItem combinedIndex, BuildProducer<ReflectiveClassBuildItem> reflectiveClass, BuildProducer<ReflectiveMethodBuildItem> reflectiveMethod) {
    final IndexView view = combinedIndex.getIndex();
    CAMEL_REFLECTIVE_CLASSES.stream().map(Class::getName).map(DotName::createSimple).map(view::getAllKnownImplementors).flatMap(Collection::stream).filter(CamelSupport::isPublic).forEach(v -> reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, v.name().toString())));
    DotName converter = DotName.createSimple(Converter.class.getName());
    List<ClassInfo> converterClasses = view.getAnnotations(converter).stream().filter(ai -> ai.target().kind() == Kind.CLASS).filter(ai -> {
        AnnotationValue av = ai.value("loader");
        boolean isLoader = av != null && av.asBoolean();
        // need to revisit with Camel 3.0.0-M3 which should improve this area
        if (ai.target().asClass().name().toString().startsWith("org.apache.camel.converter.")) {
            LOGGER.debug("Ignoring core " + ai + " " + ai.target().asClass().name());
            return false;
        } else if (isLoader) {
            LOGGER.debug("Ignoring " + ai + " " + ai.target().asClass().name());
            return false;
        } else {
            LOGGER.debug("Accepting " + ai + " " + ai.target().asClass().name());
            return true;
        }
    }).map(ai -> ai.target().asClass()).collect(Collectors.toList());
    LOGGER.debug("Converter classes: " + converterClasses);
    converterClasses.forEach(ci -> reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, ci.name().toString())));
    view.getAnnotations(converter).stream().filter(ai -> ai.target().kind() == Kind.METHOD).filter(ai -> converterClasses.contains(ai.target().asMethod().declaringClass())).map(ai -> ai.target().asMethod()).forEach(mi -> reflectiveMethod.produce(new ReflectiveMethodBuildItem(mi)));
}
Also used : PropertiesComponent(org.apache.camel.spi.PropertiesComponent) Arrays(java.util.Arrays) CamelContextHelper(org.apache.camel.support.CamelContextHelper) LoggerFactory(org.slf4j.LoggerFactory) Endpoint(org.apache.camel.Endpoint) CamelServicePatternBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) Consumer(org.apache.camel.Consumer) DefaultComponentResolver(org.apache.camel.impl.engine.DefaultComponentResolver) ReflectionConfig(org.apache.camel.quarkus.core.CamelConfig.ReflectionConfig) Path(java.nio.file.Path) ExchangeFormatter(org.apache.camel.spi.ExchangeFormatter) AnnotationValue(org.jboss.jandex.AnnotationValue) Collection(java.util.Collection) NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) ScheduledPollConsumerScheduler(org.apache.camel.spi.ScheduledPollConsumerScheduler) StreamCachingStrategy(org.apache.camel.spi.StreamCachingStrategy) CamelRoutesBuilderClassBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRoutesBuilderClassBuildItem) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) ResourcesConfig(org.apache.camel.quarkus.core.CamelConfig.ResourcesConfig) DotName(org.jboss.jandex.DotName) Component(org.apache.camel.Component) ArrayList(java.util.ArrayList) BuildStep(io.quarkus.deployment.annotations.BuildStep) ReflectiveMethodBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem) Kind(org.jboss.jandex.AnnotationTarget.Kind) ClassUtils.getPackageName(org.apache.commons.lang3.ClassUtils.getPackageName) DefaultDataFormatResolver(org.apache.camel.impl.engine.DefaultDataFormatResolver) IndexView(org.jboss.jandex.IndexView) CamelContext(org.apache.camel.CamelContext) Logger(org.slf4j.Logger) ApplicationArchivesBuildItem(io.quarkus.deployment.builditem.ApplicationArchivesBuildItem) Files(java.nio.file.Files) PathFilter(org.apache.camel.quarkus.core.deployment.util.PathFilter) Producer(org.apache.camel.Producer) DefaultLanguageResolver(org.apache.camel.impl.engine.DefaultLanguageResolver) Converter(org.apache.camel.Converter) ApplicationArchive(io.quarkus.deployment.ApplicationArchive) DataFormat(org.apache.camel.spi.DataFormat) TypeConverter(org.apache.camel.TypeConverter) CamelConfig(org.apache.camel.quarkus.core.CamelConfig) CamelServiceBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServiceBuildItem) CamelConfigFlags(org.apache.camel.quarkus.core.CamelConfigFlags) ReflectiveMethodBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem) IndexView(org.jboss.jandex.IndexView) Collection(java.util.Collection) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter) AnnotationValue(org.jboss.jandex.AnnotationValue) DotName(org.jboss.jandex.DotName) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 5 with CamelSupport

use of org.apache.camel.quarkus.core.deployment.util.CamelSupport in project camel-quarkus by apache.

the class ServicenowProcessor method registerForReflection.

@BuildStep
void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    // Get candidate DTOs annotated with ServiceNowSysParm
    String[] serviceNowDtos = index.getAnnotations(DotName.createSimple(ServiceNowSysParm.class.getName())).stream().map(AnnotationInstance::target).filter(annotationTarget -> annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS)).map(AnnotationTarget::asClass).filter(CamelSupport::isConcrete).filter(CamelSupport::isPublic).map(classInfo -> classInfo.name().toString()).filter(className -> !className.startsWith("org.apache.camel.component.servicenow.model")).toArray(String[]::new);
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, serviceNowDtos));
    reflectiveClass.produce(new ReflectiveClassBuildItem(false, true, HTTPTransportFactory.class, ServiceNowExceptionModel.class));
}
Also used : HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) IndexView(org.jboss.jandex.IndexView) ExtensionSslNativeSupportBuildItem(io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) ServiceNowExceptionModel(org.apache.camel.component.servicenow.ServiceNowExceptionModel) DotName(org.jboss.jandex.DotName) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) BuildStep(io.quarkus.deployment.annotations.BuildStep) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) AnnotationInstance(org.jboss.jandex.AnnotationInstance) AnnotationTarget(org.jboss.jandex.AnnotationTarget) ServiceNowSysParm(org.apache.camel.component.servicenow.annotations.ServiceNowSysParm) ServiceNowSysParm(org.apache.camel.component.servicenow.annotations.ServiceNowSysParm) IndexView(org.jboss.jandex.IndexView) ServiceNowExceptionModel(org.apache.camel.component.servicenow.ServiceNowExceptionModel) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)5 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)5 CamelSupport (org.apache.camel.quarkus.core.deployment.util.CamelSupport)5 IndexView (org.jboss.jandex.IndexView)5 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)4 ReflectiveClassBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem)4 DotName (org.jboss.jandex.DotName)4 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 CamelServicePatternBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem)2 Structure (ca.uhn.hl7v2.model.Structure)1 Type (ca.uhn.hl7v2.model.Type)1 ApplicationArchive (io.quarkus.deployment.ApplicationArchive)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 Record (io.quarkus.deployment.annotations.Record)1 AdditionalApplicationArchiveMarkerBuildItem (io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem)1 ApplicationArchivesBuildItem (io.quarkus.deployment.builditem.ApplicationArchivesBuildItem)1 ExtensionSslNativeSupportBuildItem (io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem)1