This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f8be20f8bf348eb3c01acb33e46a522d256db38a
Author: Guillaume Nodet <gno...@gmail.com>
AuthorDate: Fri Sep 28 11:55:14 2018 +0200

    Move StatefulService#getVersion to DefaultCamelContext
---
 .../java/org/apache/camel/StatefulService.java     |  7 ---
 .../org/apache/camel/impl/DefaultCamelContext.java | 51 ++++++++++++++++++++++
 .../org/apache/camel/support/ServiceSupport.java   | 40 -----------------
 3 files changed, 51 insertions(+), 47 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/StatefulService.java 
b/camel-core/src/main/java/org/apache/camel/StatefulService.java
index 6a9ab78..7390254 100644
--- a/camel-core/src/main/java/org/apache/camel/StatefulService.java
+++ b/camel-core/src/main/java/org/apache/camel/StatefulService.java
@@ -71,11 +71,4 @@ public interface StatefulService extends SuspendableService, 
ShutdownableService
      */
     boolean isRunAllowed();
 
-    /**
-     * Returns the version of this service
-     *
-     * @return the version
-     */
-    String getVersion();
-
 }
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 9224f40..2d04a78 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -205,6 +205,7 @@ import static 
org.apache.camel.impl.MDCUnitOfWork.MDC_CAMEL_CONTEXT_ID;
 @SuppressWarnings("deprecation")
 public class DefaultCamelContext extends ServiceSupport implements 
ModelCamelContext, ManagedCamelContext, Suspendable {
     private final Logger log = LoggerFactory.getLogger(getClass());
+    private String version;
     private final AtomicBoolean vetoStated = new AtomicBoolean();
     private JAXBContext jaxbContext;
     private CamelContextNameStrategy nameStrategy = 
createCamelContextNameStrategy();
@@ -2928,6 +2929,56 @@ public class DefaultCamelContext extends ServiceSupport 
implements ModelCamelCon
         return new Date().getTime() - startDate.getTime();
     }
 
+    public String getVersion() {
+        if (version == null) {
+            synchronized (this) {
+                if (version == null) {
+                    version = doGetVersion();
+                }
+            }
+        }
+        return version;
+    }
+
+    private String doGetVersion() {
+        String version = null;
+
+        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-core/pom.properties");
+            if (is != null) {
+                p.load(is);
+                version = p.getProperty("version", "");
+            }
+        } catch (Exception e) {
+            // ignore
+        } finally {
+            if (is != null) {
+                IOHelper.close(is);
+            }
+        }
+
+        // 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;
+    }
+
     @Override
     protected void doSuspend() throws Exception {
         EventHelper.notifyCamelContextSuspending(this);
diff --git 
a/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java 
b/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java
index e4e4df7..4667ee3 100644
--- a/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java
+++ b/camel-core/src/main/java/org/apache/camel/support/ServiceSupport.java
@@ -336,44 +336,4 @@ public abstract class ServiceSupport implements 
StatefulService {
         // noop
     }
 
-    @Override
-    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-core/pom.properties");
-            if (is != null) {
-                p.load(is);
-                version = p.getProperty("version", "");
-            }
-        } catch (Exception e) {
-            // ignore
-        } finally {
-            if (is != null) {
-                IOHelper.close(is);
-            }
-        }
-
-        // 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;
-    }
 }

Reply via email to