Modified config.properties file substitution to allow for nested property
substitution, which makes it possible to initialize the system bundle
export package property with the appropriate set of JRE packages.
Modified the config.properties file to include reasonably complete
JDK 1.5 packages, but 1.3 and 1.4 are incomplete. (FELIX-78)
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@412981 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/org.apache.felix.main/src/main/java/org/apache/felix/main/Main.java b/org.apache.felix.main/src/main/java/org/apache/felix/main/Main.java
index 33e9b6d..cb03a8f 100644
--- a/org.apache.felix.main/src/main/java/org/apache/felix/main/Main.java
+++ b/org.apache.felix.main/src/main/java/org/apache/felix/main/Main.java
@@ -19,8 +19,7 @@
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Enumeration;
-import java.util.Properties;
+import java.util.*;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.cache.BundleCache;
@@ -298,11 +297,12 @@
return;
}
- // Perform variable substitution for system properties.
+ // Perform variable substitution on specified properties.
for (Enumeration e = props.propertyNames(); e.hasMoreElements(); )
{
String name = (String) e.nextElement();
- System.setProperty(name, substVars((String) props.getProperty(name)));
+ System.setProperty(name,
+ substVars(props.getProperty(name), name, null, null));
}
}
@@ -410,81 +410,134 @@
for (Enumeration e = props.propertyNames(); e.hasMoreElements(); )
{
String name = (String) e.nextElement();
- props.setProperty(name, substVars((String) props.getProperty(name)));
+ props.setProperty(name,
+ substVars(props.getProperty(name), name, null, props));
}
return props;
}
private static final String DELIM_START = "${";
- private static final char DELIM_STOP = '}';
- private static final int DELIM_START_LEN = 2;
- private static final int DELIM_STOP_LEN = 1;
+ private static final String DELIM_STOP = "}";
/**
* <p>
- * This method performs system property variable substitution on the
- * specified string value. If the specified string contains the
- * syntax <tt>${<system-prop-name>}</tt>, then the corresponding
- * system property value is substituted for the marker.
+ * This method performs property variable substitution on the
+ * specified value. If the specified value contains the syntax
+ * <tt>${<prop-name>}</tt>, where <tt><prop-name></tt>
+ * refers to either a configuration property or a system property,
+ * then the corresponding property value is substituted for the variable
+ * placeholder. Multiple variable placeholders may exist in the
+ * specified value as well as nested variable placeholders, which
+ * are substituted from inner most to outer most. Configuration
+ * properties override system properties.
* </p>
- * @param val The string on which to perform system property substitution.
+ * @param val The string on which to perform property substitution.
+ * @param currentKey The key of the property being evaluated used to
+ * detect cycles.
+ * @param cycleMap Map of variable references used to detect nested cycles.
+ * @param configProps Set of configuration properties.
* @return The value of the specified string after system property substitution.
* @throws IllegalArgumentException If there was a syntax error in the
- * system property variable marker syntax.
+ * property placeholder syntax or a recursive variable reference.
**/
- public static String substVars(String val)
+ public static String substVars(String val, String currentKey,
+ Map cycleMap, Properties configProps)
throws IllegalArgumentException
{
- StringBuffer sbuf = new StringBuffer();
+ // If there is currently no cycle map, then create
+ // one for detecting cycles for this invocation.
+ if (cycleMap == null)
+ {
+ cycleMap = new HashMap();
+ }
+
+ // Put the current key in the cycle map.
+ cycleMap.put(currentKey, currentKey);
+
+ // Assume we have a value that is something like:
+ // "leading ${foo.${bar}} middle ${baz} trailing"
- if (val == null)
+ // Find the first ending '}' variable delimiter, which
+ // will correspond to the first deepest nested variable
+ // placeholder.
+ int stopDelim = val.indexOf(DELIM_STOP);
+
+ // Find the matching starting "${" variable delimiter
+ // by looping until we find a start delimiter that is
+ // greater than the stop delimiter we have found.
+ int startDelim = val.indexOf(DELIM_START);
+ while (stopDelim >= 0)
+ {
+ int idx = val.indexOf(DELIM_START, startDelim + DELIM_START.length());
+ if ((idx < 0) || (idx > stopDelim))
+ {
+ break;
+ }
+ else if (idx < stopDelim)
+ {
+ startDelim = idx;
+ }
+ }
+
+ // If we do not have a start or stop delimiter, then just
+ // return the existing value.
+ if ((startDelim < 0) && (stopDelim < 0))
{
return val;
}
-
- int i = 0;
- int j, k;
-
- while (true)
+ // At this point, we found a stop delimiter without a start,
+ // so throw an exception.
+ else if (((startDelim < 0) || (startDelim > stopDelim))
+ && (stopDelim >= 0))
{
- j = val.indexOf(DELIM_START, i);
- if (j == -1)
- {
- if (i == 0)
- {
- return val;
- }
- else
- {
- sbuf.append(val.substring(i, val.length()));
- return sbuf.toString();
- }
- }
- else
- {
- sbuf.append(val.substring(i, j));
- k = val.indexOf(DELIM_STOP, j);
- if (k == -1)
- {
- throw new IllegalArgumentException(
- '"' + val +
- "\" has no closing brace. Opening brace at position "
- + j + '.');
- }
- else
- {
- j += DELIM_START_LEN;
- String key = val.substring(j, k);
- // Try system properties.
- String replacement = System.getProperty(key, null);
- if (replacement != null)
- {
- sbuf.append(replacement);
- }
- i = k + DELIM_STOP_LEN;
- }
- }
+ throw new IllegalArgumentException(
+ "stop delimiter with no start delimiter: "
+ + val);
}
+
+ // At this point, we have found a variable placeholder so
+ // we must perform a variable substitution on it.
+ // Using the start and stop delimiter indices, extract
+ // the first, deepest nested variable placeholder.
+ String variable =
+ val.substring(startDelim + DELIM_START.length(), stopDelim);
+
+ // Verify that this is not a recursive variable reference.
+ if (cycleMap.get(variable) != null)
+ {
+ throw new IllegalArgumentException(
+ "recursive variable reference: " + variable);
+ }
+
+ // Get the value of the deepest nested variable placeholder.
+ // Try to configuration properties first.
+ String substValue = (configProps != null)
+ ? configProps.getProperty(variable, null)
+ : null;
+ if (substValue == null)
+ {
+ // Ignore unknown property values.
+ substValue = System.getProperty(variable, "");
+ }
+
+ // Remove the found variable from the cycle map, since
+ // it may appear more than once in the value and we don't
+ // want such situations to appear as a recursive reference.
+ cycleMap.remove(variable);
+
+ // Append the leading characters, the substituted value of
+ // the variable, and the trailing characters to get the new
+ // value.
+ val = val.substring(0, startDelim)
+ + substValue
+ + val.substring(stopDelim + DELIM_STOP.length(), val.length());
+
+ // Now perform substitution again, since there could still
+ // be substitutions to make.
+ val = substVars(val, currentKey, cycleMap, configProps);
+
+ // Return the value.
+ return val;
}
}
\ No newline at end of file
diff --git a/org.apache.felix.main/src/main/resources/config.properties b/org.apache.felix.main/src/main/resources/config.properties
index e28d343..a7468f3 100644
--- a/org.apache.felix.main/src/main/resources/config.properties
+++ b/org.apache.felix.main/src/main/resources/config.properties
@@ -5,18 +5,8 @@
org.osgi.service.packageadmin; version=1.2.0, \
org.osgi.service.startlevel; version=1.0.0, \
org.osgi.service.url; version=1.0.0, \
- javax.swing; \
- javax.swing.plaf; \
- javax.swing.event; \
- javax.swing.table; \
- javax.swing.border; \
- javax.swing.tree; \
- javax.swing.text; \
- version=1.4, \
- org.w3c.dom, \
- org.xml.sax, \
- javax.xml.parsers, \
- javax.imageio
+ ${jre-${java.specification.version}}
+
#org.osgi.framework.bootdelegation=sun.*,com.sun.*
#felix.cache.profile=foo
felix.auto.start.1= \
@@ -33,3 +23,153 @@
org.osgi.service.http.port=8080
obr.shell.telnet=on
#obr.repository.url=http://bundles.osgi.org/obr/browse?_xml=1&cmd=repository
+
+
+#
+# Java platform package export properties.
+#
+jre-1.3= \
+ javax.swing; \
+ javax.swing.plaf; \
+ javax.swing.event; \
+ javax.swing.table; \
+ javax.swing.border; \
+ javax.swing.tree; \
+ javax.swing.text; \
+ version="1.3.0"
+
+jre-1.4= \
+ javax.swing; \
+ javax.swing.plaf; \
+ javax.swing.event; \
+ javax.swing.table; \
+ javax.swing.border; \
+ javax.swing.tree; \
+ javax.swing.text; \
+ version="1.4.0"
+
+jre-1.5= \
+ javax.accessibility; \
+ javax.activity; \
+ javax.imageio; \
+ javax.imageio.event; \
+ javax.imageio.metadata; \
+ javax.imageio.plugins.bmp; \
+ javax.imageio.plugins.jpeg; \
+ javax.imageio.spi; \
+ javax.imageio.stream; \
+ javax.management; \
+ javax.management.loading; \
+ javax.management.modelmbean; \
+ javax.management.monitor; \
+ javax.management.openmbean; \
+ javax.management.relation; \
+ javax.management.remote; \
+ javax.management.remote.rmi; \
+ javax.management.timer; \
+ javax.naming; \
+ javax.naming.directory; \
+ javax.naming.event; \
+ javax.naming.ldap; \
+ javax.naming.spi; \
+ javax.print; \
+ javax.print.attribute; \
+ javax.print.attribute.standard; \
+ javax.print.event; \
+ javax.rmi; \
+ javax.rmi.CORBA; \
+ javax.rmi.ssl; \
+ javax.security.auth; \
+ javax.security.auth.callback; \
+ javax.security.auth.kerberos; \
+ javax.security.auth.login; \
+ javax.security.auth.spi; \
+ javax.security.auth.x500; \
+ javax.security.sasl; \
+ javax.sound.midi; \
+ javax.sound.midi.spi; \
+ javax.sound.sampled; \
+ javax.sound.sampled.spi; \
+ javax.sql; \
+ javax.sql.rowset; \
+ javax.sql.rowset.serial; \
+ javax.sql.rowset.spi; \
+ javax.swing; \
+ javax.swing.border; \
+ javax.swing.colorchooser; \
+ javax.swing.event; \
+ javax.swing.filechooser; \
+ javax.swing.plaf; \
+ javax.swing.plaf.basic; \
+ javax.swing.plaf.basic.icons; \
+ javax.swing.plaf.metal; \
+ javax.swing.plaf.metal.icons; \
+ javax.swing.plaf.metal.icons.ocean; \
+ javax.swing.plaf.metal.sounds; \
+ javax.swing.plaf.multi; \
+ javax.swing.plaf.synth; \
+ javax.swing.table; \
+ javax.swing.text; \
+ javax.swing.text.html; \
+ javax.swing.text.html.icons; \
+ javax.swing.text.html.parser; \
+ javax.swing.text.rtf; \
+ javax.swing.text.rtf.charsets; \
+ javax.swing.tree; \
+ javax.swing.undo; \
+ javax.transaction; \
+ javax.transaction.xa; \
+ javax.xml; \
+ javax.xml.datatype; \
+ javax.xml.namespace; \
+ javax.xml.parsers; \
+ javax.xml.transform; \
+ javax.xml.transform.dom; \
+ javax.xml.transform.sax; \
+ javax.xml.transform.stream; \
+ javax.xml.validation; \
+ javax.xml.xpath; \
+ org.ietf.jgss; \
+ org.omg.CORBA; \
+ org.omg.CORBA.DynAnyPackage; \
+ org.omg.CORBA.ORBPackage; \
+ org.omg.CORBA.TypeCodePackage; \
+ org.omg.CORBA.portable; \
+ org.omg.CORBA_2_3; \
+ org.omg.CORBA_2_3.portable; \
+ org.omg.CosNaming; \
+ org.omg.CosNaming.NamingContextExtPackage; \
+ org.omg.CosNaming.NamingContextPackage; \
+ org.omg.Dynamic; \
+ org.omg.DynamicAny; \
+ org.omg.DynamicAny.DynAnyFactoryPackage; \
+ org.omg.DynamicAny.DynAnyPackage; \
+ org.omg.IOP; \
+ org.omg.IOP.CodecFactoryPackage; \
+ org.omg.IOP.CodecPackage; \
+ org.omg.Messaging; \
+ org.omg.PortableInterceptor; \
+ org.omg.PortableInterceptor.ORBInitInfoPackage; \
+ org.omg.PortableServer; \
+ org.omg.PortableServer.CurrentPackage; \
+ org.omg.PortableServer.POAManagerPackage; \
+ org.omg.PortableServer.POAPackage; \
+ org.omg.PortableServer.ServantLocatorPackage; \
+ org.omg.PortableServer.portable; \
+ org.omg.SendingContext; \
+ org.omg.stub.java.rmi; \
+ org.omg.stub.javax.management.remote.rmi; \
+ org.w3c.dom; \
+ org.w3c.dom.bootstrap; \
+ org.w3c.dom.css; \
+ org.w3c.dom.events; \
+ org.w3c.dom.html; \
+ org.w3c.dom.ls; \
+ org.w3c.dom.ranges; \
+ org.w3c.dom.stylesheets; \
+ org.w3c.dom.traversal; \
+ org.w3c.dom.views; \
+ org.xml.sax; \
+ org.xml.sax.ext; \
+ org.xml.sax.helpers; version="1.5.0"
+