camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-10746: camel catalog - Allow to download custom version of runtime provider
Date Mon, 13 Feb 2017 13:41:26 GMT
Repository: camel
Updated Branches:
  refs/heads/master 8df158d29 -> aa7780182


CAMEL-10746: camel catalog - Allow to download custom version of runtime provider


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

Branch: refs/heads/master
Commit: aa7780182218c2800a09822936ae74120105c979
Parents: 8df158d
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Feb 13 14:32:47 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Feb 13 14:32:47 2017 +0100

----------------------------------------------------------------------
 platforms/catalog-maven/pom.xml                 |  8 +++-
 .../catalog/maven/MavenVersionManager.java      | 39 ++++++++++++++++++++
 .../catalog/maven/MavenVersionManagerTest.java  | 30 +++++++++++++++
 .../catalog/karaf/KarafRuntimeProvider.java     | 10 +++++
 .../springboot/SpringBootRuntimeProvider.java   | 10 +++++
 .../org/apache/camel/catalog/CamelCatalog.java  | 19 ++++++++++
 .../camel/catalog/DefaultCamelCatalog.java      | 11 +++++-
 .../camel/catalog/DefaultRuntimeProvider.java   | 10 +++++
 .../camel/catalog/DefaultVersionManager.java    | 12 ++++++
 .../apache/camel/catalog/RuntimeProvider.java   | 10 +++++
 .../apache/camel/catalog/VersionManager.java    | 19 ++++++++++
 platforms/pom.xml                               |  4 +-
 12 files changed, 178 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/platforms/catalog-maven/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog-maven/pom.xml b/platforms/catalog-maven/pom.xml
index eddc629..18c504e 100644
--- a/platforms/catalog-maven/pom.xml
+++ b/platforms/catalog-maven/pom.xml
@@ -55,12 +55,18 @@
       <version>${ivy-version}</version>
     </dependency>
 
+    <!-- testing -->
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
-    
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-catalog-provider-springboot</artifactId>
+      <scope>test</scope>
+    </dependency>
+
     <!-- logging -->
     <dependency>
       <groupId>org.apache.logging.log4j</groupId>

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/platforms/catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
b/platforms/catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
index ec582e4..a6814a1 100644
--- a/platforms/catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
+++ b/platforms/catalog-maven/src/main/java/org/apache/camel/catalog/maven/MavenVersionManager.java
@@ -37,6 +37,7 @@ public class MavenVersionManager implements VersionManager {
 
     private final ClassLoader classLoader = new GroovyClassLoader();
     private String version;
+    private String runtimeProviderVersion;
 
     /**
      * To add a 3rd party Maven repository.
@@ -77,7 +78,45 @@ public class MavenVersionManager implements VersionManager {
     }
 
     @Override
+    public String getRuntimeProviderLoadedVersion() {
+        return runtimeProviderVersion;
+    }
+
+    @Override
+    public boolean loadRuntimeProviderVersion(String groupId, String artifactId, String version)
{
+        try {
+            Grape.setEnableAutoDownload(true);
+
+            Map<String, Object> param = new HashMap<>();
+            param.put("classLoader", classLoader);
+            param.put("group", groupId);
+            param.put("module", artifactId);
+            param.put("version", version);
+
+            Grape.grab(param);
+
+            this.runtimeProviderVersion = version;
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    @Override
     public InputStream getResourceAsStream(String name) {
+        InputStream is = null;
+
+        if (runtimeProviderVersion != null) {
+            is = doGetResourceAsStream(name, runtimeProviderVersion);
+        }
+        if (is == null && version != null) {
+            is = doGetResourceAsStream(name, version);
+        }
+
+        return is;
+    }
+
+    private InputStream doGetResourceAsStream(String name, String version) {
         if (version == null) {
             return null;
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/platforms/catalog-maven/src/test/java/org/apache/camel/catalog/maven/MavenVersionManagerTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-maven/src/test/java/org/apache/camel/catalog/maven/MavenVersionManagerTest.java
b/platforms/catalog-maven/src/test/java/org/apache/camel/catalog/maven/MavenVersionManagerTest.java
index 195e9a4..4b8abf9 100644
--- a/platforms/catalog-maven/src/test/java/org/apache/camel/catalog/maven/MavenVersionManagerTest.java
+++ b/platforms/catalog-maven/src/test/java/org/apache/camel/catalog/maven/MavenVersionManagerTest.java
@@ -17,11 +17,13 @@
 package org.apache.camel.catalog.maven;
 
 import java.io.InputStream;
+import java.util.List;
 
 import junit.framework.TestCase;
 import org.apache.camel.catalog.CamelCatalog;
 import org.apache.camel.catalog.CatalogHelper;
 import org.apache.camel.catalog.DefaultCamelCatalog;
+import org.apache.camel.catalog.springboot.SpringBootRuntimeProvider;
 import org.junit.Test;
 
 public class MavenVersionManagerTest extends TestCase {
@@ -78,4 +80,32 @@ public class MavenVersionManagerTest extends TestCase {
         assertTrue(json.contains("connectionClose"));
     }
 
+    @Test
+    public void testRuntimeProviderLoadVersion() throws Exception {
+        CamelCatalog catalog = new DefaultCamelCatalog(false);
+        catalog.setVersionManager(new MavenVersionManager());
+        catalog.setRuntimeProvider(new SpringBootRuntimeProvider());
+
+        String version = "2.18.2";
+
+        boolean loaded = catalog.loadVersion(version);
+        assertTrue(loaded);
+
+        loaded = catalog.loadRuntimeProviderVersion(catalog.getRuntimeProvider().getProviderGroupId(),
catalog.getRuntimeProvider().getProviderArtifactId(), version);
+        assertTrue(loaded);
+
+        assertEquals(version, catalog.getLoadedVersion());
+        assertEquals(version, catalog.getRuntimeProviderLoadedVersion());
+
+        List<String> names = catalog.findComponentNames();
+
+        assertTrue(names.contains("file"));
+        assertTrue(names.contains("ftp"));
+        assertTrue(names.contains("jms"));
+        // camel-ejb does not work in spring-boot
+        assertFalse(names.contains("ejb"));
+        // camel-pac-logging does not work in spring-boot
+        assertFalse(names.contains("paxlogging"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/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 8f037bc..f02c1e8 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
@@ -58,6 +58,16 @@ public class KarafRuntimeProvider implements RuntimeProvider {
     }
 
     @Override
+    public String getProviderGroupId() {
+        return "org.apache.camel";
+    }
+
+    @Override
+    public String getProviderArtifactId() {
+        return "camel-catalog-provider-karaf";
+    }
+
+    @Override
     public String getComponentJSonSchemaDirectory() {
         return COMPONENT_DIR;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/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 7fe2117..989f557 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
@@ -58,6 +58,16 @@ public class SpringBootRuntimeProvider implements RuntimeProvider {
     }
 
     @Override
+    public String getProviderGroupId() {
+        return "org.apache.camel";
+    }
+
+    @Override
+    public String getProviderArtifactId() {
+        return "camel-catalog-provider-springboot";
+    }
+
+    @Override
     public String getComponentJSonSchemaDirectory() {
         return COMPONENT_DIR;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index 0a06efc..bc4d9fa 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -130,6 +130,25 @@ public interface CamelCatalog {
     String getLoadedVersion();
 
     /**
+     * Gets the current loaded runtime provider version used by the catalog.
+     */
+    String getRuntimeProviderLoadedVersion();
+
+    /**
+     * Attempt to load the runtime provider version to be used by the catalog.
+     * <p/>
+     * Loading the runtime provider JAR of the given version of choice may require internet
access
+     * to download the JAR from Maven central. You can pre download the JAR and install in
a local
+     * Maven repository to avoid internet access for offline environments.
+     *
+     * @param groupId  the runtime provider Maven groupId
+     * @param artifactId  the runtime provider Maven artifactId
+     * @param version  the runtime provider Maven version
+     * @return <tt>true</tt> if the version was loaded, <tt>false</tt>
if not.
+     */
+    boolean loadRuntimeProviderVersion(String groupId, String artifactId, String version);
+
+    /**
      * Find all the component names from the Camel catalog
      */
     List<String> findComponentNames();

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/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 f6509f8..e6a159b 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
@@ -39,7 +39,6 @@ import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
-import javax.print.attribute.URISyntax;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathFactory;
@@ -223,6 +222,16 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
+    public String getRuntimeProviderLoadedVersion() {
+        return versionManager.getRuntimeProviderLoadedVersion();
+    }
+
+    @Override
+    public boolean loadRuntimeProviderVersion(String groupId, String artifactId, String version)
{
+        return versionManager.loadRuntimeProviderVersion(groupId, artifactId, version);
+    }
+
+    @Override
     @SuppressWarnings("unchecked")
     public List<String> findComponentNames() {
         List<String> names = null;

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/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 3e93370..2fe0ca7 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
@@ -57,6 +57,16 @@ public class DefaultRuntimeProvider implements RuntimeProvider {
     }
 
     @Override
+    public String getProviderGroupId() {
+        return "org.apache.camel";
+    }
+
+    @Override
+    public String getProviderArtifactId() {
+        return "camel-catalog";
+    }
+
+    @Override
     public String getComponentJSonSchemaDirectory() {
         return COMPONENT_DIR;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultVersionManager.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultVersionManager.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultVersionManager.java
index 0f6e62e..c30ddbc 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultVersionManager.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultVersionManager.java
@@ -37,6 +37,18 @@ public class DefaultVersionManager implements VersionManager {
     }
 
     @Override
+    public String getRuntimeProviderLoadedVersion() {
+        // not supported
+        return null;
+    }
+
+    @Override
+    public boolean loadRuntimeProviderVersion(String groupId, String artifactId, String version)
{
+        // not supported
+        return false;
+    }
+
+    @Override
     public InputStream getResourceAsStream(String name) {
         return DefaultCamelCatalog.class.getClassLoader().getResourceAsStream(name);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/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 60d76ec..fa4c3d6 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
@@ -41,6 +41,16 @@ public interface RuntimeProvider {
     String getProviderName();
 
     /**
+     * Maven group id of the runtime provider JAR dependency.
+     */
+    String getProviderGroupId();
+
+    /**
+     * Maven artifact id of the runtime provider JAR dependency.
+     */
+    String getProviderArtifactId();
+
+    /**
      * Gets the directory where the component json files are stored in the catalog JAR file
      */
     String getComponentJSonSchemaDirectory();

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionManager.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionManager.java
b/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionManager.java
index 4dcd926..6f8aff4 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionManager.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionManager.java
@@ -41,6 +41,25 @@ public interface VersionManager {
     boolean loadVersion(String version);
 
     /**
+     * Gets the current loaded runtime provider version used by the catalog.
+     */
+    String getRuntimeProviderLoadedVersion();
+
+    /**
+     * Attempt to load the runtime provider version to be used by the catalog.
+     * <p/>
+     * Loading the runtime provider JAR of the given version of choice may require internet
access
+     * to download the JAR from Maven central. You can pre download the JAR and install in
a local
+     * Maven repository to avoid internet access for offline environments.
+     *
+     * @param groupId  the runtime provider Maven groupId
+     * @param artifactId  the runtime provider Maven artifactId
+     * @param version  the runtime provider Maven version
+     * @return <tt>true</tt> if the version was loaded, <tt>false</tt>
if not.
+     */
+    boolean loadRuntimeProviderVersion(String groupId, String artifactId, String version);
+
+    /**
      * Returns an input stream for reading the specified resource from the loaded Catalog
version.
      *
      * @param name the resource name

http://git-wip-us.apache.org/repos/asf/camel/blob/aa778018/platforms/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/pom.xml b/platforms/pom.xml
index dbee2ea..6327a97 100644
--- a/platforms/pom.xml
+++ b/platforms/pom.xml
@@ -37,12 +37,12 @@
     <module>spring-boot</module>
     <!-- run catalog last -->
     <module>catalog</module>
+    <module>catalog-provider-karaf</module>
+    <module>catalog-provider-springboot</module>
     <module>catalog-lucene</module>
     <module>catalog-maven</module>
     <module>catalog-rest</module>
     <module>catalog-rest-app</module>
-    <module>catalog-provider-karaf</module>
-    <module>catalog-provider-springboot</module>
   </modules>
 
 </project>


Mime
View raw message