You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/02/03 19:31:40 UTC

[2/7] camel git commit: CAMEL-10774: Add others to spring-boot runtime provider for camel-catalog

CAMEL-10774: Add others to spring-boot runtime provider for camel-catalog


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

Branch: refs/heads/master
Commit: fd457a400691798fce82768eeb3871538b6cd91c
Parents: bfe4fec
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Feb 3 18:43:52 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Feb 3 20:31:28 2017 +0100

----------------------------------------------------------------------
 .../springboot/SpringBootRuntimeProvider.java   |  21 +++
 .../SpringBootRuntimeProviderTest.java          |  22 +++
 .../packaging/PrepareCatalogSpringBootMojo.java | 144 ++++++++++++++++++-
 3 files changed, 185 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fd457a40/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 8e06e86..7fe2117 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
@@ -34,9 +34,11 @@ 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 OTHER_DIR = "org/apache/camel/catalog/springboot/others";
     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";
+    private static final String OTHER_CATALOG = "org/apache/camel/catalog/springboot/others.properties";
 
     private CamelCatalog camelCatalog;
 
@@ -71,6 +73,11 @@ public class SpringBootRuntimeProvider implements RuntimeProvider {
     }
 
     @Override
+    public String getOtherJSonSchemaDirectory() {
+        return OTHER_DIR;
+    }
+
+    @Override
     public List<String> findComponentNames() {
         List<String> names = new ArrayList<String>();
         InputStream is = camelCatalog.getVersionManager().getResourceAsStream(COMPONENTS_CATALOG);
@@ -112,4 +119,18 @@ public class SpringBootRuntimeProvider implements RuntimeProvider {
         return names;
     }
 
+    @Override
+    public List<String> findOtherNames() {
+        List<String> names = new ArrayList<String>();
+        InputStream is = camelCatalog.getVersionManager().getResourceAsStream(OTHER_CATALOG);
+        if (is != null) {
+            try {
+                CatalogHelper.loadLines(is, names);
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+        return names;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/fd457a40/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 28aeb8a..4c53690 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
@@ -94,6 +94,20 @@ public class SpringBootRuntimeProviderTest {
     }
 
     @Test
+    public void testFindOtherNames() throws Exception {
+        List<String> names = catalog.findOtherNames();
+
+        assertNotNull(names);
+        assertFalse(names.isEmpty());
+
+        assertTrue(names.contains("hystrix"));
+        assertTrue(names.contains("spring-boot"));
+        assertTrue(names.contains("zipkin"));
+
+        assertFalse(names.contains("blueprint"));
+    }
+
+    @Test
     public void testComponentArtifactId() throws Exception {
         String json = catalog.componentJSonSchema("ftp");
 
@@ -117,4 +131,12 @@ public class SpringBootRuntimeProviderTest {
         assertTrue(json.contains("camel-spring-starter"));
     }
 
+    @Test
+    public void testOtherArtifactId() throws Exception {
+        String json = catalog.otherJSonSchema("zipkin");
+
+        assertNotNull(json);
+        assertTrue(json.contains("camel-zipkin-starter"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/fd457a40/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 c8640a6..fa61295 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
@@ -80,6 +80,13 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
     protected File languagesOutDir;
 
     /**
+     * The output directory for others catalog
+     *
+     * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/springboot/others"
+     */
+    protected File othersOutDir;
+
+    /**
      * The directory where all spring-boot starters are
      *
      * @parameter default-value="${project.build.directory}/../../../platforms/spring-boot/components-starter"
@@ -120,6 +127,7 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
         executeComponents(starters);
         executeDataFormats(starters);
         executeLanguages(starters);
+        executeOthers(starters);
     }
 
     protected void executeComponents(Set<String> starters) throws MojoExecutionException, MojoFailureException {
@@ -237,7 +245,7 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
                         if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
                             continue;
                         }
-                        // the directory must be in the list of known features
+                        // the directory must be in the list of known starters
                         if (!starters.contains(dir.getName())) {
                             continue;
                         }
@@ -322,7 +330,7 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
                     if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
                         continue;
                     }
-                    // the directory must be in the list of known features
+                    // the directory must be in the list of known starters
                     if (!starters.contains(dir.getName())) {
                         continue;
                     }
@@ -392,6 +400,102 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
         }
     }
 
+    protected void executeOthers(Set<String> starters) throws MojoExecutionException, MojoFailureException {
+        getLog().info("Copying all Camel other json descriptors");
+
+        // lets use sorted set/maps
+        Set<File> jsonFiles = new TreeSet<File>();
+        Set<File> otherFiles = new TreeSet<File>();
+
+        // find all other from the components directory
+        if (componentsDir != null && componentsDir.isDirectory()) {
+            File[] others = componentsDir.listFiles();
+            if (others != null) {
+                for (File dir : others) {
+                    // skip camel-spring-dm
+                    if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
+                        continue;
+                    }
+                    // the directory must be in the list of known starters
+                    if (!starters.contains(dir.getName())) {
+                        continue;
+                    }
+
+                    // skip these special cases
+                    // (camel-jetty is a placeholder, as camel-jetty9 is the actual component)
+                    if ("camel-core-osgi".equals(dir.getName())
+                        || "camel-core-xml".equals(dir.getName())
+                        || "camel-http-common".equals(dir.getName())
+                        || "camel-jetty".equals(dir.getName())
+                        || "camel-jetty-common".equals(dir.getName())
+                        || "camel-linkedin".equals(dir.getName())
+                        || "camel-olingo2".equals(dir.getName())
+                        || "camel-salesforce".equals(dir.getName())) {
+                        continue;
+                    }
+
+                    if (dir.isDirectory() && !"target".equals(dir.getName())) {
+                        File target = new File(dir, "target/classes");
+                        findOtherFilesRecursive(target, jsonFiles, otherFiles, new CamelOthersFileFilter());
+                    }
+                }
+            }
+        }
+
+        getLog().info("Found " + otherFiles.size() + " other.properties files");
+        getLog().info("Found " + jsonFiles.size() + " other json files");
+
+        // make sure to create out dir
+        othersOutDir.mkdirs();
+
+        for (File file : jsonFiles) {
+            // for spring-boot we need to amend the json file to use -starter as the artifact-id
+            try {
+                String text = loadText(new FileInputStream(file));
+
+                text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\"");
+
+                // write new json file
+                File to = new File(othersOutDir, file.getName());
+                FileOutputStream fos = new FileOutputStream(to, false);
+
+                fos.write(text.getBytes());
+
+                fos.close();
+
+            } catch (IOException e) {
+                throw new MojoFailureException("Cannot write json file " + file, e);
+            }
+        }
+
+        File all = new File(othersOutDir, "../others.properties");
+        try {
+            FileOutputStream fos = new FileOutputStream(all, false);
+
+            String[] names = othersOutDir.list();
+            List<String> others = new ArrayList<String>();
+            // sort the names
+            for (String name : names) {
+                if (name.endsWith(".json")) {
+                    // strip out .json from the name
+                    String otherName = name.substring(0, name.length() - 5);
+                    others.add(otherName);
+                }
+            }
+
+            Collections.sort(others);
+            for (String name : others) {
+                fos.write(name.getBytes());
+                fos.write("\n".getBytes());
+            }
+
+            fos.close();
+
+        } catch (IOException e) {
+            throw new MojoFailureException("Error writing to file " + all);
+        }
+    }
+
     private void findComponentFilesRecursive(File dir, Set<File> found, Set<File> components, FileFilter filter) {
         File[] files = dir.listFiles(filter);
         if (files != null) {
@@ -449,6 +553,25 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
         }
     }
 
+    private void findOtherFilesRecursive(File dir, Set<File> found, Set<File> others, FileFilter filter) {
+        File[] files = dir.listFiles(filter);
+        if (files != null) {
+            for (File file : files) {
+                // skip files in root dirs as Camel does not store information there but others may do
+                boolean rootDir = "classes".equals(dir.getName()) || "META-INF".equals(dir.getName());
+                boolean jsonFile = rootDir && file.isFile() && file.getName().endsWith(".json");
+                boolean otherFile = !rootDir && file.isFile() && file.getName().equals("other.properties");
+                if (jsonFile) {
+                    found.add(file);
+                } else if (otherFile) {
+                    others.add(file);
+                } else if (file.isDirectory()) {
+                    findOtherFilesRecursive(file, found, others, filter);
+                }
+            }
+        }
+    }
+
     private class CamelComponentsFileFilter implements FileFilter {
 
         @Override
@@ -512,6 +635,23 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo {
         }
     }
 
+    private class CamelOthersFileFilter implements FileFilter {
+
+        @Override
+        public boolean accept(File pathname) {
+            if (pathname.isFile() && pathname.getName().endsWith(".json")) {
+                // must be a language json file
+                try {
+                    String json = loadText(new FileInputStream(pathname));
+                    return json != null && json.contains("\"kind\": \"other\"");
+                } catch (IOException e) {
+                    // ignore
+                }
+            }
+            return pathname.isDirectory() || (pathname.isFile() && pathname.getName().equals("other.properties"));
+        }
+    }
+
     public static void copyFile(File from, File to) throws IOException {
         FileChannel in = null;
         FileChannel out = null;