[jboss-cvs] JBossAS SVN: r87857 - in projects/jboss-osgi/trunk: bundle/blueprint/scripts and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 27 07:33:23 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-04-27 07:33:22 -0400 (Mon, 27 Apr 2009)
New Revision: 87857
Added:
projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/
projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/MicrocontainerTestCase.java
projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java
Removed:
projects/jboss-osgi/trunk/bundle/blueprint/src/main/java/org/jboss/osgi/blueprint/PropertiesBootstrapProvider.java
projects/jboss-osgi/trunk/bundle/microcontainer/src/test/
Modified:
projects/jboss-osgi/trunk/bundle/blueprint/pom.xml
projects/jboss-osgi/trunk/bundle/blueprint/scripts/assembly-bundles.xml
projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jboss-osgi-framework.properties
projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/org.jboss.osgi.spi.framework.OSGiBootstrapProvider
projects/jboss-osgi/trunk/bundle/microcontainer/pom.xml
Log:
mc bundles installs, but does nothing
Modified: projects/jboss-osgi/trunk/bundle/blueprint/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/pom.xml 2009-04-27 11:24:05 UTC (rev 87856)
+++ projects/jboss-osgi/trunk/bundle/blueprint/pom.xml 2009-04-27 11:33:22 UTC (rev 87857)
@@ -47,6 +47,12 @@
</dependency>
<dependency>
<groupId>org.jboss.osgi</groupId>
+ <artifactId>jboss-osgi-microcontainer</artifactId>
+ <version>${version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.osgi</groupId>
<artifactId>jboss-osgi-jmx</artifactId>
<version>${version}</version>
<scope>provided</scope>
Modified: projects/jboss-osgi/trunk/bundle/blueprint/scripts/assembly-bundles.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/scripts/assembly-bundles.xml 2009-04-27 11:24:05 UTC (rev 87856)
+++ projects/jboss-osgi/trunk/bundle/blueprint/scripts/assembly-bundles.xml 2009-04-27 11:33:22 UTC (rev 87857)
@@ -19,6 +19,7 @@
<include>*:org.osgi.compendium:jar</include>
<include>*:jboss-osgi-common:jar</include>
<include>*:jboss-osgi-logging:jar</include>
+ <include>*:jboss-osgi-microcontainer:jar</include>
<include>*:jboss-osgi-jmx:jar</include>
</includes>
<useStrictFiltering>true</useStrictFiltering>
Deleted: projects/jboss-osgi/trunk/bundle/blueprint/src/main/java/org/jboss/osgi/blueprint/PropertiesBootstrapProvider.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/main/java/org/jboss/osgi/blueprint/PropertiesBootstrapProvider.java 2009-04-27 11:24:05 UTC (rev 87856)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/main/java/org/jboss/osgi/blueprint/PropertiesBootstrapProvider.java 2009-04-27 11:33:22 UTC (rev 87857)
@@ -1,214 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.blueprint;
-
-//$Id$
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.jboss.osgi.spi.NotImplementedException;
-import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.jboss.osgi.spi.framework.OSGiFramework;
-import org.jboss.util.StringPropertyReplacer;
-
-/**
- * A simple properties based bootstrap provider
- *
- * @author thomas.diesler at jboss.com
- * @since 24-Apr-2009
- */
-public class PropertiesBootstrapProvider implements OSGiBootstrapProvider
-{
- /** The OSGi framework integration class: osgi.framework.impl */
- public static final String PROP_OSGI_FRAMEWORK_IMPL = "framework.impl";
-
- /** The default framework beans property: jboss.osgi.bootstrap.config */
- public static final String OSGI_BOOTSTRAP_CONFIG = "jboss.osgi.bootstrap.config";
- /** The default framework beans: jboss-osgi-bootstrap-beans.xml */
- public static final String DEFAULT_OSGI_BOOTSTRAP_PROPERTIES = "jboss-osgi-bootstrap.properties";
- /** The default framework beans property: jboss.osgi.framework.config */
- public static final String OSGI_FRAMEWORK_CONFIG = "jboss.osgi.framework.config";
- /** The default framework beans: jboss-osgi-beans.xml */
- public static final String DEFAULT_OSGI_FRAMEWORK_PROPERTIES = "jboss-osgi-framework.properties";
-
- private OSGiFramework framework;
- private boolean configured;
-
- public void configure()
- {
- throw new NotImplementedException();
- }
-
- 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, "framework.autoInstall");
- framework.setAutoInstall(installURLs);
-
- // Init the the autoStart URLs
- List<URL> startURLs = getBundleURLs(props, "framework.autoStart");
- framework.setAutoStart(startURLs);
- }
-
- private List<URL> getBundleURLs(Properties props, String key)
- {
- String bundleList = props.getProperty(key);
- if (bundleList == null)
- bundleList = "";
-
- List<URL> bundleURLs = new ArrayList<URL>();
- for (String bundle : bundleList.split("[, ]"))
- {
- if (bundle.trim().length() > 0)
- {
- URL installURL = toURL(bundle);
- bundleURLs.add(installURL);
- }
- }
- return bundleURLs;
- }
-
- private URL toURL(String path)
- {
- String realPath = StringPropertyReplacer.replaceProperties(path);
- try
- {
- URL pathURL = new URL(realPath);
- return pathURL;
- }
- catch (MalformedURLException ex)
- {
- throw new IllegalStateException("Invalid path: " + path, ex);
- }
- }
-
- 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 OSGiFramework getFramework()
- {
- if (configured == false)
- {
- String defaultFrameworkProps = System.getProperty(OSGI_FRAMEWORK_CONFIG, DEFAULT_OSGI_FRAMEWORK_PROPERTIES);
- configure(defaultFrameworkProps);
- }
- return framework;
- }
-
- public OSGiFramework getFramework(String name)
- {
- throw new NotImplementedException();
- }
-
- public Object getInstance(String name)
- {
- throw new NotImplementedException();
- }
-
- public <T> T getInstance(String name, Class<T> expectedType)
- {
- throw new NotImplementedException();
- }
-
- private void initFrameworkProperties(Properties props)
- {
- String prefix = "framework.prop.";
- Map<String,Object> frameworkProps = new HashMap<String,Object>();
- Enumeration<?> keys = props.propertyNames();
- while(keys.hasMoreElements())
- {
- String key = (String)keys.nextElement();
- if (key.startsWith(prefix))
- {
- String value = props.getProperty(key);
- key = key.substring(prefix.length());
- frameworkProps.put(key, value);
- }
- }
- framework.setProperties(frameworkProps);
- }
-
- private OSGiFramework loadFrameworkImpl(URL urlConfig, Properties props)
- {
- String frameworkImpl = props.getProperty(PROP_OSGI_FRAMEWORK_IMPL);
- if (frameworkImpl == null)
- throw new IllegalStateException("Cannot get : " + urlConfig);
-
- OSGiFramework framework;
- try
- {
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- Class<?> frameworkClass = ctxLoader.loadClass(frameworkImpl);
- framework = (OSGiFramework)frameworkClass.newInstance();
- }
- catch (Exception ex)
- {
- throw new IllegalStateException("Cannot load framework: " + frameworkImpl, ex);
- }
- return framework;
- }
-
- private Properties getBootstrapProperties(URL urlConfig)
- {
- Properties props = new Properties();
- try
- {
- InputStream inStream = urlConfig.openStream();
- props.load(inStream);
- inStream.close();
- }
- catch (IOException ex)
- {
- throw new IllegalStateException("Cannot load properties from: " + urlConfig, ex);
- }
- return props;
- }
-}
Added: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/MicrocontainerTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/MicrocontainerTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/MicrocontainerTestCase.java 2009-04-27 11:33:22 UTC (rev 87857)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.blueprint.microcontainer;
+
+//$Id$
+
+import org.jboss.osgi.spi.framework.OSGiFramework;
+import org.jboss.test.osgi.blueprint.BlueprintTest;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * A test that deployes the jboss-osgi-microcontainer bundle
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 12-Feb-2009
+ */
+public class MicrocontainerTestCase extends BlueprintTest
+{
+ public void testMBeanAccess() throws Exception
+ {
+ OSGiFramework framework = getBootstrapProvider().getFramework();
+
+ try
+ {
+ BundleContext sysContext = framework.getSystemBundleContext();
+
+ Bundle bundle = installBundle(sysContext, "bundles/jboss-osgi-microcontainer.jar", true);
+ assertEquals("Microcontainer bundle ACTIVE", Bundle.ACTIVE, bundle.getState());
+ }
+ finally
+ {
+ framework.stop();
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/bundle/blueprint/src/test/java/org/jboss/test/osgi/blueprint/microcontainer/MicrocontainerTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jboss-osgi-framework.properties
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jboss-osgi-framework.properties 2009-04-27 11:24:05 UTC (rev 87856)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/jboss-osgi-framework.properties 2009-04-27 11:33:22 UTC (rev 87857)
@@ -1,6 +1,6 @@
#
-# Properties read by the org.jboss.osgi.blueprint.PropertiesBootstrapProvider
-#
+# Properties read by the org.jboss.osgi.spi.framework.PropertiesBootstrapProvider
+#
# $Id: $
#
@@ -10,16 +10,23 @@
# Properties to configure the Framework
# All props start with 'framework.prop'
framework.prop.org.osgi.framework.storage.clean=onFirstInit
-framework.prop.org.osgi.framework.system.packages=org.jboss.logging, \
+framework.prop.org.osgi.framework.system.packages=\
+ javax.management, \
+ javax.xml.namespace, \
+ javax.xml.parsers, \
+ org.jboss.logging, \
org.osgi.framework; version=1.4, \
- javax.management
+ org.w3c.dom*, \
+ org.xml.sax*
# Bundles that need to be installed with the Framework automatically
-framework.autoInstall=file://${test.archive.directory}/bundles/org.osgi.compendium.jar
+framework.autoInstall=\
+ file://${test.archive.directory}/bundles/org.osgi.compendium.jar
# Bundles that need to be started automatically
-framework.autoStart=file://${test.archive.directory}/bundles/jboss-osgi-common.jar \
+framework.autoStart=\
file://${test.archive.directory}/bundles/org.apache.felix.log.jar \
file://${test.archive.directory}/bundles/jboss-osgi-logging.jar \
- file://${test.archive.directory}/bundles/jboss-osgi-jmx.jar
+ file://${test.archive.directory}/bundles/jboss-osgi-common.jar \
+ file://${test.archive.directory}/bundles/jboss-osgi-jmx.jar
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/org.jboss.osgi.spi.framework.OSGiBootstrapProvider
===================================================================
--- projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/org.jboss.osgi.spi.framework.OSGiBootstrapProvider 2009-04-27 11:24:05 UTC (rev 87856)
+++ projects/jboss-osgi/trunk/bundle/blueprint/src/test/resources/org.jboss.osgi.spi.framework.OSGiBootstrapProvider 2009-04-27 11:33:22 UTC (rev 87857)
@@ -1 +1 @@
-org.jboss.osgi.blueprint.PropertiesBootstrapProvider
\ No newline at end of file
+org.jboss.osgi.spi.framework.PropertiesBootstrapProvider
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/bundle/microcontainer/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/microcontainer/pom.xml 2009-04-27 11:24:05 UTC (rev 87856)
+++ projects/jboss-osgi/trunk/bundle/microcontainer/pom.xml 2009-04-27 11:33:22 UTC (rev 87857)
@@ -18,16 +18,11 @@
<!-- Dependencies -->
<dependencies>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <scope>provided</scope>
+ <groupId>org.jboss.osgi</groupId>
+ <artifactId>jboss-osgi-spi</artifactId>
+ <version>${version}</version>
</dependency>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.jboss.deployers</groupId>
<artifactId>jboss-deployers-client-spi</artifactId>
</dependency>
@@ -39,6 +34,18 @@
<groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-kernel</artifactId>
</dependency>
+
+ <!-- Provided Dependencies -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
@@ -50,43 +57,54 @@
<configuration>
<instructions>
<Bundle-SymbolicName>jboss-osgi-microcontainer</Bundle-SymbolicName>
- <Bundle-Activator>jboss-osgi-microcontainer.internal.ServiceActivator</Bundle-Activator>
+ <Bundle-Activator>org.jboss.osgi.microcontainer.internal.ServiceActivator</Bundle-Activator>
<Export-Package>
org.jboss.osgi.microcontainer;version=${version.jboss.microcontainer}
</Export-Package>
<Private-Package>
+ org.jboss.osgi.microcontainer.internal
</Private-Package>
<Import-Package>
- jboss-osgi-microcontainer.internal,
-
- javassist*,
- javax.naming,
- javax.xml.bind.*,
- org.jboss.annotation.*,
- org.jboss.beans.*,
- org.jboss.classadapter.spi,
- org.jboss.classloader.*,
- org.jboss.classloading.*,
- org.jboss.config.*,
- org.jboss.dependency.*,
- org.jboss.deployers.*,
- org.jboss.joinpoint.*,
+ com.wutka.dtd*;resolution:=optional,
+ com.sun.jdi*;resolution:=optional,
+ javassist*;resolution:=optional,
+ javax.activation;resolution:=optional,
+ javax.naming;resolution:=optional,
+ javax.xml.*;resolution:=optional,
+ org.apache.xerces*,
+ org.apache.xml.resolver*;resolution:=optional,
+ org.jboss.annotation.*;resolution:=optional,
+ org.jboss.beans.*;resolution:=optional,
+ org.jboss.classadapter.spi;resolution:=optional,
+ org.jboss.classloader.*;resolution:=optional,
+ org.jboss.classloading.*;resolution:=optional,
+ org.jboss.config.*;resolution:=optional,
+ org.jboss.dependency.*;resolution:=optional,
+ org.jboss.deployers.*;resolution:=optional,
+ org.jboss.joinpoint.*;resolution:=optional,
org.jboss.logging,
- org.jboss.managed.*,
- org.jboss.metadata.*,
- org.jboss.metatype.*,
- org.jboss.reflect.*,
- org.jboss.test,
- org.jboss.util*,
- org.jboss.virtual*,
+ org.jboss.managed.*;resolution:=optional,
+ org.jboss.metadata.*;resolution:=optional,
+ org.jboss.metatype.*;resolution:=optional,
+ org.jboss.reflect.*;resolution:=optional,
+ org.jboss.test;resolution:=optional,
+ org.jboss.util*;resolution:=optional,
+ org.jboss.virtual*;resolution:=optional,
org.jboss.xb.*,
- org.xml.sax
+ org.osgi.framework;version=1.4,
+ org.w3c.dom*,
+ org.xml.sax*,
+ sun.io;resolution:=optional
</Import-Package>
+ <Embed-Transitive>true</Embed-Transitive>
<Embed-Dependency>
- javassist,
jboss-deployers-client-spi,
jboss-deployers-vfs,
jboss-kernel,
+ jboss-vfs,
+ jbossxb,
+ xml-apis,
+ xercesImpl,
</Embed-Dependency>
</instructions>
</configuration>
Copied: projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java (from rev 87853, projects/jboss-osgi/trunk/bundle/blueprint/src/main/java/org/jboss/osgi/blueprint/PropertiesBootstrapProvider.java)
===================================================================
--- projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java (rev 0)
+++ projects/jboss-osgi/trunk/spi/src/main/java/org/jboss/osgi/spi/framework/PropertiesBootstrapProvider.java 2009-04-27 11:33:22 UTC (rev 87857)
@@ -0,0 +1,246 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.framework;
+
+//$Id$
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jboss.osgi.spi.NotImplementedException;
+import org.jboss.util.StringPropertyReplacer;
+
+/**
+ * A simple properties based bootstrap provider
+ *
+ * The PropertiesBootstrapProvider supports the following properties
+ *
+ * <ul>
+ * <li><b>framework.impl</b> - The OSGiFramework implementation</li>
+ * <li><b>framework.prop.*</b> - Properties to configure the Framework</li>
+ * <li><b>framework.autoInstall</b> - Bundles that need to be installed with the Framework automatically</li>
+ * <li><b>framework.autoStart</b> - Bundles that need to be started automatically</li>
+ * </ul>
+ *
+ * <pre>
+ * # The OSGiFramework implementation
+ * framework.impl=org.jboss.osgi.felix.framework.FelixIntegration
+ *
+ * # Properties to configure the Framework
+ * # All props start with 'framework.prop'
+ * framework.prop.org.osgi.framework.storage.clean=onFirstInit
+ * framework.prop.org.osgi.framework.system.packages=\
+ * org.jboss.logging, \
+ * org.osgi.framework; version=1.4, \
+ * javax.management
+ *
+ * # Bundles that need to be installed with the Framework automatically
+ * framework.autoInstall=\
+ * file://${test.archive.directory}/bundles/org.osgi.compendium.jar
+ *
+ * # Bundles that need to be started automatically
+ * framework.autoStart=\
+ * file://${test.archive.directory}/bundles/org.apache.felix.log.jar \
+ * file://${test.archive.directory}/bundles/jboss-osgi-logging.jar \
+ * file://${test.archive.directory}/bundles/jboss-osgi-common.jar \
+ * 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
+{
+ /** The OSGi framework integration class: osgi.framework.impl */
+ public static final String PROP_OSGI_FRAMEWORK_IMPL = "framework.impl";
+
+ /** The default framework beans property: jboss.osgi.bootstrap.config */
+ public static final String OSGI_BOOTSTRAP_CONFIG = "jboss.osgi.bootstrap.config";
+ /** The default framework beans: jboss-osgi-bootstrap-beans.xml */
+ public static final String DEFAULT_OSGI_BOOTSTRAP_PROPERTIES = "jboss-osgi-bootstrap.properties";
+ /** The default framework beans property: jboss.osgi.framework.config */
+ public static final String OSGI_FRAMEWORK_CONFIG = "jboss.osgi.framework.config";
+ /** The default framework beans: jboss-osgi-beans.xml */
+ public static final String DEFAULT_OSGI_FRAMEWORK_PROPERTIES = "jboss-osgi-framework.properties";
+
+ private OSGiFramework framework;
+ private boolean configured;
+
+ public void configure()
+ {
+ throw new NotImplementedException();
+ }
+
+ 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, "framework.autoInstall");
+ framework.setAutoInstall(installURLs);
+
+ // Init the the autoStart URLs
+ List<URL> startURLs = getBundleURLs(props, "framework.autoStart");
+ framework.setAutoStart(startURLs);
+ }
+
+ private List<URL> getBundleURLs(Properties props, String key)
+ {
+ String bundleList = props.getProperty(key);
+ if (bundleList == null)
+ bundleList = "";
+
+ List<URL> bundleURLs = new ArrayList<URL>();
+ for (String bundle : bundleList.split("[, ]"))
+ {
+ if (bundle.trim().length() > 0)
+ {
+ URL installURL = toURL(bundle);
+ bundleURLs.add(installURL);
+ }
+ }
+ return bundleURLs;
+ }
+
+ private URL toURL(String path)
+ {
+ String realPath = StringPropertyReplacer.replaceProperties(path);
+ try
+ {
+ URL pathURL = new URL(realPath);
+ return pathURL;
+ }
+ catch (MalformedURLException ex)
+ {
+ throw new IllegalStateException("Invalid path: " + path, ex);
+ }
+ }
+
+ 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 OSGiFramework getFramework()
+ {
+ if (configured == false)
+ {
+ String defaultFrameworkProps = System.getProperty(OSGI_FRAMEWORK_CONFIG, DEFAULT_OSGI_FRAMEWORK_PROPERTIES);
+ configure(defaultFrameworkProps);
+ }
+ return framework;
+ }
+
+ public OSGiFramework getFramework(String name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Object getInstance(String name)
+ {
+ throw new NotImplementedException();
+ }
+
+ public <T> T getInstance(String name, Class<T> expectedType)
+ {
+ throw new NotImplementedException();
+ }
+
+ private void initFrameworkProperties(Properties props)
+ {
+ String prefix = "framework.prop.";
+ Map<String,Object> frameworkProps = new HashMap<String,Object>();
+ Enumeration<?> keys = props.propertyNames();
+ while(keys.hasMoreElements())
+ {
+ String key = (String)keys.nextElement();
+ if (key.startsWith(prefix))
+ {
+ String value = props.getProperty(key);
+ key = key.substring(prefix.length());
+ frameworkProps.put(key, value);
+ }
+ }
+ framework.setProperties(frameworkProps);
+ }
+
+ private OSGiFramework loadFrameworkImpl(URL urlConfig, Properties props)
+ {
+ String frameworkImpl = props.getProperty(PROP_OSGI_FRAMEWORK_IMPL);
+ if (frameworkImpl == null)
+ throw new IllegalStateException("Cannot get : " + urlConfig);
+
+ OSGiFramework framework;
+ try
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ Class<?> frameworkClass = ctxLoader.loadClass(frameworkImpl);
+ framework = (OSGiFramework)frameworkClass.newInstance();
+ }
+ catch (Exception ex)
+ {
+ throw new IllegalStateException("Cannot load framework: " + frameworkImpl, ex);
+ }
+ return framework;
+ }
+
+ private Properties getBootstrapProperties(URL urlConfig)
+ {
+ Properties props = new Properties();
+ try
+ {
+ InputStream inStream = urlConfig.openStream();
+ props.load(inStream);
+ inStream.close();
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot load properties from: " + urlConfig, ex);
+ }
+ return props;
+ }
+}
More information about the jboss-cvs-commits
mailing list