You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2019/08/22 19:25:50 UTC

[camel] branch master updated (b660b52 -> 158fcf0)

This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from b660b52  Regen
     new ed22f2c  CAMEL-13893: cleanup
     new fa0a21a  CAMEL-13893: reintroduce configuration options ...
     new ea84ffa  CAMEL-13893: use XML API to modify REST XML DSL
     new 158fcf0  Regen

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 components/camel-any23/pom.xml                     |   1 -
 .../any23/spring/SpringAny23DataFormatTest.xml     |   3 +
 components/camel-blueprint/pom.xml                 |   7 ++
 components/camel-spring/pom.xml                    |   7 ++
 ...rtyDefinition.java => ConfigurationOption.java} |  37 +++----
 ...nsDefinition.java => ConfigurationOptions.java} |  32 +++---
 .../camel/model/dataformat/Any23DataFormat.java    |  18 ++--
 .../reifier/dataformat/Any23DataFormatReifier.java |   4 +-
 .../modules/ROOT/pages/aws-cw-component.adoc       |   2 +-
 .../generator/swagger/AbstractGenerateMojo.java    | 108 ++++++++++-----------
 .../maven/generator/swagger/GenerateXmlMojo.java   |  26 +++--
 .../generator/swagger/RestDslXmlGenerator.java     |  74 ++++++++++----
 .../generator/swagger/RestDslXmlGeneratorTest.java |  39 ++++++--
 13 files changed, 208 insertions(+), 150 deletions(-)
 copy core/camel-core/src/main/java/org/apache/camel/model/{PropertyDefinition.java => ConfigurationOption.java} (75%)
 copy core/camel-core/src/main/java/org/apache/camel/model/{GlobalOptionsDefinition.java => ConfigurationOptions.java} (62%)


[camel] 02/04: CAMEL-13893: reintroduce configuration options ...

Posted by zr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit fa0a21a6610a88025f16ac9cc1e3d6ac5111daf8
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Thu Aug 22 20:01:54 2019 +0200

    CAMEL-13893: reintroduce configuration options ...
    
    ...for Any23 XML configuration
    
    This reintroduces configuration options for Any23 XML configuration by
    adding `ConfigurationOptions` class that's mapped within Camel's XML
    namespace.
    
    Also adds a unit test to the REST DSL XML generator to check if the
    generated XML DSL root element is declared with default namespace.
    
    Also excludes *Helper classes from being declared in Spring and OSGi
    Blueprint schemas.
---
 .../any23/spring/SpringAny23DataFormatTest.xml     |  3 ++
 components/camel-blueprint/pom.xml                 |  7 +++
 components/camel-spring/pom.xml                    |  7 +++
 .../apache/camel/model/ConfigurationOption.java    | 53 ++++++++++++++++++++++
 .../apache/camel/model/ConfigurationOptions.java   | 51 +++++++++++++++++++++
 .../camel/model/dataformat/Any23DataFormat.java    | 18 ++++----
 .../reifier/dataformat/Any23DataFormatReifier.java |  4 +-
 7 files changed, 132 insertions(+), 11 deletions(-)

diff --git a/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml b/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml
index 213f5ff..2820541 100644
--- a/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml
+++ b/components/camel-any23/src/test/resources/org/apache/camel/dataformat/any23/spring/SpringAny23DataFormatTest.xml
@@ -29,6 +29,9 @@
 
     <dataFormats>
       <any23 id="any23" baseURI ="http://mock.foo/bar" outputFormat="TURTLE" > 
+        <configuration>
+          <option name="any23.extraction.metadata.nesting" value="off" />
+        </configuration>
         <extractors>html-head-title</extractors>
       </any23>
     </dataFormats>
diff --git a/components/camel-blueprint/pom.xml b/components/camel-blueprint/pom.xml
index 8fa489b..567e9ed 100644
--- a/components/camel-blueprint/pom.xml
+++ b/components/camel-blueprint/pom.xml
@@ -266,6 +266,13 @@
                         <source>${project.build.directory}/schema-src</source>
                     </sources>
                     <createJavaDocAnnotations>false</createJavaDocAnnotations>
+                    <schemaSourceExcludeFilters>
+                        <filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
+                            <patterns>
+                                <pattern>Helper.java</pattern>
+                            </patterns>
+                        </filter>
+                    </schemaSourceExcludeFilters>
                 </configuration>
             </plugin>
         </plugins>
diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml
index ee2f176..2849484 100644
--- a/components/camel-spring/pom.xml
+++ b/components/camel-spring/pom.xml
@@ -297,6 +297,13 @@
                         <source>${project.build.directory}/schema-src</source>
                     </sources>
                     <createJavaDocAnnotations>false</createJavaDocAnnotations>
+                    <schemaSourceExcludeFilters>
+                        <filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
+                            <patterns>
+                                <pattern>Helper.java</pattern>
+                            </patterns>
+                        </filter>
+                    </schemaSourceExcludeFilters>
                 </configuration>
             </plugin>
             <plugin>
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOption.java b/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOption.java
new file mode 100644
index 0000000..f34897d
--- /dev/null
+++ b/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOption.java
@@ -0,0 +1,53 @@
+/*
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "configuration")
+@XmlRootElement(name = "option")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ConfigurationOption {
+
+    @XmlAttribute(required = true)
+    public String name;
+
+    @XmlAttribute(required = true)
+    public String value;
+
+    public ConfigurationOption() {
+    }
+
+    public ConfigurationOption(final String name, final String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    String name() {
+        return name;
+    }
+
+    String value() {
+        return value;
+    }
+
+}
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOptions.java b/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOptions.java
new file mode 100644
index 0000000..129e747
--- /dev/null
+++ b/core/camel-core/src/main/java/org/apache/camel/model/ConfigurationOptions.java
@@ -0,0 +1,51 @@
+/*
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.spi.Metadata;
+
+@Metadata(label = "configuration")
+@XmlRootElement(name = "configuration")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ConfigurationOptions {
+    @XmlElement(name = "option")
+    public List<ConfigurationOption> globalOptions = new ArrayList<>();
+
+    public Map<String, String> asMap() {
+        return globalOptions.stream()
+            .collect(Collectors.toMap(ConfigurationOption::name, ConfigurationOption::value));
+    }
+
+    public static ConfigurationOptions from(Map<String, String> map) {
+        final ConfigurationOptions ret = new ConfigurationOptions();
+
+        map.forEach((k, v) -> ret.globalOptions.add(new ConfigurationOption(k, v)));
+
+        return ret;
+    }
+
+}
diff --git a/core/camel-core/src/main/java/org/apache/camel/model/dataformat/Any23DataFormat.java b/core/camel-core/src/main/java/org/apache/camel/model/dataformat/Any23DataFormat.java
index ec795dd..f0f8110 100644
--- a/core/camel-core/src/main/java/org/apache/camel/model/dataformat/Any23DataFormat.java
+++ b/core/camel-core/src/main/java/org/apache/camel/model/dataformat/Any23DataFormat.java
@@ -18,13 +18,14 @@ package org.apache.camel.model.dataformat;
 
 import java.util.List;
 import java.util.Map;
+
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
 
+import org.apache.camel.model.ConfigurationOptions;
 import org.apache.camel.model.DataFormatDefinition;
 import org.apache.camel.spi.Metadata;
 
@@ -39,8 +40,7 @@ public class Any23DataFormat extends DataFormatDefinition {
     @XmlAttribute
     @Metadata(defaultValue = "RDF4JMODEL")
     private Any23Type outputFormat;
-    @XmlTransient
-    private Map<String, String> configurations;
+    private ConfigurationOptions configuration = new ConfigurationOptions();
     @XmlElement
     private List<String> extractors;
     @XmlAttribute
@@ -63,13 +63,13 @@ public class Any23DataFormat extends DataFormatDefinition {
     public Any23DataFormat(String baseuri, Any23Type outputFormat, Map<String, String> configurations) {
         this(baseuri, outputFormat);
         this.outputFormat = outputFormat;
-        this.configurations = configurations;
+        this.configuration = ConfigurationOptions.from(configurations);
     }
 
     public Any23DataFormat(String baseuri, Any23Type outputFormat, Map<String, String> configurations, List<String> extractors) {
         this(baseuri, outputFormat, configurations);
         this.outputFormat = outputFormat;
-        this.configurations = configurations;
+        this.configuration = ConfigurationOptions.from(configurations);
         this.extractors = extractors;
     }
 
@@ -85,8 +85,8 @@ public class Any23DataFormat extends DataFormatDefinition {
         this.outputFormat = outputFormat;
     }
 
-    public Map<String, String> getConfigurations() {
-        return configurations;
+    public Map<String, String> getConfiguration() {
+        return configuration.asMap();
     }
 
     /**
@@ -96,8 +96,8 @@ public class Any23DataFormat extends DataFormatDefinition {
      * "https://github.com/apache/any23/blob/master/api/src/main/resources/default-configuration.properties">here</a>.
      * If not provided, a default configuration is used.
      */
-    public void setConfigurations(Map<String, String> configurations) {
-        this.configurations = configurations;
+    public void setConfiguration(Map<String, String> configurations) {
+        this.configuration = ConfigurationOptions.from(configurations);
     }
 
     public List<String> getExtractors() {
diff --git a/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/Any23DataFormatReifier.java b/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/Any23DataFormatReifier.java
index 3979217..12885f0 100644
--- a/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/Any23DataFormatReifier.java
+++ b/core/camel-core/src/main/java/org/apache/camel/reifier/dataformat/Any23DataFormatReifier.java
@@ -37,8 +37,8 @@ public class Any23DataFormatReifier extends DataFormatReifier<Any23DataFormat> {
         if (definition.getOutputFormat() != null) {
             setProperty(camelContext, dataFormat, "outputFormat", definition.getOutputFormat());
         }
-        if (definition.getConfigurations() != null) {
-            setProperty(camelContext, dataFormat, "configurations", definition.getConfigurations());
+        if (definition.getConfiguration() != null) {
+            setProperty(camelContext, dataFormat, "configurations", definition.getConfiguration());
         }
         if (definition.getExtractors() != null) {
             setProperty(camelContext, dataFormat, "extractors", definition.getExtractors());


[camel] 01/04: CAMEL-13893: cleanup

Posted by zr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ed22f2cac006a5d134ec147a942eff6f62cada4d
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Thu Aug 22 10:04:19 2019 +0200

    CAMEL-13893: cleanup
---
 components/camel-any23/pom.xml                     |   1 -
 .../generator/swagger/AbstractGenerateMojo.java    | 108 ++++++++++-----------
 .../maven/generator/swagger/GenerateXmlMojo.java   |  26 +++--
 3 files changed, 66 insertions(+), 69 deletions(-)

diff --git a/components/camel-any23/pom.xml b/components/camel-any23/pom.xml
index 0788dfb..a6a2265 100644
--- a/components/camel-any23/pom.xml
+++ b/components/camel-any23/pom.xml
@@ -85,7 +85,6 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-http</artifactId>
       <scope>test</scope>
-      <version>${project.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/AbstractGenerateMojo.java b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/AbstractGenerateMojo.java
index d24dded..cde680b 100644
--- a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/AbstractGenerateMojo.java
+++ b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/AbstractGenerateMojo.java
@@ -18,12 +18,11 @@ package org.apache.camel.maven.generator.swagger;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -54,7 +53,11 @@ import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
 abstract class AbstractGenerateMojo extends AbstractMojo {
 
     // this list should be in priority order
-    public static final String[] DEFAULT_REST_CONSUMER_COMPONENTS = new String[]{"servlet", "undertow", "jetty", "restlet", "netty-http", "spark-java", "coap"};
+    public static final String[] DEFAULT_REST_CONSUMER_COMPONENTS = new String[] {"servlet", "undertow", "jetty",
+        "restlet", "netty-http", "spark-java", "coap"};
+
+    @Parameter
+    String apiContextPath;
 
     @Parameter
     String destinationGenerator;
@@ -62,20 +65,11 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
     @Parameter
     String filterOperation;
 
-    @Parameter(defaultValue = "${project}")
-    MavenProject project;
-
-    @Parameter(defaultValue = "false")
-    boolean skip;
-
-    @Parameter(defaultValue = "${project.basedir}/src/spec/swagger.json", required = true)
-    String specificationUri;
-
-    @Parameter(defaultValue = "true")
-    boolean restConfiguration;
+    @Parameter
+    String modelNamePrefix;
 
-    @Parameter(defaultValue = "2.3.1")
-    String swaggerCodegenMavenPluginVersion;
+    @Parameter
+    String modelNameSuffix;
 
     @Parameter(defaultValue = "${project.build.directory}/generated-sources/swagger")
     String modelOutput;
@@ -83,17 +77,23 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
     @Parameter
     String modelPackage;
 
-    @Parameter
-    String modelNamePrefix;
+    @Parameter(defaultValue = "true")
+    String modelWithXml;
 
-    @Parameter
-    String modelNameSuffix;
+    @Parameter(defaultValue = "${project}")
+    MavenProject project;
 
     @Parameter(defaultValue = "true")
-    String modelWithXml;
+    boolean restConfiguration;
 
-    @Parameter
-    String apiContextPath;
+    @Parameter(defaultValue = "false")
+    boolean skip;
+
+    @Parameter(defaultValue = "${project.basedir}/src/spec/swagger.json", required = true)
+    String specificationUri;
+
+    @Parameter(defaultValue = "2.3.1")
+    String swaggerCodegenMavenPluginVersion;
 
     @Parameter(defaultValue = "${project}", readonly = true)
     private MavenProject mavenProject;
@@ -117,7 +117,7 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
         final URL[] withOutput = new URL[] {outputDirectory};
 
         try (URLClassLoader classLoader = new URLClassLoader(withOutput, contextClassLoader)) {
-            @SuppressWarnings("unchecked")
+            @SuppressWarnings({"unchecked", "rawtypes"})
             final Class<DestinationGenerator> tmp = (Class) classLoader.loadClass(destinationGenerator);
 
             if (!DestinationGenerator.class.isAssignableFrom(tmp)) {
@@ -145,13 +145,14 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
         return destinationGeneratorObject;
     }
 
-    void generateDto(String language) throws MojoExecutionException {
-        getLog().info("Generating DTO classes using io.swagger:swagger-codegen-maven-plugin:" + swaggerCodegenMavenPluginVersion);
+    void generateDto(final String language) throws MojoExecutionException {
+        getLog().info(
+            "Generating DTO classes using io.swagger:swagger-codegen-maven-plugin:" + swaggerCodegenMavenPluginVersion);
 
         // swagger-codegen-maven-plugin documentation and its supported options
         // https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen-maven-plugin
 
-        List<MojoExecutor.Element> elements = new ArrayList<>();
+        final List<MojoExecutor.Element> elements = new ArrayList<>();
         elements.add(new MojoExecutor.Element("inputSpec", specificationUri));
         elements.add(new MojoExecutor.Element("language", language));
         elements.add(new MojoExecutor.Element("generateApis", "false"));
@@ -178,25 +179,28 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
             plugin(
                 groupId("io.swagger"),
                 artifactId("swagger-codegen-maven-plugin"),
-                version(swaggerCodegenMavenPluginVersion)
-            ),
+                version(swaggerCodegenMavenPluginVersion)),
             goal("generate"),
             configuration(
-                elements.toArray(new MojoExecutor.Element[elements.size()])
-            ),
+                elements.toArray(new MojoExecutor.Element[elements.size()])),
             executionEnvironment(
                 mavenProject,
                 mavenSession,
-                pluginManager
-            )
-        );
+                pluginManager));
+    }
+
+    protected String detectCamelVersionFromClasspath() {
+        return mavenProject.getDependencies().stream().filter(
+            d -> "org.apache.camel".equals(d.getGroupId()) && ObjectHelper.isNotEmpty(d.getVersion()))
+            .findFirst().map(Dependency::getVersion).orElse(null);
     }
 
     protected String detectRestComponentFromClasspath() {
-        for (Dependency dep : mavenProject.getDependencies()) {
+        for (final Dependency dep : mavenProject.getDependencies()) {
             if ("org.apache.camel".equals(dep.getGroupId())) {
-                String aid = dep.getArtifactId();
-                Optional<String> comp = Arrays.asList(DEFAULT_REST_CONSUMER_COMPONENTS).stream().filter(c -> aid.startsWith("camel-" + c)).findFirst();
+                final String aid = dep.getArtifactId();
+                final Optional<String> comp = Arrays.asList(DEFAULT_REST_CONSUMER_COMPONENTS).stream()
+                    .filter(c -> aid.startsWith("camel-" + c)).findFirst();
                 if (comp.isPresent()) {
                     return comp.get();
                 }
@@ -209,15 +213,9 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
         return mavenProject.getDependencies().stream().anyMatch(d -> "org.springframework.boot".equals(d.getGroupId()));
     }
 
-    protected String detectCamelVersionFromClasspath() {
-        return mavenProject.getDependencies().stream().filter(
-            d -> "org.apache.camel".equals(d.getGroupId()) && ObjectHelper.isNotEmpty(d.getVersion()))
-            .findFirst().map(Dependency::getVersion).orElse(null);
-    }
-
     protected String detectSpringBootMainPackage() throws IOException {
-        for (String src : mavenProject.getCompileSourceRoots()) {
-            String d = findSpringSpringBootPackage(new File(src));
+        for (final String src : mavenProject.getCompileSourceRoots()) {
+            final String d = findSpringSpringBootPackage(new File(src));
             if (d != null) {
                 return d;
             }
@@ -225,17 +223,19 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
         return null;
     }
 
-    protected String findSpringSpringBootPackage(File dir) throws IOException {
-        File[] files = dir.listFiles();
+    protected String findSpringSpringBootPackage(final File dir) throws IOException {
+        final File[] files = dir.listFiles();
         if (files != null) {
-            for (File file : files) {
+            for (final File file : files) {
                 if (file.getName().endsWith(".java")) {
-                    String content = IOHelper.loadText(new FileInputStream(file));
-                    if (content.contains("@SpringBootApplication")) {
-                        return grabPackageName(content);
+                    try (InputStream stream = new FileInputStream(file)) {
+                        final String content = IOHelper.loadText(stream);
+                        if (content.contains("@SpringBootApplication")) {
+                            return grabPackageName(content);
+                        }
                     }
                 } else if (file.isDirectory()) {
-                    String packageName = findSpringSpringBootPackage(file);
+                    final String packageName = findSpringSpringBootPackage(file);
                     if (packageName != null) {
                         return packageName;
                     }
@@ -245,8 +245,8 @@ abstract class AbstractGenerateMojo extends AbstractMojo {
         return null;
     }
 
-    protected String grabPackageName(String content) {
-        String[] lines = content.split("\\n");
+    protected static String grabPackageName(final String content) {
+        final String[] lines = content.split("\\n");
         for (String line : lines) {
             line = line.trim();
             if (line.startsWith("package ")) {
diff --git a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlMojo.java b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlMojo.java
index 00dcfc3..02b77ec 100644
--- a/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlMojo.java
+++ b/tooling/maven/camel-restdsl-swagger-plugin/src/main/java/org/apache/camel/maven/generator/swagger/GenerateXmlMojo.java
@@ -18,15 +18,14 @@ package org.apache.camel.maven.generator.swagger;
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.IOException;
 
 import io.swagger.models.Swagger;
 import io.swagger.parser.SwaggerParser;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.generator.swagger.DestinationGenerator;
 import org.apache.camel.generator.swagger.RestDslGenerator;
 import org.apache.camel.generator.swagger.RestDslXmlGenerator;
-import org.apache.camel.generator.swagger.SpringBootProjectSourceCodeGenerator;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -39,14 +38,14 @@ import org.apache.maven.plugins.annotations.ResolutionScope;
     requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
 public class GenerateXmlMojo extends AbstractGenerateMojo {
 
-    @Parameter(defaultValue = "${project.build.directory}/generated-sources/restdsl-swagger", required = true)
-    private String outputDirectory;
+    @Parameter(defaultValue = "false")
+    private boolean blueprint;
 
     @Parameter(defaultValue = "camel-rest.xml", required = true)
     private String fileName;
 
-    @Parameter(defaultValue = "false")
-    private boolean blueprint;
+    @Parameter(defaultValue = "${project.build.directory}/generated-sources/restdsl-swagger", required = true)
+    private String outputDirectory;
 
     @Override
     public void execute() throws MojoExecutionException {
@@ -96,7 +95,7 @@ public class GenerateXmlMojo extends AbstractGenerateMojo {
                 String dep = "\n\t\t<dependency>"
                     + "\n\t\t\t<groupId>org.apache.camel</groupId>"
                     + "\n\t\t\t<artifactId>" + aid + "</artifactId>";
-                String ver = detectCamelVersionFromClasspath();
+                final String ver = detectCamelVersionFromClasspath();
                 if (ver != null) {
                     dep += "\n\t\t\t<version>" + ver + "</version>";
                 }
@@ -110,17 +109,16 @@ public class GenerateXmlMojo extends AbstractGenerateMojo {
         }
 
         try {
-            CamelContext camel = new DefaultCamelContext();
-            String xml = generator.generate(camel);
+            final CamelContext camel = new DefaultCamelContext();
+            final String xml = generator.generate(camel);
 
             // ensure output folder is created
             new File(outputDirectory).mkdirs();
-            File out = new File(outputDirectory, fileName);
-
-            FileOutputStream fos = new FileOutputStream(out);
-            fos.write(xml.getBytes());
-            fos.close();
+            final File out = new File(outputDirectory, fileName);
 
+            try (FileOutputStream fos = new FileOutputStream(out)) {
+                fos.write(xml.getBytes());
+            }
         } catch (final Exception e) {
             throw new MojoExecutionException(
                 "Unable to generate REST DSL Swagger sources from specification: " + specificationUri, e);


[camel] 03/04: CAMEL-13893: use XML API to modify REST XML DSL

Posted by zr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit ea84ffabb1053803edf213fd37419d1a4875dccd
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Thu Aug 22 20:02:58 2019 +0200

    CAMEL-13893: use XML API to modify REST XML DSL
    
    This replaces the string manipulation of XML in Swagger REST DSL XML
    generator with using XML API to perform the needed manipulation.
---
 .../generator/swagger/RestDslXmlGenerator.java     | 74 ++++++++++++++++------
 .../generator/swagger/RestDslXmlGeneratorTest.java | 39 +++++++++---
 2 files changed, 87 insertions(+), 26 deletions(-)

diff --git a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslXmlGenerator.java b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslXmlGenerator.java
index 2edf540..ecbb460 100644
--- a/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslXmlGenerator.java
+++ b/tooling/swagger-rest-dsl-generator/src/main/java/org/apache/camel/generator/swagger/RestDslXmlGenerator.java
@@ -16,11 +16,26 @@
  */
 package org.apache.camel.generator.swagger;
 
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
 import io.swagger.models.Swagger;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.model.ModelHelper;
 import org.apache.camel.model.rest.RestsDefinition;
 import org.apache.camel.util.ObjectHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
 
 public class RestDslXmlGenerator extends RestDslGenerator<RestDslXmlGenerator> {
 
@@ -30,40 +45,63 @@ public class RestDslXmlGenerator extends RestDslGenerator<RestDslXmlGenerator> {
         super(swagger);
     }
 
-    public RestDslXmlGenerator withBlueprint() {
-        this.blueprint = true;
-        return this;
-    }
-
     public String generate(final CamelContext context) throws Exception {
         final RestDefinitionEmitter emitter = new RestDefinitionEmitter(context);
 
-        final PathVisitor<RestsDefinition> restDslStatement = new PathVisitor<>(swagger.getBasePath(), emitter, filter, destinationGenerator());
+        final PathVisitor<RestsDefinition> restDslStatement = new PathVisitor<>(swagger.getBasePath(), emitter, filter,
+            destinationGenerator());
 
         swagger.getPaths().forEach(restDslStatement::visit);
 
-        RestsDefinition rests = emitter.result();
-        String xml = ModelHelper.dumpModelAsXml(context, rests);
+        final RestsDefinition rests = emitter.result();
+        final String xml = ModelHelper.dumpModelAsXml(context, rests);
+
+        final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+        builderFactory.setNamespaceAware(true);
+
+        final DocumentBuilder builder = builderFactory.newDocumentBuilder();
+
+        final Document document = builder.parse(new InputSource(new StringReader(xml)));
+
+        final Element root = document.getDocumentElement();
+
         if (blueprint) {
-            xml = xml.replace("http://camel.apache.org/schema/spring", "http://camel.apache.org/schema/blueprint");
+            document.renameNode(root, "http://camel.apache.org/schema/blueprint", root.getTagName());
         }
+
         // remove all customId attributes as we do not want them in the output
-        xml = xml.replaceAll(" customId=\"true\"", "");
-        xml = xml.replaceAll(" customId=\"false\"", "");
+        final NodeList elements = document.getElementsByTagName("*");
+        for (int i = 0; i < elements.getLength(); i++) {
+            final Element element = (Element) elements.item(i);
+            element.removeAttribute("customId");
+        }
 
         if (restComponent != null) {
-            String extra = "<restConfiguration component=\"" + restComponent + "\"";
+            final Element configuration = document.createElement("restConfiguration");
+            configuration.setAttribute("component", restComponent);
+
             if (restContextPath != null) {
-                extra = extra.concat(" contextPath=\"" + restContextPath + "\"");
+                configuration.setAttribute("contextPath", restContextPath);
             }
+
             if (ObjectHelper.isNotEmpty(apiContextPath)) {
-                extra = extra.concat(" apiContextPath=\"" + apiContextPath + "\"");
+                configuration.setAttribute("apiContextPath", apiContextPath);
             }
-            extra = extra.concat("/>");
-            xml = xml.replaceFirst("<rest>", extra + "\n    <rest>");
-            xml = xml.replaceFirst("<rest ", extra + "\n    <rest ");
+
+            root.insertBefore(configuration, root.getFirstChild());
         }
 
-        return xml;
+        final TransformerFactory transformerFactory = TransformerFactory.newInstance();
+        final Transformer transformer = transformerFactory.newTransformer();
+
+        final StringWriter writer = new StringWriter();
+        transformer.transform(new DOMSource(document), new StreamResult(writer));
+
+        return writer.toString();
+    }
+
+    public RestDslXmlGenerator withBlueprint() {
+        blueprint = true;
+        return this;
     }
 }
diff --git a/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslXmlGeneratorTest.java b/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslXmlGeneratorTest.java
index c64a506..c07143d 100644
--- a/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslXmlGeneratorTest.java
+++ b/tooling/swagger-rest-dsl-generator/src/test/java/org/apache/camel/generator/swagger/RestDslXmlGeneratorTest.java
@@ -16,16 +16,23 @@
  */
 package org.apache.camel.generator.swagger;
 
+import java.io.StringReader;
 import java.net.URI;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import io.swagger.models.Swagger;
 import io.swagger.parser.SwaggerParser;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.junit.Test;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -34,6 +41,15 @@ public class RestDslXmlGeneratorTest {
     final Swagger swagger = new SwaggerParser().read("petstore.json");
 
     @Test
+    public void shouldGenerateBlueprintXml() throws Exception {
+        final CamelContext context = new DefaultCamelContext();
+
+        final String xml = RestDslGenerator.toXml(swagger).withBlueprint().generate(context);
+        assertThat(xml).isNotEmpty();
+        assertThat(xml.contains("http://camel.apache.org/schema/blueprint"));
+    }
+
+    @Test
     public void shouldGenerateXml() throws Exception {
         final CamelContext context = new DefaultCamelContext();
 
@@ -43,12 +59,19 @@ public class RestDslXmlGeneratorTest {
     }
 
     @Test
-    public void shouldGenerateBlueprintXml() throws Exception {
+    public void shouldGenerateXmlWithDefaultnamespace() throws Exception {
         final CamelContext context = new DefaultCamelContext();
 
-        final String xml = RestDslGenerator.toXml(swagger).withBlueprint().generate(context);
-        assertThat(xml).isNotEmpty();
-        assertThat(xml.contains("http://camel.apache.org/schema/blueprint"));
+        final String xml = RestDslGenerator.toXml(swagger).generate(context);
+
+        final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+        builderFactory.setNamespaceAware(true);
+
+        final DocumentBuilder builder = builderFactory.newDocumentBuilder();
+
+        final Document document = builder.parse(new InputSource(new StringReader(xml)));
+
+        assertThat(document.isDefaultNamespace("http://camel.apache.org/schema/spring")).isTrue();
     }
 
     @Test
@@ -60,20 +83,20 @@ public class RestDslXmlGeneratorTest {
         final URI file = RestDslGeneratorTest.class.getResource("/SwaggerPetstoreXml.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
 
-        assertThat(xml).isEqualToIgnoringWhitespace(expectedContent);
+        assertThat(xml).isXmlEqualTo(expectedContent);
     }
 
     @Test
     public void shouldGenerateXmlWithRestComponent() throws Exception {
         final CamelContext context = new DefaultCamelContext();
 
-        final String xml = RestDslGenerator.toXml(swagger).withRestComponent("servlet").withRestContextPath("/foo").generate(context);
+        final String xml = RestDslGenerator.toXml(swagger).withRestComponent("servlet").withRestContextPath("/foo")
+            .generate(context);
 
         final URI file = RestDslGeneratorTest.class.getResource("/SwaggerPetstoreWithRestComponentXml.txt").toURI();
         final String expectedContent = new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
 
-        assertThat(xml).isEqualToIgnoringWhitespace(expectedContent);
+        assertThat(xml).isXmlEqualTo(expectedContent);
     }
 
-
 }


[camel] 04/04: Regen

Posted by zr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 158fcf0eb09305f129644d8ddb7c544d90a683fc
Author: Zoran Regvart <zr...@apache.org>
AuthorDate: Thu Aug 22 21:25:30 2019 +0200

    Regen
---
 docs/components/modules/ROOT/pages/aws-cw-component.adoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/components/modules/ROOT/pages/aws-cw-component.adoc b/docs/components/modules/ROOT/pages/aws-cw-component.adoc
index 826a590..1895869 100644
--- a/docs/components/modules/ROOT/pages/aws-cw-component.adoc
+++ b/docs/components/modules/ROOT/pages/aws-cw-component.adoc
@@ -172,7 +172,7 @@ URI:
 [source,java]
 -------------------------------------------------
 from("direct:start")
-.to("aws-cw://namepsace?amazonCwClient=#client");
+.to("aws-cw://namespace?amazonCwClient=#client");
 -------------------------------------------------
 
 The `#client` refers to a `AmazonCloudWatch` in the