Search in sources :

Example 1 with CapabilityBuildItem

use of io.quarkus.deployment.builditem.CapabilityBuildItem in project quarkus by quarkusio.

the class CapabilityAggregationStep method aggregateCapabilities.

/**
 * Aggregates all the capability build items. Not all the capabilities are configured in the extension descriptors.
 * Many are still produced by build steps directly.
 *
 * @param capabilities capability build items
 * @return aggregated capabilities
 */
@BuildStep
Capabilities aggregateCapabilities(List<CapabilityBuildItem> capabilities, CapabilitiesConfiguredInDescriptorsBuildItem configuredCaps, CurateOutcomeBuildItem curateOutcomeBuildItem) {
    final Map<String, Object> providedCapabilities = new HashMap<>();
    CapabilityErrors capabilityErrors = null;
    Map<String, List<String>> capsProvidedByBuildSteps = Collections.emptyMap();
    for (CapabilityBuildItem capabilityItem : capabilities) {
        final String provider = capabilityItem.getProvider();
        final String capability = capabilityItem.getName();
        final Object previous = providedCapabilities.put(capability, provider);
        if (previous != null) {
            if (previous instanceof String) {
                capabilityErrors = createIfNull(capabilityErrors);
                capabilityErrors.addConflict(capability, previous.toString());
                providedCapabilities.put(capability, capabilityErrors);
            } else {
                capabilityErrors = (CapabilityErrors) previous;
            }
            capabilityErrors.addConflict(capability, provider);
            providedCapabilities.put(capability, capabilityErrors);
        }
        if (!configuredCaps.names.contains(capability)) {
            if (capsProvidedByBuildSteps.isEmpty()) {
                capsProvidedByBuildSteps = new HashMap<>();
            }
            capsProvidedByBuildSteps.computeIfAbsent(provider, k -> new ArrayList<>(1)).add(capability);
        }
    }
    for (ExtensionCapabilities extCap : curateOutcomeBuildItem.getApplicationModel().getExtensionCapabilities()) {
        if (extCap.getRequiresCapabilities().isEmpty()) {
            continue;
        }
        for (String required : extCap.getRequiresCapabilities()) {
            if (!providedCapabilities.containsKey(required)) {
                capabilityErrors = createIfNull(capabilityErrors);
                capabilityErrors.addMissing(required, extCap.getExtension());
            }
        }
    }
    // capabilities are supposed to be configured in the extension descriptors and not produced directly by build steps
    if (!capsProvidedByBuildSteps.isEmpty()) {
        final StringWriter buf = new StringWriter();
        try (BufferedWriter writer = new BufferedWriter(buf)) {
            writer.append("The following capabilities were found to be missing from the processed extension descriptors:");
            for (Map.Entry<String, List<String>> provider : capsProvidedByBuildSteps.entrySet()) {
                for (String capability : provider.getValue()) {
                    writer.newLine();
                    writer.append(" - " + capability + " provided by ").append(provider.getKey());
                }
            }
            writer.newLine();
            writer.append("Please report this issue to the extension maintainers to get it fixed in the future releases.");
        } catch (IOException e) {
        }
        Logger.getLogger(CapabilityAggregationStep.class).warn(buf.toString());
    }
    if (capabilityErrors != null && !capabilityErrors.isEmpty()) {
        throw new IllegalStateException(capabilityErrors.report());
    }
    return new Capabilities(providedCapabilities.keySet());
}
Also used : BooleanSupplierFactoryBuildItem(io.quarkus.deployment.BooleanSupplierFactoryBuildItem) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) Logger(org.jboss.logging.Logger) Set(java.util.Set) IOException(java.io.IOException) HashMap(java.util.HashMap) SimpleBuildItem(io.quarkus.builder.item.SimpleBuildItem) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) HashSet(java.util.HashSet) Capabilities(io.quarkus.deployment.Capabilities) ExtensionCapabilities(io.quarkus.bootstrap.model.ExtensionCapabilities) BuildStep(io.quarkus.deployment.annotations.BuildStep) List(java.util.List) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) Map(java.util.Map) CapabilityErrors(io.quarkus.bootstrap.model.CapabilityErrors) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) Collections(java.util.Collections) HashMap(java.util.HashMap) ExtensionCapabilities(io.quarkus.bootstrap.model.ExtensionCapabilities) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CapabilityErrors(io.quarkus.bootstrap.model.CapabilityErrors) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) Capabilities(io.quarkus.deployment.Capabilities) ExtensionCapabilities(io.quarkus.bootstrap.model.ExtensionCapabilities) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with CapabilityBuildItem

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

Example 3 with CapabilityBuildItem

use of io.quarkus.deployment.builditem.CapabilityBuildItem 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, IndexView index, 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.valueWithDefault(index).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.valueWithDefault(index).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.valueWithDefault(index).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) IndexView(org.jboss.jandex.IndexView) 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)

Example 4 with CapabilityBuildItem

use of io.quarkus.deployment.builditem.CapabilityBuildItem in project quarkus by quarkusio.

the class CapabilityAggregationStep method provideCapabilities.

/**
 * Provides capabilities configured in the extension descriptors.
 *
 * @param producer capability build item producer
 * @param curateOutcomeBuildItem application model
 * @param supplierFactory boolean supplier factory
 */
@BuildStep
void provideCapabilities(BuildProducer<CapabilityBuildItem> producer, BuildProducer<CapabilitiesConfiguredInDescriptorsBuildItem> configuredCapsProducer, CurateOutcomeBuildItem curateOutcomeBuildItem, BooleanSupplierFactoryBuildItem supplierFactory) {
    final ApplicationModel appModel = curateOutcomeBuildItem.getApplicationModel();
    final Set<String> capabilityNames = new HashSet<>();
    for (ExtensionCapabilities contract : appModel.getExtensionCapabilities()) {
        final String provider = contract.getExtension();
        for (String capability : contract.getProvidesCapabilities()) {
            int conditionIndex = capability.indexOf('?');
            final String name = conditionIndex < 0 ? capability : capability.substring(0, conditionIndex);
            int testClassStart;
            boolean provide = true;
            while (conditionIndex > 0 && provide) {
                final boolean inv = conditionIndex < capability.length() - 1 && capability.charAt(conditionIndex + 1) == '!';
                testClassStart = conditionIndex + (inv ? 2 : 1);
                conditionIndex = capability.indexOf('?', testClassStart + 1);
                final String testClassName = capability.substring(testClassStart, conditionIndex > 0 ? conditionIndex : capability.length());
                Class<? extends BooleanSupplier> testClass;
                try {
                    testClass = Thread.currentThread().getContextClassLoader().loadClass(testClassName).asSubclass(BooleanSupplier.class);
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException("Failed to load the condition class " + testClassName + " for capability " + name, e);
                }
                provide = supplierFactory.get(testClass).getAsBoolean();
            }
            if (provide) {
                producer.produce(new CapabilityBuildItem(name, provider));
                capabilityNames.add(name);
            }
        }
    }
    configuredCapsProducer.produce(new CapabilitiesConfiguredInDescriptorsBuildItem(capabilityNames));
}
Also used : ExtensionCapabilities(io.quarkus.bootstrap.model.ExtensionCapabilities) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) CapabilityBuildItem(io.quarkus.deployment.builditem.CapabilityBuildItem) BooleanSupplier(java.util.function.BooleanSupplier) HashSet(java.util.HashSet) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildStep (io.quarkus.deployment.annotations.BuildStep)4 CapabilityBuildItem (io.quarkus.deployment.builditem.CapabilityBuildItem)4 HashSet (java.util.HashSet)4 BuildProducer (io.quarkus.deployment.annotations.BuildProducer)3 Collections (java.util.Collections)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 AnnotationsTransformerBuildItem (io.quarkus.arc.deployment.AnnotationsTransformerBuildItem)2 BeanRegistrationPhaseBuildItem (io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem)2 QualifierRegistrarBuildItem (io.quarkus.arc.deployment.QualifierRegistrarBuildItem)2 SyntheticBeanBuildItem (io.quarkus.arc.deployment.SyntheticBeanBuildItem)2 AnnotationsTransformer (io.quarkus.arc.processor.AnnotationsTransformer)2 BuildExtension (io.quarkus.arc.processor.BuildExtension)2 InjectionPointInfo (io.quarkus.arc.processor.InjectionPointInfo)2 QualifierRegistrar (io.quarkus.arc.processor.QualifierRegistrar)2 ApplicationModel (io.quarkus.bootstrap.model.ApplicationModel)2 ExtensionCapabilities (io.quarkus.bootstrap.model.ExtensionCapabilities)2 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)2 Record (io.quarkus.deployment.annotations.Record)2