davsclaus commented on a change in pull request #1344: URL: https://github.com/apache/camel-quarkus/pull/1344#discussion_r440017356
########## File path: extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelNativeImageProcessor.java ########## @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.core.deployment; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import io.quarkus.deployment.ApplicationArchive; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem; +import org.apache.camel.CamelContext; +import org.apache.camel.Component; +import org.apache.camel.Consumer; +import org.apache.camel.Converter; +import org.apache.camel.Endpoint; +import org.apache.camel.Producer; +import org.apache.camel.TypeConverter; +import org.apache.camel.impl.engine.DefaultComponentResolver; +import org.apache.camel.impl.engine.DefaultDataFormatResolver; +import org.apache.camel.impl.engine.DefaultLanguageResolver; +import org.apache.camel.quarkus.core.CamelConfig; +import org.apache.camel.quarkus.core.CamelConfig.ReflectionConfig; +import org.apache.camel.quarkus.core.CamelConfig.ResourcesConfig; +import org.apache.camel.quarkus.core.CamelConfigFlags; +import org.apache.camel.quarkus.core.deployment.spi.CamelRoutesBuilderClassBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelServiceBuildItem; +import org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem; +import org.apache.camel.quarkus.core.deployment.util.CamelSupport; +import org.apache.camel.quarkus.core.deployment.util.PathFilter; +import org.apache.camel.spi.DataFormat; +import org.apache.camel.spi.ExchangeFormatter; +import org.apache.camel.spi.PropertiesComponent; +import org.apache.camel.spi.ScheduledPollConsumerScheduler; +import org.apache.camel.spi.StreamCachingStrategy; +import org.apache.camel.support.CamelContextHelper; +import org.jboss.jandex.AnnotationTarget.Kind; +import org.jboss.jandex.AnnotationValue; +import org.jboss.jandex.ClassInfo; +import org.jboss.jandex.DotName; +import org.jboss.jandex.IndexView; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static org.apache.commons.lang3.ClassUtils.getPackageName; + +public class CamelNativeImageProcessor { + private static final Logger LOGGER = LoggerFactory.getLogger(CamelNativeImageProcessor.class); + + private static final List<Class<?>> CAMEL_REFLECTIVE_CLASSES = Arrays.asList( + Endpoint.class, + Consumer.class, + Producer.class, + TypeConverter.class, + ExchangeFormatter.class, + ScheduledPollConsumerScheduler.class, + Component.class, + CamelContext.class, + StreamCachingStrategy.class, + StreamCachingStrategy.SpoolUsedHeapMemoryLimit.class, + PropertiesComponent.class, + DataFormat.class); + + @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(); + // filter out camel-base converters which are automatically inlined in the + // CoreStaticTypeConverterLoader + // need to revisit with Camel 3.0.0-M3 which should improve this area Review comment: Yeah all converters are now non-reflective, so we should look at this in another ticket ########## File path: examples/timer-log-cdi/src/main/resources/application.properties ########## @@ -14,33 +14,17 @@ ## See the License for the specific language governing permissions and ## limitations under the License. ## --------------------------------------------------------------------------- + # # Quarkus # quarkus.banner.enabled = false -# -# Quarkus - Camel -# - -# disable build time route discovery as the only -# route defined in this project is based on CDI. -# -# This is not strictly needed for the correctness -# because camel-quarkus automatically -# filters auto-discovered routes that targets CDI -# but if is is known that routes are all leveraging -# CDI, this option will give some little boost to -# the build process -quarkus.camel.main.routes-discovery.enabled = false - -# -# Camel -# -camel.context.name = quarkus-camel-example-timer-log-cdi +# camel look-up beans using BeanManager so we don't want +# ArC to remove beans without injection points. +quarkus.arc.remove-unused-beans = false Review comment: Revisit this if this becomes a common use - I would like end users to not know or have to use such an option. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org