This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 8adb6e1 Allow multiple property sources 8adb6e1 is described below commit 8adb6e10065c93d93de584bb5cb0648dc30f1597 Author: remm <r...@apache.org> AuthorDate: Thu Mar 19 18:31:33 2020 +0100 Allow multiple property sources The problem appears with the introduction of EnvironmentPropertySource, where people could use it but prevent use of a custom property source. --- java/org/apache/tomcat/util/digester/Digester.java | 74 ++++++++++++++-------- webapps/docs/changelog.xml | 5 ++ webapps/docs/config/systemprops.xml | 3 +- 3 files changed, 53 insertions(+), 29 deletions(-) diff --git a/java/org/apache/tomcat/util/digester/Digester.java b/java/org/apache/tomcat/util/digester/Digester.java index 9326ba4..ec0e256 100644 --- a/java/org/apache/tomcat/util/digester/Digester.java +++ b/java/org/apache/tomcat/util/digester/Digester.java @@ -25,6 +25,7 @@ import java.lang.reflect.InvocationTargetException; import java.net.URI; import java.net.URISyntaxException; import java.security.Permission; +import java.util.ArrayList; import java.util.EmptyStackException; import java.util.HashMap; import java.util.List; @@ -32,6 +33,7 @@ import java.util.Map; import java.util.Properties; import java.util.PropertyPermission; import java.util.Set; +import java.util.StringTokenizer; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; @@ -84,32 +86,37 @@ public class Digester extends DefaultHandler2 { // ---------------------------------------------------------- Static Fields - protected static IntrospectionUtils.PropertySource propertySource; - private static boolean propertySourceSet = false; + protected static IntrospectionUtils.PropertySource[] propertySources; + private static boolean propertySourcesSet = false; protected static final StringManager sm = StringManager.getManager(Digester.class); static { - String className = System.getProperty("org.apache.tomcat.util.digester.PROPERTY_SOURCE"); - IntrospectionUtils.PropertySource source = null; - if (className != null) { - ClassLoader[] cls = new ClassLoader[] { Digester.class.getClassLoader(), - Thread.currentThread().getContextClassLoader() }; - for (int i = 0; i < cls.length; i++) { - try { - Class<?> clazz = Class.forName(className, true, cls[i]); - source = (IntrospectionUtils.PropertySource) - clazz.getConstructor().newInstance(); - break; - } catch (Throwable t) { - ExceptionUtils.handleThrowable(t); + String classNames = System.getProperty("org.apache.tomcat.util.digester.PROPERTY_SOURCE"); + ArrayList<IntrospectionUtils.PropertySource> sourcesList = new ArrayList<>(); + IntrospectionUtils.PropertySource[] sources = null; + if (classNames != null) { + StringTokenizer classNamesTokenizer = new StringTokenizer(classNames, ","); + while (classNamesTokenizer.hasMoreTokens()) { + String className = classNamesTokenizer.nextToken().trim(); + ClassLoader[] cls = new ClassLoader[] { Digester.class.getClassLoader(), + Thread.currentThread().getContextClassLoader() }; + for (int i = 0; i < cls.length; i++) { + try { + Class<?> clazz = Class.forName(className, true, cls[i]); + sourcesList.add((IntrospectionUtils.PropertySource) clazz.getConstructor().newInstance()); + break; + } catch (Throwable t) { + ExceptionUtils.handleThrowable(t); LogFactory.getLog("org.apache.tomcat.util.digester.Digester") .error("Unable to load property source[" + className + "].", t); + } } } + sources = sourcesList.toArray(new IntrospectionUtils.PropertySource[0]); } - if (source != null) { - propertySource = source; - propertySourceSet = true; + if (sources != null) { + propertySources = sources; + propertySourcesSet = true; } if (Boolean.getBoolean("org.apache.tomcat.util.digester.REPLACE_SYSTEM_PROPERTIES")) { replaceSystemProperties(); @@ -117,9 +124,17 @@ public class Digester extends DefaultHandler2 { } public static void setPropertySource(IntrospectionUtils.PropertySource propertySource) { - if (!propertySourceSet) { - Digester.propertySource = propertySource; - propertySourceSet = true; + if (!propertySourcesSet) { + propertySources = new IntrospectionUtils.PropertySource[1]; + propertySources[0] = propertySource; + propertySourcesSet = true; + } + } + + public static void setPropertySource(IntrospectionUtils.PropertySource[] propertySources) { + if (!propertySourcesSet) { + Digester.propertySources = propertySources; + propertySourcesSet = true; } } @@ -159,7 +174,7 @@ public class Digester extends DefaultHandler2 { } - protected IntrospectionUtils.PropertySource source[] = new IntrospectionUtils.PropertySource[] { + protected IntrospectionUtils.PropertySource[] source = new IntrospectionUtils.PropertySource[] { new SystemPropertySource() }; @@ -339,18 +354,21 @@ public class Digester extends DefaultHandler2 { public Digester() { - propertySourceSet = true; - if (propertySource != null) { - source = new IntrospectionUtils.PropertySource[] { propertySource, source[0] }; + propertySourcesSet = true; + if (propertySources != null) { + ArrayList<IntrospectionUtils.PropertySource> sourcesList = new ArrayList<>(); + for (IntrospectionUtils.PropertySource cur : propertySources) { + sourcesList.add(cur); + } + sourcesList.add(source[0]); + source = sourcesList.toArray(new IntrospectionUtils.PropertySource[0]); } } public static void replaceSystemProperties() { Log log = LogFactory.getLog(Digester.class); - if (propertySource != null) { - IntrospectionUtils.PropertySource[] propertySources = - new IntrospectionUtils.PropertySource[] { propertySource }; + if (propertySources != null) { Properties properties = System.getProperties(); Set<String> names = properties.stringPropertyNames(); for (String name : names) { diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 2fc7df9..3dbae67 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -52,6 +52,11 @@ consistently using the encoding of the web.xml file where specified and UTF-8 where no explicit encoding is specified. (markt) </fix> + <update> + Allow a comma separated list of class names for the + <code>org.apache.tomcat.util.digester.PROPERTY_SOURCE</code> + system property. (remm) + </update> </changelog> </subsection> <subsection name="Coyote"> diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml index dfb2900..1003256 100644 --- a/webapps/docs/config/systemprops.xml +++ b/webapps/docs/config/systemprops.xml @@ -40,7 +40,8 @@ <section name="Property replacements"> <properties> <property name="org.apache.tomcat.util.digester. PROPERTY_SOURCE"> - <p>Set this to a fully qualified name of a class that implements + <p>Set this to a comma separated list of fully qualified name of classes + that implement <code>org.apache.tomcat.util.IntrospectionUtils.PropertySource</code>. Required to have a public constructor with no arguments.</p> <p>Use this to add a property source, that will be invoked when --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org