This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit c43d9bd543760598b9c27b16945256151ca28bcc Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Wed Jan 29 08:03:34 2020 +0000 Upgrade to Camel 3.1.0 - WIP --- .../pages/list-of-camel-quarkus-extensions.adoc | 4 +- .../quarkus/core/CamelMainEventDispatcher.java | 5 + .../apache/camel/quarkus/core/CamelMainEvents.java | 6 + .../camel/quarkus/core/CamelMainRecorder.java | 3 +- .../core/DisabledPredicateValidatorReifier.java | 2 +- .../camel/quarkus/core/FastCamelContext.java | 17 +- .../camel/quarkus/core/FastTypeConverter.java | 6 +- extensions/readme.adoc | 4 +- .../apache/camel/quarkus/core/CamelServlet.java | 2 +- .../core/runtime/support/SupportListener.java | 4 + pom.xml | 2 +- tooling/package-maven-plugin/pom.xml | 22 + .../apache/camel/quarkus/maven/ExtMvelHelper.java | 12 +- .../camel/quarkus/maven/JSonSchemaHelper.java | 567 +++++++++++++++++++++ .../quarkus/maven/PrepareCatalogQuarkusMojo.java | 2 +- .../quarkus/maven/UpdateDocExtensionsListMojo.java | 132 ++--- 16 files changed, 697 insertions(+), 93 deletions(-) diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc index b884fda..b8e0b1d 100644 --- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc +++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc @@ -64,7 +64,7 @@ Number of Camel components: 64 in 55 JAR artifacts (0 deprecated) `aws-sqs:queueNameOrArn` | 0.2.0 | The aws-sqs component is used for sending and receiving messages to Amazon's SQS service. | link:https://camel.apache.org/components/latest/aws-translate-component.html[AWS Translate] (camel-quarkus-aws-translate) + -`aws-translate:label` | 1.0.0-M3 | The aws-kms is used for managing Amazon Translate +`aws-translate:label` | 1.0.0-M3 | The aws-translate component is used for managing Amazon Translate | link:https://camel.apache.org/components/latest/bean-component.html[Bean] (camel-quarkus-bean) + `bean:beanName` | 0.2.0 | The bean component is for invoking Java beans from Camel. @@ -73,7 +73,7 @@ Number of Camel components: 64 in 55 JAR artifacts (0 deprecated) `bean-validator:label` | 1.0.0-M1 | The Validator component performs bean validation of the message body using the Java Bean Validation API. | link:https://camel.apache.org/components/latest/class-component.html[Class] (camel-quarkus-bean) + -`class:beanName` | 0.2.0 | The class component is for invoking Java classes (Java beans) from Camel. +`class:beanName` | 0.2.0 | The Class component is for invoking Java classes (Java beans) from Camel. | link:https://camel.apache.org/components/latest/consul-component.html[Consul] (camel-quarkus-consul) + `consul:apiEndpoint` | 1.0.0-M3 | The camel consul component allows you to work with Consul, a distributed, highly available, datacenter-aware, service discovery and configuration system. diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainEventDispatcher.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainEventDispatcher.java index 1df54ab..2b6f368 100644 --- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainEventDispatcher.java +++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainEventDispatcher.java @@ -26,6 +26,11 @@ import org.apache.camel.main.MainSupport; */ public class CamelMainEventDispatcher implements org.apache.camel.main.MainListener { @Override + public void beforeConfigure(BaseMainSupport main) { + fireEvent(CamelMainEvents.BeforeConfigure.class, new CamelMainEvents.BeforeConfigure()); + } + + @Override public void configure(CamelContext context) { fireEvent(CamelMainEvents.Configure.class, new CamelMainEvents.Configure()); } diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainEvents.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainEvents.java index 122803a..75b1d0e 100644 --- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainEvents.java +++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainEvents.java @@ -21,6 +21,12 @@ public final class CamelMainEvents { } /** + * Event fired by {@link CamelMain} before the CamelContext is configured. + */ + public static class BeforeConfigure { + } + + /** * Event fired by {@link CamelMain} before the CamelContext is being created and started. */ public static class BeforeStart { diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainRecorder.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainRecorder.java index f023163..68de3ea 100644 --- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainRecorder.java +++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelMainRecorder.java @@ -21,6 +21,7 @@ import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.ShutdownContext; import io.quarkus.runtime.annotations.Recorder; import org.apache.camel.CamelContext; +import org.apache.camel.ExtendedCamelContext; import org.apache.camel.RoutesBuilder; import org.apache.camel.impl.engine.DefaultReactiveExecutor; import org.apache.camel.main.MainListener; @@ -75,7 +76,7 @@ public class CamelMainRecorder { } public void setReactiveExecutor(RuntimeValue<CamelMain> main, RuntimeValue<ReactiveExecutor> executor) { - main.getValue().getCamelContext().setReactiveExecutor(executor.getValue()); + main.getValue().getCamelContext().adapt(ExtendedCamelContext.class).setReactiveExecutor(executor.getValue()); } public void start(ShutdownContext shutdown, RuntimeValue<CamelMain> main) { diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/DisabledPredicateValidatorReifier.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/DisabledPredicateValidatorReifier.java index ee6347f..29a9eae 100644 --- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/DisabledPredicateValidatorReifier.java +++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/DisabledPredicateValidatorReifier.java @@ -29,7 +29,7 @@ public class DisabledPredicateValidatorReifier extends ValidatorReifier<Predicat } @Override - protected Validator doCreateValidator(CamelContext context) throws Exception { + protected Validator doCreateValidator(CamelContext context) { throw new UnsupportedOperationException("Please add a dependency to camel-quarkus-core-xml"); } diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java index 1a2640b..225d760 100644 --- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java +++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastCamelContext.java @@ -26,9 +26,7 @@ import org.apache.camel.AsyncProcessor; import org.apache.camel.CatalogCamelContext; import org.apache.camel.Component; import org.apache.camel.Endpoint; -import org.apache.camel.PollingConsumer; import org.apache.camel.Processor; -import org.apache.camel.Producer; import org.apache.camel.TypeConverter; import org.apache.camel.component.microprofile.config.CamelMicroProfilePropertiesSource; import org.apache.camel.health.HealthCheckRegistry; @@ -63,7 +61,6 @@ import org.apache.camel.impl.engine.DefaultValidatorRegistry; import org.apache.camel.impl.engine.EndpointKey; import org.apache.camel.impl.engine.HeadersMapFactoryResolver; import org.apache.camel.impl.engine.RestRegistryFactoryResolver; -import org.apache.camel.impl.engine.ServicePool; import org.apache.camel.impl.health.DefaultHealthCheckRegistry; import org.apache.camel.impl.transformer.TransformerKey; import org.apache.camel.impl.validator.ValidatorKey; @@ -274,16 +271,6 @@ public class FastCamelContext extends AbstractCamelContext implements CatalogCam } @Override - protected ServicePool<Producer> createProducerServicePool() { - return new ServicePool<>(Endpoint::createProducer, Producer::getEndpoint, 100); - } - - @Override - protected ServicePool<PollingConsumer> createPollingConsumerServicePool() { - return new ServicePool<>(Endpoint::createPollingConsumer, PollingConsumer::getEndpoint, 100); - } - - @Override protected UnitOfWorkFactory createUnitOfWorkFactory() { return new DefaultUnitOfWorkFactory(); } @@ -365,12 +352,12 @@ public class FastCamelContext extends AbstractCamelContext implements CatalogCam } @Override - protected TransformerRegistry<TransformerKey> createTransformerRegistry() throws Exception { + protected TransformerRegistry<TransformerKey> createTransformerRegistry() { return new DefaultTransformerRegistry(this); } @Override - protected ValidatorRegistry<ValidatorKey> createValidatorRegistry() throws Exception { + protected ValidatorRegistry<ValidatorKey> createValidatorRegistry() { return new DefaultValidatorRegistry(this); } diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java index 3a829ff..7ed602b 100644 --- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java +++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java @@ -18,8 +18,12 @@ package org.apache.camel.quarkus.core; import org.apache.camel.impl.converter.DefaultTypeConverter; import org.apache.camel.spi.TypeConverterLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FastTypeConverter extends DefaultTypeConverter { + private static final Logger LOG = LoggerFactory.getLogger(FastTypeConverter.class); + public FastTypeConverter() { super(null, null, null, null, false); } @@ -27,7 +31,7 @@ public class FastTypeConverter extends DefaultTypeConverter { @Override protected void doStart() throws Exception { for (TypeConverterLoader loader : getCamelContext().getRegistry().findByType(TypeConverterLoader.class)) { - log.debug("TypeConverterLoader: {} loading converters", loader); + LOG.debug("TypeConverterLoader: {} loading converters", loader); loader.load(this); } } diff --git a/extensions/readme.adoc b/extensions/readme.adoc index ef64f14..5ec1faa 100644 --- a/extensions/readme.adoc +++ b/extensions/readme.adoc @@ -51,7 +51,7 @@ Number of Camel components: 64 in 55 JAR artifacts (0 deprecated) `aws-sqs:queueNameOrArn` | 0.2.0 | The aws-sqs component is used for sending and receiving messages to Amazon's SQS service. | link:https://camel.apache.org/components/latest/aws-translate-component.html[AWS Translate] (camel-quarkus-aws-translate) + -`aws-translate:label` | 1.0.0-M3 | The aws-kms is used for managing Amazon Translate +`aws-translate:label` | 1.0.0-M3 | The aws-translate component is used for managing Amazon Translate | link:https://camel.apache.org/components/latest/bean-component.html[Bean] (camel-quarkus-bean) + `bean:beanName` | 0.2.0 | The bean component is for invoking Java beans from Camel. @@ -60,7 +60,7 @@ Number of Camel components: 64 in 55 JAR artifacts (0 deprecated) `bean-validator:label` | 1.0.0-M1 | The Validator component performs bean validation of the message body using the Java Bean Validation API. | link:https://camel.apache.org/components/latest/class-component.html[Class] (camel-quarkus-bean) + -`class:beanName` | 0.2.0 | The class component is for invoking Java classes (Java beans) from Camel. +`class:beanName` | 0.2.0 | The Class component is for invoking Java classes (Java beans) from Camel. | link:https://camel.apache.org/components/latest/consul-component.html[Consul] (camel-quarkus-consul) + `consul:apiEndpoint` | 1.0.0-M3 | The camel consul component allows you to work with Consul, a distributed, highly available, datacenter-aware, service discovery and configuration system. diff --git a/integration-tests/core-main/src/main/java/org/apache/camel/quarkus/core/CamelServlet.java b/integration-tests/core-main/src/main/java/org/apache/camel/quarkus/core/CamelServlet.java index 1d13b31..b243845 100644 --- a/integration-tests/core-main/src/main/java/org/apache/camel/quarkus/core/CamelServlet.java +++ b/integration-tests/core-main/src/main/java/org/apache/camel/quarkus/core/CamelServlet.java @@ -165,7 +165,7 @@ public class CamelServlet { @GET @Produces(MediaType.TEXT_PLAIN) public JsonObject reactiveExecutor() { - ReactiveExecutor executor = context.getReactiveExecutor(); + ReactiveExecutor executor = context.adapt(ExtendedCamelContext.class).getReactiveExecutor(); JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add("class", executor.getClass().getName()); diff --git a/integration-tests/support/core-main/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/SupportListener.java b/integration-tests/support/core-main/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/SupportListener.java index 962d471..decef0a 100644 --- a/integration-tests/support/core-main/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/SupportListener.java +++ b/integration-tests/support/core-main/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/SupportListener.java @@ -39,6 +39,10 @@ public class SupportListener implements MainListener { } @Override + public void beforeConfigure(BaseMainSupport main) { + } + + @Override public void beforeStart(BaseMainSupport main) { main.addRoutesBuilder(new MyBuilder()); } diff --git a/pom.xml b/pom.xml index 3e9856f..c72ea63 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <ahc.version>2.10.4</ahc.version> - <camel.version>3.0.1</camel.version> + <camel.version>3.1.0-SNAPSHOT</camel.version> <guava.version>26.0-jre</guava.version> <hapi.version>4.1.0</hapi.version> <quarkus.version>1.3.0.Alpha1</quarkus.version> diff --git a/tooling/package-maven-plugin/pom.xml b/tooling/package-maven-plugin/pom.xml index ad49f19..fc0eb30 100644 --- a/tooling/package-maven-plugin/pom.xml +++ b/tooling/package-maven-plugin/pom.xml @@ -53,6 +53,28 @@ </exclusions> </dependency> <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-support</artifactId> + <version>${camel.version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-util</artifactId> + <version>${camel.version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-core</artifactId> <exclusions> diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/ExtMvelHelper.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/ExtMvelHelper.java index 5066e5d..0b0f86e 100644 --- a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/ExtMvelHelper.java +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/ExtMvelHelper.java @@ -19,10 +19,10 @@ package org.apache.camel.quarkus.maven; import java.nio.file.Path; import org.apache.camel.maven.packaging.MvelHelper; -import org.apache.camel.maven.packaging.StringHelper; -import org.apache.camel.maven.packaging.model.ComponentModel; -import org.apache.camel.maven.packaging.model.DataFormatModel; -import org.apache.camel.maven.packaging.model.LanguageModel; +import org.apache.camel.tooling.util.Strings; +import org.apache.camel.tooling.model.ComponentModel; +import org.apache.camel.tooling.model.DataFormatModel; +import org.apache.camel.tooling.model.LanguageModel; public class ExtMvelHelper { @@ -37,7 +37,7 @@ public class ExtMvelHelper { } public String getFirstVersionShort(Object model) { - return StringHelper.cutLastZeroDigit((String) invokeGetter(model, "getFirstVersion")); + return org.apache.camel.tooling.model.Strings.cutLastZeroDigit((String) invokeGetter(model, "getFirstVersion")); } public String getDocLink(Object model) { @@ -76,6 +76,6 @@ public class ExtMvelHelper { } private String getExtensionDocName(Object model) { - return StringHelper.after((String) invokeGetter(model, "getArtifactId"), "camel-quarkus-") + ".adoc"; + return Strings.after((String) invokeGetter(model, "getArtifactId"), "camel-quarkus-") + ".adoc"; } } diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/JSonSchemaHelper.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/JSonSchemaHelper.java new file mode 100644 index 0000000..1b560d0 --- /dev/null +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/JSonSchemaHelper.java @@ -0,0 +1,567 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.maven; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.camel.util.json.JsonArray; +import org.apache.camel.util.json.JsonObject; +import org.apache.camel.util.json.Jsoner; + +/** + * Used for parsing Camel components json meta-data descriptors. + */ +public final class JSonSchemaHelper { + + private static final String[] LOGGING_LEVELS = new String[]{"ERROR", "WARN", "INFO", "DEBUG", "TRACE", "OFF"}; + + private JSonSchemaHelper() { + } + + /** + * Parses the camel-main json schema to split it into a list or rows, where each row contains key value pairs with the metadata + * + * @param json the main configuration json + * @return a list of all the rows, where each row is a set of key value pairs with metadata + * @throws RuntimeException is thrown if error parsing the json data + */ + @SuppressWarnings("unchecked") + public static List<Map<String, String>> parseMainJsonSchema(String json) { + List<Map<String, String>> answer = new ArrayList<>(); + if (json == null) { + return answer; + } + + // convert into a List<Map<String, String>> structure which is expected as output from this parser + try { + JsonObject output = (JsonObject) Jsoner.deserialize(json); + for (String key : output.keySet()) { + JsonArray array = (JsonArray) output.get(key); + if (key.equals("properties")) { + // flattern each entry in the row with name as they key, and its value as the content (its a map also) + for (Object obj : array) { + Map entry = (Map) obj; + Map<String, String> newRow = new LinkedHashMap(); + newRow.putAll(entry); + answer.add(newRow); + String name = ((Map) obj).get("name").toString(); + // use naming style with camel case + String lookupKey = dashToCamelCase(name); + newRow.put("name", lookupKey); + // its the java type + String type = newRow.get("type"); + newRow.put("javaType", type); + newRow.put("type", fromMainToType(type)); + // add known enums + if ("org.apache.camel.LoggingLevel".equals(type)) { + newRow.put("enum", "ERROR,WARN,INFO,DEBUG,TRACE,OFF"); + } else if ("org.apache.camel.ManagementStatisticsLevel".equals(type)) { + newRow.put("enum", "Extended,Default,RoutesOnly,Off"); + } else if ("org.apache.camel.spi.RestBindingMode".equals(type)) { + newRow.put("enum", "auto,off,json,xml,json_xml"); + } else if ("org.apache.camel.spi.RestHostNameResolver".equals(type)) { + newRow.put("enum", "allLocalIp,localIp,localHostName"); + } + } + } + } + } catch (Exception e) { + // wrap parsing exceptions as runtime + throw new RuntimeException("Cannot parse json", e); + } + + return answer; + } + + private static String fromMainToType(String type) { + if ("boolean".equals(type) || "java.lang.Boolean".equals(type)) { + return "boolean"; + } else if ("int".equals(type) || "java.lang.Integer".equals(type)) { + return "integer"; + } else if ("long".equals(type) || "java.lang.Long".equals(type)) { + return "integer"; + } else if ("float".equals(type) || "java.lang.Float".equals(type)) { + return "number"; + } else if ("double".equals(type) || "java.lang.Double".equals(type)) { + return "number"; + } else if ("string".equals(type) || "java.lang.String".equals(type)) { + return "string"; + } else { + return "object"; + } + } + + /** + * Parses the json schema to split it into a list or rows, where each row contains key value pairs with the metadata + * + * @param group the group to parse from such as <tt>component</tt>, <tt>componentProperties</tt>, or <tt>properties</tt>. + * @param json the json + * @return a list of all the rows, where each row is a set of key value pairs with metadata + * @throws RuntimeException is thrown if error parsing the json data + */ + @SuppressWarnings("unchecked") + public static List<Map<String, String>> parseJsonSchema(String group, String json, boolean parseProperties) { + List<Map<String, String>> answer = new ArrayList<>(); + if (json == null) { + return answer; + } + + // convert into a List<Map<String, String>> structure which is expected as output from this parser + try { + JsonObject output = (JsonObject) Jsoner.deserialize(json); + for (String key : output.keySet()) { + Map row = output.getMap(key); + if (key.equals(group)) { + if (parseProperties) { + // flattern each entry in the row with name as they key, and its value as the content (its a map also) + for (Object obj : row.entrySet()) { + Map.Entry entry = (Map.Entry) obj; + Map<String, String> newRow = new LinkedHashMap(); + newRow.put("name", entry.getKey().toString()); + + Map newData = transformMap((Map) entry.getValue()); + newRow.putAll(newData); + answer.add(newRow); + } + } else { + // flattern each entry in the row as a list of single Map<key, value> elements + Map newData = transformMap(row); + for (Object obj : newData.entrySet()) { + Map.Entry entry = (Map.Entry) obj; + Map<String, String> newRow = new LinkedHashMap<>(); + newRow.put(entry.getKey().toString(), entry.getValue().toString()); + answer.add(newRow); + } + } + } + } + } catch (Exception e) { + // wrap parsing exceptions as runtime + throw new RuntimeException("Cannot parse json", e); + } + + return answer; + } + + private static Map<String, String> transformMap(Map jsonMap) { + Map<String, String> answer = new LinkedHashMap<>(); + + for (Object rowObj : jsonMap.entrySet()) { + Map.Entry rowEntry = (Map.Entry) rowObj; + // if its a list type then its an enum, and we need to parse it as a single line separated with comma + // to be backwards compatible + Object newValue = rowEntry.getValue(); + if (newValue instanceof List) { + List<?> list = (List) newValue; + newValue = list.stream().map(Object::toString) + .collect(Collectors.joining(",")); + } + // ensure value is escaped + String value = escapeJson(newValue.toString()); + answer.put(rowEntry.getKey().toString(), value); + } + + return answer; + } + + private static String escapeJson(String value) { + // need to safe encode \r as \\r so its escaped + // need to safe encode \n as \\n so its escaped + // need to safe encode \t as \\t so its escaped + return value + .replace("\\r", "\\\\r") + .replace("\\n", "\\\\n") + .replace("\\t", "\\\\t"); + } + + public static boolean isComponentLenientProperties(List<Map<String, String>> rows) { + for (Map<String, String> row : rows) { + if (row.containsKey("lenientProperties")) { + return "true".equals(row.get("lenientProperties")); + } + } + return false; + } + + public static boolean isComponentConsumerOnly(List<Map<String, String>> rows) { + for (Map<String, String> row : rows) { + if (row.containsKey("consumerOnly")) { + return "true".equals(row.get("consumerOnly")); + } + } + return false; + } + + public static boolean isComponentProducerOnly(List<Map<String, String>> rows) { + for (Map<String, String> row : rows) { + if (row.containsKey("producerOnly")) { + return "true".equals(row.get("producerOnly")); + } + } + return false; + } + + public static boolean isPropertyConsumerOnly(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String labels = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("label")) { + labels = row.get("label"); + } + if (found) { + return labels != null && labels.contains("consumer"); + } + } + return false; + } + + public static boolean isPropertyProducerOnly(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String labels = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("label")) { + labels = row.get("label"); + } + if (found) { + return labels != null && labels.contains("producer"); + } + } + return false; + } + + public static boolean isPropertyRequired(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + boolean required = false; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("required")) { + required = "true".equals(row.get("required")); + } + if (found) { + return required; + } + } + return false; + } + + public static boolean isPropertyDeprecated(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + boolean deprecated = false; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("deprecated")) { + deprecated = "true".equals(row.get("deprecated")); + } + if (found) { + return deprecated; + } + } + return false; + } + + public static String getPropertyKind(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String kind = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("kind")) { + kind = row.get("kind"); + } + if (found) { + return kind; + } + } + return null; + } + + public static String getPropertyJavaType(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String javaType = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("javaType")) { + javaType = row.get("javaType"); + } + if (found) { + return javaType; + } + } + return null; + } + + public static boolean isPropertyBoolean(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String type = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("type")) { + type = row.get("type"); + } + if (found) { + return "boolean".equals(type); + } + } + return false; + } + + public static boolean isPropertyInteger(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String type = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("type")) { + type = row.get("type"); + } + if (found) { + return "integer".equals(type); + } + } + return false; + } + + public static boolean isPropertyArray(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String type = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("type")) { + type = row.get("type"); + } + if (found) { + return "array".equals(type); + } + } + return false; + } + + public static boolean isPropertyNumber(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String type = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("type")) { + type = row.get("type"); + } + if (found) { + return "number".equals(type); + } + } + return false; + } + + public static boolean isPropertyObject(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String type = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("type")) { + type = row.get("type"); + } + if (found) { + return "object".equals(type); + } + } + return false; + } + + public static String getPropertyDefaultValue(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String defaultValue = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("defaultValue")) { + defaultValue = row.get("defaultValue"); + } + if (found) { + return defaultValue; + } + } + return null; + } + + public static String stripOptionalPrefixFromName(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + boolean found = false; + if (row.containsKey("name")) { + String optionalPrefix = row.get("optionalPrefix"); + if (optionalPrefix != null && !optionalPrefix.isEmpty() && name.startsWith(optionalPrefix)) { + name = name.substring(optionalPrefix.length()); + // try again + return stripOptionalPrefixFromName(rows, name); + } else { + found = name.equalsIgnoreCase(row.get("name")); + } + } + if (found) { + return name; + } + } + return name; + } + + public static String getPropertyEnum(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String enums = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("enum")) { + enums = row.get("enum"); + } + if (found) { + return enums; + } + } + return null; + } + + public static String getPropertyPrefix(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String prefix = null; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("prefix")) { + prefix = row.get("prefix"); + } + if (found) { + return prefix; + } + } + return null; + } + + public static boolean isPropertyMultiValue(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + boolean multiValue = false; + boolean found = false; + if (row.containsKey("name")) { + found = name.equalsIgnoreCase(row.get("name")); + } + if (row.containsKey("multiValue")) { + multiValue = "true".equals(row.get("multiValue")); + } + if (found) { + return multiValue; + } + } + return false; + } + + public static String getPropertyNameFromNameWithPrefix(List<Map<String, String>> rows, String name) { + for (Map<String, String> row : rows) { + String propertyName = null; + boolean found = false; + if (row.containsKey("name")) { + propertyName = row.get("name"); + } + if (row.containsKey("prefix")) { + String preifx = row.get("prefix"); + found = name.startsWith(preifx); + } + if (found) { + return propertyName; + } + } + return null; + } + + public static Map<String, String> getRow(List<Map<String, String>> rows, String key) { + for (Map<String, String> row : rows) { + if (key.equals(row.get("name"))) { + return row; + } + } + return null; + } + + public static Set<String> getNames(List<Map<String, String>> rows) { + Set<String> answer = new LinkedHashSet<>(); + for (Map<String, String> row : rows) { + if (row.containsKey("name")) { + answer.add(row.get("name")); + } + } + return answer; + } + + /** + * Converts the string from dash format into camel case (hello-great-world -> helloGreatWorld) + * + * @param text the string + * @return the string camel cased + */ + private static String dashToCamelCase(String text) { + if (text == null) { + return null; + } + int length = text.length(); + if (length == 0) { + return text; + } + if (text.indexOf('-') == -1) { + return text; + } + + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < text.length(); i++) { + char c = text.charAt(i); + if (c == '-') { + i++; + sb.append(Character.toUpperCase(text.charAt(i))); + } else { + sb.append(c); + } + } + return sb.toString(); + } +} \ No newline at end of file diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java index 0ca8459..0a07936 100644 --- a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java @@ -64,7 +64,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import static org.apache.camel.maven.packaging.PackageHelper.loadText; +import static org.apache.camel.tooling.util.PackageHelper.loadText; /** * Prepares the Quarkus provider camel catalog to include component it supports diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java index bb392f4..b5fac67 100644 --- a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java @@ -33,12 +33,11 @@ import java.util.TreeSet; import static java.util.stream.Collectors.toSet; -import org.apache.camel.maven.packaging.JSonSchemaHelper; -import org.apache.camel.maven.packaging.StringHelper; -import org.apache.camel.maven.packaging.model.ComponentModel; -import org.apache.camel.maven.packaging.model.DataFormatModel; -import org.apache.camel.maven.packaging.model.LanguageModel; -import org.apache.camel.maven.packaging.model.OtherModel; +import org.apache.camel.util.StringHelper; +import org.apache.camel.tooling.model.ComponentModel; +import org.apache.camel.tooling.model.DataFormatModel; +import org.apache.camel.tooling.model.LanguageModel; +import org.apache.camel.tooling.model.OtherModel; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -49,8 +48,8 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.mvel2.templates.TemplateRuntime; -import static org.apache.camel.maven.packaging.PackageHelper.loadText; -import static org.apache.camel.maven.packaging.PackageHelper.writeText; +import static org.apache.camel.tooling.util.PackageHelper.loadText; +import static org.apache.camel.tooling.util.PackageHelper.writeText; /** * Updates the documentation in: @@ -183,7 +182,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { // how many deprecated long deprecated = components.stream() - .filter(c -> "true".equals(c.getDeprecated())) + .filter(ComponentModel::isDeprecated) .count(); // update the big readme file in the extensions dir @@ -251,7 +250,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { // how many deprecated long deprecated = models.stream() - .filter(m -> "true".equals(m.getDeprecated())) + .filter(DataFormatModel::isDeprecated) .count(); // filter out camel-core @@ -325,7 +324,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { // how many deprecated long deprecated = languages.stream() - .filter(l -> "true".equals(l.getDeprecated())) + .filter(LanguageModel::isDeprecated) .count(); // update the big readme file in the extensions dir @@ -387,7 +386,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { // how many deprecated long deprecated = others.stream() - .filter(o -> "true".equals(o.getDeprecated())) + .filter(OtherModel::isDeprecated) .count(); // update the big readme file in the extensions dir @@ -665,22 +664,22 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false); ComponentModel component = new ComponentModel(); - component.setScheme(JSonSchemaHelper.getSafeValue("scheme", rows)); - component.setSyntax(JSonSchemaHelper.getSafeValue("syntax", rows)); - component.setAlternativeSyntax(JSonSchemaHelper.getSafeValue("alternativeSyntax", rows)); - component.setAlternativeSchemes(JSonSchemaHelper.getSafeValue("alternativeSchemes", rows)); - component.setTitle(JSonSchemaHelper.getSafeValue("title", rows)); - component.setDescription(JSonSchemaHelper.getSafeValue("description", rows)); - component.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows)); - component.setLabel(JSonSchemaHelper.getSafeValue("label", rows)); - component.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows)); - component.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", rows)); - component.setConsumerOnly(JSonSchemaHelper.getSafeValue("consumerOnly", rows)); - component.setProducerOnly(JSonSchemaHelper.getSafeValue("producerOnly", rows)); - component.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows)); - component.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows)); - component.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows)); - component.setVersion(JSonSchemaHelper.getSafeValue("version", rows)); + component.setScheme(getJSonValue("scheme", rows)); + component.setSyntax(getJSonValue("syntax", rows)); + component.setAlternativeSyntax(getJSonValue("alternativeSyntax", rows)); + component.setAlternativeSchemes(getJSonValue("alternativeSchemes", rows)); + component.setTitle(getJSonValue("title", rows)); + component.setDescription(getJSonValue("description", rows)); + component.setFirstVersion(getJSonValue("firstVersion", rows)); + component.setLabel(getJSonValue("label", rows)); + component.setDeprecated(Boolean.valueOf(getJSonValue("deprecated", rows))); + component.setDeprecationNote(getJSonValue("deprecationNote", rows)); + component.setConsumerOnly(Boolean.valueOf(getJSonValue("consumerOnly", rows))); + component.setProducerOnly(Boolean.valueOf(getJSonValue("producerOnly", rows))); + component.setJavaType(getJSonValue("javaType", rows)); + component.setGroupId(getJSonValue("groupId", rows)); + component.setArtifactId(getJSonValue("artifactId", rows)); + component.setVersion(getJSonValue("version", rows)); return component; } @@ -689,18 +688,18 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("dataformat", json, false); DataFormatModel dataFormat = new DataFormatModel(); - dataFormat.setName(JSonSchemaHelper.getSafeValue("name", rows)); - dataFormat.setTitle(JSonSchemaHelper.getSafeValue("title", rows)); - dataFormat.setModelName(JSonSchemaHelper.getSafeValue("modelName", rows)); - dataFormat.setDescription(JSonSchemaHelper.getSafeValue("description", rows)); - dataFormat.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows)); - dataFormat.setLabel(JSonSchemaHelper.getSafeValue("label", rows)); - dataFormat.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows)); - dataFormat.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", rows)); - dataFormat.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows)); - dataFormat.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows)); - dataFormat.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows)); - dataFormat.setVersion(JSonSchemaHelper.getSafeValue("version", rows)); + dataFormat.setName(getJSonValue("name", rows)); + dataFormat.setTitle(getJSonValue("title", rows)); + dataFormat.setModelName(getJSonValue("modelName", rows)); + dataFormat.setDescription(getJSonValue("description", rows)); + dataFormat.setFirstVersion(getJSonValue("firstVersion", rows)); + dataFormat.setLabel(getJSonValue("label", rows)); + dataFormat.setDeprecated(Boolean.valueOf(getJSonValue("deprecated", rows))); + dataFormat.setDeprecationNote(getJSonValue("deprecationNote", rows)); + dataFormat.setJavaType(getJSonValue("javaType", rows)); + dataFormat.setGroupId(getJSonValue("groupId", rows)); + dataFormat.setArtifactId(getJSonValue("artifactId", rows)); + dataFormat.setVersion(getJSonValue("version", rows)); return dataFormat; } @@ -709,18 +708,18 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("language", json, false); LanguageModel language = new LanguageModel(); - language.setTitle(JSonSchemaHelper.getSafeValue("title", rows)); - language.setName(JSonSchemaHelper.getSafeValue("name", rows)); - language.setModelName(JSonSchemaHelper.getSafeValue("modelName", rows)); - language.setDescription(JSonSchemaHelper.getSafeValue("description", rows)); - language.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows)); - language.setLabel(JSonSchemaHelper.getSafeValue("label", rows)); - language.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows)); - language.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", rows)); - language.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows)); - language.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows)); - language.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows)); - language.setVersion(JSonSchemaHelper.getSafeValue("version", rows)); + language.setTitle(getJSonValue("title", rows)); + language.setName(getJSonValue("name", rows)); + language.setModelName(getJSonValue("modelName", rows)); + language.setDescription(getJSonValue("description", rows)); + language.setFirstVersion(getJSonValue("firstVersion", rows)); + language.setLabel(getJSonValue("label", rows)); + language.setDeprecated(Boolean.valueOf(getJSonValue("deprecated", rows))); + language.setDeprecationNote(getJSonValue("deprecationNote", rows)); + language.setJavaType(getJSonValue("javaType", rows)); + language.setGroupId(getJSonValue("groupId", rows)); + language.setArtifactId(getJSonValue("artifactId", rows)); + language.setVersion(getJSonValue("version", rows)); return language; } @@ -729,20 +728,29 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("other", json, false); OtherModel other = new OtherModel(); - other.setName(JSonSchemaHelper.getSafeValue("name", rows)); - other.setTitle(JSonSchemaHelper.getSafeValue("title", rows)); - other.setDescription(JSonSchemaHelper.getSafeValue("description", rows)); - other.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows)); - other.setLabel(JSonSchemaHelper.getSafeValue("label", rows)); - other.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows)); - other.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", rows)); - other.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows)); - other.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows)); - other.setVersion(JSonSchemaHelper.getSafeValue("version", rows)); + other.setName(getJSonValue("name", rows)); + other.setTitle(getJSonValue("title", rows)); + other.setDescription(getJSonValue("description", rows)); + other.setFirstVersion(getJSonValue("firstVersion", rows)); + other.setLabel(getJSonValue("label", rows)); + other.setDeprecated(Boolean.valueOf(getJSonValue("deprecated", rows))); + other.setDeprecationNote(getJSonValue("deprecationNote", rows)); + other.setGroupId(getJSonValue("groupId", rows)); + other.setArtifactId(getJSonValue("artifactId", rows)); + other.setVersion(getJSonValue("version", rows)); return other; } + private String getJSonValue(String key, List<Map<String, String>> rows) { + for (Map<String, String> row : rows) { + if (row.containsKey(key)) { + return row.get(key); + } + } + return ""; + } + private Path getExtensionsDocPath() { return Paths.get(websiteDocBaseDir.toString(), "extensions"); }