You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by mn...@apache.org on 2010/08/10 14:35:13 UTC

svn commit: r983960 - in /incubator/aries/trunk/application/application-runtime-framework: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/aries/ src/main/java/org/apache/aries/application/ src/mai...

Author: mnuttall
Date: Tue Aug 10 12:35:12 2010
New Revision: 983960

URL: http://svn.apache.org/viewvc?rev=983960&view=rev
Log:
ARIES-359: Isolated application support. From a patch by Chris Wilkinson. 

Added:
    incubator/aries/trunk/application/application-runtime-framework/pom.xml
    incubator/aries/trunk/application/application-runtime-framework/src/
    incubator/aries/trunk/application/application-runtime-framework/src/main/
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkFactoryImpl.java
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java
    incubator/aries/trunk/application/application-runtime-framework/src/main/resources/
    incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/
    incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/blueprint/
    incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/blueprint/bundle-framework.xml
Modified:
    incubator/aries/trunk/application/application-runtime-framework/   (props changed)

Propchange: incubator/aries/trunk/application/application-runtime-framework/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Aug 10 12:35:12 2010
@@ -0,0 +1,4 @@
+target
+.classpath
+.project
+.settings

Added: incubator/aries/trunk/application/application-runtime-framework/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/pom.xml?rev=983960&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/pom.xml (added)
+++ incubator/aries/trunk/application/application-runtime-framework/pom.xml Tue Aug 10 12:35:12 2010
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <parent>
+        <artifactId>application</artifactId>
+        <groupId>org.apache.aries.application</groupId>
+        <version>0.2-incubating-SNAPSHOT</version>
+    </parent>
+    
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>org.apache.aries.application.runtime.framework</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Aries Bundle Framework provider</name>
+    <description>
+        An equinox based bundle framework runtime implementation
+    </description>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.utils</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.testsupport</groupId>
+            <artifactId>org.apache.aries.testsupport.unit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <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>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+        	<groupId>org.eclipse</groupId>
+        	<artifactId>osgi</artifactId>
+        	<version>3.5.0.v20090520</version>
+        	<type>jar</type>
+        	<scope>provided</scope>
+        </dependency>
+    </dependencies>
+  
+</project>

Added: incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkFactoryImpl.java?rev=983960&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkFactoryImpl.java (added)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkFactoryImpl.java Tue Aug 10 12:35:12 2010
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.aries.application.runtime.framework;
+
+import java.util.Properties;
+
+import org.apache.aries.application.management.BundleFramework;
+import org.apache.aries.application.management.BundleFrameworkFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.framework.CompositeBundle;
+import org.osgi.service.framework.CompositeBundleFactory;
+
+public class BundleFrameworkFactoryImpl implements BundleFrameworkFactory
+{  
+  public BundleFramework createBundleFramework(BundleContext bc, String frameworkId,
+      Properties frameworkConfig, Properties frameworkManifest) throws BundleException
+  {
+    BundleFramework framework = null;
+    ServiceReference sr = bc.getServiceReference(CompositeBundleFactory.class.getName());
+
+    if (sr != null) {
+      CompositeBundleFactory cbf = (CompositeBundleFactory) bc.getService(sr);
+
+      CompositeBundle compositeBundle = cbf.installCompositeBundle(
+          frameworkConfig, 
+          frameworkId,
+          frameworkManifest);
+
+      framework = new BundleFrameworkImpl(compositeBundle);
+    } else throw new BundleException("Failed to obtain framework factory service");
+
+    return framework;
+  }
+}

Added: incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java?rev=983960&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java (added)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java Tue Aug 10 12:35:12 2010
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIESOR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.application.runtime.framework;
+
+import static org.apache.aries.application.utils.AppConstants.LOG_ENTRY;
+import static org.apache.aries.application.utils.AppConstants.LOG_EXCEPTION;
+import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.BundleFramework;
+import org.apache.aries.application.management.BundleRepository.BundleSuggestion;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.launch.Framework;
+import org.osgi.service.framework.CompositeBundle;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BundleFrameworkImpl implements BundleFramework
+{
+  private static final Logger LOGGER = LoggerFactory.getLogger(BundleFrameworkImpl.class);
+
+  List<Bundle> _bundles;
+  CompositeBundle _compositeBundle;
+
+  ServiceTracker _packageAdminTracker;
+
+  BundleFrameworkImpl(CompositeBundle cb)
+  {
+    _compositeBundle = cb;
+    _bundles = new ArrayList<Bundle>();
+  }
+
+  public void init() throws BundleException
+  {
+    if (_compositeBundle.getCompositeFramework().getState() != Framework.ACTIVE)
+    {
+      _compositeBundle.start(Bundle.START_ACTIVATION_POLICY);
+  
+      _packageAdminTracker = new ServiceTracker(_compositeBundle.getBundleContext(),
+          PackageAdmin.class.getName(), null);
+      _packageAdminTracker.open();
+    }
+  }
+
+  public void close() throws BundleException
+  {
+    /**
+     * TODO: Remove this work-around code 
+     * 
+     * Workaround for IllegalArgumentException during PackagePermission check
+     * See https://bugs.eclipse.org/bugs/show_bug.cgi?id=298894
+     */
+    BundleContext ctx = _compositeBundle.getBundleContext();
+    ServiceReference ref = ctx.getServiceReference(PackageAdmin.class.getName());
+    if (ref != null) {
+      try {
+        PackageAdmin pa = (PackageAdmin) ctx.getService(ref);
+        pa.refreshPackages(null);
+      } finally {
+        ctx.ungetService(ref);
+      }
+    }
+
+    // close out packageadmin service tracker
+    if (_packageAdminTracker != null) {
+      try {
+        _packageAdminTracker.close();
+      } catch (IllegalStateException ise) {
+        // Ignore this error because this can happen when we're trying to close the tracker on a
+        // framework that has closed/is closing.
+      }
+    }
+
+    _compositeBundle.stop();
+  }
+
+  public void start(Bundle b) throws BundleException
+  {
+    if (b.getState() != Bundle.ACTIVE && !isFragment(b)) 
+      b.start(Bundle.START_ACTIVATION_POLICY);
+  }
+
+  public void stop(Bundle b) throws BundleException
+  {
+    b.stop();
+  }
+
+  public Bundle getFrameworkBundle()
+  {
+    return _compositeBundle;
+  }
+
+  public BundleContext getIsolatedBundleContext()
+  {
+    return _compositeBundle.getCompositeFramework().getBundleContext();
+  }
+
+  public List<Bundle> getBundles()
+  {
+    return _bundles;
+  }
+
+  /**
+   * This method uses the PackageAdmin service to identify if a bundle
+   * is a fragment.
+   * @param b
+   * @return
+   */
+  private boolean isFragment(Bundle b)
+  {
+    LOGGER.debug(LOG_ENTRY, "isFragment", new Object[] { b });
+
+    PackageAdmin admin = null;
+    boolean isFragment = false;
+
+    try {
+      if (_packageAdminTracker != null) {
+        admin = (PackageAdmin) _packageAdminTracker.getService();
+        if (admin != null) {
+          isFragment = (admin.getBundleType(b) == PackageAdmin.BUNDLE_TYPE_FRAGMENT);
+        }
+      }
+    } catch (RuntimeException re) {
+      LOGGER.debug(LOG_EXCEPTION, re);
+    }
+
+    LOGGER.debug(LOG_EXIT, "isFragment", new Object[] { Boolean.valueOf(isFragment) });
+
+    return isFragment;
+  }
+
+  public Bundle install(BundleSuggestion suggestion, AriesApplication app) throws BundleException
+  {
+    Bundle installedBundle = suggestion.install(getIsolatedBundleContext(), app);
+    _bundles.add(installedBundle);
+    
+    return installedBundle;
+  }
+
+  public void uninstall(Bundle b) throws BundleException
+  {
+    b.uninstall();
+    _bundles.remove(b);
+  }
+}

Added: incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/blueprint/bundle-framework.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/blueprint/bundle-framework.xml?rev=983960&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/blueprint/bundle-framework.xml (added)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/blueprint/bundle-framework.xml Tue Aug 10 12:35:12 2010
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+  
+  <bean id="bundle-framework-factory" class="org.apache.aries.application.runtime.framework.BundleFrameworkFactoryImpl" />
+
+  <service interface="org.apache.aries.application.management.BundleFrameworkFactory"
+            ref="bundle-framework-factory"
+            ranking="-1"/>
+            
+</blueprint>