This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0354bc438d74b7d57cf6de3527b71c646d9043d1 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sat Mar 21 17:21:56 2020 +0100 CAMEL-14760: camel-main - Generate configurer for its own options --- core/camel-main/pom.xml | 22 ++- .../camel/ExtendedCamelContextConfigurer.java | 159 ++++++++++++++++++++ .../HystrixConfigurationPropertiesConfigurer.java | 85 +++++++++++ .../MainConfigurationPropertiesConfigurer.java | 161 +++++++++++++++++++++ ...ilience4jConfigurationPropertiesConfigurer.java | 61 ++++++++ .../RestConfigurationPropertiesConfigurer.java | 79 ++++++++++ .../apache/camel/configurer/ExtendedCamelContext | 2 + .../configurer/HystrixConfigurationProperties | 2 + .../camel/configurer/MainConfigurationProperties | 2 + .../configurer/Resilience4jConfigurationProperties | 2 + .../camel/configurer/RestConfigurationProperties | 2 + .../org/apache/camel/main/BaseMainSupport.java | 13 ++ .../camel/maven/packaging/MainConfigurerMojo.java | 153 ++++++++++++++++++++ .../packaging/PropertyMainConfigurerGenerator.java | 90 ++++++++++++ 14 files changed, 831 insertions(+), 2 deletions(-) diff --git a/core/camel-main/pom.xml b/core/camel-main/pom.xml index a126377..05570a0 100644 --- a/core/camel-main/pom.xml +++ b/core/camel-main/pom.xml @@ -17,7 +17,8 @@ limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -36,7 +37,6 @@ <label>core</label> </properties> - <dependencies> <!-- lets keep mandatory dependencies on top level so dependency tree is nicer --> @@ -128,4 +128,22 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <executions> + <execution> + <id>generate</id> + <goals> + <goal>generate-main-configurer</goal> + </goals> + <phase>process-classes</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + </project> diff --git a/core/camel-main/src/generated/java/org/apache/camel/ExtendedCamelContextConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/ExtendedCamelContextConfigurer.java new file mode 100644 index 0000000..77383e9 --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/ExtendedCamelContextConfigurer.java @@ -0,0 +1,159 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.ExtendedCamelContext; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class ExtendedCamelContextConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.ExtendedCamelContext target = (org.apache.camel.ExtendedCamelContext) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "allowaddingnewroutes": + case "AllowAddingNewRoutes": target.setAllowAddingNewRoutes(property(camelContext, boolean.class, value)); return true; + case "allowuseoriginalmessage": + case "AllowUseOriginalMessage": target.setAllowUseOriginalMessage(property(camelContext, java.lang.Boolean.class, value)); return true; + case "applicationcontextclassloader": + case "ApplicationContextClassLoader": target.setApplicationContextClassLoader(property(camelContext, java.lang.ClassLoader.class, value)); return true; + case "asyncprocessorawaitmanager": + case "AsyncProcessorAwaitManager": target.setAsyncProcessorAwaitManager(property(camelContext, org.apache.camel.spi.AsyncProcessorAwaitManager.class, value)); return true; + case "autostartup": + case "AutoStartup": target.setAutoStartup(property(camelContext, java.lang.Boolean.class, value)); return true; + case "backlogtracing": + case "BacklogTracing": target.setBacklogTracing(property(camelContext, java.lang.Boolean.class, value)); return true; + case "beanintrospection": + case "BeanIntrospection": target.setBeanIntrospection(property(camelContext, org.apache.camel.spi.BeanIntrospection.class, value)); return true; + case "caseinsensitiveheaders": + case "CaseInsensitiveHeaders": target.setCaseInsensitiveHeaders(property(camelContext, java.lang.Boolean.class, value)); return true; + case "classresolver": + case "ClassResolver": target.setClassResolver(property(camelContext, org.apache.camel.spi.ClassResolver.class, value)); return true; + case "clearmodelreferences": + case "ClearModelReferences": target.setClearModelReferences(property(camelContext, boolean.class, value)); return true; + case "componentnameresolver": + case "ComponentNameResolver": target.setComponentNameResolver(property(camelContext, org.apache.camel.spi.ComponentNameResolver.class, value)); return true; + case "componentresolver": + case "ComponentResolver": target.setComponentResolver(property(camelContext, org.apache.camel.spi.ComponentResolver.class, value)); return true; + case "configurerresolver": + case "ConfigurerResolver": target.setConfigurerResolver(property(camelContext, org.apache.camel.spi.ConfigurerResolver.class, value)); return true; + case "dataformatresolver": + case "DataFormatResolver": target.setDataFormatResolver(property(camelContext, org.apache.camel.spi.DataFormatResolver.class, value)); return true; + case "debugger": + case "Debugger": target.setDebugger(property(camelContext, org.apache.camel.spi.Debugger.class, value)); return true; + case "debugging": + case "Debugging": target.setDebugging(property(camelContext, java.lang.Boolean.class, value)); return true; + case "delayer": + case "Delayer": target.setDelayer(property(camelContext, java.lang.Long.class, value)); return true; + case "errorhandlerfactory": + case "ErrorHandlerFactory": target.setErrorHandlerFactory(property(camelContext, org.apache.camel.ErrorHandlerFactory.class, value)); return true; + case "eventnotificationapplicable": + case "EventNotificationApplicable": target.setEventNotificationApplicable(property(camelContext, boolean.class, value)); return true; + case "executorservicemanager": + case "ExecutorServiceManager": target.setExecutorServiceManager(property(camelContext, org.apache.camel.spi.ExecutorServiceManager.class, value)); return true; + case "factoryfinderresolver": + case "FactoryFinderResolver": target.setFactoryFinderResolver(property(camelContext, org.apache.camel.spi.FactoryFinderResolver.class, value)); return true; + case "globaloptions": + case "GlobalOptions": target.setGlobalOptions(property(camelContext, java.util.Map.class, value)); return true; + case "headersmapfactory": + case "HeadersMapFactory": target.setHeadersMapFactory(property(camelContext, org.apache.camel.spi.HeadersMapFactory.class, value)); return true; + case "inflightrepository": + case "InflightRepository": target.setInflightRepository(property(camelContext, org.apache.camel.spi.InflightRepository.class, value)); return true; + case "injector": + case "Injector": target.setInjector(property(camelContext, org.apache.camel.spi.Injector.class, value)); return true; + case "languageresolver": + case "LanguageResolver": target.setLanguageResolver(property(camelContext, org.apache.camel.spi.LanguageResolver.class, value)); return true; + case "loadtypeconverters": + case "LoadTypeConverters": target.setLoadTypeConverters(property(camelContext, java.lang.Boolean.class, value)); return true; + case "logexhaustedmessagebody": + case "LogExhaustedMessageBody": target.setLogExhaustedMessageBody(property(camelContext, java.lang.Boolean.class, value)); return true; + case "logmask": + case "LogMask": target.setLogMask(property(camelContext, java.lang.Boolean.class, value)); return true; + case "mdcloggingkeyspattern": + case "MDCLoggingKeysPattern": target.setMDCLoggingKeysPattern(property(camelContext, java.lang.String.class, value)); return true; + case "managementname": + case "ManagementName": target.setManagementName(property(camelContext, java.lang.String.class, value)); return true; + case "managementnamestrategy": + case "ManagementNameStrategy": target.setManagementNameStrategy(property(camelContext, org.apache.camel.spi.ManagementNameStrategy.class, value)); return true; + case "managementstrategy": + case "ManagementStrategy": target.setManagementStrategy(property(camelContext, org.apache.camel.spi.ManagementStrategy.class, value)); return true; + case "messagehistory": + case "MessageHistory": target.setMessageHistory(property(camelContext, java.lang.Boolean.class, value)); return true; + case "messagehistoryfactory": + case "MessageHistoryFactory": target.setMessageHistoryFactory(property(camelContext, org.apache.camel.spi.MessageHistoryFactory.class, value)); return true; + case "modeljaxbcontextfactory": + case "ModelJAXBContextFactory": target.setModelJAXBContextFactory(property(camelContext, org.apache.camel.spi.ModelJAXBContextFactory.class, value)); return true; + case "modeltoxmldumper": + case "ModelToXMLDumper": target.setModelToXMLDumper(property(camelContext, org.apache.camel.spi.ModelToXMLDumper.class, value)); return true; + case "name": + case "Name": target.setName(property(camelContext, java.lang.String.class, value)); return true; + case "namestrategy": + case "NameStrategy": target.setNameStrategy(property(camelContext, org.apache.camel.spi.CamelContextNameStrategy.class, value)); return true; + case "nodeidfactory": + case "NodeIdFactory": target.setNodeIdFactory(property(camelContext, org.apache.camel.spi.NodeIdFactory.class, value)); return true; + case "packagescanclassresolver": + case "PackageScanClassResolver": target.setPackageScanClassResolver(property(camelContext, org.apache.camel.spi.PackageScanClassResolver.class, value)); return true; + case "packagescanresourceresolver": + case "PackageScanResourceResolver": target.setPackageScanResourceResolver(property(camelContext, org.apache.camel.spi.PackageScanResourceResolver.class, value)); return true; + case "processorfactory": + case "ProcessorFactory": target.setProcessorFactory(property(camelContext, org.apache.camel.spi.ProcessorFactory.class, value)); return true; + case "propertiescomponent": + case "PropertiesComponent": target.setPropertiesComponent(property(camelContext, org.apache.camel.spi.PropertiesComponent.class, value)); return true; + case "reactiveexecutor": + case "ReactiveExecutor": target.setReactiveExecutor(property(camelContext, org.apache.camel.spi.ReactiveExecutor.class, value)); return true; + case "registry": + case "Registry": target.setRegistry(property(camelContext, org.apache.camel.spi.Registry.class, value)); return true; + case "restconfiguration": + case "RestConfiguration": target.setRestConfiguration(property(camelContext, org.apache.camel.spi.RestConfiguration.class, value)); return true; + case "restregistry": + case "RestRegistry": target.setRestRegistry(property(camelContext, org.apache.camel.spi.RestRegistry.class, value)); return true; + case "routecontroller": + case "RouteController": target.setRouteController(property(camelContext, org.apache.camel.spi.RouteController.class, value)); return true; + case "runtimecamelcatalog": + case "RuntimeCamelCatalog": target.setRuntimeCamelCatalog(property(camelContext, org.apache.camel.catalog.RuntimeCamelCatalog.class, value)); return true; + case "runtimeendpointregistry": + case "RuntimeEndpointRegistry": target.setRuntimeEndpointRegistry(property(camelContext, org.apache.camel.spi.RuntimeEndpointRegistry.class, value)); return true; + case "sslcontextparameters": + case "SSLContextParameters": target.setSSLContextParameters(property(camelContext, org.apache.camel.support.jsse.SSLContextParameters.class, value)); return true; + case "shutdownroute": + case "ShutdownRoute": target.setShutdownRoute(property(camelContext, org.apache.camel.ShutdownRoute.class, value)); return true; + case "shutdownrunningtask": + case "ShutdownRunningTask": target.setShutdownRunningTask(property(camelContext, org.apache.camel.ShutdownRunningTask.class, value)); return true; + case "shutdownstrategy": + case "ShutdownStrategy": target.setShutdownStrategy(property(camelContext, org.apache.camel.spi.ShutdownStrategy.class, value)); return true; + case "streamcaching": + case "StreamCaching": target.setStreamCaching(property(camelContext, java.lang.Boolean.class, value)); return true; + case "streamcachingstrategy": + case "StreamCachingStrategy": target.setStreamCachingStrategy(property(camelContext, org.apache.camel.spi.StreamCachingStrategy.class, value)); return true; + case "tracer": + case "Tracer": target.setTracer(property(camelContext, org.apache.camel.spi.Tracer.class, value)); return true; + case "tracing": + case "Tracing": target.setTracing(property(camelContext, java.lang.Boolean.class, value)); return true; + case "tracingpattern": + case "TracingPattern": target.setTracingPattern(property(camelContext, java.lang.String.class, value)); return true; + case "typeconverterregistry": + case "TypeConverterRegistry": target.setTypeConverterRegistry(property(camelContext, org.apache.camel.spi.TypeConverterRegistry.class, value)); return true; + case "typeconverterstatisticsenabled": + case "TypeConverterStatisticsEnabled": target.setTypeConverterStatisticsEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "unitofworkfactory": + case "UnitOfWorkFactory": target.setUnitOfWorkFactory(property(camelContext, org.apache.camel.spi.UnitOfWorkFactory.class, value)); return true; + case "usebreadcrumb": + case "UseBreadcrumb": target.setUseBreadcrumb(property(camelContext, java.lang.Boolean.class, value)); return true; + case "usedatatype": + case "UseDataType": target.setUseDataType(property(camelContext, java.lang.Boolean.class, value)); return true; + case "usemdclogging": + case "UseMDCLogging": target.setUseMDCLogging(property(camelContext, java.lang.Boolean.class, value)); return true; + case "uuidgenerator": + case "UuidGenerator": target.setUuidGenerator(property(camelContext, org.apache.camel.spi.UuidGenerator.class, value)); return true; + case "xmlroutesdefinitionloader": + case "XMLRoutesDefinitionLoader": target.setXMLRoutesDefinitionLoader(property(camelContext, org.apache.camel.spi.XMLRoutesDefinitionLoader.class, value)); return true; + default: return false; + } + } + +} + diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/HystrixConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/HystrixConfigurationPropertiesConfigurer.java new file mode 100644 index 0000000..aa8f79d --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/HystrixConfigurationPropertiesConfigurer.java @@ -0,0 +1,85 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.main.HystrixConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class HystrixConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.HystrixConfigurationProperties target = (org.apache.camel.main.HystrixConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "allowmaximumsizetodivergefromcoresize": + case "AllowMaximumSizeToDivergeFromCoreSize": target.setAllowMaximumSizeToDivergeFromCoreSize(property(camelContext, java.lang.Boolean.class, value)); return true; + case "circuitbreakerenabled": + case "CircuitBreakerEnabled": target.setCircuitBreakerEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "circuitbreakererrorthresholdpercentage": + case "CircuitBreakerErrorThresholdPercentage": target.setCircuitBreakerErrorThresholdPercentage(property(camelContext, java.lang.Integer.class, value)); return true; + case "circuitbreakerforceclosed": + case "CircuitBreakerForceClosed": target.setCircuitBreakerForceClosed(property(camelContext, java.lang.Boolean.class, value)); return true; + case "circuitbreakerforceopen": + case "CircuitBreakerForceOpen": target.setCircuitBreakerForceOpen(property(camelContext, java.lang.Boolean.class, value)); return true; + case "circuitbreakerrequestvolumethreshold": + case "CircuitBreakerRequestVolumeThreshold": target.setCircuitBreakerRequestVolumeThreshold(property(camelContext, java.lang.Integer.class, value)); return true; + case "circuitbreakersleepwindowinmilliseconds": + case "CircuitBreakerSleepWindowInMilliseconds": target.setCircuitBreakerSleepWindowInMilliseconds(property(camelContext, java.lang.Integer.class, value)); return true; + case "corepoolsize": + case "CorePoolSize": target.setCorePoolSize(property(camelContext, java.lang.Integer.class, value)); return true; + case "executionisolationsemaphoremaxconcurrentrequests": + case "ExecutionIsolationSemaphoreMaxConcurrentRequests": target.setExecutionIsolationSemaphoreMaxConcurrentRequests(property(camelContext, java.lang.Integer.class, value)); return true; + case "executionisolationstrategy": + case "ExecutionIsolationStrategy": target.setExecutionIsolationStrategy(property(camelContext, java.lang.String.class, value)); return true; + case "executionisolationthreadinterruptontimeout": + case "ExecutionIsolationThreadInterruptOnTimeout": target.setExecutionIsolationThreadInterruptOnTimeout(property(camelContext, java.lang.Boolean.class, value)); return true; + case "executiontimeoutenabled": + case "ExecutionTimeoutEnabled": target.setExecutionTimeoutEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "executiontimeoutinmilliseconds": + case "ExecutionTimeoutInMilliseconds": target.setExecutionTimeoutInMilliseconds(property(camelContext, java.lang.Integer.class, value)); return true; + case "fallbackenabled": + case "FallbackEnabled": target.setFallbackEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "fallbackisolationsemaphoremaxconcurrentrequests": + case "FallbackIsolationSemaphoreMaxConcurrentRequests": target.setFallbackIsolationSemaphoreMaxConcurrentRequests(property(camelContext, java.lang.Integer.class, value)); return true; + case "groupkey": + case "GroupKey": target.setGroupKey(property(camelContext, java.lang.String.class, value)); return true; + case "keepalivetime": + case "KeepAliveTime": target.setKeepAliveTime(property(camelContext, java.lang.Integer.class, value)); return true; + case "maxqueuesize": + case "MaxQueueSize": target.setMaxQueueSize(property(camelContext, java.lang.Integer.class, value)); return true; + case "maximumsize": + case "MaximumSize": target.setMaximumSize(property(camelContext, java.lang.Integer.class, value)); return true; + case "metricshealthsnapshotintervalinmilliseconds": + case "MetricsHealthSnapshotIntervalInMilliseconds": target.setMetricsHealthSnapshotIntervalInMilliseconds(property(camelContext, java.lang.Integer.class, value)); return true; + case "metricsrollingpercentilebucketsize": + case "MetricsRollingPercentileBucketSize": target.setMetricsRollingPercentileBucketSize(property(camelContext, java.lang.Integer.class, value)); return true; + case "metricsrollingpercentileenabled": + case "MetricsRollingPercentileEnabled": target.setMetricsRollingPercentileEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "metricsrollingpercentilewindowbuckets": + case "MetricsRollingPercentileWindowBuckets": target.setMetricsRollingPercentileWindowBuckets(property(camelContext, java.lang.Integer.class, value)); return true; + case "metricsrollingpercentilewindowinmilliseconds": + case "MetricsRollingPercentileWindowInMilliseconds": target.setMetricsRollingPercentileWindowInMilliseconds(property(camelContext, java.lang.Integer.class, value)); return true; + case "metricsrollingstatisticalwindowbuckets": + case "MetricsRollingStatisticalWindowBuckets": target.setMetricsRollingStatisticalWindowBuckets(property(camelContext, java.lang.Integer.class, value)); return true; + case "metricsrollingstatisticalwindowinmilliseconds": + case "MetricsRollingStatisticalWindowInMilliseconds": target.setMetricsRollingStatisticalWindowInMilliseconds(property(camelContext, java.lang.Integer.class, value)); return true; + case "queuesizerejectionthreshold": + case "QueueSizeRejectionThreshold": target.setQueueSizeRejectionThreshold(property(camelContext, java.lang.Integer.class, value)); return true; + case "requestlogenabled": + case "RequestLogEnabled": target.setRequestLogEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "threadpoolkey": + case "ThreadPoolKey": target.setThreadPoolKey(property(camelContext, java.lang.String.class, value)); return true; + case "threadpoolrollingnumberstatisticalwindowbuckets": + case "ThreadPoolRollingNumberStatisticalWindowBuckets": target.setThreadPoolRollingNumberStatisticalWindowBuckets(property(camelContext, java.lang.Integer.class, value)); return true; + case "threadpoolrollingnumberstatisticalwindowinmilliseconds": + case "ThreadPoolRollingNumberStatisticalWindowInMilliseconds": target.setThreadPoolRollingNumberStatisticalWindowInMilliseconds(property(camelContext, java.lang.Integer.class, value)); return true; + default: return false; + } + } + +} + diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java new file mode 100644 index 0000000..94897c4 --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java @@ -0,0 +1,161 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.main.MainConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class MainConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.MainConfigurationProperties target = (org.apache.camel.main.MainConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "allowaddingnewroutes": + case "AllowAddingNewRoutes": target.setAllowAddingNewRoutes(property(camelContext, boolean.class, value)); return true; + case "allowuseoriginalmessage": + case "AllowUseOriginalMessage": target.setAllowUseOriginalMessage(property(camelContext, boolean.class, value)); return true; + case "autoconfigurationenabled": + case "AutoConfigurationEnabled": target.setAutoConfigurationEnabled(property(camelContext, boolean.class, value)); return true; + case "autoconfigurationenvironmentvariablesenabled": + case "AutoConfigurationEnvironmentVariablesEnabled": target.setAutoConfigurationEnvironmentVariablesEnabled(property(camelContext, boolean.class, value)); return true; + case "autoconfigurationfailfast": + case "AutoConfigurationFailFast": target.setAutoConfigurationFailFast(property(camelContext, boolean.class, value)); return true; + case "autoconfigurationlogsummary": + case "AutoConfigurationLogSummary": target.setAutoConfigurationLogSummary(property(camelContext, boolean.class, value)); return true; + case "autostartup": + case "AutoStartup": target.setAutoStartup(property(camelContext, boolean.class, value)); return true; + case "autowirecomponentproperties": + case "AutowireComponentProperties": target.setAutowireComponentProperties(property(camelContext, boolean.class, value)); return true; + case "autowirecomponentpropertiesallowprivatesetter": + case "AutowireComponentPropertiesAllowPrivateSetter": target.setAutowireComponentPropertiesAllowPrivateSetter(property(camelContext, boolean.class, value)); return true; + case "autowirecomponentpropertiesdeep": + case "AutowireComponentPropertiesDeep": target.setAutowireComponentPropertiesDeep(property(camelContext, boolean.class, value)); return true; + case "autowirecomponentpropertiesnonnullonly": + case "AutowireComponentPropertiesNonNullOnly": target.setAutowireComponentPropertiesNonNullOnly(property(camelContext, boolean.class, value)); return true; + case "backlogtracing": + case "BacklogTracing": target.setBacklogTracing(property(camelContext, boolean.class, value)); return true; + case "beanintrospectionextendedstatistics": + case "BeanIntrospectionExtendedStatistics": target.setBeanIntrospectionExtendedStatistics(property(camelContext, boolean.class, value)); return true; + case "beanintrospectionlogginglevel": + case "BeanIntrospectionLoggingLevel": target.setBeanIntrospectionLoggingLevel(property(camelContext, org.apache.camel.LoggingLevel.class, value)); return true; + case "caseinsensitiveheaders": + case "CaseInsensitiveHeaders": target.setCaseInsensitiveHeaders(property(camelContext, boolean.class, value)); return true; + case "clearmodelreferences": + case "ClearModelReferences": target.setClearModelReferences(property(camelContext, boolean.class, value)); return true; + case "consumertemplatecachesize": + case "ConsumerTemplateCacheSize": target.setConsumerTemplateCacheSize(property(camelContext, int.class, value)); return true; + case "durationhitexitcode": + case "DurationHitExitCode": target.setDurationHitExitCode(property(camelContext, int.class, value)); return true; + case "durationmaxidleseconds": + case "DurationMaxIdleSeconds": target.setDurationMaxIdleSeconds(property(camelContext, int.class, value)); return true; + case "durationmaxmessages": + case "DurationMaxMessages": target.setDurationMaxMessages(property(camelContext, int.class, value)); return true; + case "durationmaxseconds": + case "DurationMaxSeconds": target.setDurationMaxSeconds(property(camelContext, int.class, value)); return true; + case "endpointbasicpropertybinding": + case "EndpointBasicPropertyBinding": target.setEndpointBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; + case "endpointbridgeerrorhandler": + case "EndpointBridgeErrorHandler": target.setEndpointBridgeErrorHandler(property(camelContext, boolean.class, value)); return true; + case "endpointlazystartproducer": + case "EndpointLazyStartProducer": target.setEndpointLazyStartProducer(property(camelContext, boolean.class, value)); return true; + case "endpointruntimestatisticsenabled": + case "EndpointRuntimeStatisticsEnabled": target.setEndpointRuntimeStatisticsEnabled(property(camelContext, boolean.class, value)); return true; + case "fileconfigurations": + case "FileConfigurations": target.setFileConfigurations(property(camelContext, java.lang.String.class, value)); return true; + case "hangupinterceptorenabled": + case "HangupInterceptorEnabled": target.setHangupInterceptorEnabled(property(camelContext, boolean.class, value)); return true; + case "inflightrepositorybrowseenabled": + case "InflightRepositoryBrowseEnabled": target.setInflightRepositoryBrowseEnabled(property(camelContext, boolean.class, value)); return true; + case "javaroutesexcludepattern": + case "JavaRoutesExcludePattern": target.setJavaRoutesExcludePattern(property(camelContext, java.lang.String.class, value)); return true; + case "javaroutesincludepattern": + case "JavaRoutesIncludePattern": target.setJavaRoutesIncludePattern(property(camelContext, java.lang.String.class, value)); return true; + case "jmxcreateconnector": + case "JmxCreateConnector": target.setJmxCreateConnector(property(camelContext, boolean.class, value)); return true; + case "jmxenabled": + case "JmxEnabled": target.setJmxEnabled(property(camelContext, boolean.class, value)); return true; + case "jmxmanagementnamepattern": + case "JmxManagementNamePattern": target.setJmxManagementNamePattern(property(camelContext, java.lang.String.class, value)); return true; + case "jmxmanagementstatisticslevel": + case "JmxManagementStatisticsLevel": target.setJmxManagementStatisticsLevel(property(camelContext, org.apache.camel.ManagementStatisticsLevel.class, value)); return true; + case "loadtypeconverters": + case "LoadTypeConverters": target.setLoadTypeConverters(property(camelContext, boolean.class, value)); return true; + case "logdebugmaxchars": + case "LogDebugMaxChars": target.setLogDebugMaxChars(property(camelContext, int.class, value)); return true; + case "logexhaustedmessagebody": + case "LogExhaustedMessageBody": target.setLogExhaustedMessageBody(property(camelContext, boolean.class, value)); return true; + case "logmask": + case "LogMask": target.setLogMask(property(camelContext, boolean.class, value)); return true; + case "mdcloggingkeyspattern": + case "MdcLoggingKeysPattern": target.setMdcLoggingKeysPattern(property(camelContext, java.lang.String.class, value)); return true; + case "messagehistory": + case "MessageHistory": target.setMessageHistory(property(camelContext, boolean.class, value)); return true; + case "name": + case "Name": target.setName(property(camelContext, java.lang.String.class, value)); return true; + case "packagescanroutebuilders": + case "PackageScanRouteBuilders": target.setPackageScanRouteBuilders(property(camelContext, java.lang.String.class, value)); return true; + case "producertemplatecachesize": + case "ProducerTemplateCacheSize": target.setProducerTemplateCacheSize(property(camelContext, int.class, value)); return true; + case "routefilterexcludepattern": + case "RouteFilterExcludePattern": target.setRouteFilterExcludePattern(property(camelContext, java.lang.String.class, value)); return true; + case "routefilterincludepattern": + case "RouteFilterIncludePattern": target.setRouteFilterIncludePattern(property(camelContext, java.lang.String.class, value)); return true; + case "routescollectorenabled": + case "RoutesCollectorEnabled": target.setRoutesCollectorEnabled(property(camelContext, boolean.class, value)); return true; + case "shutdownloginflightexchangesontimeout": + case "ShutdownLogInflightExchangesOnTimeout": target.setShutdownLogInflightExchangesOnTimeout(property(camelContext, boolean.class, value)); return true; + case "shutdownnowontimeout": + case "ShutdownNowOnTimeout": target.setShutdownNowOnTimeout(property(camelContext, boolean.class, value)); return true; + case "shutdownroutesinreverseorder": + case "ShutdownRoutesInReverseOrder": target.setShutdownRoutesInReverseOrder(property(camelContext, boolean.class, value)); return true; + case "shutdownsuppressloggingontimeout": + case "ShutdownSuppressLoggingOnTimeout": target.setShutdownSuppressLoggingOnTimeout(property(camelContext, boolean.class, value)); return true; + case "shutdowntimeout": + case "ShutdownTimeout": target.setShutdownTimeout(property(camelContext, int.class, value)); return true; + case "streamcachinganyspoolrules": + case "StreamCachingAnySpoolRules": target.setStreamCachingAnySpoolRules(property(camelContext, boolean.class, value)); return true; + case "streamcachingbuffersize": + case "StreamCachingBufferSize": target.setStreamCachingBufferSize(property(camelContext, int.class, value)); return true; + case "streamcachingenabled": + case "StreamCachingEnabled": target.setStreamCachingEnabled(property(camelContext, boolean.class, value)); return true; + case "streamcachingremovespooldirectorywhenstopping": + case "StreamCachingRemoveSpoolDirectoryWhenStopping": target.setStreamCachingRemoveSpoolDirectoryWhenStopping(property(camelContext, boolean.class, value)); return true; + case "streamcachingspoolcipher": + case "StreamCachingSpoolCipher": target.setStreamCachingSpoolCipher(property(camelContext, java.lang.String.class, value)); return true; + case "streamcachingspooldirectory": + case "StreamCachingSpoolDirectory": target.setStreamCachingSpoolDirectory(property(camelContext, java.lang.String.class, value)); return true; + case "streamcachingspoolthreshold": + case "StreamCachingSpoolThreshold": target.setStreamCachingSpoolThreshold(property(camelContext, long.class, value)); return true; + case "streamcachingspoolusedheapmemorylimit": + case "StreamCachingSpoolUsedHeapMemoryLimit": target.setStreamCachingSpoolUsedHeapMemoryLimit(property(camelContext, java.lang.String.class, value)); return true; + case "streamcachingspoolusedheapmemorythreshold": + case "StreamCachingSpoolUsedHeapMemoryThreshold": target.setStreamCachingSpoolUsedHeapMemoryThreshold(property(camelContext, int.class, value)); return true; + case "streamcachingstatisticsenabled": + case "StreamCachingStatisticsEnabled": target.setStreamCachingStatisticsEnabled(property(camelContext, boolean.class, value)); return true; + case "threadnamepattern": + case "ThreadNamePattern": target.setThreadNamePattern(property(camelContext, java.lang.String.class, value)); return true; + case "tracing": + case "Tracing": target.setTracing(property(camelContext, boolean.class, value)); return true; + case "tracingpattern": + case "TracingPattern": target.setTracingPattern(property(camelContext, java.lang.String.class, value)); return true; + case "usebreadcrumb": + case "UseBreadcrumb": target.setUseBreadcrumb(property(camelContext, boolean.class, value)); return true; + case "usedatatype": + case "UseDataType": target.setUseDataType(property(camelContext, boolean.class, value)); return true; + case "usemdclogging": + case "UseMdcLogging": target.setUseMdcLogging(property(camelContext, boolean.class, value)); return true; + case "xmlrests": + case "XmlRests": target.setXmlRests(property(camelContext, java.lang.String.class, value)); return true; + case "xmlroutes": + case "XmlRoutes": target.setXmlRoutes(property(camelContext, java.lang.String.class, value)); return true; + default: return false; + } + } + +} + diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/Resilience4jConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/Resilience4jConfigurationPropertiesConfigurer.java new file mode 100644 index 0000000..a45e877 --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/Resilience4jConfigurationPropertiesConfigurer.java @@ -0,0 +1,61 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.main.Resilience4jConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class Resilience4jConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.Resilience4jConfigurationProperties target = (org.apache.camel.main.Resilience4jConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "automatictransitionfromopentohalfopenenabled": + case "AutomaticTransitionFromOpenToHalfOpenEnabled": target.setAutomaticTransitionFromOpenToHalfOpenEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "bulkheadenabled": + case "BulkheadEnabled": target.setBulkheadEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "bulkheadmaxconcurrentcalls": + case "BulkheadMaxConcurrentCalls": target.setBulkheadMaxConcurrentCalls(property(camelContext, java.lang.Integer.class, value)); return true; + case "bulkheadmaxwaitduration": + case "BulkheadMaxWaitDuration": target.setBulkheadMaxWaitDuration(property(camelContext, java.lang.Integer.class, value)); return true; + case "circuitbreakerref": + case "CircuitBreakerRef": target.setCircuitBreakerRef(property(camelContext, java.lang.String.class, value)); return true; + case "configref": + case "ConfigRef": target.setConfigRef(property(camelContext, java.lang.String.class, value)); return true; + case "failureratethreshold": + case "FailureRateThreshold": target.setFailureRateThreshold(property(camelContext, java.lang.Float.class, value)); return true; + case "minimumnumberofcalls": + case "MinimumNumberOfCalls": target.setMinimumNumberOfCalls(property(camelContext, java.lang.Integer.class, value)); return true; + case "permittednumberofcallsinhalfopenstate": + case "PermittedNumberOfCallsInHalfOpenState": target.setPermittedNumberOfCallsInHalfOpenState(property(camelContext, java.lang.Integer.class, value)); return true; + case "slidingwindowsize": + case "SlidingWindowSize": target.setSlidingWindowSize(property(camelContext, java.lang.Integer.class, value)); return true; + case "slidingwindowtype": + case "SlidingWindowType": target.setSlidingWindowType(property(camelContext, java.lang.String.class, value)); return true; + case "slowcalldurationthreshold": + case "SlowCallDurationThreshold": target.setSlowCallDurationThreshold(property(camelContext, java.lang.Integer.class, value)); return true; + case "slowcallratethreshold": + case "SlowCallRateThreshold": target.setSlowCallRateThreshold(property(camelContext, java.lang.Float.class, value)); return true; + case "timeoutcancelrunningfuture": + case "TimeoutCancelRunningFuture": target.setTimeoutCancelRunningFuture(property(camelContext, java.lang.Boolean.class, value)); return true; + case "timeoutduration": + case "TimeoutDuration": target.setTimeoutDuration(property(camelContext, java.lang.Integer.class, value)); return true; + case "timeoutenabled": + case "TimeoutEnabled": target.setTimeoutEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "timeoutexecutorserviceref": + case "TimeoutExecutorServiceRef": target.setTimeoutExecutorServiceRef(property(camelContext, java.lang.String.class, value)); return true; + case "waitdurationinopenstate": + case "WaitDurationInOpenState": target.setWaitDurationInOpenState(property(camelContext, java.lang.Integer.class, value)); return true; + case "writablestacktraceenabled": + case "WritableStackTraceEnabled": target.setWritableStackTraceEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + default: return false; + } + } + +} + diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/RestConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/RestConfigurationPropertiesConfigurer.java new file mode 100644 index 0000000..f4346f7 --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/RestConfigurationPropertiesConfigurer.java @@ -0,0 +1,79 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.main.RestConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class RestConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.RestConfigurationProperties target = (org.apache.camel.main.RestConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "apicomponent": + case "ApiComponent": target.setApiComponent(property(camelContext, java.lang.String.class, value)); return true; + case "apicontextidpattern": + case "ApiContextIdPattern": target.setApiContextIdPattern(property(camelContext, java.lang.String.class, value)); return true; + case "apicontextlisting": + case "ApiContextListing": target.setApiContextListing(property(camelContext, boolean.class, value)); return true; + case "apicontextpath": + case "ApiContextPath": target.setApiContextPath(property(camelContext, java.lang.String.class, value)); return true; + case "apicontextrouteid": + case "ApiContextRouteId": target.setApiContextRouteId(property(camelContext, java.lang.String.class, value)); return true; + case "apihost": + case "ApiHost": target.setApiHost(property(camelContext, java.lang.String.class, value)); return true; + case "apiproperties": + case "ApiProperties": target.setApiProperties(property(camelContext, java.util.Map.class, value)); return true; + case "apivendorextension": + case "ApiVendorExtension": target.setApiVendorExtension(property(camelContext, boolean.class, value)); return true; + case "bindingmode": + case "BindingMode": target.setBindingMode(property(camelContext, java.lang.String.class, value)); return true; + case "clientrequestvalidation": + case "ClientRequestValidation": target.setClientRequestValidation(property(camelContext, boolean.class, value)); return true; + case "component": + case "Component": target.setComponent(property(camelContext, java.lang.String.class, value)); return true; + case "componentproperties": + case "ComponentProperties": target.setComponentProperties(property(camelContext, java.util.Map.class, value)); return true; + case "consumerproperties": + case "ConsumerProperties": target.setConsumerProperties(property(camelContext, java.util.Map.class, value)); return true; + case "contextpath": + case "ContextPath": target.setContextPath(property(camelContext, java.lang.String.class, value)); return true; + case "corsheaders": + case "CorsHeaders": target.setCorsHeaders(property(camelContext, java.util.Map.class, value)); return true; + case "dataformatproperties": + case "DataFormatProperties": target.setDataFormatProperties(property(camelContext, java.util.Map.class, value)); return true; + case "enablecors": + case "EnableCORS": target.setEnableCORS(property(camelContext, boolean.class, value)); return true; + case "endpointproperties": + case "EndpointProperties": target.setEndpointProperties(property(camelContext, java.util.Map.class, value)); return true; + case "host": + case "Host": target.setHost(property(camelContext, java.lang.String.class, value)); return true; + case "hostnameresolver": + case "HostNameResolver": target.setHostNameResolver(property(camelContext, java.lang.String.class, value)); return true; + case "jsondataformat": + case "JsonDataFormat": target.setJsonDataFormat(property(camelContext, java.lang.String.class, value)); return true; + case "port": + case "Port": target.setPort(property(camelContext, int.class, value)); return true; + case "producerapidoc": + case "ProducerApiDoc": target.setProducerApiDoc(property(camelContext, java.lang.String.class, value)); return true; + case "producercomponent": + case "ProducerComponent": target.setProducerComponent(property(camelContext, java.lang.String.class, value)); return true; + case "scheme": + case "Scheme": target.setScheme(property(camelContext, java.lang.String.class, value)); return true; + case "skipbindingonerrorcode": + case "SkipBindingOnErrorCode": target.setSkipBindingOnErrorCode(property(camelContext, boolean.class, value)); return true; + case "usexforwardheaders": + case "UseXForwardHeaders": target.setUseXForwardHeaders(property(camelContext, boolean.class, value)); return true; + case "xmldataformat": + case "XmlDataFormat": target.setXmlDataFormat(property(camelContext, java.lang.String.class, value)); return true; + default: return false; + } + } + +} + diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/ExtendedCamelContext b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/ExtendedCamelContext new file mode 100644 index 0000000..4d22c93 --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/ExtendedCamelContext @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.ExtendedCamelContextConfigurer diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/HystrixConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/HystrixConfigurationProperties new file mode 100644 index 0000000..e4e1217 --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/HystrixConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.HystrixConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/MainConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/MainConfigurationProperties new file mode 100644 index 0000000..41f0ff0 --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/MainConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.MainConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/Resilience4jConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/Resilience4jConfigurationProperties new file mode 100644 index 0000000..604dae6 --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/Resilience4jConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.Resilience4jConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/RestConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/RestConfigurationProperties new file mode 100644 index 0000000..45b7946 --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/RestConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.RestConfigurationPropertiesConfigurer diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java index 7519f52..fe1b829 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java @@ -81,6 +81,7 @@ public abstract class BaseMainSupport extends BaseService { private static final String SENSITIVE_KEYS = "passphrase|password|secretkey|accesstoken|clientsecret|authorizationtoken|sasljaasconfig"; protected final AtomicBoolean completed = new AtomicBoolean(false); + protected volatile CamelContext camelContext; protected volatile ProducerTemplate camelTemplate; @@ -140,6 +141,18 @@ public abstract class BaseMainSupport extends BaseService { configurer = ((Component) target).getComponentPropertyConfigurer(); } + if (configurer == null) { + String name = target.getClass().getSimpleName(); + if (target instanceof ExtendedCamelContext) { + // special for camel context itself as we have an extended configurer + name = "ExtendedCamelContext"; + } + + // see if there is a configurer for it + configurer = context.adapt(ExtendedCamelContext.class) + .getConfigurerResolver().resolvePropertyConfigurer(name, context); + } + try { // keep a reference of the original keys Map<String, Object> backup = new LinkedHashMap<>(properties); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/MainConfigurerMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/MainConfigurerMojo.java new file mode 100644 index 0000000..0cc5d5a --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/MainConfigurerMojo.java @@ -0,0 +1,153 @@ +/* + * 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.maven.packaging; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import org.apache.camel.tooling.model.BaseOptionModel; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.springframework.util.ReflectionUtils; + +/** + * Generate configurer classes for camel-main. + */ +@Mojo(name = "generate-main-configurer", threadSafe = true, defaultPhase = LifecyclePhase.PROCESS_CLASSES) +public class MainConfigurerMojo extends AbstractGeneratorMojo { + + /** + * The output directory for generated java source code + */ + @Parameter(defaultValue = "${project.basedir}/src/generated/java") + protected File srcOutDir; + + @Parameter(defaultValue = "${project.basedir}/src/generated/resources") + protected File resourcesOutputDir; + + private DynamicClassLoader projectClassLoader; + + private static final String[] CLASS_NAMES = new String[]{ + "org.apache.camel.main.MainConfigurationProperties", + "org.apache.camel.main.HystrixConfigurationProperties", + "org.apache.camel.main.Resilience4jConfigurationProperties", + "org.apache.camel.main.RestConfigurationProperties", + "org.apache.camel.ExtendedCamelContext"}; + + private static class Option extends BaseOptionModel { + // we just use name, type + + + public Option(String name, Class type) { + setName(name); + setJavaType(type.getName()); + } + } + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + List<String> cp = new ArrayList<>(); + cp.add(0, project.getBuild().getOutputDirectory()); + project.getDependencyArtifacts().forEach(a -> { + if (a.isResolved() && a.getFile() != null) { + cp.add(a.getFile().getPath()); + } + }); + projectClassLoader = DynamicClassLoader.createDynamicClassLoader(cp); + + for (String fqn : CLASS_NAMES) { + try { + List<Option> options = processClass(fqn); + generateConfigurer(fqn, options); + generateMetaInfConfigurer(fqn); + } catch (Exception e) { + throw new MojoExecutionException("Error processing class: " + fqn, e); + } + } + } + + private List<Option> processClass(String name) throws ClassNotFoundException { + List<Option> answer = new ArrayList<>(); + + Class clazz = projectClassLoader.loadClass(name); + // find all public setters + ReflectionUtils.doWithMethods(clazz, m -> { + boolean setter = m.getName().length() >= 4 && m.getName().startsWith("set") && Character.isUpperCase(m.getName().charAt(3)); + setter &= Modifier.isPublic(m.getModifiers()) && m.getParameterCount() == 1; + setter &= filterSetter(m); + if (setter) { + String t = Character.toUpperCase(m.getName().charAt(3)) + m.getName().substring(3 + 1); + answer.add(new Option(t, m.getParameterTypes()[0])); + } + }); + + return answer; + } + + private boolean filterSetter(Method setter) { + // special for some + if ("setBindingMode".equals(setter.getName())) { + // we only want the string setter + return setter.getParameterTypes()[0] == String.class; + } else if ("setHostNameResolver".equals(setter.getName())) { + // we only want the string setter + return setter.getParameterTypes()[0] == String.class; + } + + return true; + } + + private void generateConfigurer(String name, List<Option> options) throws IOException { + String pn = name.substring(0, name.lastIndexOf('.')); + String cn = name.substring(name.lastIndexOf('.') + 1) + "Configurer"; + String en = name; + String pfqn = name; + String psn = "org.apache.camel.support.component.PropertyConfigurerSupport"; + + StringWriter sw = new StringWriter(); + PropertyMainConfigurerGenerator.generatePropertyConfigurer(pn, cn, en, pfqn, psn, options, sw); + + String source = sw.toString(); + + String fileName = pn.replace('.', '/') + "/" + cn + ".java"; + boolean updated = updateResource(srcOutDir.toPath(), fileName, source); + if (updated) { + getLog().info("Updated " + fileName); + } + } + + protected void generateMetaInfConfigurer(String fqn) { + String name = fqn.substring(fqn.lastIndexOf('.') + 1); + try (Writer w = new StringWriter()) { + w.append("# " + GENERATED_MSG + "\n"); + w.append("class=").append(fqn + "Configurer").append("\n"); + updateResource(resourcesOutputDir.toPath(), "META-INF/services/org/apache/camel/configurer/" + name, w.toString()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyMainConfigurerGenerator.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyMainConfigurerGenerator.java new file mode 100644 index 0000000..1e98e55 --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyMainConfigurerGenerator.java @@ -0,0 +1,90 @@ +/* + * 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.maven.packaging; + +import java.io.IOException; +import java.io.Writer; +import java.util.Collection; +import java.util.Comparator; +import java.util.Optional; +import java.util.stream.Collectors; + +import org.apache.camel.tooling.model.BaseOptionModel; + +public final class PropertyMainConfigurerGenerator { + + private PropertyMainConfigurerGenerator() { + } + + public static void generatePropertyConfigurer(String pn, String cn, String en, + String pfqn, String psn, + Collection<? extends BaseOptionModel> options, Writer w) throws IOException { + w.write("/* " + AbstractGeneratorMojo.GENERATED_MSG + " */\n"); + w.write("package " + pn + ";\n"); + w.write("\n"); + w.write("import org.apache.camel.CamelContext;\n"); + w.write("import org.apache.camel.spi.GeneratedPropertyConfigurer;\n"); + w.write("import " + pfqn + ";\n"); + w.write("\n"); + w.write("/**\n"); + w.write(" * " + AbstractGeneratorMojo.GENERATED_MSG + "\n"); + w.write(" */\n"); + w.write("@SuppressWarnings(\"unchecked\")\n"); + w.write("public class " + cn + " extends " + psn + " implements GeneratedPropertyConfigurer {\n"); + w.write("\n"); + if (!options.isEmpty()) { + + // sort options A..Z so they always have same order + options = options.stream().sorted(Comparator.comparing(BaseOptionModel::getName)).collect(Collectors.toList()); + w.write(" @Override\n"); + w.write(" public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) {\n"); + if (!options.isEmpty()) { + w.write(" " + en + " target = (" + en + ") obj;\n"); + w.write(" switch (ignoreCase ? name.toLowerCase() : name) {\n"); + for (BaseOptionModel option : options) { + String getOrSet = option.getName(); + getOrSet = Character.toUpperCase(getOrSet.charAt(0)) + getOrSet.substring(1); + String setterLambda = setterLambda(getOrSet, option.getJavaType()); + if (!option.getName().toLowerCase().equals(option.getName())) { + w.write(String.format(" case \"%s\":\n", option.getName().toLowerCase())); + } + w.write(String.format(" case \"%s\": %s; return true;\n", option.getName(), setterLambda)); + } + w.write(" default: return false;\n"); + w.write(" }\n"); + } + w.write(" }\n"); + } + w.write("\n"); + w.write("}\n"); + w.write("\n"); + } + + private static String setterLambda(String getOrSet, String type) { + // type may contain generics so remove those + if (type.indexOf('<') != -1) { + type = type.substring(0, type.indexOf('<')); + } + type = type.replace('$', '.'); + getOrSet = "target.set" + getOrSet; + + // ((LogComponent) target).setGroupSize(property(camelContext, + // java.lang.Integer.class, value)) + return String.format("%s(property(camelContext, %s.class, value))", getOrSet, type); + } + +}