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 2021/03/29 05:50:14 UTC

[camel] branch master updated: CAMEL-16412: Fix file path resolver to support the old env. syntax style for loading properties files from ENV variables.

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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new da64602  CAMEL-16412: Fix file path resolver to support the old env. syntax style for loading properties files from ENV variables.
da64602 is described below

commit da646026ca5004a29f33589bde7b24de287afb06
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 29 07:48:33 2021 +0200

    CAMEL-16412: Fix file path resolver to support the old env. syntax style for loading properties files from ENV variables.
---
 .../org/apache/camel/catalog/docs/properties-component.adoc  |  2 +-
 core/camel-base/src/main/docs/properties-component.adoc      |  2 +-
 .../java/org/apache/camel/util/FilePathResolverTest.java     |  2 ++
 .../main/java/org/apache/camel/util/FilePathResolver.java    | 12 ++++++++++--
 docs/components/modules/ROOT/pages/properties-component.adoc |  2 +-
 5 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/properties-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/properties-component.adoc
index c0cf697..36ff2f7 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/properties-component.adoc
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/properties-component.adoc
@@ -127,7 +127,7 @@ In the location above we defined a location using the file scheme using
 the JVM system property with key `karaf.home`.
 
 To use an OS environment variable instead you would have to prefix with
-env:
+`env:`. You can also prefix with `env.`, however this style is not recommended because all the other functions use colon.
 
 [source]
 ----
diff --git a/core/camel-base/src/main/docs/properties-component.adoc b/core/camel-base/src/main/docs/properties-component.adoc
index c0cf697..36ff2f7 100644
--- a/core/camel-base/src/main/docs/properties-component.adoc
+++ b/core/camel-base/src/main/docs/properties-component.adoc
@@ -127,7 +127,7 @@ In the location above we defined a location using the file scheme using
 the JVM system property with key `karaf.home`.
 
 To use an OS environment variable instead you would have to prefix with
-env:
+`env:`. You can also prefix with `env.`, however this style is not recommended because all the other functions use colon.
 
 [source]
 ----
diff --git a/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java b/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
index 19b182a..6b54a73 100644
--- a/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/util/FilePathResolverTest.java
@@ -29,6 +29,7 @@ public class FilePathResolverTest {
     public void testFilePathResolver() throws Exception {
         assertEquals("/foo/bar", FilePathResolver.resolvePath("/foo/bar"));
 
+        assertEquals("/foo/myserver/bar", FilePathResolver.resolvePath("/foo/${env:FOO_SERVICE_HOST}/bar"));
         assertEquals("/foo/myserver/bar", FilePathResolver.resolvePath("/foo/${env.FOO_SERVICE_HOST}/bar"));
 
         String tmp = System.getProperty("java.io.tmpdir");
@@ -40,6 +41,7 @@ public class FilePathResolverTest {
         assertEquals("/myprefix/" + tmp + "bar/Carlsberg",
                 FilePathResolver.resolvePath("/myprefix/${java.io.tmpdir}bar/${beer}"));
 
+        assertEquals("/foo/myserver/bar/Carlsberg", FilePathResolver.resolvePath("/foo/${env:FOO_SERVICE_HOST}/bar/${beer}"));
         assertEquals("/foo/myserver/bar/Carlsberg", FilePathResolver.resolvePath("/foo/${env.FOO_SERVICE_HOST}/bar/${beer}"));
     }
 }
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/FilePathResolver.java b/core/camel-util/src/main/java/org/apache/camel/util/FilePathResolver.java
index adb14f5..04672fd 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/FilePathResolver.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/FilePathResolver.java
@@ -29,7 +29,7 @@ public final class FilePathResolver {
      * <p/>
      * The pattern is:
      * <ul>
-     * <li><tt>${env.key}</tt> for environment variables.</li>
+     * <li><tt>${env:key}</tt> or <tt>${env.key}</tt> for environment variables.</li>
      * <li><tt>${key}</tt> for JVM system properties.</li>
      * </ul>
      * For example: <tt>${env.KARAF_HOME}/data/logs</tt>
@@ -46,7 +46,15 @@ public final class FilePathResolver {
 
         String[] functions = StringHelper.splitOnCharacter(path, "}", count);
         for (String fun : functions) {
-            int pos = fun.indexOf("${env.");
+            int pos = fun.indexOf("${env:");
+            if (pos != -1) {
+                String key = fun.substring(pos + 6);
+                String value = System.getenv(key);
+                if (value != null) {
+                    path = path.replace("${env:" + key + "}", value);
+                }
+            }
+            pos = fun.indexOf("${env.");
             if (pos != -1) {
                 String key = fun.substring(pos + 6);
                 String value = System.getenv(key);
diff --git a/docs/components/modules/ROOT/pages/properties-component.adoc b/docs/components/modules/ROOT/pages/properties-component.adoc
index afd2dff..a4ac5f2 100644
--- a/docs/components/modules/ROOT/pages/properties-component.adoc
+++ b/docs/components/modules/ROOT/pages/properties-component.adoc
@@ -129,7 +129,7 @@ In the location above we defined a location using the file scheme using
 the JVM system property with key `karaf.home`.
 
 To use an OS environment variable instead you would have to prefix with
-env:
+`env:`. You can also prefix with `env.`, however this style is not recommended because all the other functions use colon.
 
 [source]
 ----