[jboss-osgi-commits] JBoss-OSGI SVN: r91713 - in projects/jboss-osgi/projects/runtime/felix/trunk: src/main/java/org/jboss/osgi/felix and 1 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Tue Jul 28 11:07:40 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-07-28 11:07:38 -0400 (Tue, 28 Jul 2009)
New Revision: 91713

Added:
   projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixFrameworkFactory.java
   projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java
   projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixLogger.java
   projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/FrameworkLaunchTestCase.java
Removed:
   projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/framework/
Modified:
   projects/jboss-osgi/projects/runtime/felix/trunk/pom.xml
   projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/SystemBundleTestCase.java
Log:
Add FrameworkLaunch test

Modified: projects/jboss-osgi/projects/runtime/felix/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/felix/trunk/pom.xml	2009-07-28 15:01:15 UTC (rev 91712)
+++ projects/jboss-osgi/projects/runtime/felix/trunk/pom.xml	2009-07-28 15:07:38 UTC (rev 91713)
@@ -20,7 +20,7 @@
   <artifactId>jboss-osgi-runtime-felix</artifactId>
   <packaging>jar</packaging>
 
-  <version>1.0.0</version>
+  <version>1.0.1-SNAPSHOT</version>
 
   <!-- Parent -->
   <parent>
@@ -30,10 +30,9 @@
   </parent>
 
   <properties>
-    <version.apache.felix.core>1.2.0</version.apache.felix.core>
-    <version.felix.framework>1.8.1</version.felix.framework>
+    <version.felix.framework>1.9.0-SNAPSHOT</version.felix.framework>
     <version.jboss.microcontainer>2.0.5.GA</version.jboss.microcontainer>
-    <version.jboss.osgi.spi>1.0.0</version.jboss.osgi.spi>
+    <version.jboss.osgi.spi>1.0.1-SNAPSHOT</version.jboss.osgi.spi>
   </properties>
 
   <!-- Dependencies -->
@@ -48,11 +47,6 @@
       <artifactId>org.apache.felix.framework</artifactId>
       <version>${version.felix.framework}</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.felix</groupId>
-      <artifactId>org.osgi.compendium</artifactId>
-      <version>${version.apache.felix.core}</version>
-    </dependency>
 
     <!-- Test Dependencies -->
     <dependency>

Added: projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixFrameworkFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixFrameworkFactory.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixFrameworkFactory.java	2009-07-28 15:07:38 UTC (rev 91713)
@@ -0,0 +1,45 @@
+/*
+ * 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.felix;
+
+//$Id$
+
+import java.util.Map;
+
+import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
+/**
+ * The Felix {@link FrameworkFactory}
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-Jul-2009
+ */
+public class FelixFrameworkFactory implements FrameworkFactory
+{
+   @Override
+   public Framework newFramework(Map configuration)
+   {
+      return null;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixFrameworkFactory.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java (from rev 91584, projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixIntegration.java	2009-07-28 15:07:38 UTC (rev 91713)
@@ -0,0 +1,251 @@
+/*
+ * 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.felix;
+
+//$Id$
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.framework.Felix;
+import org.jboss.logging.Logger;
+import org.jboss.osgi.spi.FrameworkException;
+import org.jboss.osgi.spi.framework.OSGiFramework;
+import org.jboss.osgi.spi.logging.ExportedPackageHelper;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+/**
+ * An abstraction of an OSGi Framework
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public class FelixIntegration implements OSGiFramework
+{
+   // Provide logging
+   final Logger log = Logger.getLogger(FelixIntegration.class);
+
+   private Map<String, Object> properties = new HashMap<String, Object>();
+   private List<URL> autoInstall = new ArrayList<URL>();
+   private List<URL> autoStart = new ArrayList<URL>();
+
+   private Felix framework;
+
+   public Map<String, Object> getProperties()
+   {
+      return properties;
+   }
+
+   public void setProperties(Map<String, Object> props)
+   {
+      this.properties = props;
+   }
+
+   public List<URL> getAutoInstall()
+   {
+      return autoInstall;
+   }
+
+   public void setAutoInstall(List<URL> autoInstall)
+   {
+      this.autoInstall = autoInstall;
+   }
+
+   public List<URL> getAutoStart()
+   {
+      return autoStart;
+   }
+
+   public void setAutoStart(List<URL> autoStart)
+   {
+      this.autoStart = autoStart;
+   }
+
+   public Bundle getBundle()
+   {
+      assertFrameworkStart();
+      return framework;
+   }
+
+   public BundleContext getBundleContext()
+   {
+      return getBundle().getBundleContext();
+   }
+
+   public void create()
+   {
+      String implVersion = getClass().getPackage().getImplementationVersion();
+      log.info("OSGi Integration Felix - " + implVersion);
+
+      // When a Felix instance is embedded in a host application,
+      // the host application must inform the Felix instance that it is embedded
+      properties.put("felix.embedded.execution", "true");
+
+      // An instance of Logger that the framework uses as its default logger
+      properties.put("felix.log.logger", new FelixLogger());
+
+      // Init the System Bundle
+      framework = new Felix(properties);
+   }
+
+   public void start()
+   {
+      // Create the Felix instance
+      assertFrameworkCreate();
+      
+      // Start the System Bundle
+      try
+      {
+         framework.start();
+      }
+      catch (BundleException ex)
+      {
+         throw new FrameworkException("Cannot start system bundle", ex);
+      }
+      
+      // Get system bundle context
+      BundleContext context = framework.getBundleContext();
+      if (context == null)
+         throw new FrameworkException("Cannot obtain system context");
+
+      // Log the the framework packages
+      ExportedPackageHelper packageHelper = new ExportedPackageHelper(context);
+      packageHelper.logExportedPackages(getBundle());
+      
+      Map<URL, Bundle> autoBundles = new HashMap<URL, Bundle>();
+
+      // Add the autoStart bundles to autoInstall
+      for (URL bundleURL : autoStart)
+      {
+         autoInstall.add(bundleURL);
+      }
+
+      // Install autoInstall bundles
+      for (URL bundleURL : autoInstall)
+      {
+         try
+         {
+            Bundle bundle = context.installBundle(bundleURL.toString());
+            long bundleId = bundle.getBundleId();
+            log.info("Installed bundle [" + bundleId + "]: " + bundle.getSymbolicName());
+            autoBundles.put(bundleURL, bundle);
+         }
+         catch (BundleException ex)
+         {
+            stop();
+            throw new IllegalStateException("Cannot install bundle: " + bundleURL, ex);
+         }
+      }
+
+      // Start autoStart bundles
+      for (URL bundleURL : autoStart)
+      {
+         try
+         {
+            Bundle bundle = autoBundles.get(bundleURL);
+            if (bundle != null)
+            {
+               bundle.start();
+               packageHelper.logExportedPackages(bundle);
+               log.info("Started bundle: " + bundle.getSymbolicName());
+            }
+         }
+         catch (BundleException ex)
+         {
+            stop();
+            throw new IllegalStateException("Cannot start bundle: " + bundleURL, ex);
+         }
+      }
+   }
+
+   public void stop()
+   {
+      if (framework != null)
+      {
+         // Running the Felix shutdown in a separate thread that gets 
+         // interrupted after a 10sec timeout. This is a workaround for
+         //
+         // [FELIX-1311] Felix shutdown may lead to dead lock
+         // https://issues.apache.org/jira/browse/FELIX-1311
+         Runnable runnable = new Runnable()
+         {
+            public void run()
+            {
+               try
+               {
+                  framework.stop();
+                  framework.waitForStop(5000);
+                  framework = null;
+                  log.debug("SystemBundle STOPPED");
+               }
+               catch (BundleException ex)
+               {
+                  log.error("Cannot stop Felix", ex);
+               }
+               catch (InterruptedException ex)
+               {
+                  log.error("Cannot stop Felix", ex);
+               }
+            }
+         };
+         
+         Thread thread = new Thread(runnable);
+         thread.start();
+
+         int sleep = 500;
+         int timeout = 10000;
+         while (framework != null && timeout > 0)
+         {
+            try
+            {
+               Thread.sleep(sleep);
+               timeout -= sleep;
+            }
+            catch (InterruptedException ex)
+            {
+               // ignore
+            }
+         }
+         
+         if (timeout == 0 && thread.isAlive())
+            thread.interrupt();
+      }
+   }
+
+   private void assertFrameworkCreate()
+   {
+      if (framework == null)
+         create();
+   }
+
+   private void assertFrameworkStart()
+   {
+      assertFrameworkCreate();
+      if ((framework.getState() & Bundle.ACTIVE) == 0)
+         start();
+   }
+}
\ No newline at end of file

Copied: projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixLogger.java (from rev 91584, projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/framework/FelixLogger.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixLogger.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/felix/trunk/src/main/java/org/jboss/osgi/felix/FelixLogger.java	2009-07-28 15:07:38 UTC (rev 91713)
@@ -0,0 +1,84 @@
+/*
+ * 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.felix;
+
+//$Id: FelixIntegration.java 84730 2009-02-25 12:57:23Z thomas.diesler at jboss.com $
+
+import org.apache.felix.moduleloader.ResourceNotFoundException;
+import org.jboss.logging.Logger;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * An integration with the Felix Logger.
+ * 
+ * This Logger gets registered with the Felix framework and 
+ * delegates framework log messages to the JBoss logger.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public class FelixLogger extends org.apache.felix.framework.Logger
+{
+   // Provide logging
+   final Logger log = Logger.getLogger(FelixLogger.class);
+
+   public FelixLogger()
+   {
+      setLogLevel(LOG_DEBUG);
+   }
+
+   @Override
+   protected void doLog(ServiceReference sref, int level, String msg, Throwable throwable)
+   {
+      if (sref != null)
+         msg = sref + ": " + msg;
+
+      // An unresolved bundle causes a WARNING that comes with an exception
+      // Currently we log WARNING exceptions at DEBUG level      
+      
+      if (level == LOG_DEBUG)
+      {
+         // [FELIX-1124] ResourceNotFoundException too verbose
+         // https://issues.apache.org/jira/browse/FELIX-1124
+         if (throwable instanceof ResourceNotFoundException)
+         {  
+            msg = "ResourceNotFoundException: " + msg;
+            throwable = null;
+         }
+         log.debug(msg, throwable);
+      }
+      else if (level == LOG_INFO)
+      {
+         log.info(msg, throwable);
+      }
+      else if (level == LOG_WARNING)
+      {
+         log.warn(msg);
+         if (throwable != null)
+            log.debug(msg, throwable);
+      }
+      else if (level == LOG_ERROR)
+      {
+         log.error(msg, throwable);
+      }
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/FrameworkLaunchTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/FrameworkLaunchTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/FrameworkLaunchTestCase.java	2009-07-28 15:07:38 UTC (rev 91713)
@@ -0,0 +1,48 @@
+/*
+ * 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.felix;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.osgi.spi.framework.FrameworkLoader;
+import org.junit.Test;
+import org.osgi.framework.launch.Framework;
+
+/**
+ * Test OSGi System bundle access
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 27-Jul-2009
+ */
+public class FrameworkLaunchTestCase 
+{
+   @Test
+   public void testFrameworkLaunch()
+   {
+      Framework framework = FrameworkLoader.newFramework(null);
+      
+      assertEquals("BundleId == 0", 0, framework.getBundleId());
+      assertEquals("SymbolicName", "org.apache.felix.framework", framework.getSymbolicName());
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/FrameworkLaunchTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/SystemBundleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/SystemBundleTestCase.java	2009-07-28 15:01:15 UTC (rev 91712)
+++ projects/jboss-osgi/projects/runtime/felix/trunk/src/test/java/org/jboss/test/osgi/felix/SystemBundleTestCase.java	2009-07-28 15:07:38 UTC (rev 91713)
@@ -25,7 +25,7 @@
 
 import static org.junit.Assert.assertEquals;
 
-import org.jboss.osgi.felix.framework.FelixIntegration;
+import org.jboss.osgi.felix.FelixIntegration;
 import org.jboss.osgi.spi.framework.OSGiBootstrap;
 import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
 import org.jboss.osgi.spi.framework.OSGiFramework;



More information about the jboss-osgi-commits mailing list