You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/11/24 11:18:17 UTC
[camel] branch master updated: CAMEL-15886: components -
Configurers for components dont include collection value metadata
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
The following commit(s) were added to refs/heads/master by this push:
new 4e65658 CAMEL-15886: components - Configurers for components dont include collection value metadata
4e65658 is described below
commit 4e656584ad39d490d214ac0bc9c92c1eb7a51d8a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 24 12:17:48 2020 +0100
CAMEL-15886: components - Configurers for components dont include collection value metadata
---
.../camel/tooling/model/BaseOptionModel.java | 10 +--
.../packaging/AbstractGenerateConfigurerMojo.java | 4 --
.../packaging/EndpointSchemaGeneratorMojo.java | 74 ++++++++++++++++++++++
.../packaging/PropertyConfigurerGenerator.java | 4 +-
4 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseOptionModel.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseOptionModel.java
index 2148e73..583cf54 100644
--- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseOptionModel.java
+++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/BaseOptionModel.java
@@ -47,7 +47,7 @@ public abstract class BaseOptionModel {
protected String configurationClass;
protected String configurationField;
protected String description;
- protected String extra; // optional and currently only used by configurer
+ protected String nestedType; // optional and currently only used by configurer
// todo: move this as a helper method
protected boolean newGroup; // special for documentation rendering
@@ -260,12 +260,12 @@ public abstract class BaseOptionModel {
this.newGroup = newGroup;
}
- public String getExtra() {
- return extra;
+ public String getNestedType() {
+ return nestedType;
}
- public void setExtra(String extra) {
- this.extra = extra;
+ public void setNestedType(String nestedType) {
+ this.nestedType = nestedType;
}
public String getShortGroup() {
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
index a0c3a1c..fc88b26 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGenerateConfigurerMojo.java
@@ -102,10 +102,6 @@ public abstract class AbstractGenerateConfigurerMojo extends AbstractGeneratorMo
setGetterMethod(getter);
}
- public void setNestedType(String nestedType) {
- // store in extra
- setExtra(nestedType);
- }
}
public AbstractGenerateConfigurerMojo() {
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
index 70f7b8f..e5e07c5 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java
@@ -769,6 +769,29 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
}
}
+ // generics for collection types
+ String nestedType = null;
+ String desc = fieldTypeName;
+ if (desc.contains("<") && desc.contains(">")) {
+ desc = Strings.between(desc, "<", ">");
+ // if it has additional nested types, then we only want the outer type
+ int pos = desc.indexOf('<');
+ if (pos != -1) {
+ desc = desc.substring(0, pos);
+ }
+ // if its a map then it has a key/value, so we only want the last part
+ pos = desc.indexOf(',');
+ if (pos != -1) {
+ desc = desc.substring(pos + 1);
+ }
+ desc = desc.replace('$', '.');
+ desc = desc.trim();
+ // skip if the type is generic or a wildcard
+ if (!desc.isEmpty() && desc.indexOf('?') == -1 && !desc.contains(" extends ")) {
+ nestedType = desc;
+ }
+ }
+
// prepare default value so its value is correct according to its type
defaultValue = getDefaultValue(defaultValue, fieldTypeName, isDuration);
@@ -813,6 +836,7 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
option.setGroup(group);
option.setLabel(label);
option.setEnums(enums);
+ option.setNestedType(nestedType);
option.setConfigurationClass(nestedTypeName);
option.setConfigurationField(nestedFieldName);
componentModel.addComponentOption(option);
@@ -940,6 +964,30 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
boolean isAutowired = metadata != null && metadata.autowired();
String group = EndpointHelper.labelAsGroupName(label, componentModel.isConsumerOnly(),
componentModel.isProducerOnly());
+
+ // generics for collection types
+ String nestedType = null;
+ String desc = fieldTypeName;
+ if (desc.contains("<") && desc.contains(">")) {
+ desc = Strings.between(desc, "<", ">");
+ // if it has additional nested types, then we only want the outer type
+ int pos = desc.indexOf('<');
+ if (pos != -1) {
+ desc = desc.substring(0, pos);
+ }
+ // if its a map then it has a key/value, so we only want the last part
+ pos = desc.indexOf(',');
+ if (pos != -1) {
+ desc = desc.substring(pos + 1);
+ }
+ desc = desc.replace('$', '.');
+ desc = desc.trim();
+ // skip if the type is generic or a wildcard
+ if (!desc.isEmpty() && desc.indexOf('?') == -1 && !desc.contains(" extends ")) {
+ nestedType = desc;
+ }
+ }
+
BaseOptionModel option;
if (componentOption) {
option = new ComponentOptionModel();
@@ -962,6 +1010,7 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
option.setGroup(group);
option.setLabel(label);
option.setEnums(enums);
+ option.setNestedType(nestedType);
option.setConfigurationClass(nestedTypeName);
option.setConfigurationField(nestedFieldName);
if (componentModel.getEndpointOptions().stream().noneMatch(opt -> name.equals(opt.getName()))) {
@@ -1062,6 +1111,30 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
boolean isAutowired = metadata != null && metadata.autowired();
String group = EndpointHelper.labelAsGroupName(label, componentModel.isConsumerOnly(),
componentModel.isProducerOnly());
+
+ // generics for collection types
+ String nestedType = null;
+ String desc = fieldTypeName;
+ if (desc.contains("<") && desc.contains(">")) {
+ desc = Strings.between(desc, "<", ">");
+ // if it has additional nested types, then we only want the outer type
+ int pos = desc.indexOf('<');
+ if (pos != -1) {
+ desc = desc.substring(0, pos);
+ }
+ // if its a map then it has a key/value, so we only want the last part
+ pos = desc.indexOf(',');
+ if (pos != -1) {
+ desc = desc.substring(pos + 1);
+ }
+ desc = desc.replace('$', '.');
+ desc = desc.trim();
+ // skip if the type is generic or a wildcard
+ if (!desc.isEmpty() && desc.indexOf('?') == -1 && !desc.contains(" extends ")) {
+ nestedType = desc;
+ }
+ }
+
BaseOptionModel option;
if (componentOption) {
option = new ComponentOptionModel();
@@ -1085,6 +1158,7 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo {
option.setGroup(group);
option.setLabel(label);
option.setEnums(enums);
+ option.setNestedType(nestedType);
option.setConfigurationClass(nestedTypeName);
option.setConfigurationField(nestedFieldName);
option.setPrefix(paramPrefix);
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyConfigurerGenerator.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyConfigurerGenerator.java
index 585bb03..8c61382 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyConfigurerGenerator.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PropertyConfigurerGenerator.java
@@ -222,7 +222,7 @@ public final class PropertyConfigurerGenerator {
// nested type was stored in extra as we use BaseOptionModel to hold the option data
boolean hasNestedTypes
- = options.stream().map(BaseOptionModel::getExtra).anyMatch(s -> s != null && !s.trim().isEmpty());
+ = options.stream().map(BaseOptionModel::getNestedType).anyMatch(s -> s != null && !s.trim().isEmpty());
if (hasNestedTypes) {
w.write("\n");
w.write(" @Override\n");
@@ -230,7 +230,7 @@ public final class PropertyConfigurerGenerator {
if (!options.isEmpty()) {
w.write(" switch (ignoreCase ? name.toLowerCase() : name) {\n");
for (BaseOptionModel option : options) {
- String nestedType = option.getExtra();
+ String nestedType = option.getNestedType();
if (nestedType != null && !nestedType.isEmpty()) {
nestedType = nestedType.replace('$', '.');
if (!option.getName().toLowerCase().equals(option.getName())) {