Repository: camel
Updated Branches:
  refs/heads/mention ce9f90df4 -> a419ffe7c


CAMEL-10800: camel-connector generate connector-schema.json file into the 
source code so its easier to browse.


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

Branch: refs/heads/mention
Commit: a419ffe7c58ccb123bd53c6b7845e5e1941cbc0b
Parents: ce9f90d
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue Feb 7 16:36:15 2017 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Feb 7 16:36:15 2017 +0100

----------------------------------------------------------------------
 .../camel/maven/connector/ConnectorMojo.java    | 18 +++++++++-
 .../camel/maven/connector/FileHelper.java       | 37 ++++++++++++++++++++
 .../main/resources/camel-connector-schema.json  | 25 +++++++++++++
 .../main/resources/camel-connector-schema.json  | 25 +++++++++++++
 .../main/resources/camel-connector-schema.json  | 22 ++++++++++++
 .../main/resources/camel-connector-schema.json  | 24 +++++++++++++
 6 files changed, 150 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a419ffe7/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java
----------------------------------------------------------------------
diff --git 
a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java
 
b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java
index dbda8ac..94df1e6 100644
--- 
a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java
+++ 
b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/ConnectorMojo.java
@@ -48,6 +48,13 @@ public class ConnectorMojo extends AbstractJarMojo {
     private File classesDirectory;
 
     /**
+     * Whether to generate JSon schema files to the sources directory 
(<tt>src/main/resources</tt>) which allows the files to be stored together with 
the source code.
+     * If this options is <tt>false</tt> the JSon schema files are generated 
into <tt>target/classes</tt> and only included in the built JAR.
+     */
+    @Parameter(defaultValue = "true")
+    private boolean generateToSources;
+
+    /**
      * Whether to include the git url for the git repository of the source 
code for the Camel connector
      */
     @Parameter(defaultValue = "false")
@@ -72,6 +79,9 @@ public class ConnectorMojo extends AbstractJarMojo {
     @Override
     public File createArchive() throws MojoExecutionException {
 
+        // project root folder
+        File root = classesDirectory.getParentFile().getParentFile();
+
         String gitUrl = null;
 
         // find the component dependency and get its .json file
@@ -103,7 +113,6 @@ public class ConnectorMojo extends AbstractJarMojo {
                         // update file
                         
mapper.writerWithDefaultPrettyPrinter().writeValue(file, dto);
                         // update source file also
-                        File root = 
classesDirectory.getParentFile().getParentFile();
                         file = new File(root, 
"src/main/resources/camel-connector.json");
                         if (file.exists()) {
                             getLog().info("Updating gitUrl to " + file);
@@ -161,6 +170,13 @@ public class ConnectorMojo extends AbstractJarMojo {
                     fos = new FileOutputStream(out, false);
                     fos.write(newJson.getBytes());
                     fos.close();
+
+                    if (generateToSources) {
+                        // copy the file into the sources as well
+                        File from = new File(classesDirectory, 
"camel-connector-schema.json");
+                        File to = new File(root, 
"src/main/resources/camel-connector-schema.json");
+                        FileHelper.copyFile(from, to);
+                    }
                 }
 
                 // build json schema for component that only has the 
selectable options

http://git-wip-us.apache.org/repos/asf/camel/blob/a419ffe7/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/FileHelper.java
----------------------------------------------------------------------
diff --git 
a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/FileHelper.java
 
b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/FileHelper.java
index a7c7502..ae01138 100644
--- 
a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/FileHelper.java
+++ 
b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/FileHelper.java
@@ -17,12 +17,16 @@
 package org.apache.camel.maven.connector;
 
 import java.io.BufferedReader;
+import java.io.Closeable;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.LineNumberReader;
+import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -100,4 +104,37 @@ public final class FileHelper {
 
         return lines;
     }
+
+    public static void copyFile(File from, File to) throws IOException {
+        FileChannel in = null;
+        FileChannel out = null;
+        try {
+            in = new FileInputStream(from).getChannel();
+            out = new FileOutputStream(to).getChannel();
+
+            long size = in.size();
+            long position = 0;
+            while (position < size) {
+                position += in.transferTo(position, 4096, out);
+            }
+        } finally {
+            close(in);
+            close(out);
+        }
+    }
+
+    /**
+     * Closes the given resource if it is available, logging any closing 
exceptions to the given log.
+     */
+    public static void close(Closeable closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/a419ffe7/connectors/examples/bar-connector/src/main/resources/camel-connector-schema.json
----------------------------------------------------------------------
diff --git 
a/connectors/examples/bar-connector/src/main/resources/camel-connector-schema.json
 
b/connectors/examples/bar-connector/src/main/resources/camel-connector-schema.json
new file mode 100644
index 0000000..1c0dcdd
--- /dev/null
+++ 
b/connectors/examples/bar-connector/src/main/resources/camel-connector-schema.json
@@ -0,0 +1,25 @@
+{
+  "component": {
+    "kind": "component",
+    "baseScheme": "beverage",
+    "scheme": "bar",
+    "syntax": "bar:drink",
+    "title": "Bar",
+    "description": "To order drinks from the bar",
+    "label": "bar",
+    "deprecated": "false",
+    "async": "false",
+    "producerOnly": "true",
+    "javaType": "org.foo.connector.BarComponent",
+    "groupId": "org.foo",
+    "artifactId": "bar-connector",
+    "version": "2.19.0-SNAPSHOT"
+  },
+  "componentProperties": {
+  },
+  "properties": {
+    "drink": 
{"kind":"path","group":"producer","required":"true","type":"object","javaType":"org.beverage.Beverages","enum":"Beer,GinTonic,Wine","deprecated":"false","secret":"false","description":"What
 drink to order"},
+    "amount": 
{"kind":"parameter","group":"producer","type":"integer","javaType":"int","deprecated":"false","secret":"false","defaultValue":"2","description":"Number
 of drinks in the order"},
+    "celebrity": 
{"kind":"parameter","group":"producer","type":"boolean","javaType":"boolean","deprecated":"false","secret":"false","defaultValue":"false","description":"Is
 this a famous person ordering"}
+  }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a419ffe7/connectors/examples/foo-connector/src/main/resources/camel-connector-schema.json
----------------------------------------------------------------------
diff --git 
a/connectors/examples/foo-connector/src/main/resources/camel-connector-schema.json
 
b/connectors/examples/foo-connector/src/main/resources/camel-connector-schema.json
new file mode 100644
index 0000000..eeca92c
--- /dev/null
+++ 
b/connectors/examples/foo-connector/src/main/resources/camel-connector-schema.json
@@ -0,0 +1,25 @@
+{
+  "component": {
+    "kind": "component",
+    "baseScheme": "timer",
+    "scheme": "foo",
+    "syntax": "foo:timerName",
+    "title": "Foo",
+    "description": "Something cool",
+    "label": "foo,timer",
+    "deprecated": "false",
+    "async": "false",
+    "consumerOnly": "true",
+    "javaType": "org.foo.connector.FooComponent",
+    "groupId": "org.foo",
+    "artifactId": "foo-connector",
+    "version": "2.19.0-SNAPSHOT"
+  },
+  "componentProperties": {
+  },
+  "properties": {
+    "timerName": 
{"kind":"path","group":"consumer","required":"true","type":"string","javaType":"java.lang.String","deprecated":"false","secret":"false","description":"The
 name of the timer"},
+    "period": 
{"kind":"parameter","group":"consumer","type":"integer","javaType":"long","deprecated":"false","secret":"false","defaultValue":"5000","description":"If
 greater than 0 generate periodic events every period milliseconds. The default 
value is 1000. You can also specify time values using units such as 60s (60 
seconds) 5m30s (5 minutes and 30 seconds) and 1h (1 hour)."},
+    "repeatCount": 
{"kind":"parameter","group":"consumer","type":"integer","javaType":"long","deprecated":"false","secret":"false","defaultValue":"0","description":"Specifies
 a maximum limit of number of fires. So if you set it to 1 the timer will only 
fire once. If you set it to 5 it will only fire five times. A value of zero or 
negative means fire forever."}
+  }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a419ffe7/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
----------------------------------------------------------------------
diff --git 
a/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
 
b/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
new file mode 100644
index 0000000..a2228a0
--- /dev/null
+++ 
b/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
@@ -0,0 +1,22 @@
+{
+  "component": {
+    "kind": "component",
+    "baseScheme": "twitter",
+    "scheme": "twitter-mention",
+    "syntax": "twitter-mention:kind",
+    "title": "TwitterMention",
+    "description": "Connection from twitter when anyone mention you",
+    "label": "twitter",
+    "deprecated": "false",
+    "async": "false",
+    "consumerOnly": "true",
+    "javaType": "org.foo.mention.TwitterMentionComponent",
+    "groupId": "org.foo",
+    "artifactId": "twitter-mention-connector",
+    "version": "2.19.0-SNAPSHOT"
+  },
+  "componentProperties": {
+  },
+  "properties": {
+  }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a419ffe7/connectors/examples/wine-connector/src/main/resources/camel-connector-schema.json
----------------------------------------------------------------------
diff --git 
a/connectors/examples/wine-connector/src/main/resources/camel-connector-schema.json
 
b/connectors/examples/wine-connector/src/main/resources/camel-connector-schema.json
new file mode 100644
index 0000000..4aff244
--- /dev/null
+++ 
b/connectors/examples/wine-connector/src/main/resources/camel-connector-schema.json
@@ -0,0 +1,24 @@
+{
+  "component": {
+    "kind": "component",
+    "baseScheme": "beverage",
+    "scheme": "wine",
+    "syntax": "wine:drink",
+    "title": "Wine",
+    "description": "To order wine from the bar",
+    "label": "bar",
+    "deprecated": "false",
+    "async": "false",
+    "producerOnly": "true",
+    "javaType": "org.foo.connector.WineComponent",
+    "groupId": "org.foo",
+    "artifactId": "wine-connector",
+    "version": "2.19.0-SNAPSHOT"
+  },
+  "componentProperties": {
+  },
+  "properties": {
+    "drink": 
{"kind":"path","group":"producer","required":"true","type":"object","javaType":"org.beverage.Beverages","enum":["Wine"],"deprecated":"false","secret":"false","description":"You
 can only order wine","defaultValue":"Wine"},
+    "amount": 
{"kind":"parameter","group":"producer","type":"integer","javaType":"int","deprecated":"false","secret":"false","defaultValue":"1","description":"Number
 of drinks in the order"}
+  }
+}

Reply via email to