[jboss-osgi-commits] JBoss-OSGI SVN: r95922 - in projects/jboss-osgi/projects: spi/trunk/src/main/java/org/jboss/osgi/spi/framework and 1 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Mon Nov 2 10:49:39 EST 2009
Author: thomas.diesler at jboss.com
Date: 2009-11-02 10:49:38 -0500 (Mon, 02 Nov 2009)
New Revision: 95922
Removed:
projects/jboss-osgi/projects/bundles/husky/trunk/testsuite/src/test/resources/META-INF/
Modified:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrap.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/ServiceLoader.java
Log:
Support better bootstrap defaults
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrap.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrap.java 2009-11-02 15:12:47 UTC (rev 95921)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrap.java 2009-11-02 15:49:38 UTC (rev 95922)
@@ -160,6 +160,9 @@
*/
public static OSGiBootstrapProvider getBootstrapProvider()
{
+ if (log == null)
+ log = LoggerFactory.getLogger(OSGiBootstrap.class);
+
OSGiBootstrapProvider provider = null;
List<OSGiBootstrapProvider> providers = ServiceLoader.loadServices(OSGiBootstrapProvider.class);
@@ -173,13 +176,15 @@
}
catch (Exception ex)
{
- Logger tmplog = LoggerFactory.getLogger(OSGiBootstrap.class);
- tmplog.debug("Cannot configure [" + aux.getClass().getName() + "]", ex);
+ log.debug("Cannot configure [" + aux.getClass().getName() + "]", ex);
}
}
if (provider == null)
- throw new IllegalStateException("Cannot obtain bootstrap provider");
+ {
+ provider = new PropertiesBootstrapProvider();
+ log.debug("Using default: " + PropertiesBootstrapProvider.class.getName());
+ }
return provider;
}
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java 2009-11-02 15:12:47 UTC (rev 95921)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java 2009-11-02 15:49:38 UTC (rev 95922)
@@ -37,7 +37,6 @@
import java.util.Properties;
import java.util.Set;
-import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.internal.StringPropertyReplacer;
import org.jboss.osgi.spi.util.ExportedPackageHelper;
import org.jboss.osgi.spi.util.ServiceLoader;
@@ -57,6 +56,7 @@
* <ul>
* <li><b>org.jboss.osgi.spi.framework.autoInstall</b> - Bundles that need to be installed with the Framework automatically</li>
* <li><b>org.jboss.osgi.spi.framework.autoStart</b> - Bundles that need to be started automatically</li>
+ * <li><b>org.jboss.osgi.spi.framework.extra</b> - An URL to extra properties, which recursivly may conatin this property.</li>
* </ul>
*
* All other properties are passed on to configure the framework.
@@ -114,14 +114,57 @@
public void configure()
{
- configure(System.getProperty(OSGI_FRAMEWORK_CONFIG, DEFAULT_OSGI_FRAMEWORK_PROPERTIES));
+ configureInternal(System.getProperty(OSGI_FRAMEWORK_CONFIG, DEFAULT_OSGI_FRAMEWORK_PROPERTIES));
}
+ public void configure(String resourceConfig)
+ {
+ if (resourceConfig == null)
+ throw new IllegalArgumentException("Null resouce name");
+
+ URL urlConfig = Thread.currentThread().getContextClassLoader().getResource(resourceConfig);
+ if (urlConfig == null)
+ throw new IllegalStateException("Cannot find resource: " + resourceConfig);
+
+ configure(urlConfig);
+ }
+
public void configure(URL urlConfig)
{
- // Read the configuration properties
- final Map<String, Object> props = getBootstrapProperties(urlConfig);
+ if (urlConfig == null)
+ throw new IllegalArgumentException("Null config url");
+
+ Map<String, Object> props = getBootstrapProperties(urlConfig);
+ initFrameworkInstance(props);
+ }
+ public void configure(InputStream streamConfig)
+ {
+ Map<String, Object> props = getBootstrapProperties(streamConfig);
+ initFrameworkInstance(props);
+ }
+
+ private void configureInternal(String resourceConfig)
+ {
+ if (resourceConfig == null)
+ throw new IllegalArgumentException("Null resouce name");
+
+ Map<String, Object> props;
+ URL urlConfig = Thread.currentThread().getContextClassLoader().getResource(resourceConfig);
+ if (urlConfig != null)
+ {
+ props = getBootstrapProperties(urlConfig);
+ }
+ else
+ {
+ props = new HashMap<String, Object>();
+ log.debug("Bootstrap using framework defaults");
+ }
+ initFrameworkInstance(props);
+ }
+
+ private void initFrameworkInstance(final Map<String, Object> props)
+ {
// Load the framework instance
final Framework frameworkImpl = createFramework(props);
framework = new FrameworkWrapper(frameworkImpl)
@@ -156,7 +199,7 @@
// Register system services
registerSystemServices(context);
-
+
// Install autoInstall bundles
for (URL bundleURL : autoInstall)
{
@@ -184,11 +227,11 @@
{
// Unregister system services
unregisterSystemServices(getBundleContext());
-
+
super.stop();
}
};
-
+
configured = true;
}
@@ -199,7 +242,7 @@
Framework framework = factory.newFramework(properties);
return framework;
}
-
+
/**
* Overwrite to register system services before bundles get installed.
*/
@@ -207,7 +250,7 @@
{
// no default system services
}
-
+
/**
* Overwrite to unregister system services before bundles get installed.
*/
@@ -215,7 +258,7 @@
{
// no default system services
}
-
+
private List<URL> getBundleURLs(Map<String, Object> props, String key)
{
String bundleList = (String)props.get(key);
@@ -248,107 +291,107 @@
}
}
- public void configure(String resourceConfig)
- {
- URL urlConfig = Thread.currentThread().getContextClassLoader().getResource(resourceConfig);
- if (urlConfig == null)
- throw new IllegalStateException("Cannot find resource: " + resourceConfig);
-
- configure(urlConfig);
- }
-
- public void configure(InputStream streamConfig)
- {
- throw new NotImplementedException();
- }
-
public Framework getFramework()
{
if (configured == false)
- {
- String defaultFrameworkProps = System.getProperty(OSGI_FRAMEWORK_CONFIG, DEFAULT_OSGI_FRAMEWORK_PROPERTIES);
- configure(defaultFrameworkProps);
- }
+ configureInternal(System.getProperty(OSGI_FRAMEWORK_CONFIG, DEFAULT_OSGI_FRAMEWORK_PROPERTIES));
+
return framework;
}
- @SuppressWarnings("unchecked")
private Map<String, Object> getBootstrapProperties(URL urlConfig)
{
- Properties props = new Properties();
+ Map<String, Object> props = null;
try
{
- InputStream inStream = urlConfig.openStream();
- props.load(inStream);
- inStream.close();
+ InputStream propStream = urlConfig.openStream();
+ props = getBootstrapProperties(propStream);
+ propStream.close();
}
catch (IOException ex)
{
- throw new IllegalStateException("Cannot load properties from: " + urlConfig, ex);
+ throw new IllegalStateException("Cannot configure from: " + urlConfig, ex);
}
+ return props;
+ }
+ @SuppressWarnings("unchecked")
+ private Map<String, Object> getBootstrapProperties(InputStream propStream)
+ {
+ if (propStream == null)
+ throw new IllegalArgumentException("Null properties stream");
+
Map<String, Object> propMap = new HashMap<String, Object>();
-
- // Process property list
- Enumeration<String> keys = (Enumeration<String>)props.propertyNames();
- while (keys.hasMoreElements())
+ try
{
- String key = keys.nextElement();
- String value = props.getProperty(key);
+ Properties props = new Properties();
+ props.load(propStream);
+ propStream.close();
- // Replace property variables
- value = StringPropertyReplacer.replaceProperties(value);
- propMap.put(key, value);
+ // Process property list
+ Enumeration<String> keys = (Enumeration<String>)props.propertyNames();
+ while (keys.hasMoreElements())
+ {
+ String key = keys.nextElement();
+ String value = props.getProperty(key);
- if (key.endsWith(".instance"))
- {
- try
+ // Replace property variables
+ value = StringPropertyReplacer.replaceProperties(value);
+ propMap.put(key, value);
+
+ if (key.endsWith(".instance"))
{
- String subkey = key.substring(0, key.lastIndexOf(".instance"));
- Object instance = Class.forName(value).newInstance();
- propMap.put(subkey, instance);
+ try
+ {
+ String subkey = key.substring(0, key.lastIndexOf(".instance"));
+ Object instance = Class.forName(value).newInstance();
+ propMap.put(subkey, instance);
+ }
+ catch (Exception ex)
+ {
+ log.error("Cannot load " + key + "=" + value, ex);
+ }
}
- catch (Exception ex)
- {
- log.error("Cannot load " + key + "=" + value, ex);
- }
}
- }
- // Merge optional extra properties
- String extraPropsValue = (String)propMap.get(PROP_OSGI_FRAMEWORK_EXTRA);
- if (extraPropsValue != null)
- {
- URL extraPropsURL = null;
- try
+ // Merge optional extra properties
+ String extraPropsValue = (String)propMap.get(PROP_OSGI_FRAMEWORK_EXTRA);
+ if (extraPropsValue != null)
{
- extraPropsURL = new URL(extraPropsValue);
- }
- catch (MalformedURLException e)
- {
- // ignore;
- }
- if (extraPropsURL == null)
- {
- File propsFile = new File(extraPropsValue);
+ URL extraPropsURL = null;
try
{
- extraPropsURL = propsFile.toURL();
+ extraPropsURL = new URL(extraPropsValue);
}
catch (MalformedURLException e)
{
// ignore;
}
- }
+ if (extraPropsURL == null)
+ {
+ File propsFile = new File(extraPropsValue);
+ try
+ {
+ extraPropsURL = propsFile.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore;
+ }
+ }
- if (extraPropsURL == null)
- throw new IllegalStateException("Invalid properties URL: " + extraPropsValue);
+ if (extraPropsURL == null)
+ throw new IllegalStateException("Invalid properties URL: " + extraPropsValue);
- propMap.remove(PROP_OSGI_FRAMEWORK_EXTRA);
- Map<String, Object> extraProps = getBootstrapProperties(extraPropsURL);
- propMap.putAll(extraProps);
+ propMap.remove(PROP_OSGI_FRAMEWORK_EXTRA);
+ Map<String, Object> extraProps = getBootstrapProperties(extraPropsURL.openStream());
+ propMap.putAll(extraProps);
+ }
}
-
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot load properties", ex);
+ }
return propMap;
}
}
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/ServiceLoader.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/ServiceLoader.java 2009-11-02 15:12:47 UTC (rev 95921)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/ServiceLoader.java 2009-11-02 15:49:38 UTC (rev 95922)
@@ -94,9 +94,6 @@
}
}
- if (services.size() == 0)
- throw new IllegalStateException("Failed to load services from: META-INF/services/" + serviceClass.getName());
-
return services;
}
More information about the jboss-osgi-commits
mailing list