Search in sources :

Example 1 with CamelContextCustomizerBuildItem

use of org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem in project camel-quarkus by apache.

the class CamelContextCustomizerTest method buildCustomizer.

static Consumer<BuildChainBuilder> buildCustomizer() {
    return new Consumer<BuildChainBuilder>() {

        @Override
        public void accept(BuildChainBuilder builder) {
            builder.addBuildStep(new BuildStep() {

                @Override
                public void execute(BuildContext context) {
                    String methodName = "execute";
                    BytecodeRecorderImpl bri = new BytecodeRecorderImpl(true, getClass().getSimpleName(), methodName, Integer.toString(methodName.hashCode()), true, s -> null);
                    RuntimeValue<CamelContextCustomizer> value = bri.newInstance(RestConfigurationCustomizer.class.getName());
                    context.produce(new CamelContextCustomizerBuildItem(value));
                    context.produce(new StaticBytecodeRecorderBuildItem(bri));
                }
            }).produces(CamelContextCustomizerBuildItem.class).produces(StaticBytecodeRecorderBuildItem.class).build();
        }
    };
}
Also used : CamelContextCustomizer(org.apache.camel.spi.CamelContextCustomizer) CamelContextCustomizerBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem) Consumer(java.util.function.Consumer) BuildContext(io.quarkus.builder.BuildContext) BuildChainBuilder(io.quarkus.builder.BuildChainBuilder) BuildStep(io.quarkus.builder.BuildStep) StaticBytecodeRecorderBuildItem(io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem) BytecodeRecorderImpl(io.quarkus.deployment.recording.BytecodeRecorderImpl)

Example 2 with CamelContextCustomizerBuildItem

use of org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem in project camel-quarkus by apache.

the class KameletProcessor method configureTemplates.

@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelContextCustomizerBuildItem configureTemplates(List<KameletResolverBuildItem> resolvers, KameletConfiguration configuration, KameletRecorder recorder) throws Exception {
    List<RouteTemplateDefinition> definitions = new ArrayList<>();
    List<KameletResolver> kameletResolvers = resolvers.stream().map(KameletResolverBuildItem::getResolver).sorted(Comparator.comparingInt(Ordered::getOrder)).collect(Collectors.toList());
    CamelContext context = new DefaultCamelContext();
    ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
    for (String id : configuration.identifiers.orElse(Collections.emptyList())) {
        for (KameletResolver resolver : kameletResolvers) {
            final Optional<Resource> resource = resolver.resolve(id, ecc);
            if (!resource.isPresent()) {
                continue;
            }
            Collection<RoutesBuilder> rbs = ecc.getRoutesLoader().findRoutesBuilders(resource.get());
            for (RoutesBuilder rb : rbs) {
                RouteBuilder routeBuilder = (RouteBuilder) rb;
                routeBuilder.configure();
                if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() == 0) {
                    throw new IllegalStateException("No kamelet template was created for " + "kamelet:" + id + ". It might be that the kamelet was malformed?");
                } else if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() > 1) {
                    throw new IllegalStateException("A kamelet is not supposed to create more than one route (" + "kamelet:" + id + "," + "routes: " + routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() + ")");
                }
                definitions.add(routeBuilder.getRouteTemplateCollection().getRouteTemplates().get(0));
            }
        }
    }
    return new CamelContextCustomizerBuildItem(recorder.createTemplateLoaderCustomizer(definitions));
}
Also used : CamelContext(org.apache.camel.CamelContext) ExtendedCamelContext(org.apache.camel.ExtendedCamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) ArrayList(java.util.ArrayList) Ordered(org.apache.camel.Ordered) Resource(org.apache.camel.spi.Resource) RouteTemplateDefinition(org.apache.camel.model.RouteTemplateDefinition) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContextCustomizerBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem) ExtendedCamelContext(org.apache.camel.ExtendedCamelContext) RoutesBuilder(org.apache.camel.RoutesBuilder) Record(io.quarkus.deployment.annotations.Record) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

CamelContextCustomizerBuildItem (org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem)2 BuildChainBuilder (io.quarkus.builder.BuildChainBuilder)1 BuildContext (io.quarkus.builder.BuildContext)1 BuildStep (io.quarkus.builder.BuildStep)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Record (io.quarkus.deployment.annotations.Record)1 StaticBytecodeRecorderBuildItem (io.quarkus.deployment.builditem.StaticBytecodeRecorderBuildItem)1 BytecodeRecorderImpl (io.quarkus.deployment.recording.BytecodeRecorderImpl)1 ArrayList (java.util.ArrayList)1 Consumer (java.util.function.Consumer)1 CamelContext (org.apache.camel.CamelContext)1 ExtendedCamelContext (org.apache.camel.ExtendedCamelContext)1 Ordered (org.apache.camel.Ordered)1 RoutesBuilder (org.apache.camel.RoutesBuilder)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 RouteTemplateDefinition (org.apache.camel.model.RouteTemplateDefinition)1 CamelContextCustomizer (org.apache.camel.spi.CamelContextCustomizer)1 Resource (org.apache.camel.spi.Resource)1