This is an automated email from the ASF dual-hosted git repository.
remm 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 9730818 Allow multiple property sources
9730818 is described below
commit 9730818c0df0fda5b4106de4b1a409b036899334
Author: remm <[email protected]>
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 | 76 +++++++++++++---------
webapps/docs/changelog.xml | 5 ++
webapps/docs/config/systemprops.xml | 3 +-
3 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/java/org/apache/tomcat/util/digester/Digester.java
b/java/org/apache/tomcat/util/digester/Digester.java
index 46d80d0..6b0d1f7 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,31 +86,36 @@ 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);
-
LogFactory.getLog(Digester.class).error(sm.getString("digester.propertySourceLoadError",
className), 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(Digester.class).error(sm.getString("digester.propertySourceLoadError",
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();
@@ -116,9 +123,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;
}
}
@@ -146,7 +161,7 @@ public class Digester extends DefaultHandler2 {
}
- protected IntrospectionUtils.PropertySource source[] = new
IntrospectionUtils.PropertySource[] {
+ protected IntrospectionUtils.PropertySource[] source = new
IntrospectionUtils.PropertySource[] {
new SystemPropertySource() };
@@ -326,18 +341,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 34d3cd6..315c1d4 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 4da50f9..bd4a98a 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: [email protected]
For additional commands, e-mail: [email protected]