Search in sources :

Example 1 with CamelRecorder

use of org.apache.camel.quarkus.core.CamelRecorder in project camel-quarkus by apache.

the class CamelProcessor method typeConverterRegistry.

/*
     * Discover {@link TypeConverterLoader}.
     */
@SuppressWarnings("unchecked")
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelTypeConverterRegistryBuildItem typeConverterRegistry(CamelRecorder recorder, ApplicationArchivesBuildItem applicationArchives, List<CamelTypeConverterLoaderBuildItem> additionalLoaders, CombinedIndexBuildItem combinedIndex, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
    IndexView index = combinedIndex.getIndex();
    RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder.createTypeConverterRegistry();
    // 
    // This should be simplified by searching for classes implementing TypeConverterLoader but that
    // would lead to have org.apache.camel.impl.converter.AnnotationTypeConverterLoader taken into
    // account even if it should not.
    // 
    final ClassLoader TCCL = Thread.currentThread().getContextClassLoader();
    for (ApplicationArchive archive : applicationArchives.getAllApplicationArchives()) {
        for (Path root : archive.getRootDirs()) {
            Path path = root.resolve(BaseTypeConverterRegistry.META_INF_SERVICES_TYPE_CONVERTER_LOADER);
            if (!Files.isRegularFile(path)) {
                continue;
            }
            try {
                Files.readAllLines(path, StandardCharsets.UTF_8).stream().map(String::trim).filter(l -> !l.isEmpty()).filter(l -> !l.startsWith("#")).map(l -> (Class<? extends TypeConverterLoader>) CamelSupport.loadClass(l, TCCL)).forEach(loader -> recorder.addTypeConverterLoader(typeConverterRegistry, loader));
            } catch (IOException e) {
                throw new RuntimeException("Error discovering TypeConverterLoader", e);
            }
        }
    }
    Set<String> internalConverters = new HashSet<>();
    // ignore all @converters from org.apache.camel:camel-* dependencies
    for (ApplicationArchive archive : applicationArchives.getAllApplicationArchives()) {
        ArtifactKey artifactKey = archive.getKey();
        if (artifactKey != null && "org.apache.camel".equals(artifactKey.getGroupId()) && artifactKey.getArtifactId().startsWith("camel-")) {
            internalConverters.addAll(archive.getIndex().getAnnotations(DotName.createSimple(Converter.class.getName())).stream().filter(a -> a.target().kind() == AnnotationTarget.Kind.CLASS).map(a -> a.target().asClass().name().toString()).collect(Collectors.toSet()));
        }
    }
    Set<Class> convertersClasses = index.getAnnotations(DotName.createSimple(Converter.class.getName())).stream().filter(a -> a.target().kind() == AnnotationTarget.Kind.CLASS && (a.value("generateBulkLoader") == null || !a.value("generateBulkLoader").asBoolean()) && (a.value("generateLoader") == null || !a.value("generateLoader").asBoolean())).map(a -> a.target().asClass().name().toString()).filter(s -> !internalConverters.contains(s)).map(s -> CamelSupport.loadClass(s, TCCL)).collect(Collectors.toSet());
    recorder.loadAnnotatedConverters(typeConverterRegistry, convertersClasses);
    // 
    for (CamelTypeConverterLoaderBuildItem item : additionalLoaders) {
        recorder.addTypeConverterLoader(typeConverterRegistry, item.getValue());
    }
    return new CamelTypeConverterRegistryBuildItem(typeConverterRegistry);
}
Also used : Path(java.nio.file.Path) UnremovableBeanBuildItem(io.quarkus.arc.deployment.UnremovableBeanBuildItem) CamelComponentNameResolverBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelComponentNameResolverBuildItem) LoggerFactory(org.slf4j.LoggerFactory) Overridable(io.quarkus.deployment.annotations.Overridable) CamelTypeConverterRegistryBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelTypeConverterRegistryBuildItem) 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) Capabilities(io.quarkus.deployment.Capabilities) AdditionalBeanBuildItem(io.quarkus.arc.deployment.AdditionalBeanBuildItem) BaseTypeConverterRegistry(org.apache.camel.impl.converter.BaseTypeConverterRegistry) CamelModelJAXBContextFactoryBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelModelJAXBContextFactoryBuildItem) CamelRecorder(org.apache.camel.quarkus.core.CamelRecorder) CamelServiceDestination(org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination) AnnotationTarget(org.jboss.jandex.AnnotationTarget) Path(java.nio.file.Path) TypeConverterLoader(org.apache.camel.spi.TypeConverterLoader) Builder(org.apache.camel.quarkus.core.FastFactoryFinderResolver.Builder) BeanRegistrationPhaseBuildItem(io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem) Predicate(java.util.function.Predicate) CamelModelToXMLDumperBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelModelToXMLDumperBuildItem) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) Set(java.util.Set) NativeImageResourceBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) RoutesBuilderClassExcludeBuildItem(org.apache.camel.quarkus.core.deployment.spi.RoutesBuilderClassExcludeBuildItem) Modifier(java.lang.reflect.Modifier) CamelProducers(org.apache.camel.quarkus.core.CamelProducers) CamelRoutesBuilderClassBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRoutesBuilderClassBuildItem) ReflectiveClassBuildItem(io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem) Record(io.quarkus.deployment.annotations.Record) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) DotName(org.jboss.jandex.DotName) Type(org.jboss.jandex.Type) ContainerBeansBuildItem(org.apache.camel.quarkus.core.deployment.spi.ContainerBeansBuildItem) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) BuildStep(io.quarkus.deployment.annotations.BuildStep) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) RuntimeValue(io.quarkus.runtime.RuntimeValue) TypeConverterRegistry(org.apache.camel.spi.TypeConverterRegistry) IndexView(org.jboss.jandex.IndexView) CamelCapabilities(org.apache.camel.quarkus.core.CamelCapabilities) SchemaResource(org.apache.camel.quarkus.core.deployment.catalog.SchemaResource) CamelFactoryFinderResolverBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelFactoryFinderResolverBuildItem) Logger(org.slf4j.Logger) ApplicationArchivesBuildItem(io.quarkus.deployment.builditem.ApplicationArchivesBuildItem) FileUtils(org.apache.camel.quarkus.core.util.FileUtils) Files(java.nio.file.Files) PathFilter(org.apache.camel.quarkus.core.deployment.util.PathFilter) CamelTypeConverterLoaderBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelTypeConverterLoaderBuildItem) IOException(java.io.IOException) CamelServiceFilterBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem) BuildTimeCamelCatalog(org.apache.camel.quarkus.core.deployment.catalog.BuildTimeCamelCatalog) Converter(org.apache.camel.Converter) ApplicationArchive(io.quarkus.deployment.ApplicationArchive) CamelConfig(org.apache.camel.quarkus.core.CamelConfig) BuildTimeCamelCatalogBuildItem(org.apache.camel.quarkus.core.deployment.spi.BuildTimeCamelCatalogBuildItem) CamelServiceBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServiceBuildItem) BuildTimeJsonSchemaResolver(org.apache.camel.quarkus.core.deployment.catalog.BuildTimeJsonSchemaResolver) BuildExtension(io.quarkus.arc.processor.BuildExtension) CamelConfigFlags(org.apache.camel.quarkus.core.CamelConfigFlags) CamelServiceFilter(org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilter) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) CamelTypeConverterLoaderBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelTypeConverterLoaderBuildItem) IndexView(org.jboss.jandex.IndexView) CamelTypeConverterRegistryBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelTypeConverterRegistryBuildItem) IOException(java.io.IOException) ApplicationArchive(io.quarkus.deployment.ApplicationArchive) TypeConverterLoader(org.apache.camel.spi.TypeConverterLoader) BaseTypeConverterRegistry(org.apache.camel.impl.converter.BaseTypeConverterRegistry) TypeConverterRegistry(org.apache.camel.spi.TypeConverterRegistry) Converter(org.apache.camel.Converter) HashSet(java.util.HashSet) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with CamelRecorder

use of org.apache.camel.quarkus.core.CamelRecorder in project camel-quarkus by apache.

the class CamelRegistryProcessor method bindBeansToRegistry.

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
public void bindBeansToRegistry(CamelRecorder recorder, CamelConfig camelConfig, ApplicationArchivesBuildItem applicationArchives, ContainerBeansBuildItem containerBeans, CamelRegistryBuildItem registry, // CamelContextBuildItem placeholder ensures this build step runs after the CamelContext is created
CamelContextBuildItem camelContextBuildItem, List<CamelBeanBuildItem> registryItems, List<CamelServiceFilterBuildItem> serviceFilters, List<CamelServicePatternBuildItem> servicePatterns) {
    final ClassLoader TCCL = Thread.currentThread().getContextClassLoader();
    final PathFilter pathFilter = servicePatterns.stream().filter(patterns -> patterns.getDestination() == CamelServiceDestination.REGISTRY).collect(PathFilter.Builder::new, (builder, patterns) -> builder.patterns(patterns.isInclude(), patterns.getPatterns()), PathFilter.Builder::combine).include(camelConfig.service.registry.includePatterns).exclude(camelConfig.service.registry.excludePatterns).build();
    CamelSupport.services(applicationArchives, pathFilter).filter(si -> !containerBeans.getBeans().contains(si)).filter(si -> {
        // 
        // by default all the service found in META-INF/service/org/apache/camel are
        // bound to the registry but some of the services are then replaced or set
        // to the camel context directly by extension so it does not make sense to
        // instantiate them in this phase.
        // 
        boolean blacklisted = serviceFilters.stream().anyMatch(filter -> filter.getPredicate().test(si));
        if (blacklisted) {
            LOGGER.debug("Ignore service: {}", si);
        }
        return !blacklisted;
    }).forEach(si -> {
        LOGGER.debug("Binding bean with name: {}, type {}", si.name, si.type);
        recorder.bind(registry.getRegistry(), si.name, CamelSupport.loadClass(si.type, TCCL));
    });
    registryItems.stream().filter(item -> !containerBeans.getBeans().contains(item)).forEach(item -> {
        LOGGER.debug("Binding bean with name: {}, type {}", item.getName(), item.getType());
        if (item.getValue().isPresent()) {
            recorder.bind(registry.getRegistry(), item.getName(), CamelSupport.loadClass(item.getType(), TCCL), item.getValue().get());
        } else {
            // the instance of the service will be instantiated by the recorder, this avoid
            // creating a recorder for trivial services.
            recorder.bind(registry.getRegistry(), item.getName(), CamelSupport.loadClass(item.getType(), TCCL));
        }
    });
}
Also used : CamelRuntimeTaskBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem) Record(io.quarkus.deployment.annotations.Record) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) CamelContextBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem) Logger(org.slf4j.Logger) ApplicationArchivesBuildItem(io.quarkus.deployment.builditem.ApplicationArchivesBuildItem) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) CamelRuntimeBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem) PathFilter(org.apache.camel.quarkus.core.deployment.util.PathFilter) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) LoggerFactory(org.slf4j.LoggerFactory) CamelServiceFilterBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem) ContainerBeansBuildItem(org.apache.camel.quarkus.core.deployment.spi.ContainerBeansBuildItem) CamelRegistryBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRegistryBuildItem) CamelServicePatternBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep) List(java.util.List) CamelConfig(org.apache.camel.quarkus.core.CamelConfig) CamelRecorder(org.apache.camel.quarkus.core.CamelRecorder) CamelServiceDestination(org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination) PathFilter(org.apache.camel.quarkus.core.deployment.util.PathFilter) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with CamelRecorder

use of org.apache.camel.quarkus.core.CamelRecorder in project camel-quarkus by apache.

the class InjectionPointsProcessor method produceBeans.

void produceBeans(CamelRecorder recorder, List<CapabilityBuildItem> capabilities, BuildProducer<SyntheticBeanBuildItem> syntheticBeans, BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinitions, AtomicReference<Boolean> beanCapabilityAvailable, AnnotationInstance annot, final DotName fieldType, String annotationTarget, DotName declaringClass) {
    try {
        Class<?> clazz = Class.forName(fieldType.toString(), false, Thread.currentThread().getContextClassLoader());
        if (ProducerTemplate.class.isAssignableFrom(clazz)) {
            syntheticBeans.produce(SyntheticBeanBuildItem.configure(fieldType).setRuntimeInit().scope(Singleton.class).supplier(recorder.createProducerTemplate(annot.value().asString())).addQualifier(annot).done());
        /*
                 * Note that ProducerTemplate injection points not having @EndpointInject are produced via
                 * CamelProducers.camelProducerTemplate()
                 */
        } else if (FluentProducerTemplate.class.isAssignableFrom(clazz)) {
            syntheticBeans.produce(SyntheticBeanBuildItem.configure(fieldType).setRuntimeInit().scope(Singleton.class).supplier(recorder.createFluentProducerTemplate(annot.value().asString())).addQualifier(annot).done());
        /*
                 * Note that FluentProducerTemplate injection points not having @EndpointInject are produced via
                 * CamelProducers.camelFluentProducerTemplate()
                 */
        } else if (clazz.isInterface()) {
            if (beanCapabilityAvailable.get() == null) {
                beanCapabilityAvailable.set(capabilities.stream().map(CapabilityBuildItem::getName).anyMatch(feature -> CamelCapabilities.BEAN.equals(feature)));
            }
            if (!beanCapabilityAvailable.get()) {
                throw new IllegalStateException("Add camel-quarkus-bean dependency to be able to use @org.apache.camel.Produce on fields with interface type: " + fieldType.toString() + " " + annotationTarget + " in " + declaringClass.toString());
            }
            proxyDefinitions.produce(new NativeImageProxyDefinitionBuildItem(fieldType.toString()));
            syntheticBeans.produce(SyntheticBeanBuildItem.configure(fieldType).setRuntimeInit().scope(Singleton.class).supplier(recorder.produceProxy(clazz, annot.value().asString())).addQualifier(annot).done());
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : CamelRuntimeTaskBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem) SyntheticBeanBuildItem(io.quarkus.arc.deployment.SyntheticBeanBuildItem) Record(io.quarkus.deployment.annotations.Record) EndpointInject(org.apache.camel.EndpointInject) Logger(org.jboss.logging.Logger) DotName(org.jboss.jandex.DotName) Type(org.jboss.jandex.Type) Component(org.apache.camel.Component) Endpoint(org.apache.camel.Endpoint) ClassInfo(org.jboss.jandex.ClassInfo) FieldInfo(org.jboss.jandex.FieldInfo) Singleton(javax.inject.Singleton) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) Produce(org.apache.camel.Produce) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) BuildStep(io.quarkus.deployment.annotations.BuildStep) MethodInfo(org.jboss.jandex.MethodInfo) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) CamelRecorder(org.apache.camel.quarkus.core.CamelRecorder) Map(java.util.Map) Kind(org.jboss.jandex.AnnotationTarget.Kind) ProducerTemplate(org.apache.camel.ProducerTemplate) NativeImageProxyDefinitionBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem) AnnotationTarget(org.jboss.jandex.AnnotationTarget) Named(javax.inject.Named) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) CamelCapabilities(org.apache.camel.quarkus.core.CamelCapabilities) BeanRegistrationPhaseBuildItem(io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) InjectionPointsRecorder(org.apache.camel.quarkus.core.InjectionPointsRecorder) Set(java.util.Set) InjectionPointInfo(io.quarkus.arc.processor.InjectionPointInfo) Objects(java.util.Objects) QualifierRegistrarBuildItem(io.quarkus.arc.deployment.QualifierRegistrarBuildItem) AnnotationsTransformer(io.quarkus.arc.processor.AnnotationsTransformer) QualifierRegistrar(io.quarkus.arc.processor.QualifierRegistrar) List(java.util.List) AnnotationInstance(org.jboss.jandex.AnnotationInstance) Collections(java.util.Collections) BuildExtension(io.quarkus.arc.processor.BuildExtension) FluentProducerTemplate(org.apache.camel.FluentProducerTemplate) Singleton(javax.inject.Singleton) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) NativeImageProxyDefinitionBuildItem(io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)3 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)3 Record (io.quarkus.deployment.annotations.Record)3 List (java.util.List)3 CamelRecorder (org.apache.camel.quarkus.core.CamelRecorder)3 BeanRegistrationPhaseBuildItem (io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem)2 BuildExtension (io.quarkus.arc.processor.BuildExtension)2 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)2 ApplicationArchivesBuildItem (io.quarkus.deployment.builditem.ApplicationArchivesBuildItem)2 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 CamelCapabilities (org.apache.camel.quarkus.core.CamelCapabilities)2 CamelConfig (org.apache.camel.quarkus.core.CamelConfig)2 CamelRuntimeTaskBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem)2 CamelServiceDestination (org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination)2 CamelServiceFilterBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelServiceFilterBuildItem)2 CamelServicePatternBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem)2 ContainerBeansBuildItem (org.apache.camel.quarkus.core.deployment.spi.ContainerBeansBuildItem)2 CamelSupport (org.apache.camel.quarkus.core.deployment.util.CamelSupport)2