On 06/08/2020 12:26, jfcl...@apache.org wrote:
> This is an automated email from the ASF dual-hosted git repository.
> 
> jfclere pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/tomcat.git
> 
> 
> The following commit(s) were added to refs/heads/master by this push:
>      new e7896ee  Allow recursive substitution of properties. Add tests and 
> use indexOf("${") instead indexOf('$').
>      new ec5e948  Merge pull request #309 from jfclere/trunk
> e7896ee is described below
> 
> commit e7896ee44a3c9f2cff4b93bca9ae6112917f6c88
> Author: Jean-Frederic Clere <jfcl...@gmail.com>
> AuthorDate: Fri Jun 26 09:50:09 2020 +0200
> 
>     Allow recursive substitution of properties.
>     Add tests and use indexOf("${") instead indexOf('$').

Change log?
Docs?

Or did I miss a commit somewhere?

Mark


> ---
>  java/org/apache/tomcat/util/IntrospectionUtils.java | 21 
> +++++++++++++++++++--
>  .../apache/tomcat/util/TestIntrospectionUtils.java  | 12 ++++++++++++
>  2 files changed, 31 insertions(+), 2 deletions(-)
> 
> diff --git a/java/org/apache/tomcat/util/IntrospectionUtils.java 
> b/java/org/apache/tomcat/util/IntrospectionUtils.java
> index 78ab66f..9f12323 100644
> --- a/java/org/apache/tomcat/util/IntrospectionUtils.java
> +++ b/java/org/apache/tomcat/util/IntrospectionUtils.java
> @@ -285,8 +285,17 @@ public final class IntrospectionUtils {
>      public static String replaceProperties(String value,
>              Hashtable<Object,Object> staticProp, PropertySource 
> dynamicProp[],
>              ClassLoader classLoader) {
> +            return replaceProperties(value, staticProp, dynamicProp, 
> classLoader, 0);
> +    }
>  
> -        if (value.indexOf('$') < 0) {
> +    private static String replaceProperties(String value,
> +            Hashtable<Object,Object> staticProp, PropertySource 
> dynamicProp[],
> +            ClassLoader classLoader, int iterationCount) {
> +        if (value.indexOf("${") < 0) {
> +            return value;
> +        }
> +        if (iterationCount >=20) {
> +            log.warn("System property failed to update and remains [" + 
> value + "]");
>              return value;
>          }
>          StringBuilder sb = new StringBuilder();
> @@ -332,7 +341,15 @@ public final class IntrospectionUtils {
>          }
>          if (prev < value.length())
>              sb.append(value.substring(prev));
> -        return sb.toString();
> +        String newval = sb.toString();
> +        if (newval.indexOf("${") < 0) {
> +            return newval;
> +        }
> +        if (newval.equals(value))
> +            return value;
> +        if (log.isDebugEnabled())
> +            log.debug("IntrospectionUtils.replaceProperties iter on: " + 
> newval);
> +        return replaceProperties(newval, staticProp, dynamicProp, 
> classLoader, iterationCount+1);
>      }
>  
>      private static String getProperty(String name, Hashtable<Object, Object> 
> staticProp,
> diff --git a/test/org/apache/tomcat/util/TestIntrospectionUtils.java 
> b/test/org/apache/tomcat/util/TestIntrospectionUtils.java
> index ed9fe39..73ea86a 100644
> --- a/test/org/apache/tomcat/util/TestIntrospectionUtils.java
> +++ b/test/org/apache/tomcat/util/TestIntrospectionUtils.java
> @@ -143,5 +143,17 @@ public class TestIntrospectionUtils {
>  
>          Assert.assertEquals("abc${normal}xyz", 
> IntrospectionUtils.replaceProperties(
>                  "abc${normal}xyz", properties, null, null));
> +
> +        properties.setProperty("my.ajp.port", "8009");
> +        properties.setProperty("tomcat.ajp.port", "${my.ajp.port}");
> +        Assert.assertEquals("8009", IntrospectionUtils.replaceProperties(
> +                "${tomcat.ajp.port}", properties, null, null));
> +
> +    }
> +    @Test
> +    public void testReplacePropertiesRecursively() {
> +        Properties properties = new Properties();
> +        properties.setProperty("replaceMe", "something ${replaceMe}");
> +        IntrospectionUtils.replaceProperties("${replaceMe}", properties, 
> null, null);
>      }
>  }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: dev-h...@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to