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:45 UTC

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

CAMEL-10774: Add others to karaf 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/bfe4fec7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/bfe4fec7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/bfe4fec7

Branch: refs/heads/master
Commit: bfe4fec7ef6c2a95f911558a8106f530108fb192
Parents: 794e382
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Feb 3 18:34:53 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Feb 3 20:31:28 2017 +0100

----------------------------------------------------------------------
 .../catalog/karaf/KarafRuntimeProvider.java     |  23 +++-
 .../catalog/karaf/KarafRuntimeProviderTest.java |  15 +++
 .../packaging/PrepareCatalogKarafMojo.java      | 126 ++++++++++++++++++-
 3 files changed, 161 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bfe4fec7/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 86811e4..8f037bc 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
@@ -26,7 +26,7 @@ import org.apache.camel.catalog.CatalogHelper;
 import org.apache.camel.catalog.RuntimeProvider;
 
 /**
- * A karaf based {@link RuntimeProvider} which only includes the supported Camel components, data formats, and languages
+ * A karaf based {@link RuntimeProvider} which only includes the supported Camel components, data formats, languages and others
  * which can be installed in Karaf using the Camel Karaf features.xml descriptor.
  */
 public class KarafRuntimeProvider implements RuntimeProvider {
@@ -34,9 +34,11 @@ 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 OTHER_DIR = "org/apache/camel/catalog/karaf/others";
     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";
+    private static final String OTHER_CATALOG = "org/apache/camel/catalog/karaf/others.properties";
 
     private CamelCatalog camelCatalog;
 
@@ -71,6 +73,11 @@ public class KarafRuntimeProvider 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 KarafRuntimeProvider 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/bfe4fec7/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java b/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
index c652b2f..74425de 100644
--- a/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
+++ b/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
@@ -90,4 +90,19 @@ public class KarafRuntimeProviderTest {
         assertTrue(names.contains("xpath"));
     }
 
+    @Test
+    public void testFindOtherNames() throws Exception {
+        List<String> names = catalog.findOtherNames();
+
+        assertNotNull(names);
+        assertFalse(names.isEmpty());
+
+        assertTrue(names.contains("blueprint"));
+        assertTrue(names.contains("hystrix"));
+        assertTrue(names.contains("swagger-java"));
+        assertTrue(names.contains("zipkin"));
+
+        assertFalse(names.contains("spring-boot"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/bfe4fec7/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
index 8ee7a15..c60522b 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
@@ -85,6 +85,13 @@ public class PrepareCatalogKarafMojo extends AbstractMojo {
     protected File languagesOutDir;
 
     /**
+     * The output directory for others catalog
+     *
+     * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/karaf/others"
+     */
+    protected File othersOutDir;
+
+    /**
      * The karaf features directory
      *
      * @parameter default-value="${project.build.directory}/../../../platforms/karaf/features/src/main/resources/"
@@ -125,6 +132,7 @@ public class PrepareCatalogKarafMojo extends AbstractMojo {
         executeComponents(features);
         executeDataFormats(features);
         executeLanguages(features);
+        executeOthers(features);
     }
 
     protected void executeComponents(Set<String> features) throws MojoExecutionException, MojoFailureException {
@@ -144,7 +152,6 @@ public class PrepareCatalogKarafMojo extends AbstractMojo {
                         continue;
                     }
 
-
                     if (dir.isDirectory() && !"target".equals(dir.getName())) {
                         File target = new File(dir, "target/classes");
 
@@ -160,7 +167,6 @@ public class PrepareCatalogKarafMojo extends AbstractMojo {
                             target = new File(dir, "camel-linkedin-component/target/classes");
                         }
 
-
                         findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
                     }
                 }
@@ -366,6 +372,86 @@ public class PrepareCatalogKarafMojo extends AbstractMojo {
         }
     }
 
+    protected void executeOthers(Set<String> features) 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 languages from the components directory
+        if (componentsDir != null && componentsDir.isDirectory()) {
+            File[] others = componentsDir.listFiles();
+            if (others != null) {
+                for (File dir : others) {
+                    // the directory must be in the list of known features
+                    if (!features.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) {
+            File to = new File(othersOutDir, file.getName());
+            try {
+                copyFile(file, to);
+            } catch (IOException e) {
+                throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, 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) {
@@ -423,6 +509,25 @@ public class PrepareCatalogKarafMojo 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
@@ -486,6 +591,23 @@ public class PrepareCatalogKarafMojo 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;