camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] camel git commit: First cut of mvn goal to generate/update component readme.md file. Make the plugin update the existing adoc file to keep the endpoint options up to date.
Date Wed, 27 Jan 2016 13:31:07 GMT
First cut of mvn goal to generate/update component readme.md file. Make the plugin update the
existing adoc file to keep the endpoint options up to date.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2cabc80b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2cabc80b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2cabc80b

Branch: refs/heads/master
Commit: 2cabc80ba6ddd12ba104d4811f5674a435dc7338
Parents: 4da48df
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Jan 27 14:30:14 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Jan 27 14:30:56 2016 +0100

----------------------------------------------------------------------
 components/camel-ahc/src/main/docs/ahc.adoc     |  33 ++++--
 .../maven/packaging/ReadmeComponentMojo.java    | 105 ++++++++++---------
 .../maven/packaging/model/ComponentModel.java   |  13 +--
 .../src/main/resources/component-options.mvel   |  30 +-----
 4 files changed, 89 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2cabc80b/components/camel-ahc/src/main/docs/ahc.adoc
----------------------------------------------------------------------
diff --git a/components/camel-ahc/src/main/docs/ahc.adoc b/components/camel-ahc/src/main/docs/ahc.adoc
index 5cc500f..b4b87f8 100644
--- a/components/camel-ahc/src/main/docs/ahc.adoc
+++ b/components/camel-ahc/src/main/docs/ahc.adoc
@@ -77,19 +77,30 @@ The AHC component supports 12 endpoint options which are listed below:
 AhcComponent Options
 ^^^^^^^^^^^^^^^^^^^^
 
-[width="100%",cols="10%,10%,80%",options="header",]
+
+
+
+
+
+// component options: START
+The AHC component supports 6 options which are listed below.
+
+
+[width="100%",cols="2s,1m,8",options="header"]
 |=======================================================================
-|Name |Default Value |Description
-|`client` |`null` |To use a custom `com.ning.http.client.AsyncHttpClient`.
-|`clientConfig` |`null` |To configure the `AsyncHttpClient` to use a custom
-`com.ning.http.client.AsyncHttpClientConfig`.
-|`binding` |`null` |To use a custom `org.apache.camel.component.ahc.AhcBinding`.
-|`sslContextParameters` |`null` |*Camel 2.9:* To configure custom SSL/TLS configuration options
at the
-component level.  See  link:ahc.html[Using the JSSE Configuration
-Utility] for more details.  Note that configuring this option will
-override any SSL/TLS configuration options provided through the
-clientConfig option at the endpoint or component level.
+| Name | Java Type | Description
+| client | AsyncHttpClient | To use a custom AsyncHttpClient
+| binding | AhcBinding | To use a custom AhcBinding which allows to control how to bind between
AHC and Camel.
+| clientConfig | AsyncHttpClientConfig | To configure the AsyncHttpClient to use a custom
com.ning.http.client.AsyncHttpClientConfig instance.
+| sslContextParameters | SSLContextParameters | Reference to a org.apache.camel.util.jsse.SSLContextParameters
in the Registry. Note that configuring this option will override any SSL/TLS configuration
options provided through the clientConfig option at the endpoint or component level.
+| allowJavaSerializedObject | boolean | Whether to allow java serialization when a request
uses context-type=application/x-java-serialized-object This is by default turned off. If you
enable this then be aware that Java will deserialize the incoming data from the request to
Java and that can be a potential security risk.
+| headerFilterStrategy | HeaderFilterStrategy | To use a custom HeaderFilterStrategy to filter
header to and from Camel message.
 |=======================================================================
+// component options: END
+
+
+
+
 
 
 Notice that setting any of the options on the `AhcComponent` will

http://git-wip-us.apache.org/repos/asf/camel/blob/2cabc80b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java
index 1276cf4..a6ed564 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ReadmeComponentMojo.java
@@ -18,7 +18,6 @@ package org.apache.camel.maven.packaging;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
@@ -91,33 +90,69 @@ public class ReadmeComponentMojo extends AbstractMojo {
         // only if there is components we should update the documentation files
         if (!componentNames.isEmpty()) {
             getLog().info("Found " + componentNames.size() + " components");
-
             for (String componentName : componentNames) {
                 String json = loadComponentJson(jsonFiles, componentName);
                 if (json != null) {
-
-                    // file
                     File file = new File(docDir, componentName + ".adoc");
-
                     ComponentModel model = generateComponentModel(componentName, json);
-                    String header = templateComponentHeader(model);
-                    String options = templateComponentOptions(model);
-                    String options2 = templateEndpointOptions(model);
 
-//                    getLog().info(header);
-//                    getLog().info(options);
-//                    getLog().info(options2);
+                    boolean updated = false;
+                    if (model.getComponentOptions() != null) {
+                        String options = templateComponentOptions(model);
+                        updated |= updateComponentOptions(file, options);
+                    }
+                    if (model.getEndpointOptions() != null) {
+                        String options = templateEndpointOptions(model);
+                        updated |= updateEndpointOptions(file, options);
+                    }
 
-                    // update the endpoint options
-                    updateEndpointOptions(file, options2);
+                    if (updated) {
+                        getLog().info("Updated file: " + file);
+                    } else {
+                        getLog().info("No changes to file: " + file);
+                    }
                 }
             }
         }
     }
 
-    private void updateEndpointOptions(File file, String changed) throws MojoExecutionException
{
+    private boolean updateComponentOptions(File file, String changed) throws MojoExecutionException
{
         if (!file.exists()) {
-            return;
+            return false;
+        }
+
+        try {
+            String text = loadText(new FileInputStream(file));
+
+            String existing = StringHelper.between(text, "// component options: START", "//
component options: END");
+            if (existing != null) {
+                // remove leading line breaks etc
+                existing = existing.trim();
+                changed = changed.trim();
+                if (existing.equals(changed)) {
+                    return false;
+                } else {
+                    String before = StringHelper.before(text, "// component options: START");
+                    String after = StringHelper.after(text, "// component options: END");
+                    text = before + "\n// component options: START\n" + changed + "\n// component
options: END\n" + after;
+                    writeText(file, text);
+                    return true;
+                }
+            } else {
+                getLog().warn("Cannot find markers in file " + file);
+                getLog().warn("Add the following markers");
+                getLog().warn("\t// component options: START");
+                getLog().warn("\t// component options: END");
+                return false;
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Error reading file " + file + " Reason: " +
e, e);
+        }
+    }
+
+    private boolean updateEndpointOptions(File file, String changed) throws MojoExecutionException
{
+        if (!file.exists()) {
+            return false;
         }
 
         try {
@@ -129,19 +164,20 @@ public class ReadmeComponentMojo extends AbstractMojo {
                 existing = existing.trim();
                 changed = changed.trim();
                 if (existing.equals(changed)) {
-                    getLog().info("No changes to file: " + file);
+                    return false;
                 } else {
-                    getLog().info("Updating file: " + file);
                     String before = StringHelper.before(text, "// endpoint options: START");
                     String after = StringHelper.after(text, "// endpoint options: END");
                     text = before + "\n// endpoint options: START\n" + changed + "\n// endpoint
options: END\n" + after;
                     writeText(file, text);
+                    return true;
                 }
             } else {
                 getLog().warn("Cannot find markers in file " + file);
                 getLog().warn("Add the following markers");
                 getLog().warn("\t// endpoint options: START");
                 getLog().warn("\t// endpoint options: END");
+                return false;
             }
         } catch (Exception e) {
             throw new MojoExecutionException("Error reading file " + file + " Reason: " +
e, e);
@@ -184,7 +220,6 @@ public class ReadmeComponentMojo extends AbstractMojo {
         component.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
 
         rows = JSonSchemaHelper.parseJsonSchema("componentProperties", json, true);
-        List<ComponentOptionModel> componentOptions = new ArrayList<ComponentOptionModel>();
         for (Map<String, String> row : rows) {
             ComponentOptionModel option = new ComponentOptionModel();
             option.setName(getSafeValue("name", row));
@@ -193,12 +228,10 @@ public class ReadmeComponentMojo extends AbstractMojo {
             option.setJavaType(getSafeValue("javaType", row));
             option.setDeprecated(getSafeValue("deprecated", row));
             option.setDescription(getSafeValue("description", row));
-            componentOptions.add(option);
+            component.addComponentOption(option);
         }
-        component.setComponentOptions(componentOptions);
 
         rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
-        List<EndpointOptionModel> endpointOptions = new ArrayList<EndpointOptionModel>();
         for (Map<String, String> row : rows) {
             EndpointOptionModel option = new EndpointOptionModel();
             option.setName(getSafeValue("name", row));
@@ -213,16 +246,13 @@ public class ReadmeComponentMojo extends AbstractMojo {
             option.setDeprecated(getSafeValue("deprecated", row));
             option.setDefaultValue(getSafeValue("defaultValue", row));
             option.setDescription(getSafeValue("description", row));
-
             // lets put required in the description
             if ("true".equals(option.getRequired())) {
                 String desc = "*Required* " + option.getDescription();
                 option.setDescription(desc);
             }
-
-            endpointOptions.add(option);
+            component.addEndpointOption(option);
         }
-        component.setEndpointOptions(endpointOptions);
 
         return component;
     }
@@ -285,29 +315,4 @@ public class ReadmeComponentMojo extends AbstractMojo {
         return componentNames;
     }
 
-    private File initReadMeFile() throws MojoExecutionException {
-        File readmeDir = new File(buildDir, "..");
-        File readmeFile = new File(readmeDir, "readme.md");
-
-        // see if a file with name readme.md exists in any kind of case
-        String[] names = readmeDir.list(new FilenameFilter() {
-            @Override
-            public boolean accept(File dir, String name) {
-                return "readme.md".equalsIgnoreCase(name);
-            }
-        });
-        if (names != null && names.length == 1) {
-            readmeFile = new File(readmeDir, names[0]);
-        }
-
-        boolean exists = readmeFile.exists();
-        if (exists) {
-            getLog().info("Using existing " + readmeFile.getName() + " file");
-        } else {
-            getLog().info("Creating new readme.md file");
-        }
-
-        return readmeFile;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/2cabc80b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java
index 045e227..38c5a8e 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.maven.packaging.model;
 
+import java.util.ArrayList;
 import java.util.List;
 
 public class ComponentModel {
@@ -34,8 +35,8 @@ public class ComponentModel {
     private String groupId;
     private String artifactId;
     private String version;
-    private List<ComponentOptionModel> componentOptions;
-    private List<EndpointOptionModel> endpointOptions;
+    private final List<ComponentOptionModel> componentOptions = new ArrayList<ComponentOptionModel>();
+    private final List<EndpointOptionModel> endpointOptions = new ArrayList<EndpointOptionModel>();
 
     public String getKind() {
         return kind;
@@ -153,16 +154,16 @@ public class ComponentModel {
         return componentOptions;
     }
 
-    public void setComponentOptions(List<ComponentOptionModel> componentOptions) {
-        this.componentOptions = componentOptions;
+    public void addComponentOption(ComponentOptionModel option) {
+        componentOptions.add(option);
     }
 
     public List<EndpointOptionModel> getEndpointOptions() {
         return endpointOptions;
     }
 
-    public void setEndpointOptions(List<EndpointOptionModel> endpointOptions) {
-        this.endpointOptions = endpointOptions;
+    public void addEndpointOption(EndpointOptionModel option) {
+        endpointOptions.add(option);
     }
 
     public String getShortJavaType() {

http://git-wip-us.apache.org/repos/asf/camel/blob/2cabc80b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel
b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel
index 2fef2fa..394e49c 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel
+++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/component-options.mvel
@@ -1,31 +1,11 @@
-### Component options
-
 @if{componentOptions.isEmpty()}
 The @{title} component has no options.
 @else{}
 The @{title} component supports @{componentOptions.size()} options which are listed below.
-
-| Name | Java Type | Description |
-| ---- | --------- | ----------- |
-@foreach{row : componentOptions}| @{row.name} | `@{row.shortJavaType}` | @{row.description}
|
 @end{}
 
-#### Configuring component options
-
-The @{title} component can be configured using Java code as shown:
-
-```java
-   @{shortJavaType} @{scheme} = camelContext.getComponent("@{scheme}", @{shortJavaType}.class);
-   @{scheme}.setFoo(...);
-   @{scheme}.setBar(...);
-```
-
-And in XML you can configure the @{title} component as a <bean> as shown:
-
-```xml
-   <bean id="@{scheme}" class="@{javaType}">
-     <property name="foo" value="..."/>
-     <property name="bar" value="..."/>
-   </bean>
-```
-@end{}
+[width="100%",cols="2s,1m,8",options="header"]
+|=======================================================================
+| Name | Java Type | Description
+@foreach{row : componentOptions}| @{row.name} | @{row.shortJavaType} | @{row.description}
+@end{}|=======================================================================


Mime
View raw message