Author: fmeschbe
Date: Thu Jan 29 12:30:53 2009
New Revision: 738835
URL: http://svn.apache.org/viewvc?rev=738835&view=rev
Log:
FELIX-712 Upgrade to Felix Framework 1.4.1 and fix properties
Modified:
incubator/sling/trunk/launchpad/base/pom.xml
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/Loader.java
incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties
Modified: incubator/sling/trunk/launchpad/base/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/pom.xml?rev=738835&r1=738834&r2=738835&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/pom.xml (original)
+++ incubator/sling/trunk/launchpad/base/pom.xml Thu Jan 29 12:30:53 2009
@@ -186,6 +186,12 @@
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>1.4.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
@@ -203,12 +209,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>1.0.4</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.eclipse.equinox.http</groupId>
<artifactId>servlet</artifactId>
<version>1.0.0-v20070606</version>
Modified:
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java?rev=738835&r1=738834&r2=738835&view=diff
==============================================================================
---
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
(original)
+++
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/Sling.java
Thu Jan 29 12:30:53 2009
@@ -16,8 +16,6 @@
*/
package org.apache.sling.launchpad.base.impl;
-import static
org.apache.felix.framework.util.FelixConstants.EMBEDDED_EXECUTION_PROP;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -40,6 +38,7 @@
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.Logger;
+import org.apache.felix.framework.util.FelixConstants;
import org.apache.sling.launchpad.base.shared.Notifiable;
import org.apache.sling.launchpad.base.shared.SharedConstants;
import org.osgi.framework.BundleActivator;
@@ -53,32 +52,32 @@
/**
* The <code>Sling</code> serves as the starting point for Sling.
* <ul>
- * <li>The {...@link #Sling(Logger, ResourceProvider, Map)} method launches
- * Apache <code>Felix</code> as the OSGi framework implementation we use.
+ * <li>The {...@link #Sling(Logger, ResourceProvider, Map)} method launches
Apache
+ * <code>Felix</code> as the OSGi framework implementation we use.
* </ul>
* <p>
* <b>Launch Configuration</b>
* <p>
- * The Apache <code>Felix</code> framework requires configuration parameters
- * to be specified for startup. This servlet builds the list of parameters from
+ * The Apache <code>Felix</code> framework requires configuration parameters to
+ * be specified for startup. This servlet builds the list of parameters from
* three locations:
* <ol>
- * <li>The <code>com/day/osgi/servlet/Sling.properties</code> is read from
- * the servlet class path. This properties file contains default settings.</li>
- * <li>Extensions of this servlet may provide additional properties to be
- * loaded overwriting the {...@link #loadPropertiesOverride(Map)} method.
+ * <li>The <code>sling.properties</code> file is read from the servlet class
+ * path. This properties file contains default settings.</li>
+ * <li>Extensions of this servlet may provide additional properties to be
loaded
+ * overwriting the {...@link #loadPropertiesOverride(Map)} method.
* <li>Finally, web application init parameters are added to the properties and
* may overwrite existing properties of the same name(s).
* </ol>
* <p>
* After loading all properties, variable substitution takes place on the
* property values. A variable is indicated as
<code>${<prop-name>}</code>
- * where <code><prop-name></code> is the name of a system or
- * configuration property (configuration properties override system
properties).
- * Variables may be nested and are resolved from inner-most to outer-most. For
- * example, the property value <code>${outer-${inner}}</code> is resolved by
- * first resolving <code>${inner}</code> and then resolving the property whose
- * name is the catenation of <code>outer-</code> and the result of resolving
+ * where <code><prop-name></code> is the name of a system or
configuration
+ * property (configuration properties override system properties). Variables
may
+ * be nested and are resolved from inner-most to outer-most. For example, the
+ * property value <code>${outer-${inner}}</code> is resolved by first resolving
+ * <code>${inner}</code> and then resolving the property whose name is the
+ * catenation of <code>outer-</code> and the result of resolving
* <code>${inner}</code>.
* <p>
*/
@@ -212,16 +211,16 @@
// ensure execution environment
this.setExecutionEnvironment(props);
- // make sure Felix does not exit the VM when terminating ...
- props.put(EMBEDDED_EXECUTION_PROP, "true");
-
// the custom activator list just contains this servlet
List<BundleActivator> activators = new ArrayList<BundleActivator>();
activators.add(this);
activators.add(new BootstrapInstaller(logger, resourceProvider));
// create the framework and start it
- Felix tmpFelix = new SlingFelix(notifiable, logger, props, activators);
+ Map<String, Object> felixProps = new HashMap<String, Object>(props);
+ felixProps.put(FelixConstants.LOG_LOGGER_PROP, logger);
+ felixProps.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP,
activators);
+ Felix tmpFelix = new SlingFelix(notifiable, props);
tmpFelix.start();
// only assign field if start succeeds
@@ -247,7 +246,27 @@
// shutdown the Felix container
if (myFelix != null) {
logger.log(Logger.LOG_INFO, "Shutting down Sling");
- myFelix.stopAndWait();
+ try {
+
+ myFelix.stop();
+ myFelix.waitForStop(0);
+
+ } catch (BundleException be) {
+
+ // may be thrown by stop, log but continue
+ logger.log(Logger.LOG_ERROR,
+ "Failure initiating Framework Shutdown", be);
+
+ } catch (InterruptedException ie) {
+
+ // may be thrown by waitForStop, log but continue
+ logger.log(
+ Logger.LOG_ERROR,
+ "Interrupted while waiting for the Framework
Termination",
+ ie);
+
+ }
+
logger.log(Logger.LOG_INFO, "Sling stopped");
}
}
@@ -326,78 +345,83 @@
// The config properties file is either specified by a system
// property or it is in the same directory as the Felix JAR file.
// Try to load it from one of these places.
- Map<String, String> props = new HashMap<String, String>();
+ final Map<String, String> staticProps = new HashMap<String, String>();
// Read the properties file.
- this.load(props, CONFIG_PROPERTIES);
+ this.load(staticProps, CONFIG_PROPERTIES);
// resolve inclusions (and remove property)
- this.loadIncludes(props, null);
+ this.loadIncludes(staticProps, null);
// overwrite default properties with initial overwrites
if (propOverwrite != null) {
- props.putAll(propOverwrite);
+ staticProps.putAll(propOverwrite);
}
// check whether sling.home is overwritten by system property
- String slingHome = props.get(SharedConstants.SLING_HOME);
+ String slingHome = staticProps.get(SharedConstants.SLING_HOME);
if (slingHome == null || slingHome.length() == 0) {
throw new BundleException("sling.home property is missing, cannot
start");
}
// resolve variables and ensure sling.home is an absolute path
- slingHome = substVars(slingHome, SharedConstants.SLING_HOME, null,
props);
+ slingHome = substVars(slingHome, SharedConstants.SLING_HOME, null,
staticProps);
File slingHomeFile = new File(slingHome).getAbsoluteFile();
slingHome = slingHomeFile.getAbsolutePath();
// overlay with ${sling.home}/sling.properties
this.logger.log(Logger.LOG_INFO, "Starting sling in " + slingHome);
File propFile = new File(slingHome, CONFIG_PROPERTIES);
- this.load(props, propFile);
+ this.load(staticProps, propFile);
+ // migrate old properties to new properties
+ migrateProp(staticProps, "felix.cache.profiledir",
Constants.FRAMEWORK_STORAGE);
+ migrateProp(staticProps, "felix.startlevel.framework",
Constants.FRAMEWORK_BEGINNING_STARTLEVEL);
+ migrateProp(staticProps, "sling.osgi-core-packages",
"osgi-core-packages");
+ migrateProp(staticProps, "sling.osgi-compendium-services",
"osgi-compendium-services");
+
// create a copy of the properties to perform variable substitution
- Map<String, String> origProps = props;
- props = new HashMap<String, String>();
- props.putAll(origProps);
+ final Map<String, String> runtimeProps = new HashMap<String, String>();
+ runtimeProps.putAll(staticProps);
// check system properties for any overrides (except sling.home !)
- String ignoreSystemProperties =
props.get(SLING_IGNORE_SYSTEM_PROPERTIES);
+ String ignoreSystemProperties =
runtimeProps.get(SLING_IGNORE_SYSTEM_PROPERTIES);
if (!"true".equalsIgnoreCase(ignoreSystemProperties)) {
- for (String name : props.keySet()) {
+ for (String name : runtimeProps.keySet()) {
String sysProp = System.getProperty(name);
if (sysProp != null) {
- props.put(name, sysProp);
+ runtimeProps.put(name, sysProp);
}
}
}
// resolve inclusions again
- this.loadIncludes(props, slingHome);
+ this.loadIncludes(runtimeProps, slingHome);
// overwrite properties, this is not persisted as such
- this.loadPropertiesOverride(props);
+ this.loadPropertiesOverride(runtimeProps);
// resolve boot delegation and system packages
- this.resolve(props, "org.osgi.framework.bootdelegation",
+ this.resolve(runtimeProps, "org.osgi.framework.bootdelegation",
"sling.bootdelegation.");
- this.resolve(props, "org.osgi.framework.system.packages",
+ this.resolve(runtimeProps, "org.osgi.framework.system.packages",
"sling.system.packages.");
// reset back the sling home property
// might have been overwritten by system properties, included
// files or the sling.properties file
- origProps.put(SharedConstants.SLING_HOME, slingHome);
- props.put(SharedConstants.SLING_HOME, slingHome);
- props.put(SLING_HOME_URL, slingHomeFile.toURI().toString());
+ staticProps.put(SharedConstants.SLING_HOME, slingHome);
+ runtimeProps.put(SharedConstants.SLING_HOME, slingHome);
+ runtimeProps.put(SLING_HOME_URL, slingHomeFile.toURI().toString());
// Perform variable substitution for system properties.
- for (Entry<String, String> entry : props.entrySet()) {
+ for (Entry<String, String> entry : runtimeProps.entrySet()) {
entry.setValue(substVars(entry.getValue(), entry.getKey(), null,
- props));
+ runtimeProps));
}
// look for context:/ URLs to substitute
- for (Entry<String, String> entry : props.entrySet()) {
+ for (Entry<String, String> entry : runtimeProps.entrySet()) {
String name = entry.getKey();
String value = entry.getValue();
if (value != null && value.startsWith("context:/")) {
@@ -423,7 +447,7 @@
entry.setValue(target.getAbsolutePath());
// also set the new property on the unsubstituted props
- origProps.put(name, "${sling.home}" + path);
+ staticProps.put(name, "${sling.home}" + path);
} catch (IOException ioe) {
this.logger.log(Logger.LOG_ERROR, "Cannot copy file "
@@ -454,7 +478,7 @@
// copy the values into a temporary properties structure to store
Properties tmp = new Properties();
- tmp.putAll(origProps);
+ tmp.putAll(staticProps);
tmp.store(os, "Overlay properties for configuration");
} catch (Exception ex) {
this.logger.log(Logger.LOG_ERROR,
@@ -469,7 +493,7 @@
}
}
- return props;
+ return runtimeProps;
}
/**
@@ -536,6 +560,37 @@
}
}
+ /**
+ * Converts an old Felix framework property into a new (standard or
modified
+ * Felix framework) property. If a property named <code>oldName</code> does
+ * not exist in the <code>props</code> map, the map is not modified. If
such
+ * a property exists it is removed and add to the map with the
+ * <code>newName</code> key. If both properties <code>oldName</code> and
+ * <code>newName</code> exist, the property <code>newName</code> is
replaced
+ * with the value of the property <code>oldName</code>.
+ *
+ * @param props The map of properties containing the property to rename
+ * @param oldName The old key of the property value
+ * @param newName The new key of the property value
+ */
+ private void migrateProp(Map<String, String> props, String oldName,
+ String newName) {
+ String propValue = props.remove(oldName);
+ if (propValue != null) {
+ String previousNewValue = props.put(newName, propValue);
+ if (previousNewValue != null) {
+ logger.log(Logger.LOG_WARNING, "Old value (" + previousNewValue
+ + ") of property " + newName + " by value: " + propValue);
+ } else {
+ logger.log(Logger.LOG_INFO, "Property " + oldName + " ("
+ + propValue + ") renamed to " + newName);
+ }
+ } else {
+ logger.log(Logger.LOG_DEBUG, "Property " + oldName
+ + " does not exist, nothing to do");
+ }
+ }
+
private void setInstallBundles(Map<String, String> props) {
String prefix = "sling.install.";
Set<String> levels = new TreeSet<String>();
Modified:
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java?rev=738835&r1=738834&r2=738835&view=diff
==============================================================================
---
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java
(original)
+++
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/impl/SlingFelix.java
Thu Jan 29 12:30:53 2009
@@ -36,13 +36,8 @@
private Notifier notifierThread;
- public SlingFelix(Notifiable notifiable, Logger arg0, Map<?, ?> arg1,
List<?> arg2) {
- super(arg0, arg1, arg2);
- this.notifiable = notifiable;
- }
-
- public SlingFelix(Notifiable notifiable, Map<?, ?> arg1, List<?> arg2) {
- super(arg1, arg2);
+ public SlingFelix(Notifiable notifiable, Map<?, ?> props) {
+ super(props);
this.notifiable = notifiable;
}
@@ -68,7 +63,7 @@
public void stop(int status) throws BundleException {
startNotifier(false, null);
- super.stop(/*TODO status*/);
+ super.stop(status);
}
private synchronized void startNotifier(boolean restart, InputStream ins) {
@@ -106,7 +101,12 @@
@Override
public void run() {
- stopAndWait();
+
+ try {
+ waitForStop(0);
+ } catch (InterruptedException ie) {
+ // TODO: log
+ }
if (restart) {
notifiable.updated(updateFile);
Modified:
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/Loader.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/Loader.java?rev=738835&r1=738834&r2=738835&view=diff
==============================================================================
---
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/Loader.java
(original)
+++
incubator/sling/trunk/launchpad/base/src/main/java/org/apache/sling/launchpad/base/shared/Loader.java
Thu Jan 29 12:30:53 2009
@@ -58,7 +58,7 @@
File launcherJarFile = getLauncherJarFile(slingHome);
if (!launcherJarFile.canRead()) {
throw new IllegalArgumentException("Sling Launcher JAR "
- + launcherJarFile + " cannot is not accessible");
+ + launcherJarFile + " is not accessible");
}
URL launcherJarURL;
@@ -110,6 +110,9 @@
* file. If the existing file is not older than the contents of the
launcher
* JAR file, the file is not replaced.
*
+ * @return <code>true</code> if the launcher JAR file has been installed or
+ * updated. If the launcher JAR is already up to date,
+ * <code>false</code> is returned.
* @throws IOException If an error occurrs transferring the contents
*/
public static boolean installLauncherJar(URL launcherJar, String slingHome)
Modified:
incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties?rev=738835&r1=738834&r2=738835&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties
(original)
+++ incubator/sling/trunk/launchpad/base/src/main/resources/sling.properties
Thu Jan 29 12:30:53 2009
@@ -104,13 +104,12 @@
#
# Felix Framework profile directory. This is by default the "felix" directory
# below the application home directory.
-felix.cache.profiledir = ${sling.home}/felix
org.osgi.framework.storage = ${sling.home}/felix
#
# Default initial Framework start level
-felix.startlevel.framework=30
+org.osgi.framework.startlevel=30
#
@@ -181,43 +180,49 @@
# Package Specifications for org.osgi.framework.system.packages
# osgi-core-packages : OSGi Core Specification packages
# osgi-compendium-services : OSGi Compendium Specification packages
-#
+#
+# Note: These properties are actually prefixed with "sling." and are renamed
+# to their correct equivalen (without the "sling." prefix) when loading
+# the properties to launch the framework. This is done to be able to
+# overwrite the values from the sling.properties file in case of an
+# OSGi API update.
-osgi-core-packages= \
+sling.osgi-core-packages= \
org.osgi.framework; version=1.4.0, \
+ org.osgi.framework.hooks.service, \
+ org.osgi.framework.launch, \
org.osgi.service.condpermadmin; version=1.0.0, \
org.osgi.service.packageadmin; version=1.2.0, \
org.osgi.service.permissionadmin; version=1.2.0, \
org.osgi.service.startlevel; version=1.1.0, \
org.osgi.service.url; version=1.0.0
-osgi-compendium-services= \
- org.osgi.service.log; version=1.3, \
- org.osgi.service.http; version=1.2, \
- org.osgi.service.device; version=1.1, \
- org.osgi.service.cm; version=1.2, \
- org.osgi.service.metatype; version=1.1, \
- org.osgi.service.prefs; version=1.1, \
- org.osgi.service.useradmin; version=1.1, \
- org.osgi.service.wireadmin; version=1.0, \
- org.osgi.service.io; version=1.0, \
- org.osgi.service.provisioning; version=1.1, \
- org.osgi.service.upnp; version=1.1, \
- org.osgi.service.component; version=1.0, \
- org.osgi.service.event; version=1.1, \
- org.osgi.service.deploymentadmin; version=1.0, \
- org.osgi.service.deploymentadmin.spi; version=1.0, \
- org.osgi.service.application; version=1.0, \
- info.dmtree; version=1.0, \
- info.dmtree.notification; version=1.0, \
- info.dmtree.notification.spi; version=1.0, \
- info.dmtree.registry; version=1.0, \
- info.dmtree.security; version=1.0, \
- info.dmtree.spi; version=1.0, \
- org.osgi.service.monitor; version=1.0, \
- org.osgi.application; version=1.0, \
- org.osgi.util.tracker; version=1.3.2, \
- org.osgi.util.xml; version=1.0, \
- org.osgi.util.position; version=1.0, \
- org.osgi.util.measurement; version=1.0
-
+sling.osgi-compendium-services= \
+ org.osgi.service.application;version="1.0", \
+ org.osgi.service.cm;version="1.2", \
+ org.osgi.service.component;version="1.0", \
+ org.osgi.service.deploymentadmin;version="1.0", \
+
org.osgi.service.deploymentadmin.spi;uses:="org.osgi.service.deploymentadmin";version="1.0",
\
+ org.osgi.service.device;version="1.1", \
+ org.osgi.service.event;version="1.1", \
+ org.osgi.service.http;version="1.2", \
+ org.osgi.service.io;version="1.0", \
+ org.osgi.service.log;version="1.3", \
+ org.osgi.service.metatype;version="1.1", \
+ org.osgi.service.monitor;version="1.0", \
+ org.osgi.service.prefs;version="1.1", \
+ org.osgi.service.provisioning;version="1.1", \
+ org.osgi.service.upnp;version="1.1", \
+ org.osgi.service.useradmin;version="1.1", \
+ org.osgi.service.wireadmin;version="1.0", \
+ info.dmtree.notification;version="1.0", \
+ info.dmtree.notification.spi;uses:="info.dmtree.notification";version="1.0", \
+ info.dmtree.registry;uses:="info.dmtree.notification";version="1.0", \
+ info.dmtree.security;version="1.0", \
+ info.dmtree.spi;version="1.0", \
+ org.osgi.util.gsm;version="1.0", \
+ org.osgi.util.measurement;version="1.0", \
+ org.osgi.util.mobile;version="1.0", \
+ org.osgi.util.position;uses:="org.osgi.util.measurement";version="1.0", \
+ org.osgi.util.tracker;version="1.3.3", \
+ org.osgi.util.xml;version="1.0"
\ No newline at end of file