camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [12/13] camel git commit: CAMEL-8232: Camel Toolbox - Include documentation about data formats
Date Tue, 13 Jan 2015 17:04:38 GMT
CAMEL-8232: Camel Toolbox - Include documentation about data formats


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

Branch: refs/heads/master
Commit: bd54575d99449d94637b10cbb51d711109a96027
Parents: 616d512
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Jan 13 15:22:42 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jan 13 17:33:30 2015 +0100

----------------------------------------------------------------------
 camel-core/pom.xml                              |  9 +-
 ...FormatConfigurationAndDocumentationTest.java |  5 +-
 .../maven/packaging/PackageDataFormatMojo.java  | 96 +++++++++++++-------
 3 files changed, 74 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bd54575d/camel-core/pom.xml
----------------------------------------------------------------------
diff --git a/camel-core/pom.xml b/camel-core/pom.xml
index 8540900..c8789c9 100644
--- a/camel-core/pom.xml
+++ b/camel-core/pom.xml
@@ -282,7 +282,6 @@
             <id>components</id>
             <goals>
               <goal>generate-components-list</goal>
-              <goal>generate-dataformats-list</goal>
             </goals>
             <phase>generate-resources</phase>
           </execution>
@@ -293,6 +292,14 @@
             </goals>
             <phase>process-classes</phase>
           </execution>
+          <!-- camel-core needs to generate dataformats after compilation -->
+          <execution>
+            <id>dataformats</id>
+            <goals>
+              <goal>generate-dataformats-list</goal>
+            </goals>
+            <phase>process-classes</phase>
+          </execution>
         </executions>
       </plugin>
     </plugins>

http://git-wip-us.apache.org/repos/asf/camel/blob/bd54575d/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
b/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
index be463b3..09d8d66 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
@@ -18,7 +18,6 @@ package org.apache.camel.impl;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class StringDataFormatConfigurationAndDocumentationTest extends ContextTestSupport
{
@@ -29,14 +28,14 @@ public class StringDataFormatConfigurationAndDocumentationTest extends
ContextTe
     }
 
     @Test
-    @Ignore
     public void testDataFormatJsonSchema() throws Exception {
         CamelContext context = new DefaultCamelContext();
         String json = context.getDataFormatParameterJsonSchema("string");
         assertNotNull("Should have found some auto-generated JSON", json);
         log.info(json);
 
-        assertTrue(json.contains("\"description\": \"Represents the String (text based) DataFormat\""));
+        assertTrue(json.contains("\"name\": \"string\""));
+        assertTrue(json.contains("\"modelName\": \"string\""));
         assertTrue(json.contains("\"charset\": { \"kind\": \"attribute\", \"required\": \"false\",
\"type\": \"string\", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\" }"));
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/bd54575d/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java
index 06c34ff..ee61f54 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java
@@ -48,6 +48,7 @@ import static org.apache.camel.maven.packaging.PackageHelper.parseAsMap;
  *
  * @goal generate-dataformats-list
  * @execute phase="generate-resources"
+ * @execute phase="process-classes"
  */
 public class PackageDataFormatMojo extends AbstractMojo {
 
@@ -142,44 +143,54 @@ public class PackageDataFormatMojo extends AbstractMojo {
                     URL url = new URL("file", null, core.getAbsolutePath());
                     URLClassLoader loader = new URLClassLoader(new URL[]{url});
                     for (String name : javaTypes.keySet()) {
-                        InputStream is = loader.getResourceAsStream("org/apache/camel/model/dataformat/"
+ name + ".json");
-                        if (is != null) {
-                            String json = loadText(is);
-                            if (json != null) {
-                                DataFormatModel dataFormatModel = new DataFormatModel();
-                                dataFormatModel.setName(name);
-                                dataFormatModel.setDescription(project.getDescription());
-                                dataFormatModel.setJavaType(javaTypes.get(name));
-                                dataFormatModel.setGroupId(project.getGroupId());
-                                dataFormatModel.setArtifactId(project.getArtifactId());
-                                dataFormatModel.setVersion(project.getVersion());
-
-                                List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model",
json, false);
-                                for (Map<String, String> row : rows) {
-                                    if (row.containsKey("label")) {
-                                        dataFormatModel.setLabel(row.get("label"));
-                                    } else {
-                                        dataFormatModel.setLabel("");
+                        String modelName = asModelName(name);
+                        InputStream is = loader.getResourceAsStream("org/apache/camel/model/dataformat/"
+ modelName + ".json");
+                        if (is == null) {
+                            // use file input stream if we build camel-core itself, and thus
do not have a JAR which can be loaded by URLClassLoader
+                            is = new FileInputStream(new File(core, "org/apache/camel/model/dataformat/"
+ modelName + ".json"));
+                        }
+                        String json = loadText(is);
+                        if (json != null) {
+                            DataFormatModel dataFormatModel = new DataFormatModel();
+                            dataFormatModel.setName(name);
+                            dataFormatModel.setModelName(modelName);
+                            dataFormatModel.setDescription(project.getDescription());
+                            dataFormatModel.setJavaType(javaTypes.get(name));
+                            dataFormatModel.setGroupId(project.getGroupId());
+                            dataFormatModel.setArtifactId(project.getArtifactId());
+                            dataFormatModel.setVersion(project.getVersion());
+
+                            List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model",
json, false);
+                            for (Map<String, String> row : rows) {
+                                if (row.containsKey("label")) {
+                                    dataFormatModel.setLabel(row.get("label"));
+                                } else {
+                                    dataFormatModel.setLabel("");
+                                }
+                                // override description for camel-core, as otherwise its
too generic
+                                if ("camel-core".equals(project.getArtifactId())) {
+                                    if (row.containsKey("description")) {
+                                        dataFormatModel.setLabel(row.get("description"));
                                     }
                                 }
-                                getLog().debug("Model " + dataFormatModel);
+                            }
+                            getLog().debug("Model " + dataFormatModel);
 
-                                // build json schema for the data format
-                                String properties = after(json, "  \"properties\": {");
-                                String schema = createParameterJsonSchema(dataFormatModel,
properties);
-                                getLog().debug("JSon schema\n" + schema);
+                            // build json schema for the data format
+                            String properties = after(json, "  \"properties\": {");
+                            String schema = createParameterJsonSchema(dataFormatModel, properties);
+                            getLog().debug("JSon schema\n" + schema);
 
-                                // write this to the directory
-                                File dir = new File(schemaOutDir, schemaSubDirectory(dataFormatModel.getJavaType()));
-                                dir.mkdirs();
+                            // write this to the directory
+                            File dir = new File(schemaOutDir, schemaSubDirectory(dataFormatModel.getJavaType()));
+                            dir.mkdirs();
 
-                                File out = new File(dir, name + ".json");
-                                FileOutputStream fos = new FileOutputStream(out, false);
-                                fos.write(schema.getBytes());
-                                fos.close();
+                            File out = new File(dir, name + ".json");
+                            FileOutputStream fos = new FileOutputStream(out, false);
+                            fos.write(schema.getBytes());
+                            fos.close();
 
-                                getLog().info("Generated " + out + " containing JSon schema
for " + name + " data format");
-                            }
+                            getLog().info("Generated " + out + " containing JSon schema for
" + name + " data format");
                         }
                     }
                 }
@@ -218,6 +229,16 @@ public class PackageDataFormatMojo extends AbstractMojo {
         }
     }
 
+    private String asModelName(String name) {
+        // special for some data formats
+        if ("json-gson".equals(name) || "json-jackson".equals(name) || "json-xstream".equals(name))
{
+            return "json";
+        } else if ("bindy-csv".equals(name) || "bindy-fixed".equals(name) || "bindy-kvp".equals(name))
{
+            return "bindy";
+        }
+        return name;
+    }
+
     private Artifact findCamelCoreArtifact(MavenProject project) {
         // maybe this project is camel-core itself
         Artifact artifact = project.getArtifact();
@@ -247,6 +268,7 @@ public class PackageDataFormatMojo extends AbstractMojo {
         // component model
         buffer.append("\n \"dataformat\": {");
         buffer.append("\n    \"name\": \"").append(dataFormatModel.getName()).append("\",");
+        buffer.append("\n    \"modelName\": \"").append(dataFormatModel.getModelName()).append("\",");
         buffer.append("\n    \"description\": \"").append(dataFormatModel.getDescription()).append("\",");
         buffer.append("\n    \"label\": \"").append(dataFormatModel.getLabel()).append("\",");
         buffer.append("\n    \"javaType\": \"").append(dataFormatModel.getJavaType()).append("\",");
@@ -262,6 +284,7 @@ public class PackageDataFormatMojo extends AbstractMojo {
 
     private class DataFormatModel {
         private String name;
+        private String modelName;
         private String description;
         private String label;
         private String javaType;
@@ -277,6 +300,14 @@ public class PackageDataFormatMojo extends AbstractMojo {
             this.name = name;
         }
 
+        public String getModelName() {
+            return modelName;
+        }
+
+        public void setModelName(String modelName) {
+            this.modelName = modelName;
+        }
+
         public String getDescription() {
             return description;
         }
@@ -329,6 +360,7 @@ public class PackageDataFormatMojo extends AbstractMojo {
         public String toString() {
             return "DataFormatModel["
                     + "name='" + name + '\''
+                    + ", modelName='" + modelName + '\''
                     + ", description='" + description + '\''
                     + ", label='" + label + '\''
                     + ", javaType='" + javaType + '\''


Mime
View raw message