Search in sources :

Example 1 with ReflectiveMethodBuildItem

use of io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem 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)

Aggregations

ApplicationArchive (io.quarkus.deployment.ApplicationArchive)1 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 ApplicationArchivesBuildItem (io.quarkus.deployment.builditem.ApplicationArchivesBuildItem)1 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)1 NativeImageResourceBuildItem (io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem)1 ReflectiveClassBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem)1 ReflectiveMethodBuildItem (io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 CamelContext (org.apache.camel.CamelContext)1 Component (org.apache.camel.Component)1 Consumer (org.apache.camel.Consumer)1 Converter (org.apache.camel.Converter)1