camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/5] camel git commit: Add version to camel-catalog api
Date Sun, 18 Oct 2015 11:07:57 GMT
Add version to camel-catalog api


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

Branch: refs/heads/camel-2.16.x
Commit: 68b6cd148222e6ece10d70cfa9340c457cf4f64c
Parents: 70098b0
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Oct 17 16:45:05 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Oct 18 13:10:01 2015 +0200

----------------------------------------------------------------------
 .../org/apache/camel/catalog/CamelCatalog.java  |  5 ++
 .../camel/catalog/DefaultCamelCatalog.java      |  7 ++
 .../org/apache/camel/catalog/VersionHelper.java | 73 ++++++++++++++++++++
 .../apache/camel/catalog/CamelCatalogTest.java  |  6 ++
 4 files changed, 91 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/68b6cd14/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 43847d9..350c2d4 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
@@ -29,6 +29,11 @@ import javax.management.MXBean;
 public interface CamelCatalog {
 
     /**
+     * The version of this Camel Catalog
+     */
+    String getCatalogVersion();
+
+    /**
      * Find all the component names from the Camel catalog
      */
     List<String> findComponentNames();

http://git-wip-us.apache.org/repos/asf/camel/blob/68b6cd14/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 a510fc5..1641495 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
@@ -57,6 +57,13 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     private static final Pattern SYNTAX_PATTERN = Pattern.compile("(\\w+)");
 
+    private final VersionHelper version = new VersionHelper();
+
+    @Override
+    public String getCatalogVersion() {
+        return version.getVersion();
+    }
+
     @Override
     public List<String> findComponentNames() {
         List<String> names = new ArrayList<String>();

http://git-wip-us.apache.org/repos/asf/camel/blob/68b6cd14/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionHelper.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionHelper.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionHelper.java
new file mode 100644
index 0000000..e1c69bc
--- /dev/null
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/VersionHelper.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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
+ *
+ *      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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.catalog;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * To get the version of this catalog.
+ */
+public class VersionHelper {
+
+    private static volatile String version;
+
+    public synchronized String getVersion() {
+        if (version != null) {
+            return version;
+        }
+        InputStream is = null;
+        // try to load from maven properties first
+        try {
+            Properties p = new Properties();
+            is = getClass().getResourceAsStream("/META-INF/maven/org.apache.camel/camel-catalog/pom.properties");
+            if (is != null) {
+                p.load(is);
+                version = p.getProperty("version", "");
+            }
+        } catch (Exception e) {
+            // ignore
+        } finally {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (Exception e) {
+                    // ignore
+                }
+            }
+        }
+
+        // fallback to using Java API
+        if (version == null) {
+            Package aPackage = getClass().getPackage();
+            if (aPackage != null) {
+                version = aPackage.getImplementationVersion();
+                if (version == null) {
+                    version = aPackage.getSpecificationVersion();
+                }
+            }
+        }
+
+        if (version == null) {
+            // we could not compute the version so use a blank
+            version = "";
+        }
+
+        return version;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/68b6cd14/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index e905e81..ab69fed 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -30,6 +30,12 @@ public class CamelCatalogTest extends TestCase {
     private CamelCatalog catalog = new DefaultCamelCatalog();
 
     @Test
+    public void testGetVersion() throws Exception {
+        String version = catalog.getCatalogVersion();
+        assertNotNull(version);
+    }
+
+    @Test
     public void testFindLanguageNames() throws Exception {
         List<String> names = catalog.findLanguageNames();
 


Mime
View raw message