[jboss-osgi-commits] JBoss-OSGI SVN: r90923 - projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Wed Jul 8 02:59:36 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-07-08 02:59:34 -0400 (Wed, 08 Jul 2009)
New Revision: 90923
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
Log:
[JBOSGI-98] Support configuration per profile
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-07-08 06:58:59 UTC (rev 90922)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/OSGiBootstrap.java 2009-07-08 06:59:34 UTC (rev 90923)
@@ -27,10 +27,13 @@
import static org.jboss.osgi.spi.Constants.OSGI_SERVER_HOME;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLClassLoader;
import java.util.Enumeration;
import java.util.Properties;
@@ -96,7 +99,7 @@
public void run()
{
- initSystemProperties();
+ initBootstrap();
OSGiBootstrapProvider bootProvider = getBootstrapProvider();
OSGiFramework framework = bootProvider.getFramework();
@@ -108,7 +111,7 @@
thread.start();
}
- private void initSystemProperties()
+ private void initBootstrap()
{
osgiHome = System.getProperty(OSGI_HOME);
if (osgiHome == null)
@@ -116,14 +119,27 @@
osgiServerHome = osgiHome + "/server/" + serverName;
+ // Replace the context class loader with one that contains the server conf dir
+ File serverConfDir = new File(osgiServerHome + "/conf");
+ if (serverConfDir.exists())
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ URLClassLoader confLoader = new URLClassLoader(new URL[] { toURL(serverConfDir) }, ctxLoader);
+ Thread.currentThread().setContextClassLoader(confLoader);
+ }
+
+ // This property must be set before the logger is obtained
+ System.setProperty(OSGI_SERVER_HOME, osgiServerHome);
+ log = Logger.getLogger(OSGiBootstrap.class);
+
Properties defaults = new Properties();
defaults.setProperty(OSGI_SERVER_NAME, serverName);
defaults.setProperty(OSGI_SERVER_HOME, osgiServerHome);
defaults.setProperty(JBOSS_BIND_ADDRESS, bindAdress);
defaults.setProperty(JAVA_PROTOCOL_HANDLERS, "org.jboss.net.protocol|org.jboss.virtual.protocol");
- getLogger().debug("JBoss OSGi System Properties");
- getLogger().debug(" " + OSGI_SERVER_HOME + "=" + osgiServerHome);
+ log.debug("JBoss OSGi System Properties");
+ log.debug(" " + OSGI_SERVER_HOME + "=" + osgiServerHome);
Enumeration<?> defaultNames = defaults.propertyNames();
while (defaultNames.hasMoreElements())
@@ -134,21 +150,11 @@
{
String propValue = defaults.getProperty(propName);
System.setProperty(propName, propValue);
- getLogger().debug(" " + propName + "=" + propValue);
+ log.debug(" " + propName + "=" + propValue);
}
}
}
- private Logger getLogger()
- {
- if (log == null)
- {
- System.setProperty(OSGI_SERVER_HOME, osgiServerHome);
- log = Logger.getLogger(OSGiBootstrap.class);
- }
- return log;
- }
-
/*
* * Get an instance of an OSGiBootstrapProvider.
*/
@@ -196,6 +202,18 @@
return provider;
}
+ private URL toURL(File file)
+ {
+ try
+ {
+ return file.toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalArgumentException("Invalid file: " + file);
+ }
+ }
+
class StartupThread extends Thread
{
private OSGiFramework framework;
@@ -231,7 +249,7 @@
if (lastChange > afterStart)
{
float diff = (lastChange - beforeStart) / 1000f;
- getLogger().info("JBossOSGi Runtime started in " + diff + "sec");
+ log.info("JBossOSGi Runtime started in " + diff + "sec");
}
service.removeScanListener(this);
}
@@ -240,7 +258,7 @@
}
float diff = (afterStart - beforeStart) / 1000f;
- getLogger().info("JBossOSGi Runtime booted in " + diff + "sec");
+ log.info("JBossOSGi Runtime booted in " + diff + "sec");
Reader br = new InputStreamReader(System.in);
try
@@ -269,9 +287,9 @@
public void run()
{
- getLogger().info("Initiating shutdown ...");
+ log.info("Initiating shutdown ...");
framework.stop();
- getLogger().info("Shutdown complete");
+ log.info("Shutdown complete");
}
}
}
\ No newline at end of file
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-07-08 06:58:59 UTC (rev 90922)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java 2009-07-08 06:59:34 UTC (rev 90923)
@@ -23,6 +23,7 @@
//$Id$
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
@@ -75,59 +76,62 @@
* file://${test.archive.directory}/bundles/jboss-osgi-jmx.jar \
* file://${test.archive.directory}/bundles/jboss-osgi-microcontainer.jar
* </pre>
- *
+ *
* @author thomas.diesler at jboss.com
* @since 24-Apr-2009
*/
-public class PropertiesBootstrapProvider implements OSGiBootstrapProvider
+public class PropertiesBootstrapProvider implements OSGiBootstrapProvider
{
/** The default framework property: jboss.osgi.framework.properties */
public static final String OSGI_FRAMEWORK_CONFIG = "jboss.osgi.framework.properties";
/** The default framework config: jboss-osgi-framework.properties */
public static final String DEFAULT_OSGI_FRAMEWORK_PROPERTIES = "jboss-osgi-framework.properties";
-
+
/** The OSGi framework integration class: org.jboss.osgi.spi.framework.impl */
public static final String PROP_OSGI_FRAMEWORK_IMPL = "org.jboss.osgi.spi.framework.impl";
- /** The OSGi framework integration class: org.jboss.osgi.spi.framework.autoInstall */
+ /** Optional list of bundles that get installed automatically: org.jboss.osgi.spi.framework.autoInstall */
public static final String PROP_OSGI_FRAMEWORK_AUTO_INSTALL = "org.jboss.osgi.spi.framework.autoInstall";
- /** The OSGi framework integration class: org.jboss.osgi.spi.framework.autoStart */
+ /** Optional list of bundles that get started automatically: org.jboss.osgi.spi.framework.autoStart */
public static final String PROP_OSGI_FRAMEWORK_AUTO_START = "org.jboss.osgi.spi.framework.autoStart";
-
+ /** Optional path to extra properties: org.jboss.osgi.spi.framework.extra */
+ public static final String PROP_OSGI_FRAMEWORK_EXTRA = "org.jboss.osgi.spi.framework.extra";
+
private static Set<String> internalProps = new HashSet<String>();
static
{
internalProps.add(PROP_OSGI_FRAMEWORK_IMPL);
internalProps.add(PROP_OSGI_FRAMEWORK_AUTO_INSTALL);
internalProps.add(PROP_OSGI_FRAMEWORK_AUTO_START);
+ internalProps.add(PROP_OSGI_FRAMEWORK_EXTRA);
}
-
+
private OSGiFramework framework;
private boolean configured;
-
+
public void configure()
{
- throw new NotImplementedException();
+ configure(DEFAULT_OSGI_FRAMEWORK_PROPERTIES);
}
public void configure(URL urlConfig)
{
// Read the configuration properties
Properties props = getBootstrapProperties(urlConfig);
-
+
// Load the framework instance
framework = loadFrameworkImpl(urlConfig, props);
-
+
// Process Framework props
initFrameworkProperties(props);
// Init the the autoInstall URLs
List<URL> installURLs = getBundleURLs(props, PROP_OSGI_FRAMEWORK_AUTO_INSTALL);
framework.setAutoInstall(installURLs);
-
+
// Init the the autoStart URLs
List<URL> startURLs = getBundleURLs(props, PROP_OSGI_FRAMEWORK_AUTO_START);
framework.setAutoStart(startURLs);
-
+
configured = true;
}
@@ -136,7 +140,7 @@
String bundleList = props.getProperty(key);
if (bundleList == null)
bundleList = "";
-
+
List<URL> bundleURLs = new ArrayList<URL>();
for (String bundle : bundleList.split("[, ]"))
{
@@ -159,7 +163,7 @@
}
catch (MalformedURLException ex)
{
- throw new IllegalStateException("Invalid path: " + path, ex);
+ throw new IllegalStateException("Invalid path: " + path, ex);
}
}
@@ -204,9 +208,9 @@
private void initFrameworkProperties(Properties props)
{
- Map<String,Object> frameworkProps = new HashMap<String,Object>();
+ Map<String, Object> frameworkProps = new HashMap<String, Object>();
Enumeration<?> keys = props.propertyNames();
- while(keys.hasMoreElements())
+ while (keys.hasMoreElements())
{
String key = (String)keys.nextElement();
if (internalProps.contains(key) == false)
@@ -223,7 +227,7 @@
String frameworkImpl = props.getProperty(PROP_OSGI_FRAMEWORK_IMPL);
if (frameworkImpl == null)
throw new IllegalStateException("Cannot get : " + urlConfig);
-
+
OSGiFramework framework;
try
{
@@ -250,7 +254,7 @@
}
catch (IOException ex)
{
- throw new IllegalStateException("Cannot load properties from: " + urlConfig, ex);
+ throw new IllegalStateException("Cannot load properties from: " + urlConfig, ex);
}
// Replace system properties
@@ -261,6 +265,42 @@
String value = props.getProperty(key);
props.setProperty(key, StringPropertyReplacer.replaceProperties(value));
}
+
+ // Merge optional extra properties
+ String extraPropsValue = props.getProperty(PROP_OSGI_FRAMEWORK_EXTRA);
+ if (extraPropsValue != null)
+ {
+ URL extraPropsURL = null;
+ try
+ {
+ 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);
+
+ props.remove(PROP_OSGI_FRAMEWORK_EXTRA);
+ Properties extraProps = getBootstrapProperties(extraPropsURL);
+ props.putAll(extraProps);
+ }
+
return props;
}
+
}
More information about the jboss-osgi-commits
mailing list