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

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


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

commit 6cd35fae6cf4b441c39ffe5cc5814b0a2db9d4d1
Author: Claus Ibsen <claus.ib...@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 eea8af6..42d4a96 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 eea8af6..42d4a96 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 0672e0a..902833a 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
@@ -26,6 +26,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");
@@ -37,6 +38,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 7521355..357e68d 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]
 ----

Reply via email to