You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cw...@apache.org on 2010/11/15 16:14:30 UTC
svn commit: r1035299 - in /incubator/aries/trunk/application:
application-api/src/main/java/org/apache/aries/application/management/spi/framework/
application-runtime-framework-management/
application-runtime-framework-management/src/main/java/org/apac...
Author: cwilkin
Date: Mon Nov 15 15:14:28 2010
New Revision: 1035299
URL: http://svn.apache.org/viewvc?rev=1035299&view=rev
Log:
ARIES-493 : Refactor completed. Also added synchronization on a common object plus general clean up
Added:
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfiguration.java
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfigurationFactory.java
incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/
incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationFactoryImpl.java
incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationImpl.java
incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/
incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkConstants.java
incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkUtils.java
Removed:
incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/FrameworkConstants.java
incubator/aries/trunk/application/application-utils/src/main/java/org/apache/aries/application/utils/runtime/InstallUtils.java
Modified:
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java
incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java
incubator/aries/trunk/application/application-runtime-framework-management/pom.xml
incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java
incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/SharedBundleFramework.java
incubator/aries/trunk/application/application-runtime-framework-management/src/main/resources/OSGI-INF/blueprint/bundle-framework-management.xml
incubator/aries/trunk/application/application-runtime-framework/pom.xml
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/resources/OSGI-INF/blueprint/bundle-framework.xml
incubator/aries/trunk/application/application-runtime-isolated/pom.xml
incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java
incubator/aries/trunk/application/application-runtime-repository/pom.xml
Added: incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfiguration.java?rev=1035299&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfiguration.java (added)
+++ incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfiguration.java Mon Nov 15 15:14:28 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.management.spi.framework;
+
+import java.util.Properties;
+
+public interface BundleFrameworkConfiguration {
+
+ public String getFrameworkID();
+
+ public Properties getFrameworkProperties();
+
+ public Properties getFrameworkManifest();
+}
Added: incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfigurationFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfigurationFactory.java?rev=1035299&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfigurationFactory.java (added)
+++ incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkConfigurationFactory.java Mon Nov 15 15:14:28 2010
@@ -0,0 +1,45 @@
+/*
+ * 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.management.spi.framework;
+
+import org.apache.aries.application.management.AriesApplication;
+import org.osgi.framework.BundleContext;
+
+public interface BundleFrameworkConfigurationFactory
+{
+ /**
+ * Create a BundleFrameworkConfiguration with basic config
+ * @param parentCtx
+ * @return
+ */
+ public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId,
+ BundleContext parentCtx);
+
+ /**
+ * Create a BundleFrameworkConiguration for an application framework based
+ * on a given AriesApplication.
+ * @param parentCtx
+ * @param app
+ * @return
+ */
+ public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId,
+ BundleContext parentCtx, AriesApplication app);
+
+}
Modified: incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java (original)
+++ incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkFactory.java Mon Nov 15 15:14:28 2010
@@ -19,7 +19,6 @@
package org.apache.aries.application.management.spi.framework;
-import java.util.Properties;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -28,14 +27,10 @@ public interface BundleFrameworkFactory
/**
* Creates a new isolated bundle framework with the properties provided.
* @param bc The context in which to install the new framework
- * @param frameworkId The id of the new framework
- * @param frameworkConfig The config properties used to configure the new framework
- * @param frameworkManifest The manifest used to install the new bundle associated with the framework
+ * @param config The BundleFrameworkConfiguration object used to configure the returned framework
* @return
* @throws BundleException
*/
- public BundleFramework createBundleFramework(BundleContext bc,
- String frameworkId,
- Properties frameworkConfig,
- Properties frameworkManifest) throws BundleException;
+ public BundleFramework createBundleFramework(BundleContext bc, BundleFrameworkConfiguration config)
+ throws BundleException;
}
Modified: incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java (original)
+++ incubator/aries/trunk/application/application-api/src/main/java/org/apache/aries/application/management/spi/framework/BundleFrameworkManager.java Mon Nov 15 15:14:28 2010
@@ -29,12 +29,18 @@ import org.apache.aries.application.Depl
import org.apache.aries.application.DeploymentMetadata;
import org.apache.aries.application.management.AriesApplication;
import org.apache.aries.application.management.UpdateException;
-import org.apache.aries.application.management.spi.repository.ContextException;
import org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion;
public interface BundleFrameworkManager
{
/**
+ * All additions/removals of frameworks and bundles from the shared bundle framework are
+ * performed under this object lock. Users bypassing this api and performing operations on
+ * the underlying OSGi frameworks should be sure to hold this lock.
+ */
+ Object SHARED_FRAMEWORK_LOCK = new Object();
+
+ /**
* Gets the BundleFramework object associated with the given bundle
* @param frameworkBundle - The bundle representing the bundle framework
* @return
Modified: incubator/aries/trunk/application/application-runtime-framework-management/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework-management/pom.xml?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework-management/pom.xml (original)
+++ incubator/aries/trunk/application/application-runtime-framework-management/pom.xml Mon Nov 15 15:14:28 2010
@@ -32,6 +32,14 @@
A bundle framework manager implementation
</description>
+ <properties>
+ <aries.osgi.export.pkg>
+ </aries.osgi.export.pkg>
+ <aries.osgi.private.pkg>
+ org.apache.aries.application.runtime.framework.management
+ </aries.osgi.private.pkg>
+ </properties>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
Modified: incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java (original)
+++ incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java Mon Nov 15 15:14:28 2010
@@ -38,12 +38,14 @@ import org.apache.aries.application.Depl
import org.apache.aries.application.management.AriesApplication;
import org.apache.aries.application.management.UpdateException;
import org.apache.aries.application.management.spi.framework.BundleFramework;
+import org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration;
+import org.apache.aries.application.management.spi.framework.BundleFrameworkConfigurationFactory;
import org.apache.aries.application.management.spi.framework.BundleFrameworkFactory;
import org.apache.aries.application.management.spi.framework.BundleFrameworkManager;
import org.apache.aries.application.management.spi.repository.ContextException;
import org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion;
import org.apache.aries.application.management.spi.update.UpdateStrategy;
-import org.apache.aries.application.utils.runtime.InstallUtils;
+import org.apache.aries.application.runtime.framework.utils.EquinoxFrameworkUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -59,11 +61,12 @@ public class BundleFrameworkManagerImpl
BundleContext _ctx;
BundleFramework _sharedBundleFramework;
BundleFrameworkFactory _bundleFrameworkFactory;
+ BundleFrameworkConfigurationFactory _bundleFrameworkConfigurationFactory;
Map<Bundle, BundleFramework> _frameworks = new HashMap<Bundle, BundleFramework>();
Map<AriesApplication, BundleFramework> _frameworksByApp = new HashMap<AriesApplication, BundleFramework>();
private List<UpdateStrategy> _updateStrategies = Collections.emptyList();
- public void setUpdateStrategies(List<UpdateStrategy> updateStrategies)
+ public void setUpdateStrategies(List<UpdateStrategy> updateStrategies)
{
_updateStrategies = updateStrategies;
}
@@ -78,33 +81,52 @@ public class BundleFrameworkManagerImpl
_bundleFrameworkFactory = bff;
}
+ public void setBundleFrameworkConfigurationFactory(BundleFrameworkConfigurationFactory bfcf)
+ {
+ _bundleFrameworkConfigurationFactory = bfcf;
+ }
+
public void init()
{
- try {
- _sharedBundleFramework = SharedBundleFramework.getSharedBundleFramework(_ctx,
- _bundleFrameworkFactory);
- _frameworks.put(_sharedBundleFramework.getFrameworkBundle(), _sharedBundleFramework);
- } catch (ContextException e) {
- LOGGER.error(LOG_EXCEPTION, e);
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ try {
+ _sharedBundleFramework = SharedBundleFramework.getSharedBundleFramework(_ctx,
+ _bundleFrameworkConfigurationFactory,
+ _bundleFrameworkFactory);
+ _frameworks.put(_sharedBundleFramework.getFrameworkBundle(), _sharedBundleFramework);
+ } catch (ContextException e) {
+ LOGGER.error(LOG_EXCEPTION, e);
+ }
}
}
public BundleFramework getBundleFramework(Bundle frameworkBundle)
{
- return _frameworks.get(frameworkBundle);
+ BundleFramework framework = null;
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ framework = _frameworks.get(frameworkBundle);
+ }
+ return framework;
}
public Bundle installIsolatedBundles(Collection<BundleSuggestion> bundlesToInstall,
AriesApplication app) throws BundleException
{
- // We need to create a new isolated framework for this content and install
- // the bundles to it
- BundleFramework isolatedFramework = isolatedInstall(bundlesToInstall, app);
+ Bundle frameworkBundle = null;
- _frameworks.put(isolatedFramework.getFrameworkBundle(), isolatedFramework);
- _frameworksByApp.put(app, isolatedFramework);
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ // We need to create a new isolated framework for this content and install
+ // the bundles to it
+ BundleFramework isolatedFramework = isolatedInstall(bundlesToInstall, _sharedBundleFramework
+ .getIsolatedBundleContext(), app);
- return isolatedFramework.getFrameworkBundle();
+ _frameworks.put(isolatedFramework.getFrameworkBundle(), isolatedFramework);
+ _frameworksByApp.put(app, isolatedFramework);
+
+ frameworkBundle = isolatedFramework.getFrameworkBundle();
+ }
+
+ return frameworkBundle;
}
public Collection<Bundle> installSharedBundles(Collection<BundleSuggestion> bundlesToInstall,
@@ -112,113 +134,49 @@ public class BundleFrameworkManagerImpl
{
Collection<Bundle> installedBundles = new ArrayList<Bundle>();
- // Shared bundle : Install to the shared bundle framework
- for (BundleSuggestion suggestion : bundlesToInstall)
- installedBundles.add(_sharedBundleFramework.install(suggestion, app));
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ // Shared bundle : Install to the shared bundle framework
+ for (BundleSuggestion suggestion : bundlesToInstall)
+ installedBundles.add(_sharedBundleFramework.install(suggestion, app));
+ }
return installedBundles;
}
- private BundleFramework isolatedInstall(
- Collection<BundleSuggestion> bundlesToBeInstalled,
- AriesApplication app)
- throws BundleException
+ private BundleFramework isolatedInstall(Collection<BundleSuggestion> bundlesToBeInstalled,
+ BundleContext parentCtx, AriesApplication app) throws BundleException
{
LOGGER.debug(LOG_ENTRY, "isolatedInstall", new Object[] { bundlesToBeInstalled, app });
- BundleFramework bundleFramework = null;
- BundleContext parentCtx = _sharedBundleFramework.getIsolatedBundleContext();
- DeploymentMetadata deploymentMF = app.getDeploymentMetadata();
-
/**
- * Set up framework config properties
+ * Build the configuration information for this application framework
*/
- Properties frameworkConfig = new Properties();
- String osgiFrameworkLocation = parentCtx.getProperty(FrameworkConstants.OSGI_FRAMEWORK);
- if (osgiFrameworkLocation != null) {
- frameworkConfig.put(FrameworkConstants.OSGI_FRAMEWORK, osgiFrameworkLocation);
-
- // let's only set javax.transaction as system extra packages because of the split package.
- // It is reasonable to do so because we always flow userTransaction service into child framework anyway.
- frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "javax.transaction;version=1.1.0");
- }
+ BundleFrameworkConfiguration config = _bundleFrameworkConfigurationFactory
+ .createBundleFrameworkConfig(app.getApplicationMetadata().getApplicationScope(), parentCtx,
+ app);
/**
- * Set up BundleManifest for the framework bundle
- */
- Properties frameworkBundleManifest = new Properties();
- frameworkBundleManifest.put(Constants.BUNDLE_SYMBOLICNAME, deploymentMF.getApplicationSymbolicName());
- frameworkBundleManifest.put(Constants.BUNDLE_VERSION, deploymentMF.getApplicationVersion().toString());
-
- /**
- * Set up Import-Package header for framework manifest
- */
- // Extract the import packages and remove anything we already have available in the current framework
- Collection<Content> imports =
- InstallUtils.calculateImports(
- deploymentMF.getImportPackage(),
- InstallUtils.getExportPackages(_sharedBundleFramework.getIsolatedBundleContext()));
-
- if (imports != null && !imports.isEmpty())
- {
- StringBuffer buffer = new StringBuffer();
- for (Content i : imports)
- buffer.append(InstallUtils.contentToString(i) + ",");
- frameworkBundleManifest.put(Constants.IMPORT_PACKAGE, buffer.substring(0, buffer.length()-1));
- }
-
- /**
- * Set up CompositeServiceFilter-Import header for framework manifest
- */
- StringBuffer serviceImportFilter =
- new StringBuffer("(" + Constants.OBJECTCLASS + "=javax.transaction.TransactionSynchronizationRegistry)");
-
- for (Filter importFilter : app.getDeploymentMetadata().getDeployedServiceImport()) {
- if (serviceImportFilter.length() > 0) {
- serviceImportFilter.append(",");
- }
- serviceImportFilter.append(importFilter.toString());
- }
-
- frameworkBundleManifest.put("CompositeServiceFilter-Import",
- serviceImportFilter.toString());
-
- /**
* Install and start the new isolated bundle framework
*/
- bundleFramework =
- _bundleFrameworkFactory.createBundleFramework(
- parentCtx,
- app.getApplicationMetadata().getApplicationScope(),
- frameworkConfig,
- frameworkBundleManifest);
+ BundleFramework bundleFramework = _bundleFrameworkFactory.createBundleFramework(parentCtx,
+ config);
// We should now have a bundleFramework
if (bundleFramework != null) {
- boolean frameworkStarted = false;
- try {
- // Start the empty framework bundle
- bundleFramework.init();
- frameworkStarted = true;
- } catch (BundleException e) {
- // This may fail if the framework bundle has exports but we will retry later
- }
-
/**
* Install the bundles into the new framework
*/
-
+
List<Bundle> installedBundles = new ArrayList<Bundle>();
BundleContext frameworkBundleContext = bundleFramework.getIsolatedBundleContext();
if (frameworkBundleContext != null) {
for (BundleSuggestion suggestion : bundlesToBeInstalled)
installedBundles.add(bundleFramework.install(suggestion, app));
}
-
+
// Finally, start the whole lot
- if (!frameworkStarted)
- bundleFramework.init();
+ bundleFramework.init();
}
LOGGER.debug(LOG_EXIT, "isolatedInstall", bundleFramework);
@@ -228,109 +186,126 @@ public class BundleFrameworkManagerImpl
public BundleFramework getSharedBundleFramework()
{
- return _sharedBundleFramework;
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ return _sharedBundleFramework;
+ }
}
public void uninstallBundle(Bundle b) throws BundleException
{
- BundleFramework framework = getBundleFramework(b);
- if (framework != null) framework.close();
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ BundleFramework framework = getBundleFramework(b);
+ if (framework != null) framework.close();
+ }
}
public void startBundle(Bundle b) throws BundleException
{
- BundleFramework framework = getBundleFramework(b);
- if (framework != null) // App Content
- {
- for (Bundle bundle : framework.getBundles())
- framework.start(bundle);
- } else // Shared bundle
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ BundleFramework framework = getBundleFramework(b);
+ if (framework != null) // App Content
+ {
+ for (Bundle bundle : framework.getBundles())
+ framework.start(bundle);
+ } else // Shared bundle
_sharedBundleFramework.start(b);
+ }
}
public void stopBundle(Bundle b) throws BundleException
{
- BundleFramework framework = getBundleFramework(b);
- if (framework != null) // App Content
- {
- for (Bundle bundle : framework.getBundles())
- framework.stop(bundle);
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ BundleFramework framework = getBundleFramework(b);
+ if (framework != null) // App Content
+ {
+ for (Bundle bundle : framework.getBundles())
+ framework.stop(bundle);
+ }
+ // Do not stop shared bundles
}
- // Do not stop shared bundles
}
- public boolean allowsUpdate(DeploymentMetadata newMetadata, DeploymentMetadata oldMetadata)
+ public boolean allowsUpdate(DeploymentMetadata newMetadata, DeploymentMetadata oldMetadata)
{
for (UpdateStrategy strategy : _updateStrategies) {
if (strategy.allowsUpdate(newMetadata, oldMetadata)) {
return true;
}
}
-
+
return false;
}
- public void updateBundles(
- final DeploymentMetadata newMetadata,
- final DeploymentMetadata oldMetadata,
- final AriesApplication app,
- final BundleLocator locator,
- final Set<Bundle> bundles,
- final boolean startBundles)
- throws UpdateException
+ public void updateBundles(final DeploymentMetadata newMetadata,
+ final DeploymentMetadata oldMetadata, final AriesApplication app,
+ final BundleLocator locator, final Set<Bundle> bundles, final boolean startBundles)
+ throws UpdateException
{
UpdateStrategy strategy = null;
-
+
for (UpdateStrategy us : _updateStrategies) {
if (us.allowsUpdate(newMetadata, oldMetadata)) {
strategy = us;
break;
}
}
-
- if (strategy == null) throw new IllegalArgumentException("No UpdateStrategy supports the supplied DeploymentMetadata changes.");
-
- final BundleFramework appFwk = _frameworksByApp.get(app);
-
- strategy.update(new UpdateStrategy.UpdateInfo() {
-
- public void register(Bundle bundle) {
- bundles.add(bundle);
- }
-
- public void unregister(Bundle bundle) {
- bundles.remove(bundle);
- }
-
- public Map<DeploymentContent, BundleSuggestion> suggestBundle(Collection<DeploymentContent> bundles) throws BundleException {
- return locator.suggestBundle(bundles);
- }
-
- public boolean startBundles() {
- return startBundles;
- }
-
- public BundleFramework getSharedFramework() {
- return _sharedBundleFramework;
- }
-
- public DeploymentMetadata getOldMetadata() {
- return oldMetadata;
- }
-
- public DeploymentMetadata getNewMetadata() {
- return newMetadata;
- }
-
- public AriesApplication getApplication() {
- return app;
- }
-
- public BundleFramework getAppFramework() {
- return appFwk;
- }
- });
+
+ if (strategy == null)
+ throw new IllegalArgumentException(
+ "No UpdateStrategy supports the supplied DeploymentMetadata changes.");
+
+ synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
+ final BundleFramework appFwk = _frameworksByApp.get(app);
+
+ strategy.update(new UpdateStrategy.UpdateInfo() {
+
+ public void register(Bundle bundle)
+ {
+ bundles.add(bundle);
+ }
+
+ public void unregister(Bundle bundle)
+ {
+ bundles.remove(bundle);
+ }
+
+ public Map<DeploymentContent, BundleSuggestion> suggestBundle(
+ Collection<DeploymentContent> bundles) throws BundleException
+ {
+ return locator.suggestBundle(bundles);
+ }
+
+ public boolean startBundles()
+ {
+ return startBundles;
+ }
+
+ public BundleFramework getSharedFramework()
+ {
+ return _sharedBundleFramework;
+ }
+
+ public DeploymentMetadata getOldMetadata()
+ {
+ return oldMetadata;
+ }
+
+ public DeploymentMetadata getNewMetadata()
+ {
+ return newMetadata;
+ }
+
+ public AriesApplication getApplication()
+ {
+ return app;
+ }
+
+ public BundleFramework getAppFramework()
+ {
+ return appFwk;
+ }
+ });
+ }
}
-
-
+
}
Modified: incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/SharedBundleFramework.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/SharedBundleFramework.java?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/SharedBundleFramework.java (original)
+++ incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/SharedBundleFramework.java Mon Nov 15 15:14:28 2010
@@ -28,6 +28,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.aries.application.management.spi.framework.BundleFramework;
+import org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration;
+import org.apache.aries.application.management.spi.framework.BundleFrameworkConfigurationFactory;
import org.apache.aries.application.management.spi.framework.BundleFrameworkFactory;
import org.apache.aries.application.management.spi.repository.ContextException;
@@ -35,62 +37,50 @@ import static org.apache.aries.applicati
import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
public class SharedBundleFramework
-{
+{
private static final Logger LOGGER = LoggerFactory.getLogger(SharedBundleFramework.class);
-
private static BundleFramework sharedFramework;
/**
- * This is not the right way to make blueprint usable by applications, but it is all
- * we have time to make work. I have locked down the version ranges so that this can
- * be fixed properly in the future. NB The org.osgi.service.blueprint
- * package is deliberately unversioned as it is not part of the osgi compendium.
+ * This is not the right way to make blueprint usable by applications, but
+ * it is all we have time to make work. I have locked down the version
+ * ranges so that this can be fixed properly in the future. NB The
+ * org.osgi.service.blueprint package is deliberately unversioned as it is
+ * not part of the osgi compendium.
*/
private static final String RUNTIME_PACKAGES = "org.osgi.service.blueprint,org.osgi.service.blueprint.container;version=\"[1.0.0,1.0.1]\",org.osgi.service.blueprint.reflect;version=\"[1.0.0,1.0.1]\",org.apache.aries.transaction.exception;version=\"[0.1,1.0.0)\"";
/**
- * create using any bundle context in EBA App framework
- * as we want to create a child framework under EBA App framework
+ * create using any bundle context in EBA App framework as we want to create
+ * a child framework under EBA App framework
+ *
* @param bc
* @throws BundleException
* @throws InvalidSyntaxException
*/
private static void createSharedBundleFramework(BundleContext bc,
+ BundleFrameworkConfigurationFactory bundleFrameworkConfigFactory,
BundleFrameworkFactory bundleFrameworkFactory) throws ContextException
{
- LOGGER.debug(LOG_ENTRY, "createSharedBundleFramework", new Object[] {bc, bundleFrameworkFactory});
+ LOGGER.debug(LOG_ENTRY, "createSharedBundleFramework", new Object[] { bc,
+ bundleFrameworkFactory });
try {
- // Set up the isolated framework
- Properties frameworkConfig = new Properties();
- frameworkConfig.put("osgi.console", "0");
-
- String osgiFrameworkLocation = bc.getProperty(FrameworkConstants.OSGI_FRAMEWORK);
- if (osgiFrameworkLocation != null) {
-
- frameworkConfig.put(FrameworkConstants.OSGI_FRAMEWORK, osgiFrameworkLocation);
- if (bc.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA) != null)
- {
- frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, bc
- .getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA));
- }
- }
-
- Properties compositeManifest = new Properties();
- compositeManifest.put(Constants.BUNDLE_SYMBOLICNAME, BundleFramework.SHARED_BUNDLE_FRAMEWORK);
-
- //Add blueprint so that it is available to applications.
- compositeManifest.put(Constants.IMPORT_PACKAGE, RUNTIME_PACKAGES);
- sharedFramework = bundleFrameworkFactory.createBundleFramework(bc, BundleFramework.SHARED_BUNDLE_FRAMEWORK,
- frameworkConfig, compositeManifest);
+ BundleFrameworkConfiguration config =
+ new SharedBundleFrameworkConfiguration(
+ bundleFrameworkConfigFactory.createBundleFrameworkConfig(
+ BundleFramework.SHARED_BUNDLE_FRAMEWORK,
+ bc));
+
+ sharedFramework = bundleFrameworkFactory.createBundleFramework(bc, config);
sharedFramework.init();
-
+
} catch (BundleException e) {
LOGGER.debug(LOG_EXIT, "createSharedBundleFramework", e);
- throw new ContextException(
- "Unable to create or start the shared framework composite bundle " + sharedFramework, e);
+ throw new ContextException("Unable to create or start the shared framework composite bundle "
+ + sharedFramework, e);
}
LOGGER.debug(LOG_EXIT, "createSharedBundleFramework");
@@ -99,23 +89,64 @@ public class SharedBundleFramework
/**
* pass in the EBA framework bundle context and get the shared bundle
* framework associated with the bundle context
- * @param bc any bundle context in EBA framework
- * @return the composite bundle associated with the shared bundle framework
+ *
+ * @param bc
+ * any bundle context in EBA framework
+ * @return the composite bundle associated with the shared bundle framework
* @throws BundleException
* @throws InvalidSyntaxException
* @throws SharedFrameworkCreationException
*/
public synchronized static BundleFramework getSharedBundleFramework(BundleContext bc,
+ BundleFrameworkConfigurationFactory bfcf,
BundleFrameworkFactory bff) throws ContextException
{
- LOGGER.debug(LOG_ENTRY, "getSharedBundleFramework", new Object[] {bc, bff});
-
+ LOGGER.debug(LOG_ENTRY, "getSharedBundleFramework", new Object[] { bc, bff });
+
if (sharedFramework == null) {
- createSharedBundleFramework(bc, bff);
+ createSharedBundleFramework(bc, bfcf, bff);
}
-
+
LOGGER.debug(LOG_EXIT, "getSharedBundleFramework", sharedFramework);
return sharedFramework;
}
+
+ /**
+ * Wrapper for the basic framework configuration
+ * @author cwilkin
+ *
+ */
+ private static class SharedBundleFrameworkConfiguration implements BundleFrameworkConfiguration
+ {
+ BundleFrameworkConfiguration basicConfig = null;
+
+ public SharedBundleFrameworkConfiguration(BundleFrameworkConfiguration basicConfig) {
+ this.basicConfig = basicConfig;
+ }
+
+ public String getFrameworkID()
+ {
+ return basicConfig.getFrameworkID();
+ }
+
+ public Properties getFrameworkManifest()
+ {
+
+ Properties compositeManifest = basicConfig.getFrameworkManifest();
+
+ compositeManifest.put(Constants.BUNDLE_SYMBOLICNAME, BundleFramework.SHARED_BUNDLE_FRAMEWORK);
+
+ // Add blueprint so that it is available to applications.
+ compositeManifest.put(Constants.IMPORT_PACKAGE, RUNTIME_PACKAGES);
+
+ return compositeManifest;
+ }
+
+ public Properties getFrameworkProperties()
+ {
+ return basicConfig.getFrameworkProperties();
+ }
+
+ }
}
Modified: incubator/aries/trunk/application/application-runtime-framework-management/src/main/resources/OSGI-INF/blueprint/bundle-framework-management.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework-management/src/main/resources/OSGI-INF/blueprint/bundle-framework-management.xml?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework-management/src/main/resources/OSGI-INF/blueprint/bundle-framework-management.xml (original)
+++ incubator/aries/trunk/application/application-runtime-framework-management/src/main/resources/OSGI-INF/blueprint/bundle-framework-management.xml Mon Nov 15 15:14:28 2010
@@ -21,6 +21,7 @@
<bean id="equinox-bundle-framework-manager" class="org.apache.aries.application.runtime.framework.management.BundleFrameworkManagerImpl" init-method="init">
<property name="bundleFrameworkFactory" ref="bundle-framework-factory"/>
+ <property name="bundleFrameworkConfigurationFactory" ref="bundle-framework-configuration-factory"/>
<property name="bundleContext" ref="blueprintBundleContext"/>
<property name="updateStrategies" ref="strategies" />
</bean>
@@ -30,6 +31,8 @@
ranking="-1"/>
<reference id="bundle-framework-factory" interface="org.apache.aries.application.management.spi.framework.BundleFrameworkFactory"/>
+
+ <reference id="bundle-framework-configuration-factory" interface="org.apache.aries.application.management.spi.framework.BundleFrameworkConfigurationFactory"/>
<reference-list id="strategies" interface="org.apache.aries.application.management.spi.update.UpdateStrategy" availability="optional" />
Modified: 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=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/pom.xml (original)
+++ incubator/aries/trunk/application/application-runtime-framework/pom.xml Mon Nov 15 15:14:28 2010
@@ -32,6 +32,16 @@
An equinox based bundle framework runtime implementation
</description>
+ <properties>
+ <aries.osgi.export.pkg>
+ org.apache.aries.application.runtime.framework.utils
+ </aries.osgi.export.pkg>
+ <aries.osgi.private.pkg>
+ org.apache.aries.application.runtime.framework;
+ org.apache.aries.application.runtime.framework.config
+ </aries.osgi.private.pkg>
+ </properties>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
Modified: 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=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkFactoryImpl.java (original)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkFactoryImpl.java Mon Nov 15 15:14:28 2010
@@ -19,9 +19,8 @@
package org.apache.aries.application.runtime.framework;
-import java.util.Properties;
-
import org.apache.aries.application.management.spi.framework.BundleFramework;
+import org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration;
import org.apache.aries.application.management.spi.framework.BundleFrameworkFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -31,8 +30,7 @@ import org.osgi.service.framework.Compos
public class BundleFrameworkFactoryImpl implements BundleFrameworkFactory
{
- public BundleFramework createBundleFramework(BundleContext bc, String frameworkId,
- Properties frameworkConfig, Properties frameworkManifest) throws BundleException
+ public BundleFramework createBundleFramework(BundleContext bc, BundleFrameworkConfiguration config) throws BundleException
{
BundleFramework framework = null;
ServiceReference sr = bc.getServiceReference(CompositeBundleFactory.class.getName());
@@ -41,9 +39,9 @@ public class BundleFrameworkFactoryImpl
CompositeBundleFactory cbf = (CompositeBundleFactory) bc.getService(sr);
CompositeBundle compositeBundle = cbf.installCompositeBundle(
- frameworkConfig,
- frameworkId,
- frameworkManifest);
+ config.getFrameworkProperties(),
+ config.getFrameworkID(),
+ config.getFrameworkManifest());
framework = new BundleFrameworkImpl(compositeBundle);
} else throw new BundleException("Failed to obtain framework factory service");
Added: incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationFactoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationFactoryImpl.java?rev=1035299&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationFactoryImpl.java (added)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationFactoryImpl.java Mon Nov 15 15:14:28 2010
@@ -0,0 +1,133 @@
+/*
+ * 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.config;
+
+import java.util.Collection;
+import java.util.Properties;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.DeploymentMetadata;
+import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration;
+import org.apache.aries.application.management.spi.framework.BundleFrameworkConfigurationFactory;
+import org.apache.aries.application.runtime.framework.utils.EquinoxFrameworkConstants;
+import org.apache.aries.application.runtime.framework.utils.EquinoxFrameworkUtils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+
+public class BundleFrameworkConfigurationFactoryImpl implements BundleFrameworkConfigurationFactory
+{
+
+ public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId,
+ BundleContext parentCtx, AriesApplication app)
+ {
+
+ BundleFrameworkConfiguration config = null;
+ DeploymentMetadata metadata = app.getDeploymentMetadata();
+ /**
+ * Set up framework config properties
+ */
+ Properties frameworkConfig = new Properties();
+
+ String flowedSystemPackages = EquinoxFrameworkUtils.calculateSystemPackagesToFlow(
+ EquinoxFrameworkUtils.getSystemExtraPkgs(parentCtx), metadata.getImportPackage());
+ frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, flowedSystemPackages);
+
+ /**
+ * Set up BundleManifest for the framework bundle
+ */
+ Properties frameworkBundleManifest = new Properties();
+ frameworkBundleManifest.put(Constants.BUNDLE_SYMBOLICNAME, metadata
+ .getApplicationSymbolicName());
+ frameworkBundleManifest.put(Constants.BUNDLE_VERSION, metadata.getApplicationVersion()
+ .toString());
+
+ /**
+ * Set up Import-Package header for framework manifest
+ */
+ // Extract the import packages and remove anything we already have available in the current framework
+ Collection<Content> imports = EquinoxFrameworkUtils.calculateImports(metadata
+ .getImportPackage(), EquinoxFrameworkUtils.getExportPackages(parentCtx));
+
+ if (imports != null && !imports.isEmpty()) {
+ StringBuffer buffer = new StringBuffer();
+ for (Content i : imports)
+ buffer.append(EquinoxFrameworkUtils.contentToString(i) + ",");
+ frameworkBundleManifest.put(Constants.IMPORT_PACKAGE, buffer
+ .substring(0, buffer.length() - 1));
+ }
+
+ /**
+ * Set up CompositeServiceFilter-Import header for framework manifest
+ */
+ StringBuffer serviceImportFilter = new StringBuffer("(" + Constants.OBJECTCLASS + "="
+ + EquinoxFrameworkConstants.TRANSACTION_REGISTRY_BUNDLE + ")");
+
+ for (Filter importFilter : metadata.getDeployedServiceImport()) {
+ if (serviceImportFilter.length() > 0) {
+ serviceImportFilter.append(",");
+ }
+ serviceImportFilter.append(importFilter.toString());
+ }
+
+ frameworkBundleManifest.put(EquinoxFrameworkConstants.COMPOSITE_SERVICE_FILTER_IMPORT,
+ serviceImportFilter.toString());
+
+ config = new BundleFrameworkConfigurationImpl(frameworkId, frameworkConfig,
+ frameworkBundleManifest);
+
+ return config;
+ }
+
+ public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId,
+ BundleContext parentCtx)
+ {
+ BundleFrameworkConfiguration config = null;
+
+ /**
+ * Set up framework config properties
+ */
+ Properties frameworkConfig = new Properties();
+
+ if (parentCtx.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA) != null)
+ frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, parentCtx
+ .getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA));
+
+ /**
+ * Set up BundleManifest for the framework bundle
+ */
+ Properties frameworkBundleManifest = new Properties();
+
+ /**
+ * Set up CompositeServiceFilter-Import header for framework manifest
+ */
+ StringBuffer serviceImportFilter = new StringBuffer("(" + Constants.OBJECTCLASS + "="
+ + EquinoxFrameworkConstants.TRANSACTION_REGISTRY_BUNDLE + ")");
+
+ frameworkBundleManifest.put(EquinoxFrameworkConstants.COMPOSITE_SERVICE_FILTER_IMPORT,
+ serviceImportFilter.toString());
+
+ config = new BundleFrameworkConfigurationImpl(frameworkId, frameworkConfig,
+ frameworkBundleManifest);
+
+ return config;
+ }
+}
Added: incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationImpl.java?rev=1035299&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationImpl.java (added)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/config/BundleFrameworkConfigurationImpl.java Mon Nov 15 15:14:28 2010
@@ -0,0 +1,56 @@
+/*
+ * 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.config;
+
+import java.util.Properties;
+
+import org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration;
+
+public class BundleFrameworkConfigurationImpl implements BundleFrameworkConfiguration
+{
+
+ String frameworkId;
+ Properties frameworkBundleManifest;
+ Properties frameworkConfig;
+
+ public BundleFrameworkConfigurationImpl(String frameworkId, Properties frameworkConfig,
+ Properties frameworkBundleManifest)
+ {
+ this.frameworkId = frameworkId;
+ this.frameworkConfig = frameworkConfig;
+ this.frameworkBundleManifest = frameworkBundleManifest;
+ }
+
+ public String getFrameworkID()
+ {
+ return frameworkId;
+ }
+
+ public Properties getFrameworkManifest()
+ {
+ return frameworkBundleManifest;
+ }
+
+ public Properties getFrameworkProperties()
+ {
+ return frameworkConfig;
+ }
+
+}
Added: incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkConstants.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkConstants.java?rev=1035299&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkConstants.java (added)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkConstants.java Mon Nov 15 15:14:28 2010
@@ -0,0 +1,29 @@
+/*
+ * 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.utils;
+
+public interface EquinoxFrameworkConstants
+{
+ public static final String TRANSACTION_BUNDLE = "javax.transaction";
+ public static final String TRANSACTION_BUNDLE_VERSION = "1.1.0";
+ public static final String TRANSACTION_REGISTRY_BUNDLE = "javax.transaction.TransactionSynchronizationRegistry";
+ public static final String COMPOSITE_SERVICE_FILTER_IMPORT = "CompositeServiceFilter-Import";
+
+}
Added: incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkUtils.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkUtils.java?rev=1035299&view=auto
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkUtils.java (added)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/utils/EquinoxFrameworkUtils.java Mon Nov 15 15:14:28 2010
@@ -0,0 +1,246 @@
+/*
+ * 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.utils;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.aries.application.Content;
+import org.apache.aries.application.VersionRange;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValueMap;
+import org.apache.aries.application.utils.manifest.ManifestHeaderProcessor.NameValuePair;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+public class EquinoxFrameworkUtils
+{
+
+ public static Collection<Content> getExportPackages(BundleContext isolatedBundleContext)
+ {
+ Set<Content> exports = new HashSet<Content>();
+
+ Bundle sysBundle = isolatedBundleContext.getBundle(0);
+ if (sysBundle != null && sysBundle.getHeaders() != null) {
+ String exportString = (String) sysBundle.getHeaders().get(Constants.EXPORT_PACKAGE);
+ if (exportString != null) {
+ for (NameValuePair<String, NameValueMap<String, String>> nvp : ManifestHeaderProcessor
+ .parseExportString(exportString))
+ exports.add(ManifestHeaderProcessor.parseContent(nvp.getName(), nvp.getValue()));
+ }
+ }
+ return Collections.unmodifiableSet(exports);
+ }
+
+ public static Collection<Content> getSystemExtraPkgs(BundleContext context)
+ {
+ Set<Content> extraPkgs = new HashSet<Content>();
+
+ String exportString = context.getProperty(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
+ if (exportString != null) {
+ for (NameValuePair<String, NameValueMap<String, String>> nvp : ManifestHeaderProcessor
+ .parseExportString(exportString))
+ extraPkgs.add(ManifestHeaderProcessor.parseContent(nvp.getName(), nvp.getValue()));
+ }
+
+ return Collections.unmodifiableSet(extraPkgs);
+ }
+
+ public static Collection<Content> calculateImports(final Collection<Content> importPackage,
+ final Collection<Content> exportPackages)
+ {
+ Set<Content> results = new HashSet<Content>();
+ if (importPackage != null && !importPackage.isEmpty()) {
+ for (Content exportPkg : exportPackages) {
+ for (Content importPkg : importPackage) {
+ if (!(importPkg.getContentName().equals(exportPkg.getContentName())
+ && importPkg.getVersion().equals(exportPkg.getVersion()))) {
+ results.add(importPkg);
+ }
+ }
+ }
+ }
+ return Collections.unmodifiableSet(results);
+ }
+
+ public static String contentToString(Content content)
+ {
+ StringBuffer value = new StringBuffer();
+ value.append(content.getContentName());
+
+ Map<String, String> nvm = content.getNameValueMap();
+
+ for (Map.Entry<String, String> entry : nvm.entrySet()) {
+ if (entry.getKey().equalsIgnoreCase(Constants.VERSION_ATTRIBUTE) || entry.getKey().equalsIgnoreCase(Constants.BUNDLE_VERSION_ATTRIBUTE)) {
+ value.append(";" + entry.getKey() + "=\"" + entry.getValue() + "\"");
+ } else {
+ value.append(";" + entry.getKey() + "=" + entry.getValue());
+ }
+ }
+
+ return value.toString();
+ }
+
+ /**
+ * Calculates which system packages should be flowed
+ * to a child framework based on what packages the
+ * child framework imports. Equinox will require anything imported by the
+ * child framework which is available from the system bundle
+ * in the parent framework to come from the system bundle
+ * in the child framework. However, we don't want to flow
+ * all the extra system packages by default since we want CBAs
+ * which use them to explicitly import them.
+ * @param importPackage
+ * @return
+ * @throws CompositeBundleCalculateException
+ */
+ public static String calculateSystemPackagesToFlow(final Collection<Content> systemExports,
+ final Collection<Content> imports)
+ {
+
+ // Let's always set javax.transaction as system extra packages because of the split package.
+ // It is reasonable to do so because we always flow userTransaction service into child framework anyway.
+ NameValueMap<String, String> map = new NameValueMap<String, String>();
+ map.put(EquinoxFrameworkConstants.TRANSACTION_BUNDLE, EquinoxFrameworkConstants.TRANSACTION_BUNDLE_VERSION);
+ Map<String, Map<String, String>> resultMap = new HashMap<String, Map<String, String>>();
+ resultMap.put(EquinoxFrameworkConstants.TRANSACTION_BUNDLE, map);
+
+ // let's go through the import list to build the resultMap
+ for (Content nvp : imports) {
+ String name = nvp.getContentName().trim();
+ // if it exist in the list of packages exported by the system, we need to add it to the result
+ if (existInExports(name, nvp.getNameValueMap(), systemExports)) {
+ /* We've now ensured the versions match, but not worried too
+ * much about other constraints like company or any of the
+ * other things which could be added to a version statement.
+ * We don't want to flow system packages we don't need to,
+ * but we're not in the business of provisioning, so we'll
+ * let OSGi decide whether every constraint is satisfied
+ * and resolve the bundle or not, as appropriate.
+ */
+
+ for (Content nvpp : systemExports) {
+ if (nvpp.getContentName().trim().equals(name)) {
+ Map<String, String> frameworkVersion = nvpp.getNameValueMap();
+ resultMap.put(name, frameworkVersion);
+ // We don't break here since we're too lazy to check the version
+ // again and so we might end up flowing multiple statements for the
+ // same package (but with different versions). Better this than
+ // accidentally flowing the wrong version if we hit it first.
+ }
+ }
+ }
+ }
+
+ StringBuffer result = new StringBuffer();
+ for (String key : resultMap.keySet()) {
+ result.append(getString(key, resultMap) + ",");
+ }
+ String toReturn = trimEndString(result.toString().trim(), ",");
+
+ return toReturn;
+
+ }
+
+ /**
+ * check if the value in nvm already exist in the exports
+ * @param key
+ * @param nvm
+ * @param exports
+ * @return boolean whether the value in nvm already exist in the exports
+ */
+ private static boolean existInExports(String key, Map<String, String> nvm,
+ final Collection<Content> exports)
+ {
+ boolean value = false;
+ for (Content nvp : exports) {
+ if (nvp.getContentName().trim().equals(key.trim())) {
+ // ok key equal. let's check the version
+ // if version is higher, we still want to import, for example javax.transaction;version=1.1
+ String vi = nvm.get(Constants.VERSION_ATTRIBUTE);
+ String ve = nvp.getNameValueMap().get(Constants.VERSION_ATTRIBUTE);
+ if (vi == null || vi.length() == 0) {
+ vi = "0.0.0";
+ }
+
+ if (ve == null || ve.length() == 0) {
+ ve = "0.0.0";
+ }
+
+ if (vi.indexOf(",") == -1) {
+
+ if (new Version(vi).compareTo(new Version(ve)) <= 0) {
+ // we got it covered in our exports
+ value = true;
+ }
+ } else {
+ // parse vi into version range.
+ VersionRange vri = ManifestHeaderProcessor.parseVersionRange(vi);
+ Version minV = vri.getMinimumVersion();
+ Version maxV = vri.getMaximumVersion();
+ if (minV.compareTo(new Version(ve)) < 0 && maxV.compareTo(new Version(ve)) > 0) {
+ value = true;
+ } else if (minV.compareTo(new Version(ve)) == 0 && !!!vri.isMinimumExclusive()) {
+ value = true;
+ } else if (maxV.compareTo(new Version(ve)) == 0 && !!!vri.isMaximumExclusive()) {
+ value = true;
+ }
+ }
+
+ }
+ }
+
+ return value;
+ }
+
+ private static String trimEndString(String s, String trim)
+ {
+ if (s.startsWith(trim)) {
+ s = s.substring(trim.length());
+ }
+ if (s.endsWith(trim)) {
+ s = s.substring(0, s.length() - trim.length());
+ }
+ return s;
+ }
+
+ private static String getString(String key, Map<String, Map<String, String>> imports)
+ {
+ StringBuffer value = new StringBuffer();
+ value.append(key);
+
+ Map<String, String> nvm = imports.get(key);
+
+ for (Map.Entry<String, String> entry : nvm.entrySet()) {
+ if (entry.getKey().equalsIgnoreCase(Constants.VERSION_ATTRIBUTE) || entry.getKey().equalsIgnoreCase(Constants.BUNDLE_VERSION_ATTRIBUTE)) {
+ value.append(";" + entry.getKey() + "=\"" + entry.getValue() + "\"");
+ } else {
+ value.append(";" + entry.getKey() + "=" + entry.getValue());
+ }
+ }
+
+ return value.toString();
+ }
+}
Modified: 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=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/blueprint/bundle-framework.xml (original)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/resources/OSGI-INF/blueprint/bundle-framework.xml Mon Nov 15 15:14:28 2010
@@ -20,9 +20,15 @@
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="bundle-framework-factory" class="org.apache.aries.application.runtime.framework.BundleFrameworkFactoryImpl" />
+
+ <bean id="bundle-framework-configuration-factory" class="org.apache.aries.application.runtime.framework.config.BundleFrameworkConfigurationFactoryImpl" />
<service interface="org.apache.aries.application.management.spi.framework.BundleFrameworkFactory"
ref="bundle-framework-factory"
ranking="-1"/>
+ <service interface="org.apache.aries.application.management.spi.framework.BundleFrameworkConfigurationFactory"
+ ref="bundle-framework-configuration-factory"
+ ranking="-1"/>
+
</blueprint>
Modified: incubator/aries/trunk/application/application-runtime-isolated/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-isolated/pom.xml?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-isolated/pom.xml (original)
+++ incubator/aries/trunk/application/application-runtime-isolated/pom.xml Mon Nov 15 15:14:28 2010
@@ -32,6 +32,14 @@
An isolated application runtime implementation
</description>
+ <properties>
+ <aries.osgi.export.pkg>
+ </aries.osgi.export.pkg>
+ <aries.osgi.private.pkg>
+ org.apache.aries.application.runtime.isolated.impl
+ </aries.osgi.private.pkg>
+ </properties>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
Modified: incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java (original)
+++ incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java Mon Nov 15 15:14:28 2010
@@ -78,8 +78,7 @@ public class ApplicationContextImpl impl
}
/**
- * Called to install the application, if called multiple times the subsequent
- * calls will be ignored.
+ * Called to install the application.
* @return whether the installation is successful
*
*/
Modified: incubator/aries/trunk/application/application-runtime-repository/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-repository/pom.xml?rev=1035299&r1=1035298&r2=1035299&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-repository/pom.xml (original)
+++ incubator/aries/trunk/application/application-runtime-repository/pom.xml Mon Nov 15 15:14:28 2010
@@ -32,6 +32,14 @@
An bundle repository runtime implementation
</description>
+ <properties>
+ <aries.osgi.export.pkg>
+ </aries.osgi.export.pkg>
+ <aries.osgi.private.pkg>
+ org.apache.aries.application.runtime.repository
+ </aries.osgi.private.pkg>
+ </properties>
+
<dependencies>
<dependency>
<groupId>junit</groupId>