This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch sandbox/camel-3.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit baaf890a15b174030a90752df392f8128bdb9961 Author: aldettinger <[email protected]> AuthorDate: Tue Oct 16 20:03:56 2018 +0200 CAMEL-12888: Fixed the short java type generation in camel-package-maven-plugin --- camel-core/src/main/docs/seda-component.adoc | 2 +- camel-core/src/main/docs/stub-component.adoc | 2 +- camel-core/src/main/docs/vm-component.adoc | 2 +- .../src/main/docs/ehcache-component.adoc | 2 +- .../src/main/docs/guava-eventbus-component.adoc | 2 +- .../src/main/docs/milo-server-component.adoc | 4 +- tooling/maven/camel-package-maven-plugin/pom.xml | 20 ++++++++ .../packaging/model/ComponentOptionModel.java | 14 +---- .../packaging/model/ComponentOptionModelTest.java | 59 ++++++++++++++++++++++ 9 files changed, 87 insertions(+), 20 deletions(-) diff --git a/camel-core/src/main/docs/seda-component.adoc b/camel-core/src/main/docs/seda-component.adoc index d12159c..cdc99f3 100644 --- a/camel-core/src/main/docs/seda-component.adoc +++ b/camel-core/src/main/docs/seda-component.adoc @@ -48,7 +48,7 @@ The SEDA component supports 6 options, which are listed below. | Name | Description | Default | Type | *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue (i.e., the number of messages it can hold). | 1000 | int | *concurrentConsumers* (consumer) | Sets the default number of concurrent threads processing exchanges. | 1 | int -| *defaultQueueFactory* (advanced) | Sets the default queue factory. | | Exchange> +| *defaultQueueFactory* (advanced) | Sets the default queue factory. | | BlockingQueueFactory | *defaultBlockWhenFull* (producer) | Whether a thread that sends messages to a full SEDA queue will block until the queue's capacity is no longer exhausted. By default, an exception will be thrown stating that the queue is full. By enabling this option, the calling thread will instead block and wait until the message can be accepted. | false | boolean | *defaultOfferTimeout* (producer) | Whether a thread that sends messages to a full SEDA queue will block until the queue's capacity is no longer exhausted. By default, an exception will be thrown stating that the queue is full. By enabling this option, where a configured timeout can be added to the block case. Utilizing the .offer(timeout) method of the underlining java queue | | long | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean diff --git a/camel-core/src/main/docs/stub-component.adoc b/camel-core/src/main/docs/stub-component.adoc index eb112d3..8f7840c 100644 --- a/camel-core/src/main/docs/stub-component.adoc +++ b/camel-core/src/main/docs/stub-component.adoc @@ -38,7 +38,7 @@ The Stub component supports 6 options, which are listed below. | Name | Description | Default | Type | *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue (i.e., the number of messages it can hold). | 1000 | int | *concurrentConsumers* (consumer) | Sets the default number of concurrent threads processing exchanges. | 1 | int -| *defaultQueueFactory* (advanced) | Sets the default queue factory. | | Exchange> +| *defaultQueueFactory* (advanced) | Sets the default queue factory. | | BlockingQueueFactory | *defaultBlockWhenFull* (producer) | Whether a thread that sends messages to a full SEDA queue will block until the queue's capacity is no longer exhausted. By default, an exception will be thrown stating that the queue is full. By enabling this option, the calling thread will instead block and wait until the message can be accepted. | false | boolean | *defaultOfferTimeout* (producer) | Whether a thread that sends messages to a full SEDA queue will block until the queue's capacity is no longer exhausted. By default, an exception will be thrown stating that the queue is full. By enabling this option, where a configured timeout can be added to the block case. Utilizing the .offer(timeout) method of the underlining java queue | | long | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean diff --git a/camel-core/src/main/docs/vm-component.adoc b/camel-core/src/main/docs/vm-component.adoc index 8e1c3a9..9b9279a 100644 --- a/camel-core/src/main/docs/vm-component.adoc +++ b/camel-core/src/main/docs/vm-component.adoc @@ -68,7 +68,7 @@ The VM component supports 6 options, which are listed below. | Name | Description | Default | Type | *queueSize* (advanced) | Sets the default maximum capacity of the SEDA queue (i.e., the number of messages it can hold). | 1000 | int | *concurrentConsumers* (consumer) | Sets the default number of concurrent threads processing exchanges. | 1 | int -| *defaultQueueFactory* (advanced) | Sets the default queue factory. | | Exchange> +| *defaultQueueFactory* (advanced) | Sets the default queue factory. | | BlockingQueueFactory | *defaultBlockWhenFull* (producer) | Whether a thread that sends messages to a full SEDA queue will block until the queue's capacity is no longer exhausted. By default, an exception will be thrown stating that the queue is full. By enabling this option, the calling thread will instead block and wait until the message can be accepted. | false | boolean | *defaultOfferTimeout* (producer) | Whether a thread that sends messages to a full SEDA queue will block until the queue's capacity is no longer exhausted. By default, an exception will be thrown stating that the queue is full. By enabling this option, where a configured timeout can be added to the block case. Utilizing the .offer(timeout) method of the underlining java queue | | long | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean diff --git a/components/camel-ehcache/src/main/docs/ehcache-component.adoc b/components/camel-ehcache/src/main/docs/ehcache-component.adoc index 05a787a..f4cc6c8 100644 --- a/components/camel-ehcache/src/main/docs/ehcache-component.adoc +++ b/components/camel-ehcache/src/main/docs/ehcache-component.adoc @@ -48,7 +48,7 @@ The Ehcache component supports 7 options, which are listed below. | *configuration* (advanced) | Sets the global component configuration | | EhcacheConfiguration | *cacheManager* (common) | The cache manager | | CacheManager | *cacheManager Configuration* (common) | The cache manager configuration | | Configuration -| *cacheConfiguration* (common) | The default cache configuration to be used to create caches. | | CacheConfiguration<?,?> +| *cacheConfiguration* (common) | The default cache configuration to be used to create caches. | | CacheConfiguration | *cachesConfigurations* (common) | A map of caches configurations to be used to create caches. | | Map | *cacheConfigurationUri* (common) | URI pointing to the Ehcache XML configuration file's location | | String | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean diff --git a/components/camel-guava-eventbus/src/main/docs/guava-eventbus-component.adoc b/components/camel-guava-eventbus/src/main/docs/guava-eventbus-component.adoc index 9f3eeeb..cdf00cd 100644 --- a/components/camel-guava-eventbus/src/main/docs/guava-eventbus-component.adoc +++ b/components/camel-guava-eventbus/src/main/docs/guava-eventbus-component.adoc @@ -54,7 +54,7 @@ The Guava EventBus component supports 3 options, which are listed below. |=== | Name | Description | Default | Type | *eventBus* (common) | To use the given Guava EventBus instance | | EventBus -| *listenerInterface* (common) | The interface with method(s) marked with the Subscribe annotation. Dynamic proxy will be created over the interface so it could be registered as the EventBus listener. Particularly useful when creating multi-event listeners and for handling DeadEvent properly. This option cannot be used together with eventClass option. | | Class<?> +| *listenerInterface* (common) | The interface with method(s) marked with the Subscribe annotation. Dynamic proxy will be created over the interface so it could be registered as the EventBus listener. Particularly useful when creating multi-event listeners and for handling DeadEvent properly. This option cannot be used together with eventClass option. | | Class | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |=== // component options: END diff --git a/components/camel-milo/src/main/docs/milo-server-component.adoc b/components/camel-milo/src/main/docs/milo-server-component.adoc index 696f00c..da22842 100644 --- a/components/camel-milo/src/main/docs/milo-server-component.adoc +++ b/components/camel-milo/src/main/docs/milo-server-component.adoc @@ -42,7 +42,7 @@ The OPC UA Server component supports 20 options, which are listed below. | *serverName* (common) | Server name | | String | *hostname* (common) | Server hostname | | String | *securityPolicies* (common) | Security policies | | Set -| *securityPoliciesById* (common) | Security policies by URI or name | | String> +| *securityPoliciesById* (common) | Security policies by URI or name | | Collection | *userAuthentication Credentials* (common) | Set user password combinations in the form of user1:pwd1,user2:pwd2 Usernames and passwords will be URL decoded | | String | *enableAnonymous Authentication* (common) | Enable anonymous authentication, disabled by default | false | boolean | *usernameSecurityPolicy Uri* (common) | Set the UserTokenPolicy used when | | SecurityPolicy @@ -50,7 +50,7 @@ The OPC UA Server component supports 20 options, which are listed below. | *buildInfo* (common) | Server build info | | BuildInfo | *serverCertificate* (common) | Server certificate | | Result | *certificateManager* (common) | Server certificate manager | | CertificateManager -| *certificateValidator* (common) | Validator for client certificates | | CertificateValidator> +| *certificateValidator* (common) | Validator for client certificates | | Supplier | *defaultCertificate Validator* (common) | Validator for client certificates using default file based approach | | File | *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean |=== diff --git a/tooling/maven/camel-package-maven-plugin/pom.xml b/tooling/maven/camel-package-maven-plugin/pom.xml index fae77f1..c8c540a 100644 --- a/tooling/maven/camel-package-maven-plugin/pom.xml +++ b/tooling/maven/camel-package-maven-plugin/pom.xml @@ -172,6 +172,26 @@ <groupId>org.apache.camel</groupId> <artifactId>spi-annotations</artifactId> </dependency> + + <!-- testing --> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>${junit-jupiter-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>${junit-jupiter-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + <version>${junit-jupiter-version}</version> + <scope>test</scope> + </dependency> </dependencies> <profiles> diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java index d74f314..ba758a5 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentOptionModel.java @@ -155,20 +155,8 @@ public class ComponentOptionModel { } public String getShortJavaType(int watermark) { - if (javaType.startsWith("java.util.Map")) { - return "Map"; - } else if (javaType.startsWith("java.util.Set")) { - return "Set"; - } else if (javaType.startsWith("java.util.List")) { - return "List"; - } - - String text = javaType; - int pos = text.lastIndexOf("."); - if (pos != -1) { - text = text.substring(pos + 1); - } + String text = javaType.replaceAll("<.*>", "").replaceAll(".*[.]([^.]+)", "$1"); // if its some kind of java object then lets wrap it as its long if ("object".equals(type)) { diff --git a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/model/ComponentOptionModelTest.java b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/model/ComponentOptionModelTest.java new file mode 100644 index 0000000..65d289c --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/model/ComponentOptionModelTest.java @@ -0,0 +1,59 @@ +/** + * 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.model; + +import java.util.stream.Stream; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.params.provider.Arguments.arguments; + +public class ComponentOptionModelTest { + + ComponentOptionModel componentOptionModelUnderTest; + + @BeforeEach + public void setup() { + componentOptionModelUnderTest = new ComponentOptionModel(); + } + + static Stream<Arguments> getShortJavaTypeVarations() { + return Stream.of( + arguments("String", "String"), + arguments("String", "java.lang.String"), + arguments("List", "List<String>"), + arguments("List", "java.util.List<String>"), + arguments("List", "List<java.lang.String>"), + arguments("BlockingQueue", "java.util.concurrent.BlockingQueue<org.apache.camel.Exchange>"), + arguments("List", "java.util.List<Map<String,Integer>>"), + arguments("List", "java.util.List<Map<java.lang.String,Integer>>"), + arguments("List", "java.util.List<Map<String,java.lang.Integer>>"), + arguments("List", "java.util.List<Map<java.lang.String,java.lang.Integer>>"), + arguments("List", "java.util.List<java.util.Map<java.lang.String,java.lang.Integer>>")); + }; + + @ParameterizedTest + @MethodSource("getShortJavaTypeVarations") + public void getShortTypeShouldSucceed(String expectedShortJavaType, String javaType) { + componentOptionModelUnderTest.setJavaType(javaType); + Assertions.assertEquals(expectedShortJavaType, componentOptionModelUnderTest.getShortJavaType()); + } +}
