[1/3] camel git commit: Factorize Json schema loading code

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[1/3] camel git commit: Factorize Json schema loading code

davsclaus-2
Repository: camel
Updated Branches:
  refs/heads/master 6eb2abe89 -> 0ab557c0c


Factorize Json schema loading code

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

Branch: refs/heads/master
Commit: a3ecc2145ac7a5dc12c63c7d9044cb47b71a1ddc
Parents: 39376f5
Author: Aurelien Pupier <[hidden email]>
Authored: Thu Apr 20 14:18:54 2017 +0200
Committer: Claus Ibsen <[hidden email]>
Committed: Thu Apr 20 17:07:31 2017 +0200

----------------------------------------------------------------------
 .../catalog/maven/ConnectorArtifactHelper.java  | 39 ++++++--------------
 1 file changed, 11 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a3ecc214/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java
index 475eb91..454b639 100644
--- a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java
+++ b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java
@@ -32,38 +32,21 @@ public final class ConnectorArtifactHelper {
 
     public static String[] loadJSonSchemas(ClassLoader classLoader) {
         String[] answer = new String[3];
+        answer[0] = loadJsonSchema(classLoader, "camel-connector.json");
+        answer[1] = loadJsonSchema(classLoader, "camel-connector-schema.json");
+        answer[2] = loadJsonSchema(classLoader, "camel-component-schema.json");
+        return answer;
+    }
 
-        String path = "camel-connector.json";
-        try {
-            InputStream is = classLoader.getResourceAsStream(path);
-            if (is != null) {
-                answer[0] = loadText(is);
-            }
-        } catch (Throwable e) {
-            LOG.warn("Error loading " + path + " file", e);
-        }
-
-        path = "camel-connector-schema.json";
-        try {
-            InputStream is = classLoader.getResourceAsStream(path);
-            if (is != null) {
-                answer[1] = loadText(is);
-            }
-        } catch (Throwable e) {
-            LOG.warn("Error loading " + path + " file", e);
-        }
-
-        path = "camel-component-schema.json";
-        try {
-            InputStream is = classLoader.getResourceAsStream(path);
+ private static String loadJsonSchema(ClassLoader classLoader, String jsonSchemaPath) {
+ try (InputStream is = classLoader.getResourceAsStream(jsonSchemaPath)) {
             if (is != null) {
-                answer[2] = loadText(is);
+                return loadText(is);
             }
         } catch (Throwable e) {
-            LOG.warn("Error loading " + path + " file", e);
+            LOG.warn("Error loading " + jsonSchemaPath + " file", e);
         }
-
-        return answer;
-    }
+ return null;
+ }
 
 }

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[2/3] camel git commit: Close GroovyClassLoader

davsclaus-2
Close GroovyClassLoader

it avoids to have files that can't be deleted on Windows

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

Branch: refs/heads/master
Commit: 39376f59d04ce35e1ca290ab14e3412a7030d2d1
Parents: 6eb2abe
Author: Aurelien Pupier <[hidden email]>
Authored: Thu Apr 20 14:06:20 2017 +0200
Committer: Claus Ibsen <[hidden email]>
Committed: Thu Apr 20 17:07:31 2017 +0200

----------------------------------------------------------------------
 .../maven/DefaultMavenArtifactProvider.java     | 41 ++++++++++----------
 1 file changed, 21 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/39376f59/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java
index 99d0a47..1a7f3cb 100644
--- a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java
+++ b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java
@@ -73,26 +73,27 @@ public class DefaultMavenArtifactProvider implements MavenArtifactProvider {
 
             Grape.setEnableAutoDownload(true);
 
-            final ClassLoader classLoader = new GroovyClassLoader();
-
-            Map<String, Object> param = new HashMap<>();
-            param.put("classLoader", classLoader);
-            param.put("group", groupId);
-            param.put("module", artifactId);
-            param.put("version", version);
-            // no need to download transitive dependencies as we only need to check the component or connector itself
-            param.put("validate", false);
-            param.put("transitive", false);
-
-            LOG.debug("Downloading {}:{}:{}", groupId, artifactId, version);
-            Grape.grab(param);
-
-            // the classloader can load content from the downloaded JAR
-            if (camelCatalog != null) {
-                scanCamelComponents(camelCatalog, classLoader, names);
-            }
-            if (camelConnectorCatalog != null) {
-                scanCamelConnectors(camelConnectorCatalog, classLoader, groupId, artifactId, version, names);
+            try (final GroovyClassLoader classLoader = new GroovyClassLoader()){
+
+             Map<String, Object> param = new HashMap<>();
+             param.put("classLoader", classLoader);
+             param.put("group", groupId);
+             param.put("module", artifactId);
+             param.put("version", version);
+             // no need to download transitive dependencies as we only need to check the component or connector itself
+             param.put("validate", false);
+             param.put("transitive", false);
+
+             LOG.debug("Downloading {}:{}:{}", groupId, artifactId, version);
+             Grape.grab(param);
+
+             // the classloader can load content from the downloaded JAR
+             if (camelCatalog != null) {
+             scanCamelComponents(camelCatalog, classLoader, names);
+             }
+             if (camelConnectorCatalog != null) {
+             scanCamelConnectors(camelConnectorCatalog, classLoader, groupId, artifactId, version, names);
+             }
             }
 
         } catch (Exception e) {

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[3/3] camel git commit: Fixed CS. This closes #1646. This closes #1645

davsclaus-2
In reply to this post by davsclaus-2
Fixed CS. This closes #1646. This closes #1645


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

Branch: refs/heads/master
Commit: 0ab557c0ca3b830b913e991c3b5683e52bb85655
Parents: a3ecc21
Author: Claus Ibsen <[hidden email]>
Authored: Thu Apr 20 17:09:51 2017 +0200
Committer: Claus Ibsen <[hidden email]>
Committed: Thu Apr 20 17:09:51 2017 +0200

----------------------------------------------------------------------
 .../catalog/maven/ConnectorArtifactHelper.java  |  8 ++--
 .../maven/DefaultMavenArtifactProvider.java     | 46 ++++++++++----------
 2 files changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0ab557c0/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java
index 454b639..b233e95 100644
--- a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java
+++ b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/ConnectorArtifactHelper.java
@@ -38,15 +38,15 @@ public final class ConnectorArtifactHelper {
         return answer;
     }
 
- private static String loadJsonSchema(ClassLoader classLoader, String jsonSchemaPath) {
- try (InputStream is = classLoader.getResourceAsStream(jsonSchemaPath)) {
+    private static String loadJsonSchema(ClassLoader classLoader, String jsonSchemaPath) {
+        try (InputStream is = classLoader.getResourceAsStream(jsonSchemaPath)) {
             if (is != null) {
                 return loadText(is);
             }
         } catch (Throwable e) {
             LOG.warn("Error loading " + jsonSchemaPath + " file", e);
         }
- return null;
- }
+        return null;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0ab557c0/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java
----------------------------------------------------------------------
diff --git a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java
index 1a7f3cb..9361195 100644
--- a/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java
+++ b/platforms/camel-catalog-maven/src/main/java/org/apache/camel/catalog/maven/DefaultMavenArtifactProvider.java
@@ -73,27 +73,27 @@ public class DefaultMavenArtifactProvider implements MavenArtifactProvider {
 
             Grape.setEnableAutoDownload(true);
 
-            try (final GroovyClassLoader classLoader = new GroovyClassLoader()){
-
-             Map<String, Object> param = new HashMap<>();
-             param.put("classLoader", classLoader);
-             param.put("group", groupId);
-             param.put("module", artifactId);
-             param.put("version", version);
-             // no need to download transitive dependencies as we only need to check the component or connector itself
-             param.put("validate", false);
-             param.put("transitive", false);
-
-             LOG.debug("Downloading {}:{}:{}", groupId, artifactId, version);
-             Grape.grab(param);
-
-             // the classloader can load content from the downloaded JAR
-             if (camelCatalog != null) {
-             scanCamelComponents(camelCatalog, classLoader, names);
-             }
-             if (camelConnectorCatalog != null) {
-             scanCamelConnectors(camelConnectorCatalog, classLoader, groupId, artifactId, version, names);
-             }
+            try (final GroovyClassLoader classLoader = new GroovyClassLoader()) {
+
+                Map<String, Object> param = new HashMap<>();
+                param.put("classLoader", classLoader);
+                param.put("group", groupId);
+                param.put("module", artifactId);
+                param.put("version", version);
+                // no need to download transitive dependencies as we only need to check the component or connector itself
+                param.put("validate", false);
+                param.put("transitive", false);
+
+                LOG.debug("Downloading {}:{}:{}", groupId, artifactId, version);
+                Grape.grab(param);
+
+                // the classloader can load content from the downloaded JAR
+                if (camelCatalog != null) {
+                    scanCamelComponents(camelCatalog, classLoader, names);
+                }
+                if (camelConnectorCatalog != null) {
+                    scanCamelConnectors(camelConnectorCatalog, classLoader, groupId, artifactId, version, names);
+                }
             }
 
         } catch (Exception e) {
@@ -129,8 +129,8 @@ public class DefaultMavenArtifactProvider implements MavenArtifactProvider {
     }
 
     protected void scanCamelConnectors(CamelConnectorCatalog camelConnectorCatalog, ClassLoader classLoader,
-                                          String groupId, String artifactId, String version,
-                                          Set<String> names) {
+                                       String groupId, String artifactId, String version,
+                                       Set<String> names) {
         String[] json = loadJSonSchemas(classLoader);
         if (json != null) {
             if (!camelConnectorCatalog.hasConnector(groupId, artifactId, version)) {

Loading...