This is an automated email from the ASF dual-hosted git repository. lburgazzoli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit d7768d69513b9f9a82fdae7f3bbf9fa2d185cfab Author: Luca Burgazzoli <[email protected]> AuthorDate: Thu Feb 25 19:20:11 2021 +0100 CAMEL-12545: create a yaml based route loader (add support for auto generated TryDefinition) --- .../java/org/apache/camel/spi/Metadata.java | 1 - .../apache/camel/spi/annotations/DslProperty.java | 31 ++++++++ .../camel/model/CircuitBreakerDefinition.java | 2 + .../java/org/apache/camel/model/TryDefinition.java | 13 ++++ .../EndpointConsumerDeserializersResolver.java | 4 - .../EndpointProducerDeserializersResolver.java | 5 -- .../dsl/yaml/deserializers/ModelDeserializers.java | 58 ++++++++------ .../dsl/yaml/deserializers/CustomResolver.java | 4 +- .../deserializers/TryDefinitionDeserializer.java | 61 --------------- .../dsl/yaml/GenerateYamlDeserializersMojo.java | 24 +++--- .../maven/dsl/yaml/GenerateYamlSupportMojo.java | 32 +++++++- .../src/generated/resources/camel-yaml-dsl.json | 91 +++++++++++----------- .../org/apache/camel/dsl/yaml/TryTest.groovy | 39 ++++------ .../main/java/org/apache/camel/spi/Metadata.java | 1 - .../apache/camel/spi/annotations/DslProperty.java | 31 ++++++++ 15 files changed, 216 insertions(+), 181 deletions(-) diff --git a/core/camel-api/src/generated/java/org/apache/camel/spi/Metadata.java b/core/camel-api/src/generated/java/org/apache/camel/spi/Metadata.java index 19be69a..f37ea43 100644 --- a/core/camel-api/src/generated/java/org/apache/camel/spi/Metadata.java +++ b/core/camel-api/src/generated/java/org/apache/camel/spi/Metadata.java @@ -132,5 +132,4 @@ public @interface Metadata { * specify which options each implementation only supports. */ String includeProperties() default ""; - } diff --git a/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/DslProperty.java b/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/DslProperty.java new file mode 100644 index 0000000..b2bf04b --- /dev/null +++ b/core/camel-api/src/generated/java/org/apache/camel/spi/annotations/DslProperty.java @@ -0,0 +1,31 @@ +/* + * 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.spi.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Internal annotation used to include fields otherwise excluded because annotate with XmlTransient. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface DslProperty { + String name() default ""; +} diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/CircuitBreakerDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/CircuitBreakerDefinition.java index 77fb7d7..a248419 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/CircuitBreakerDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/CircuitBreakerDefinition.java @@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.DslProperty; @Metadata(label = "eip,routing,circuitbreaker") @XmlRootElement(name = "circuitBreaker") @@ -42,6 +43,7 @@ public class CircuitBreakerDefinition extends OutputDefinition<CircuitBreakerDef private FaultToleranceConfigurationDefinition faultToleranceConfiguration; @XmlAttribute private String configurationRef; + @DslProperty @XmlTransient private OnFallbackDefinition onFallback; diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/TryDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/TryDefinition.java index 9dd687e..069769c 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/TryDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/TryDefinition.java @@ -30,6 +30,7 @@ import javax.xml.bind.annotation.XmlTransient; import org.apache.camel.Predicate; import org.apache.camel.spi.AsPredicate; import org.apache.camel.spi.Metadata; +import org.apache.camel.spi.annotations.DslProperty; /** * Marks the beginning of a try, catch, finally block @@ -38,8 +39,10 @@ import org.apache.camel.spi.Metadata; @XmlRootElement(name = "doTry") @XmlAccessorType(XmlAccessType.FIELD) public class TryDefinition extends OutputDefinition<TryDefinition> { + @DslProperty @XmlTransient private List<CatchDefinition> catchClauses; + @DslProperty @XmlTransient private FinallyDefinition finallyClause; @XmlTransient @@ -136,6 +139,11 @@ public class TryDefinition extends OutputDefinition<TryDefinition> { // Properties // ------------------------------------------------------------------------- + @XmlTransient + public void setCatchClauses(List<CatchDefinition> catchClauses) { + this.catchClauses = catchClauses; + } + public List<CatchDefinition> getCatchClauses() { if (catchClauses == null) { checkInitialized(); @@ -143,6 +151,11 @@ public class TryDefinition extends OutputDefinition<TryDefinition> { return catchClauses; } + @XmlTransient + public void setFinallyClause(FinallyDefinition finallyClause) { + this.finallyClause = finallyClause; + } + public FinallyDefinition getFinallyClause() { if (finallyClause == null) { checkInitialized(); diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/EndpointConsumerDeserializersResolver.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/EndpointConsumerDeserializersResolver.java index 76a2a53..41507eb 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/EndpointConsumerDeserializersResolver.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/EndpointConsumerDeserializersResolver.java @@ -31,16 +31,12 @@ public final class EndpointConsumerDeserializersResolver implements YamlDeserial case "atomix-set": case "atomix-value": case "avro": - case "aws-ddbstream": - case "aws-s3": case "aws-swf": case "aws2-ddbstream": case "aws2-kinesis": case "aws2-s3": case "aws2-sqs": - case "azure-blob": case "azure-eventhubs": - case "azure-queue": case "azure-storage-blob": case "azure-storage-datalake": case "azure-storage-queue": diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/EndpointProducerDeserializersResolver.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/EndpointProducerDeserializersResolver.java index 8529c20..6f8e22d 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/EndpointProducerDeserializersResolver.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/EndpointProducerDeserializersResolver.java @@ -34,9 +34,6 @@ public final class EndpointProducerDeserializersResolver implements YamlDeserial case "atomix-set": case "atomix-value": case "avro": - case "aws-cw": - case "aws-ddb": - case "aws-s3": case "aws-swf": case "aws2-athena": case "aws2-cw": @@ -58,9 +55,7 @@ public final class EndpointProducerDeserializersResolver implements YamlDeserial case "aws2-sqs": case "aws2-sts": case "aws2-translate": - case "azure-blob": case "azure-eventhubs": - case "azure-queue": case "azure-storage-blob": case "azure-storage-datalake": case "azure-storage-queue": diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java index ac67574..3a3f325 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java @@ -1357,7 +1357,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { properties = { @YamlProperty(name = "inherit-error-handler", type = "boolean"), @YamlProperty(name = "otherwise", type = "object:org.apache.camel.model.OtherwiseDefinition"), - @YamlProperty(name = "when-clauses", type = "array:org.apache.camel.model.WhenDefinition"), + @YamlProperty(name = "when", type = "array:org.apache.camel.model.WhenDefinition"), @YamlProperty(name = "steps", type = "array:org.apache.camel.model.ProcessorDefinition") } ) @@ -3565,9 +3565,9 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "enable-cors", type = "string"), @YamlProperty(name = "method", type = "string"), @YamlProperty(name = "out-type", type = "string"), - @YamlProperty(name = "params", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), + @YamlProperty(name = "param", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), @YamlProperty(name = "produces", type = "string"), - @YamlProperty(name = "response-msgs", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), + @YamlProperty(name = "response-message", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), @YamlProperty(name = "route-id", type = "string"), @YamlProperty(name = "security", type = "array:org.apache.camel.model.rest.SecurityDefinition"), @YamlProperty(name = "skip-binding-on-error-code", type = "string"), @@ -4794,9 +4794,9 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "enable-cors", type = "string"), @YamlProperty(name = "method", type = "string"), @YamlProperty(name = "out-type", type = "string"), - @YamlProperty(name = "params", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), + @YamlProperty(name = "param", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), @YamlProperty(name = "produces", type = "string"), - @YamlProperty(name = "response-msgs", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), + @YamlProperty(name = "response-message", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), @YamlProperty(name = "route-id", type = "string"), @YamlProperty(name = "security", type = "array:org.apache.camel.model.rest.SecurityDefinition"), @YamlProperty(name = "skip-binding-on-error-code", type = "string"), @@ -5212,9 +5212,9 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "enable-cors", type = "string"), @YamlProperty(name = "method", type = "string"), @YamlProperty(name = "out-type", type = "string"), - @YamlProperty(name = "params", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), + @YamlProperty(name = "param", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), @YamlProperty(name = "produces", type = "string"), - @YamlProperty(name = "response-msgs", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), + @YamlProperty(name = "response-message", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), @YamlProperty(name = "route-id", type = "string"), @YamlProperty(name = "security", type = "array:org.apache.camel.model.rest.SecurityDefinition"), @YamlProperty(name = "skip-binding-on-error-code", type = "string"), @@ -8699,9 +8699,9 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "enable-cors", type = "string"), @YamlProperty(name = "method", type = "string"), @YamlProperty(name = "out-type", type = "string"), - @YamlProperty(name = "params", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), + @YamlProperty(name = "param", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), @YamlProperty(name = "produces", type = "string"), - @YamlProperty(name = "response-msgs", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), + @YamlProperty(name = "response-message", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), @YamlProperty(name = "route-id", type = "string"), @YamlProperty(name = "security", type = "array:org.apache.camel.model.rest.SecurityDefinition"), @YamlProperty(name = "skip-binding-on-error-code", type = "string"), @@ -9031,9 +9031,9 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "enable-cors", type = "string"), @YamlProperty(name = "method", type = "string"), @YamlProperty(name = "out-type", type = "string"), - @YamlProperty(name = "params", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), + @YamlProperty(name = "param", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), @YamlProperty(name = "produces", type = "string"), - @YamlProperty(name = "response-msgs", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), + @YamlProperty(name = "response-message", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), @YamlProperty(name = "route-id", type = "string"), @YamlProperty(name = "security", type = "array:org.apache.camel.model.rest.SecurityDefinition"), @YamlProperty(name = "skip-binding-on-error-code", type = "string"), @@ -9361,9 +9361,9 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "enable-cors", type = "string"), @YamlProperty(name = "method", type = "string"), @YamlProperty(name = "out-type", type = "string"), - @YamlProperty(name = "params", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), + @YamlProperty(name = "param", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), @YamlProperty(name = "produces", type = "string"), - @YamlProperty(name = "response-msgs", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), + @YamlProperty(name = "response-message", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), @YamlProperty(name = "route-id", type = "string"), @YamlProperty(name = "security", type = "array:org.apache.camel.model.rest.SecurityDefinition"), @YamlProperty(name = "skip-binding-on-error-code", type = "string"), @@ -10616,7 +10616,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "security-definitions", type = "object:org.apache.camel.model.rest.RestSecuritiesDefinition"), @YamlProperty(name = "skip-binding-on-error-code", type = "string"), @YamlProperty(name = "tag", type = "string"), - @YamlProperty(name = "verbs", type = "array:org.apache.camel.model.rest.VerbDefinition") + @YamlProperty(name = "verb", type = "array:org.apache.camel.model.rest.VerbDefinition") } ) public static class RestDefinitionDeserializer extends YamlDeserializerBase<RestDefinition> { @@ -11201,7 +11201,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { types = org.apache.camel.model.rest.RestsDefinition.class, order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, nodes = "rests", - properties = @YamlProperty(name = "rests", type = "array:org.apache.camel.model.rest.RestDefinition") + properties = @YamlProperty(name = "rest", type = "array:org.apache.camel.model.rest.RestDefinition") ) public static class RestsDefinitionDeserializer extends YamlDeserializerBase<RestsDefinition> { public RestsDefinitionDeserializer() { @@ -11640,7 +11640,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { types = org.apache.camel.model.RouteTemplatesDefinition.class, order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, nodes = "route-templates", - properties = @YamlProperty(name = "route-templates", type = "array:org.apache.camel.model.RouteTemplateDefinition") + properties = @YamlProperty(name = "route-template", type = "array:org.apache.camel.model.RouteTemplateDefinition") ) public static class RouteTemplatesDefinitionDeserializer extends YamlDeserializerBase<RouteTemplatesDefinition> { public RouteTemplatesDefinitionDeserializer() { @@ -11673,7 +11673,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { types = org.apache.camel.model.RoutesDefinition.class, order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, nodes = "routes", - properties = @YamlProperty(name = "routes", type = "array:org.apache.camel.model.RouteDefinition") + properties = @YamlProperty(name = "route", type = "array:org.apache.camel.model.RouteDefinition") ) public static class RoutesDefinitionDeserializer extends YamlDeserializerBase<RoutesDefinition> { public RoutesDefinitionDeserializer() { @@ -14612,6 +14612,8 @@ public final class ModelDeserializers extends YamlDeserializerSupport { order = org.apache.camel.dsl.yaml.common.YamlDeserializerResolver.ORDER_LOWEST - 1, nodes = "do-try", properties = { + @YamlProperty(name = "do-catch", type = "array:org.apache.camel.model.CatchDefinition"), + @YamlProperty(name = "do-finally", type = "object:org.apache.camel.model.FinallyDefinition"), @YamlProperty(name = "inherit-error-handler", type = "boolean"), @YamlProperty(name = "steps", type = "array:org.apache.camel.model.ProcessorDefinition") } @@ -14630,6 +14632,16 @@ public final class ModelDeserializers extends YamlDeserializerSupport { protected boolean setProperty(TryDefinition target, String propertyKey, String propertyName, Node node) { switch(propertyKey) { + case "do-catch": { + java.util.List<org.apache.camel.model.CatchDefinition> val = asFlatList(node, org.apache.camel.model.CatchDefinition.class); + target.setCatchClauses(val); + break; + } + case "do-finally": { + org.apache.camel.model.FinallyDefinition val = asType(node, org.apache.camel.model.FinallyDefinition.class); + target.setFinallyClause(val); + break; + } case "inherit-error-handler": { String val = asText(node); target.setInheritErrorHandler(java.lang.Boolean.valueOf(val)); @@ -14659,7 +14671,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "delimiter", type = "string"), @YamlProperty(name = "empty-value", type = "string"), @YamlProperty(name = "header-extraction-enabled", type = "boolean"), - @YamlProperty(name = "headers", type = "array:org.apache.camel.model.dataformat.UniVocityHeader"), + @YamlProperty(name = "univocity-header", type = "array:org.apache.camel.model.dataformat.UniVocityHeader"), @YamlProperty(name = "headers-disabled", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "ignore-leading-whitespaces", type = "boolean"), @@ -14801,7 +14813,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "comment", type = "string"), @YamlProperty(name = "empty-value", type = "string"), @YamlProperty(name = "header-extraction-enabled", type = "boolean"), - @YamlProperty(name = "headers", type = "array:org.apache.camel.model.dataformat.UniVocityHeader"), + @YamlProperty(name = "univocity-header", type = "array:org.apache.camel.model.dataformat.UniVocityHeader"), @YamlProperty(name = "headers-disabled", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "ignore-leading-whitespaces", type = "boolean"), @@ -14980,7 +14992,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "empty-value", type = "string"), @YamlProperty(name = "escape-char", type = "string"), @YamlProperty(name = "header-extraction-enabled", type = "boolean"), - @YamlProperty(name = "headers", type = "array:org.apache.camel.model.dataformat.UniVocityHeader"), + @YamlProperty(name = "univocity-header", type = "array:org.apache.camel.model.dataformat.UniVocityHeader"), @YamlProperty(name = "headers-disabled", type = "boolean"), @YamlProperty(name = "id", type = "string"), @YamlProperty(name = "ignore-leading-whitespaces", type = "boolean"), @@ -15511,9 +15523,9 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "enable-cors", type = "string"), @YamlProperty(name = "method", type = "string"), @YamlProperty(name = "out-type", type = "string"), - @YamlProperty(name = "params", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), + @YamlProperty(name = "param", type = "array:org.apache.camel.model.rest.RestOperationParamDefinition"), @YamlProperty(name = "produces", type = "string"), - @YamlProperty(name = "response-msgs", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), + @YamlProperty(name = "response-message", type = "array:org.apache.camel.model.rest.RestOperationResponseMsgDefinition"), @YamlProperty(name = "route-id", type = "string"), @YamlProperty(name = "security", type = "array:org.apache.camel.model.rest.SecurityDefinition"), @YamlProperty(name = "skip-binding-on-error-code", type = "string"), @@ -15828,7 +15840,7 @@ public final class ModelDeserializers extends YamlDeserializerSupport { @YamlProperty(name = "copy", type = "boolean"), @YamlProperty(name = "dynamic-uri", type = "boolean"), @YamlProperty(name = "executor-service-ref", type = "string"), - @YamlProperty(name = "headers", type = "array:org.apache.camel.model.SetHeaderDefinition"), + @YamlProperty(name = "set-header", type = "array:org.apache.camel.model.SetHeaderDefinition"), @YamlProperty(name = "ignore-invalid-endpoint", type = "boolean"), @YamlProperty(name = "inherit-error-handler", type = "boolean"), @YamlProperty(name = "body", type = "object:org.apache.camel.model.ExpressionSubElementDefinition"), diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/CustomResolver.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/CustomResolver.java index 845785c..16b29bb 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/CustomResolver.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/CustomResolver.java @@ -54,8 +54,8 @@ public class CustomResolver implements YamlDeserializerResolver { return new BeansDeserializer(); case "error-handler": return new ErrorHandlerBuilderDeserializer(); - case "do-try": - return new TryDefinitionDeserializer(); + //case "do-try": + // return new TryDefinitionDeserializer(); case "org.apache.camel.model.ProcessorDefinition": return new ProcessorDefinitionDeserializer(); default: diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/TryDefinitionDeserializer.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/TryDefinitionDeserializer.java deleted file mode 100644 index 267efe1..0000000 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/main/java/org/apache/camel/dsl/yaml/deserializers/TryDefinitionDeserializer.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.dsl.yaml.deserializers; - -import org.apache.camel.dsl.yaml.common.YamlDeserializationContext; -import org.apache.camel.dsl.yaml.common.YamlDeserializerResolver; -import org.apache.camel.model.CatchDefinition; -import org.apache.camel.model.FinallyDefinition; -import org.apache.camel.model.TryDefinition; -import org.apache.camel.spi.annotations.YamlProperty; -import org.apache.camel.spi.annotations.YamlType; -import org.snakeyaml.engine.v2.nodes.Node; - -@YamlType( - nodes = "do-try", - types = TryDefinition.class, - order = YamlDeserializerResolver.ORDER_DEFAULT, - properties = { - @YamlProperty(name = "__extends", type = "ref:org.apache.camel.model.TryDefinition"), - @YamlProperty(name = "do-catch", type = "object:org.apache.camel.model.CatchDefinition"), - @YamlProperty(name = "do-finally", type = "object:org.apache.camel.model.FinallyDefinition") - }) -public class TryDefinitionDeserializer extends ModelDeserializers.TryDefinitionDeserializer { - @Override - protected void handleUnknownProperty(TryDefinition target, String propertyKey, String propertyName, Node value) { - switch (propertyKey) { - case "do-catch": { - YamlDeserializationContext dc = getDeserializationContext(value); - CatchDefinition definition = dc.construct(propertyKey, value, CatchDefinition.class); - - target.addOutput(definition); - break; - } - case "do-finally": { - YamlDeserializationContext dc = getDeserializationContext(value); - FinallyDefinition definition = dc.construct(propertyKey, value, FinallyDefinition.class); - - target.addOutput(definition); - break; - } - default: - super.handleUnknownProperty(target, propertyKey, propertyName, value); - break; - - } - } -} diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java index 94659c8..ff755a0 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java @@ -599,18 +599,8 @@ public class GenerateYamlDeserializersMojo extends GenerateYamlSupportMojo { @SuppressWarnings("MethodLength") private void generateSetValue(CodeBlock.Builder cb, FieldInfo field, Collection<AnnotationSpec> annotations) { - if(hasAnnotation(field, XML_TRANSIENT_CLASS)) { - ClassInfo ci = view.getClassByName(field.type().name()); - if (ci == null) { - return; - } - - switch (ci.name().toString()) { - case "org.apache.camel.model.OnFallbackDefinition": - break; - default: - return; - } + if(hasAnnotation(field, XML_TRANSIENT_CLASS) && !hasAnnotation(field, DSL_PROPERTY_ANNOTATION)) { + return; } // @@ -750,7 +740,10 @@ public class GenerateYamlDeserializersMojo extends GenerateYamlSupportMojo { cb.endControlFlow(); annotations.add( - yamlPropertyWithSubtype(fieldName, "array", parametrizedType.name().toString(), isRequired(field)) + yamlPropertyWithSubtype( + StringHelper.camelCaseToDash(name).toLowerCase(Locale.US), + "array", + parametrizedType.name().toString(), isRequired(field)) ); } return; @@ -790,7 +783,10 @@ public class GenerateYamlDeserializersMojo extends GenerateYamlSupportMojo { cb.endControlFlow(); annotations.add( - yamlPropertyWithSubtype(fieldName, "array", parametrizedType.name().toString(), isRequired(field)) + yamlPropertyWithSubtype( + StringHelper.camelCaseToDash(name).toLowerCase(Locale.US), + "array", + parametrizedType.name().toString(), isRequired(field)) ); } return; diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSupportMojo.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSupportMojo.java index 88f1a0a..5b16c1e 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSupportMojo.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlSupportMojo.java @@ -34,6 +34,7 @@ import com.squareup.javapoet.AnnotationSpec; import com.squareup.javapoet.ClassName; import org.apache.camel.maven.dsl.yaml.support.IndexerSupport; import org.apache.camel.util.AntPathMatcher; +import org.apache.camel.util.ObjectHelper; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Parameter; @@ -101,6 +102,8 @@ public abstract class GenerateYamlSupportMojo extends AbstractMojo { = DotName.createSimple("org.apache.camel.spi.annotations.YamlIn"); public static final DotName YAML_OUT_ANNOTATION = DotName.createSimple("org.apache.camel.spi.annotations.YamlOut"); + public static final DotName DSL_PROPERTY_ANNOTATION + = DotName.createSimple("org.apache.camel.spi.annotations.DslProperty"); public static final ClassName CN_DESERIALIZER_RESOLVER = ClassName.get("org.apache.camel.dsl.yaml.common", "YamlDeserializerResolver"); @@ -156,14 +159,23 @@ public abstract class GenerateYamlSupportMojo extends AbstractMojo { // ************************** protected static boolean hasAnnotation(ClassInfo target, DotName annotationName) { + if (target == null) { + return false; + } return target.classAnnotation(annotationName) != null; } protected static boolean hasAnnotation(FieldInfo target, DotName annotationName) { + if (target == null) { + return false; + } return target.annotation(annotationName) != null; } protected static boolean hasAnnotationValue(ClassInfo target, DotName annotationName, String name) { + if (target == null) { + return false; + } return annotationValue( target.classAnnotation(annotationName), name).isPresent(); @@ -176,18 +188,27 @@ public abstract class GenerateYamlSupportMojo extends AbstractMojo { } protected static Optional<AnnotationValue> annotationValue(ClassInfo target, DotName annotationName, String name) { + if (target == null) { + return Optional.empty(); + } return annotationValue( target.classAnnotation(annotationName), name); } protected static Optional<AnnotationValue> annotationValue(FieldInfo target, DotName annotationName, String name) { + if (target == null) { + return Optional.empty(); + } return annotationValue( target.annotation(annotationName), name); } protected static Optional<AnnotationValue> annotationValue(MethodInfo target, DotName annotationName, String name) { + if (target == null) { + return Optional.empty(); + } return annotationValue( target.annotation(annotationName), name); @@ -510,7 +531,12 @@ public abstract class GenerateYamlSupportMojo extends AbstractMojo { } protected String fieldName(FieldInfo field) { + ClassInfo ct = view.getClassByName(field.type().name()); + return firstPresent( + annotationValue(field, DSL_PROPERTY_ANNOTATION, "name") + .map(AnnotationValue::asString) + .filter(value -> ObjectHelper.isNotEmpty(value)), annotationValue(field, XML_VALUE_ANNOTATION_CLASS, "name") .map(AnnotationValue::asString) .filter(value -> !"##default".equals(value)), @@ -519,7 +545,11 @@ public abstract class GenerateYamlSupportMojo extends AbstractMojo { .filter(value -> !"##default".equals(value)), annotationValue(field, XML_ELEMENT_ANNOTATION_CLASS, "name") .map(AnnotationValue::asString) - .filter(value -> !"##default".equals(value))).orElseGet(field::name); + .filter(value -> !"##default".equals(value)), + annotationValue(ct, XML_ROOT_ELEMENT_ANNOTATION_CLASS, "name") + .map(AnnotationValue::asString) + .filter(value -> !"##default".equals(value))) + .orElseGet(field::name); } protected boolean isRequired(FieldInfo fi) { diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json index 9855ccf..f3c79b6 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/camel-yaml-dsl.json @@ -388,7 +388,7 @@ "$ref" : "#/items/definitions/org.apache.camel.model.ProcessorDefinition" } }, - "when-clauses" : { + "when" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.WhenDefinition" @@ -1977,7 +1977,7 @@ "org.apache.camel.model.RouteTemplatesDefinition" : { "type" : "object", "properties" : { - "route-templates" : { + "route-template" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.RouteTemplateDefinition" @@ -1988,7 +1988,7 @@ "org.apache.camel.model.RoutesDefinition" : { "type" : "object", "properties" : { - "routes" : { + "route" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.RouteDefinition" @@ -2497,7 +2497,10 @@ "type" : "object", "properties" : { "do-catch" : { - "$ref" : "#/items/definitions/org.apache.camel.model.CatchDefinition" + "type" : "array", + "items" : { + "$ref" : "#/items/definitions/org.apache.camel.model.CatchDefinition" + } }, "do-finally" : { "$ref" : "#/items/definitions/org.apache.camel.model.FinallyDefinition" @@ -2722,12 +2725,6 @@ "executor-service-ref" : { "type" : "string" }, - "headers" : { - "type" : "array", - "items" : { - "$ref" : "#/items/definitions/org.apache.camel.model.SetHeaderDefinition" - } - }, "ignore-invalid-endpoint" : { "type" : "boolean" }, @@ -2743,6 +2740,12 @@ "processor-ref" : { "type" : "string" }, + "set-header" : { + "type" : "array", + "items" : { + "$ref" : "#/items/definitions/org.apache.camel.model.SetHeaderDefinition" + } + }, "uri" : { "type" : "string" } @@ -4559,12 +4562,6 @@ "header-extraction-enabled" : { "type" : "boolean" }, - "headers" : { - "type" : "array", - "items" : { - "$ref" : "#/items/definitions/org.apache.camel.model.dataformat.UniVocityHeader" - } - }, "headers-disabled" : { "type" : "boolean" }, @@ -4603,6 +4600,12 @@ }, "skip-empty-lines" : { "type" : "boolean" + }, + "univocity-header" : { + "type" : "array", + "items" : { + "$ref" : "#/items/definitions/org.apache.camel.model.dataformat.UniVocityHeader" + } } } }, @@ -4621,12 +4624,6 @@ "header-extraction-enabled" : { "type" : "boolean" }, - "headers" : { - "type" : "array", - "items" : { - "$ref" : "#/items/definitions/org.apache.camel.model.dataformat.UniVocityHeader" - } - }, "headers-disabled" : { "type" : "boolean" }, @@ -4665,6 +4662,12 @@ }, "skip-trailing-chars-until-newline" : { "type" : "boolean" + }, + "univocity-header" : { + "type" : "array", + "items" : { + "$ref" : "#/items/definitions/org.apache.camel.model.dataformat.UniVocityHeader" + } } } }, @@ -4697,12 +4700,6 @@ "header-extraction-enabled" : { "type" : "boolean" }, - "headers" : { - "type" : "array", - "items" : { - "$ref" : "#/items/definitions/org.apache.camel.model.dataformat.UniVocityHeader" - } - }, "headers-disabled" : { "type" : "boolean" }, @@ -4732,6 +4729,12 @@ }, "skip-empty-lines" : { "type" : "boolean" + }, + "univocity-header" : { + "type" : "array", + "items" : { + "$ref" : "#/items/definitions/org.apache.camel.model.dataformat.UniVocityHeader" + } } } }, @@ -5629,7 +5632,7 @@ "out-type" : { "type" : "string" }, - "params" : { + "param" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationParamDefinition" @@ -5638,7 +5641,7 @@ "produces" : { "type" : "string" }, - "response-msgs" : { + "response-message" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationResponseMsgDefinition" @@ -5703,7 +5706,7 @@ "out-type" : { "type" : "string" }, - "params" : { + "param" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationParamDefinition" @@ -5712,7 +5715,7 @@ "produces" : { "type" : "string" }, - "response-msgs" : { + "response-message" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationResponseMsgDefinition" @@ -5777,7 +5780,7 @@ "out-type" : { "type" : "string" }, - "params" : { + "param" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationParamDefinition" @@ -5786,7 +5789,7 @@ "produces" : { "type" : "string" }, - "response-msgs" : { + "response-message" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationResponseMsgDefinition" @@ -5851,7 +5854,7 @@ "out-type" : { "type" : "string" }, - "params" : { + "param" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationParamDefinition" @@ -5860,7 +5863,7 @@ "produces" : { "type" : "string" }, - "response-msgs" : { + "response-message" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationResponseMsgDefinition" @@ -5925,7 +5928,7 @@ "out-type" : { "type" : "string" }, - "params" : { + "param" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationParamDefinition" @@ -5934,7 +5937,7 @@ "produces" : { "type" : "string" }, - "response-msgs" : { + "response-message" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationResponseMsgDefinition" @@ -5999,7 +6002,7 @@ "out-type" : { "type" : "string" }, - "params" : { + "param" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationParamDefinition" @@ -6008,7 +6011,7 @@ "produces" : { "type" : "string" }, - "response-msgs" : { + "response-message" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationResponseMsgDefinition" @@ -6223,7 +6226,7 @@ "tag" : { "type" : "string" }, - "verbs" : { + "verb" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.VerbDefinition" @@ -6428,7 +6431,7 @@ "org.apache.camel.model.rest.RestsDefinition" : { "type" : "object", "properties" : { - "rests" : { + "rest" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestDefinition" @@ -6472,7 +6475,7 @@ "out-type" : { "type" : "string" }, - "params" : { + "param" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationParamDefinition" @@ -6481,7 +6484,7 @@ "produces" : { "type" : "string" }, - "response-msgs" : { + "response-message" : { "type" : "array", "items" : { "$ref" : "#/items/definitions/org.apache.camel.model.rest.RestOperationResponseMsgDefinition" diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/TryTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/TryTest.groovy index afec59f..2188bad 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/TryTest.groovy +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/TryTest.groovy @@ -34,21 +34,17 @@ class TryTest extends YamlTestSupport { - to: "log:when-a" - to: "log:when-b" do-catch: - exception: + - exception: - "java.io.FileNotFoundException" - "java.io.IOException" steps: - to: "log:io-error" ''' then: - context.routeDefinitions.size() == 1 - with(context.routeDefinitions[0], RouteDefinition) { input.endpointUri == 'direct:start' with (outputs[0], TryDefinition) { - outputs.size() == 3 - catchClauses.size() == 1 catchClauses[0].outputs.size() == 1 catchClauses[0].exceptions.contains('java.io.FileNotFoundException') @@ -70,7 +66,7 @@ class TryTest extends YamlTestSupport { - to: "log:when-a" - to: "log:when-b" do-catch: - exception: + - exception: - "java.io.FileNotFoundException" - "java.io.IOException" on-when: @@ -79,14 +75,10 @@ class TryTest extends YamlTestSupport { - to: "log:io-error" ''' then: - context.routeDefinitions.size() == 1 - with(context.routeDefinitions[0], RouteDefinition) { input.endpointUri == 'direct:start' with (outputs[0], TryDefinition) { - outputs.size() == 3 - catchClauses.size() == 1 catchClauses[0].outputs.size() == 1 catchClauses[0].exceptions.contains('java.io.FileNotFoundException') @@ -112,7 +104,7 @@ class TryTest extends YamlTestSupport { - to: "log:when-a" - to: "log:when-b" do-catch: - exception: + - exception: - "java.io.FileNotFoundException" - "java.io.IOException" on-when: @@ -124,24 +116,25 @@ class TryTest extends YamlTestSupport { - to: "log:finally" ''' then: - context.routeDefinitions.size() == 1 - with(context.routeDefinitions[0], RouteDefinition) { input.endpointUri == 'direct:start' with (outputs[0], TryDefinition) { - outputs.size() == 4 - catchClauses.size() == 1 - catchClauses[0].outputs.size() == 1 - catchClauses[0].exceptions.contains('java.io.FileNotFoundException') - catchClauses[0].exceptions.contains('java.io.IOException') - with(catchClauses[0].onWhen.expression, SimpleExpression) { - expression == '${body.size()} == 1' + with(catchClauses[0]) { + outputs.size() == 1 + exceptions.contains('java.io.FileNotFoundException') + exceptions.contains('java.io.IOException') + + with(onWhen.expression, SimpleExpression) { + expression == '${body.size()} == 1' + } } - finallyClause.outputs.size() == 1 + with(finallyClause) { + outputs.size() == 1 + } } } } @@ -161,14 +154,10 @@ class TryTest extends YamlTestSupport { - to: "log:finally" ''' then: - context.routeDefinitions.size() == 1 - with(context.routeDefinitions[0], RouteDefinition) { input.endpointUri == 'direct:start' with (outputs[0], TryDefinition) { - outputs.size() == 3 - catchClauses.size() == 0 finallyClause.outputs.size() == 1 } } diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/Metadata.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/Metadata.java index 19be69a..f37ea43 100644 --- a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/Metadata.java +++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/Metadata.java @@ -132,5 +132,4 @@ public @interface Metadata { * specify which options each implementation only supports. */ String includeProperties() default ""; - } diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/DslProperty.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/DslProperty.java new file mode 100644 index 0000000..b2bf04b --- /dev/null +++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/annotations/DslProperty.java @@ -0,0 +1,31 @@ +/* + * 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.spi.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Internal annotation used to include fields otherwise excluded because annotate with XmlTransient. + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface DslProperty { + String name() default ""; +}
