camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [07/10] camel git commit: CAMEL-10434: Camel catalog support different runtimes to provide their supported list of components etc.
Date Mon, 07 Nov 2016 16:50:53 GMT
CAMEL-10434: Camel catalog support different runtimes to provide their supported list of components
etc.


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

Branch: refs/heads/camel-2.18.x
Commit: 84a5a6e2fa268a93f8df4355552c070ed81db5fc
Parents: 473d90a
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Nov 7 16:05:18 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Nov 7 16:46:52 2016 +0100

----------------------------------------------------------------------
 .../catalog/karaf/KarafRuntimeProvider.java     | 18 ++++++
 .../springboot/SpringBootRuntimeProvider.java   | 18 ++++++
 .../SpringBootRuntimeProviderTest.java          | 24 ++++++++
 .../camel/catalog/DefaultCamelCatalog.java      |  9 +--
 .../camel/catalog/DefaultRuntimeProvider.java   | 18 ++++++
 .../apache/camel/catalog/RuntimeProvider.java   | 20 +++++--
 .../packaging/PrepareCatalogSpringBootMojo.java | 63 +++++++++++++++-----
 7 files changed, 144 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/84a5a6e2/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
b/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
index 67c80c3..86811e4 100644
--- a/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
+++ b/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
@@ -31,6 +31,9 @@ import org.apache.camel.catalog.RuntimeProvider;
  */
 public class KarafRuntimeProvider implements RuntimeProvider {
 
+    private static final String COMPONENT_DIR = "org/apache/camel/catalog/karaf/components";
+    private static final String DATAFORMAT_DIR = "org/apache/camel/catalog/karaf/dataformats";
+    private static final String LANGUAGE_DIR = "org/apache/camel/catalog/karaf/languages";
     private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/karaf/components.properties";
     private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/karaf/dataformats.properties";
     private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/karaf/languages.properties";
@@ -53,6 +56,21 @@ public class KarafRuntimeProvider implements RuntimeProvider {
     }
 
     @Override
+    public String getComponentJSonSchemaDirectory() {
+        return COMPONENT_DIR;
+    }
+
+    @Override
+    public String getDataFormatJSonSchemaDirectory() {
+        return DATAFORMAT_DIR;
+    }
+
+    @Override
+    public String getLanguageJSonSchemaDirectory() {
+        return LANGUAGE_DIR;
+    }
+
+    @Override
     public List<String> findComponentNames() {
         List<String> names = new ArrayList<String>();
         InputStream is = camelCatalog.getVersionManager().getResourceAsStream(COMPONENTS_CATALOG);

http://git-wip-us.apache.org/repos/asf/camel/blob/84a5a6e2/platforms/catalog-provider-springboot/src/main/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-springboot/src/main/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProvider.java
b/platforms/catalog-provider-springboot/src/main/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProvider.java
index 8b61ede..8e06e86 100644
--- a/platforms/catalog-provider-springboot/src/main/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProvider.java
+++ b/platforms/catalog-provider-springboot/src/main/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProvider.java
@@ -31,6 +31,9 @@ import org.apache.camel.catalog.RuntimeProvider;
  */
 public class SpringBootRuntimeProvider implements RuntimeProvider {
 
+    private static final String COMPONENT_DIR = "org/apache/camel/catalog/springboot/components";
+    private static final String DATAFORMAT_DIR = "org/apache/camel/catalog/springboot/dataformats";
+    private static final String LANGUAGE_DIR = "org/apache/camel/catalog/springboot/languages";
     private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/springboot/components.properties";
     private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/springboot/dataformats.properties";
     private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/springboot/languages.properties";
@@ -53,6 +56,21 @@ public class SpringBootRuntimeProvider implements RuntimeProvider {
     }
 
     @Override
+    public String getComponentJSonSchemaDirectory() {
+        return COMPONENT_DIR;
+    }
+
+    @Override
+    public String getDataFormatJSonSchemaDirectory() {
+        return DATAFORMAT_DIR;
+    }
+
+    @Override
+    public String getLanguageJSonSchemaDirectory() {
+        return LANGUAGE_DIR;
+    }
+
+    @Override
     public List<String> findComponentNames() {
         List<String> names = new ArrayList<String>();
         InputStream is = camelCatalog.getVersionManager().getResourceAsStream(COMPONENTS_CATALOG);

http://git-wip-us.apache.org/repos/asf/camel/blob/84a5a6e2/platforms/catalog-provider-springboot/src/test/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProviderTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-springboot/src/test/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProviderTest.java
b/platforms/catalog-provider-springboot/src/test/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProviderTest.java
index 879129d..28aeb8a 100644
--- a/platforms/catalog-provider-springboot/src/test/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProviderTest.java
+++ b/platforms/catalog-provider-springboot/src/test/java/org/apache/camel/catalog/springboot/SpringBootRuntimeProviderTest.java
@@ -93,4 +93,28 @@ public class SpringBootRuntimeProviderTest {
         assertTrue(names.contains("xpath"));
     }
 
+    @Test
+    public void testComponentArtifactId() throws Exception {
+        String json = catalog.componentJSonSchema("ftp");
+
+        assertNotNull(json);
+        assertTrue(json.contains("camel-ftp-starter"));
+    }
+
+    @Test
+    public void testDataFormatArtifactId() throws Exception {
+        String json = catalog.dataFormatJSonSchema("bindy-csv");
+
+        assertNotNull(json);
+        assertTrue(json.contains("camel-bindy-starter"));
+    }
+
+    @Test
+    public void testLanguageArtifactId() throws Exception {
+        String json = catalog.languageJSonSchema("spel");
+
+        assertNotNull(json);
+        assertTrue(json.contains("camel-spring-starter"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/84a5a6e2/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index e498a7b..dc4a10b 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -74,9 +74,6 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     private static final String MODELS_CATALOG = "org/apache/camel/catalog/models.properties";
     private static final String MODEL_DIR = "org/apache/camel/catalog/models";
-    private static final String COMPONENT_DIR = "org/apache/camel/catalog/components";
-    private static final String DATAFORMAT_DIR = "org/apache/camel/catalog/dataformats";
-    private static final String LANGUAGE_DIR = "org/apache/camel/catalog/languages";
     private static final String DOC_DIR = "org/apache/camel/catalog/docs";
     private static final String ARCHETYPES_CATALOG = "org/apache/camel/catalog/archetypes/archetype-catalog.xml";
     private static final String SCHEMAS_XML = "org/apache/camel/catalog/schemas";
@@ -457,7 +454,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     @Override
     public String componentJSonSchema(String name) {
-        String file = COMPONENT_DIR + "/" + name + ".json";
+        String file = runtimeProvider.getComponentJSonSchemaDirectory() + "/" + name + ".json";
 
         String answer = null;
         if (caching) {
@@ -503,7 +500,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     @Override
     public String dataFormatJSonSchema(String name) {
-        String file = DATAFORMAT_DIR + "/" + name + ".json";
+        String file = runtimeProvider.getDataFormatJSonSchemaDirectory() + "/" + name + ".json";
 
         String answer = null;
         if (caching) {
@@ -554,7 +551,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
             name = "bean";
         }
 
-        String file = LANGUAGE_DIR + "/" + name + ".json";
+        String file = runtimeProvider.getLanguageJSonSchemaDirectory() + "/" + name + ".json";
 
         String answer = null;
         if (caching) {

http://git-wip-us.apache.org/repos/asf/camel/blob/84a5a6e2/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
index a18d193..acdf6a4 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
@@ -23,6 +23,9 @@ import java.util.List;
 
 public class DefaultRuntimeProvider implements RuntimeProvider {
 
+    private static final String COMPONENT_DIR = "org/apache/camel/catalog/components";
+    private static final String DATAFORMAT_DIR = "org/apache/camel/catalog/dataformats";
+    private static final String LANGUAGE_DIR = "org/apache/camel/catalog/languages";
     private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/components.properties";
     private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/dataformats.properties";
     private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/languages.properties";
@@ -52,6 +55,21 @@ public class DefaultRuntimeProvider implements RuntimeProvider {
     }
 
     @Override
+    public String getComponentJSonSchemaDirectory() {
+        return COMPONENT_DIR;
+    }
+
+    @Override
+    public String getDataFormatJSonSchemaDirectory() {
+        return DATAFORMAT_DIR;
+    }
+
+    @Override
+    public String getLanguageJSonSchemaDirectory() {
+        return LANGUAGE_DIR;
+    }
+
+    @Override
     public List<String> findComponentNames() {
         List<String> names = new ArrayList<String>();
         InputStream is = camelCatalog.getVersionManager().getResourceAsStream(COMPONENTS_CATALOG);

http://git-wip-us.apache.org/repos/asf/camel/blob/84a5a6e2/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
index 2ab844f..2bd7fd8 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
@@ -25,11 +25,6 @@ import java.util.List;
  */
 public interface RuntimeProvider {
 
-    // TODO: maven archetype GAV
-    // original GAV
-    // spring-boot GAV
-    // karaf feature name
-
     /**
      * Gets the {@link CamelCatalog}
      */
@@ -46,6 +41,21 @@ public interface RuntimeProvider {
     String getProviderName();
 
     /**
+     * Gets the directory where the component json files are stored in the catalog JAR file
+     */
+    String getComponentJSonSchemaDirectory();
+
+    /**
+     * Gets the directory where the data format json files are stored in the catalog JAR
file
+     */
+    String getDataFormatJSonSchemaDirectory();
+
+    /**
+     * Gets the directory where the language json files are stored in the catalog JAR file
+     */
+    String getLanguageJSonSchemaDirectory();
+
+    /**
      * Find all the component names from the Camel catalog supported by the provider
      */
     List<String> findComponentNames();

http://git-wip-us.apache.org/repos/asf/camel/blob/84a5a6e2/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java
index dffc9de..d0f4841 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java
@@ -5,9 +5,9 @@
  * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      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.
@@ -24,11 +24,11 @@ import java.io.IOException;
 import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.TreeSet;
+import java.util.regex.Pattern;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -47,6 +47,8 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
 
     public static final int BUFFER_SIZE = 128 * 1024;
 
+    private static final Pattern ARTIFACT_PATTERN = Pattern.compile("\"artifactId\": \"camel-(.*)\"");
+
     /**
      * The maven project.
      *
@@ -170,14 +172,23 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
         // make sure to create out dir
         componentsOutDir.mkdirs();
 
-        Set<String> alternativeSchemes = new HashSet<>();
-
         for (File file : jsonFiles) {
-            File to = new File(componentsOutDir, file.getName());
+            // for spring-boot we need to amend the json file to use -starter as the artifact-id
             try {
-                copyFile(file, to);
+                String text = loadText(new FileInputStream(file));
+
+                text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\"");
+
+                // write new json file
+                File to = new File(componentsOutDir, file.getName());
+                FileOutputStream fos = new FileOutputStream(to, false);
+
+                fos.write(text.getBytes());
+
+                fos.close();
+
             } catch (IOException e) {
-                throw new MojoFailureException("Cannot copy file from " + file + " ->
" + to, e);
+                throw new MojoFailureException("Cannot write json file " + file, e);
             }
         }
 
@@ -248,11 +259,22 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
         dataFormatsOutDir.mkdirs();
 
         for (File file : jsonFiles) {
-            File to = new File(dataFormatsOutDir, file.getName());
+            // for spring-boot we need to amend the json file to use -starter as the artifact-id
             try {
-                copyFile(file, to);
+                String text = loadText(new FileInputStream(file));
+
+                text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\"");
+
+                // write new json file
+                File to = new File(dataFormatsOutDir, file.getName());
+                FileOutputStream fos = new FileOutputStream(to, false);
+
+                fos.write(text.getBytes());
+
+                fos.close();
+
             } catch (IOException e) {
-                throw new MojoFailureException("Cannot copy file from " + file + " ->
" + to, e);
+                throw new MojoFailureException("Cannot write json file " + file, e);
             }
         }
 
@@ -323,11 +345,22 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
         languagesOutDir.mkdirs();
 
         for (File file : jsonFiles) {
-            File to = new File(languagesOutDir, file.getName());
+            // for spring-boot we need to amend the json file to use -starter as the artifact-id
             try {
-                copyFile(file, to);
+                String text = loadText(new FileInputStream(file));
+
+                text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\"");
+
+                // write new json file
+                File to = new File(languagesOutDir, file.getName());
+                FileOutputStream fos = new FileOutputStream(to, false);
+
+                fos.write(text.getBytes());
+
+                fos.close();
+
             } catch (IOException e) {
-                throw new MojoFailureException("Cannot copy file from " + file + " ->
" + to, e);
+                throw new MojoFailureException("Cannot write json file " + file, e);
             }
         }
 


Mime
View raw message