[jboss-cvs] JBossAS SVN: r90925 - in projects/jboss-osgi: projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal and 13 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 8 06:12:32 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-07-08 06:12:31 -0400 (Wed, 08 Jul 2009)
New Revision: 90925
Added:
projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeploymentRegistryServiceImpl.java
projects/jboss-osgi/projects/integration/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartLevelDeployer.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentRegistryService.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleDeployment.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd
Removed:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI108TestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/SomeBean.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/SomeBeanMBean.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleB/
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi108-bundleA.bnd
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi108-bundleB.bnd
Modified:
projects/jboss-osgi/projects/bundles/common/trunk/pom.xml
projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/AbstractCommonServicesActivator.java
projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java
projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/SystemDeployerService.java
projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java
projects/jboss-osgi/projects/bundles/webconsole/trunk/src/main/java/org/jboss/osgi/service/webconsole/internal/plugins/BundlesPlugin.java
projects/jboss-osgi/projects/bundles/webconsole/trunk/src/main/java/org/jboss/osgi/service/webconsole/internal/plugins/InstallActionExt.java
projects/jboss-osgi/projects/integration/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
projects/jboss-osgi/projects/integration/jbossas/trunk/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/Constants.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeployerService.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentScannerService.java
projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/ActivatorBundleA.java
Log:
[JBOSGI-99] No explicit control over bundle.start()
Modified: projects/jboss-osgi/projects/bundles/common/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/common/trunk/pom.xml 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/bundles/common/trunk/pom.xml 2009-07-08 10:12:31 UTC (rev 90925)
@@ -76,6 +76,7 @@
org.jboss.osgi.spi.util;version="1.0",
org.osgi.framework;version=1.4,
org.osgi.service.log;version=1.3,
+ org.osgi.service.startlevel;version=1.1,
org.osgi.util.tracker
</Import-Package>
</instructions>
Modified: projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/AbstractCommonServicesActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/AbstractCommonServicesActivator.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/AbstractCommonServicesActivator.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -30,6 +30,7 @@
import javax.management.StandardMBean;
import org.jboss.osgi.spi.service.DeployerService;
+import org.jboss.osgi.spi.service.DeploymentRegistryService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
@@ -62,6 +63,10 @@
protected DeployerService registerDeployerServices(BundleContext context)
{
+ // Register the DeploymentRegistryService
+ DeploymentRegistryService registry = new DeploymentRegistryServiceImpl(context);
+ context.registerService(DeploymentRegistryService.class.getName(), registry, null);
+
// Register the SystemDeployerService
Properties props = new Properties();
props.put("provider", "system");
Modified: projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java
===================================================================
--- projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeployerServiceDelegate.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -26,8 +26,7 @@
import java.net.URL;
import org.jboss.osgi.spi.service.DeployerService;
-import org.jboss.osgi.spi.util.BundleInfo;
-import org.osgi.framework.Bundle;
+import org.jboss.osgi.spi.util.BundleDeployment;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
@@ -50,27 +49,9 @@
this.context = context;
}
- public Bundle getBundle(BundleInfo info)
+ public void deploy(BundleDeployment[] bundles) throws BundleException
{
DeployerService service = getDefaultDeployerService();
- return service.getBundle(info);
- }
-
- public BundleInfo getBundleInfo(URL url) throws BundleException
- {
- DeployerService service = getDefaultDeployerService();
- return service.getBundleInfo(url);
- }
-
- public BundleInfo getBundleInfo(Bundle bundle)
- {
- DeployerService service = getDefaultDeployerService();
- return service.getBundleInfo(bundle);
- }
-
- public void deploy(BundleInfo[] bundles) throws BundleException
- {
- DeployerService service = getDefaultDeployerService();
service.deploy(bundles);
}
@@ -80,9 +61,9 @@
service.deploy(url);
}
- public void undeploy(BundleInfo[] bundles) throws BundleException
+ public void undeploy(BundleDeployment[] bundles) throws BundleException
{
- for (BundleInfo info : bundles)
+ for (BundleDeployment info : bundles)
undeploy(info.getLocation());
}
Added: projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeploymentRegistryServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeploymentRegistryServiceImpl.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/DeploymentRegistryServiceImpl.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -0,0 +1,126 @@
+/*
+ * 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.common.internal;
+
+//$Id: SystemDeployerService.java 90894 2009-07-07 11:58:40Z thomas.diesler at jboss.com $
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.jboss.osgi.spi.service.DeployerService;
+import org.jboss.osgi.spi.service.DeploymentRegistryService;
+import org.jboss.osgi.spi.util.BundleDeployment;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * A {@link DeployerService} that installs/uninstalls the bundles directly on the OSGi framework without going through the MC registered deployers.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class DeploymentRegistryServiceImpl implements DeploymentRegistryService
+{
+ private Set<BundleDeployment> deployments = new HashSet<BundleDeployment>();
+
+ public DeploymentRegistryServiceImpl(BundleContext context)
+ {
+ }
+
+ public BundleDeployment createBundleDeployment(URL url) throws BundleException
+ {
+ Manifest manifest;
+ try
+ {
+ JarFile jarFile = new JarFile(url.getPath());
+ manifest = jarFile.getManifest();
+ jarFile.close();
+ }
+ catch (IOException ex)
+ {
+ throw new BundleException("Cannot get manifest from: " + url);
+
+ }
+
+ Attributes attribs = manifest.getMainAttributes();
+ String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
+ if (symbolicName == null)
+ throw new BundleException("Cannot obtain Bundle-SymbolicName for: " + url);
+
+ String version = attribs.getValue(Constants.BUNDLE_VERSION);
+ return new BundleDeployment(url, symbolicName, version);
+ }
+
+ public void registerBundleDeployment(BundleDeployment dep)
+ {
+ deployments.add(dep);
+ }
+
+ public void unregisterBundleDeployment(BundleDeployment dep)
+ {
+ deployments.remove(dep);
+ }
+
+ public BundleDeployment getBundleDeployment(String symbolicName, String version)
+ {
+ if (symbolicName == null)
+ throw new IllegalArgumentException("Cannot obtain bundle deployment for null symbolic name");
+
+ BundleDeployment dep = null;
+ for (BundleDeployment auxDep : deployments)
+ {
+ String auxName = auxDep.getSymbolicName();
+ String auxVersion = auxDep.getVersion();
+ if (symbolicName.equals(auxName) && (version == null || version.equals(auxVersion)))
+ {
+ dep = auxDep;
+ break;
+ }
+ }
+
+ return dep;
+ }
+
+ public BundleDeployment getBundleDeployment(URL url)
+ {
+ if (url == null)
+ throw new IllegalArgumentException("Cannot obtain bundle deployment for: null");
+
+ BundleDeployment dep = null;
+ for (BundleDeployment auxDep : deployments)
+ {
+ if (url.equals(auxDep.getLocation()))
+ {
+ dep = auxDep;
+ break;
+ }
+ }
+
+ return dep;
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/SystemDeployerService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/SystemDeployerService.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/bundles/common/trunk/src/main/java/org/jboss/osgi/common/internal/SystemDeployerService.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -23,27 +23,23 @@
//$Id$
-import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
import org.jboss.osgi.common.log.LogServiceTracker;
import org.jboss.osgi.spi.management.ManagedBundleService;
import org.jboss.osgi.spi.service.DeployerService;
-import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.osgi.spi.service.DeploymentRegistryService;
+import org.jboss.osgi.spi.util.BundleDeployment;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
+import org.osgi.service.startlevel.StartLevel;
+import org.osgi.util.tracker.ServiceTracker;
/**
* A {@link DeployerService} that installs/uninstalls the bundles directly on the OSGi framework without going through the MC registered deployers.
@@ -55,7 +51,8 @@
{
private LogServiceTracker log;
private BundleContext context;
- private Map<String, Bundle> deployments = new HashMap<String, Bundle>();
+ private ServiceTracker registryTracker;
+ private ServiceTracker startLevelTracker;
public SystemDeployerService(BundleContext context)
{
@@ -63,165 +60,122 @@
this.context = context;
}
- public BundleInfo getBundleInfo(URL url) throws BundleException
+ public void deploy(BundleDeployment[] depArr) throws BundleException
{
- Manifest manifest;
- try
- {
- JarFile jarFile = new JarFile(url.getPath());
- manifest = jarFile.getManifest();
- jarFile.close();
- }
- catch (IOException ex)
- {
- throw new BundleException("Cannot get manifest from: " + url);
-
- }
-
- Attributes attribs = manifest.getMainAttributes();
- String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
- if (symbolicName == null)
- throw new BundleException("Cannot obtain Bundle-SymbolicName for: " + url);
-
- String version = attribs.getValue(Constants.BUNDLE_VERSION);
- return new BundleInfo(url, symbolicName, version);
- }
-
- public BundleInfo getBundleInfo(Bundle bundle)
- {
- if (bundle == null)
- throw new IllegalArgumentException("Cannot obtain bundle info for: null");
+ DeploymentRegistryService registry = getDeploymentRegistry();
- URL location = null;
- for (String auxLoc : deployments.keySet())
+ Map<BundleDeployment, Bundle> bundleMap = new HashMap<BundleDeployment, Bundle>();
+ for (BundleDeployment dep : depArr)
{
- Bundle auxBnd = deployments.get(auxLoc);
- if (auxBnd.equals(bundle))
- {
- location = toURL(auxLoc);
- break;
- }
- }
-
- BundleInfo info = null;
- if (location != null)
- {
- String symbolicName = bundle.getSymbolicName();
- String version = (String)bundle.getHeaders().get(Constants.BUNDLE_VERSION);
- info = new BundleInfo(location, symbolicName, version);
- }
- return info;
- }
-
- public Bundle getBundle(BundleInfo info)
- {
- String symbolicName = info.getSymbolicName();
- String version = info.getVersion();
-
- Bundle bundle = null;
- for (Bundle aux : context.getBundles())
- {
- if (aux.getSymbolicName().equals(symbolicName))
- {
- String auxVersion = (String)aux.getHeaders().get(Constants.BUNDLE_VERSION);
- if (version == null || version.equals(auxVersion))
- {
- bundle = aux;
- break;
- }
- }
- }
- return bundle;
- }
-
- public void deploy(BundleInfo[] bundleInfos) throws BundleException
- {
- // Install the NEW bundles
- List<Bundle> bundles = new ArrayList<Bundle>();
- for (BundleInfo info : bundleInfos)
- {
try
{
- String location = info.getLocation().toExternalForm();
+ String location = dep.getLocation().toExternalForm();
Bundle bundle = context.installBundle(location);
log.log(LogService.LOG_INFO, "Installed: " + bundle);
-
- deployments.put(location, bundle);
+
registerManagedBundle(bundle);
- bundles.add(bundle);
+ bundleMap.put(dep, bundle);
+
+ registry.registerBundleDeployment(dep);
}
catch (BundleException ex)
{
- log.log(LogService.LOG_ERROR, "Cannot install bundle: " + info, ex);
+ log.log(LogService.LOG_ERROR, "Cannot install bundle: " + dep, ex);
}
}
// Start the installed bundles
- for (Bundle bundle : bundles)
+ for (BundleDeployment dep : depArr)
{
- try
+ Bundle bundle = bundleMap.get(dep);
+
+ StartLevel startLevel = getStartLevel();
+ if (dep.getStartLevel() > 0)
{
- log.log(LogService.LOG_DEBUG, "Start: " + bundle);
- bundle.start();
+ startLevel.setBundleStartLevel(bundle, dep.getStartLevel());
}
- catch (BundleException ex)
+
+ if (dep.isAutoStart())
{
- log.log(LogService.LOG_ERROR, "Cannot start bundle: " + bundle, ex);
+ try
+ {
+ log.log(LogService.LOG_DEBUG, "Start: " + bundle);
+ bundle.start();
+ }
+ catch (BundleException ex)
+ {
+ log.log(LogService.LOG_ERROR, "Cannot start bundle: " + bundle, ex);
+ }
}
}
}
- public void undeploy(BundleInfo[] bundleInfos) throws BundleException
+ public void undeploy(BundleDeployment[] depArr) throws BundleException
{
- for (BundleInfo info : bundleInfos)
+ DeploymentRegistryService registry = getDeploymentRegistry();
+
+ for (BundleDeployment dep : depArr)
{
- URL location = info.getLocation();
- if (location != null)
+ Bundle bundle = getBundle(dep);
+ if (bundle != null)
{
- undeploy(location);
- }
- else
- {
- Bundle bundle = getBundle(info);
- if (bundle == null)
- throw new IllegalStateException("Cannot obtain bundle for: " + info);
+ registry.unregisterBundleDeployment(dep);
unregisterManagedBundle(bundle);
bundle.uninstall();
-
log.log(LogService.LOG_INFO, "Uninstalled: " + bundle);
}
+ else
+ {
+ log.log(LogService.LOG_WARNING, "Cannot obtain bundle for: " + dep);
+ }
}
}
- // Note, in contrary to deploy(BundleInfo[]) this
- // method does not start the bundle. The client
- // is expected to do that
public void deploy(URL url) throws BundleException
{
- Bundle bundle = context.installBundle(url.toExternalForm());
- log.log(LogService.LOG_INFO, "Installed: " + bundle);
- deployments.put(url.toExternalForm(), bundle);
- registerManagedBundle(bundle);
+ DeploymentRegistryService registry = getDeploymentRegistry();
+ BundleDeployment dep = registry.createBundleDeployment(url);
+ deploy(new BundleDeployment[] { dep });
}
- public boolean undeploy(URL url) throws BundleException
+ public boolean undeploy(URL url) throws BundleException
{
- Bundle bundle = deployments.remove(url.toExternalForm());
- if (bundle != null)
+ DeploymentRegistryService registry = getDeploymentRegistry();
+ BundleDeployment dep = registry.getBundleDeployment(url);
+ if (dep != null)
{
- unregisterManagedBundle(bundle);
- bundle.uninstall();
- log.log(LogService.LOG_INFO, "Uninstalled: " + bundle);
+ undeploy(new BundleDeployment[] { dep });
return true;
}
else
{
- log.log(LogService.LOG_WARNING, "Cannot find bundle for: " + url);
+ log.log(LogService.LOG_WARNING, "Cannot find deployment for: " + url);
return false;
}
}
+ private Bundle getBundle(BundleDeployment dep)
+ {
+ String symbolicName = dep.getSymbolicName();
+ String version = dep.getVersion();
+
+ Bundle bundle = null;
+ for (Bundle aux : context.getBundles())
+ {
+ if (aux.getSymbolicName().equals(symbolicName))
+ {
+ String auxVersion = (String)aux.getHeaders().get(Constants.BUNDLE_VERSION);
+ if (version == null || version.equals(auxVersion))
+ {
+ bundle = aux;
+ break;
+ }
+ }
+ }
+ return bundle;
+ }
+
private void registerManagedBundle(Bundle bundle)
{
ServiceReference sref = context.getServiceReference(ManagedBundleService.class.getName());
@@ -249,16 +203,24 @@
log.log(LogService.LOG_DEBUG, "No ManagedBundleService. Cannot unregister managed bundle: " + bundle);
}
}
-
- private URL toURL(String location)
+
+ private DeploymentRegistryService getDeploymentRegistry()
{
- try
+ if (registryTracker == null)
{
- return new URL(location);
+ registryTracker = new ServiceTracker(context, DeploymentRegistryService.class.getName(), null);
+ registryTracker.open();
}
- catch (MalformedURLException e)
+ return (DeploymentRegistryService)registryTracker.getService();
+ }
+
+ private StartLevel getStartLevel()
+ {
+ if (startLevelTracker == null)
{
- throw new IllegalArgumentException("Invalid URL location: " + location);
+ startLevelTracker = new ServiceTracker(context, StartLevel.class.getName(), null);
+ startLevelTracker.open();
}
+ return (StartLevel)startLevelTracker.getService();
}
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/bundles/hotdeploy/trunk/src/main/java/org/jboss/osgi/service/hotdeploy/internal/DeploymentScannerImpl.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -38,11 +38,13 @@
import org.jboss.osgi.common.log.LogServiceTracker;
import org.jboss.osgi.spi.service.DeployerService;
+import org.jboss.osgi.spi.service.DeploymentRegistryService;
import org.jboss.osgi.spi.service.DeploymentScannerService;
-import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.osgi.spi.util.BundleDeployment;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
@@ -62,11 +64,12 @@
private long scanCount;
private long lastChange;
+ private DeploymentRegistryService registry;
private DeployerService deployer;
private ScannerThread scannerThread;
- private List<BundleInfo> lastScan = new ArrayList<BundleInfo>();
+ private List<BundleDeployment> lastScan = new ArrayList<BundleDeployment>();
private Set<ScanListener> listeners = new LinkedHashSet<ScanListener>();
- private Map<String, BundleInfo> bundleInfoCache = new HashMap<String, BundleInfo>();
+ private Map<String, BundleDeployment> deploymentCache = new HashMap<String, BundleDeployment>();
private boolean traceBundles = false;
public DeploymentScannerImpl(BundleContext context)
@@ -74,10 +77,14 @@
this.log = new LogServiceTracker(context);
this.context = context;
- // Get the DeployerServiceDelegate
+ // Get the DeployerService
ServiceReference sref = context.getServiceReference(DeployerService.class.getName());
deployer = (DeployerService)context.getService(sref);
+ // Get the DeploymentRegistryService
+ sref = context.getServiceReference(DeploymentRegistryService.class.getName());
+ registry = (DeploymentRegistryService)context.getService(sref);
+
initScanner(context);
}
@@ -141,10 +148,10 @@
for (ScanListener listener : scanListeners)
listener.beforeScan(this);
- List<BundleInfo> currScan = Arrays.asList(getBundleInfos());
+ List<BundleDeployment> currScan = Arrays.asList(getBundleDeployments());
if (traceBundles)
- logBundleInfos("Current Scan", currScan);
+ logBundleDeployments("Current Scan", currScan);
int oldDiff = processOldDeployments(currScan);
int newDiff = processNewDeployments(currScan);
@@ -159,42 +166,42 @@
listener.afterScan(this);
}
- private void logBundleInfos(String message, List<BundleInfo> bundleInfos)
+ private void logBundleDeployments(String message, List<BundleDeployment> bundleDeps)
{
System.out.println(message);
- for (BundleInfo info : bundleInfos)
+ for (BundleDeployment dep : bundleDeps)
{
- System.out.println(" " + info);
+ System.out.println(" " + dep);
}
}
- private int processOldDeployments(List<BundleInfo> currScan)
+ private int processOldDeployments(List<BundleDeployment> currScan)
{
- List<BundleInfo> diff = new ArrayList<BundleInfo>();
+ List<BundleDeployment> diff = new ArrayList<BundleDeployment>();
// Detect OLD bundles that are not in the current scan
- for (BundleInfo info : lastScan)
+ for (BundleDeployment dep : lastScan)
{
- if (currScan.contains(info) == false)
+ if (currScan.contains(dep) == false)
{
- Bundle bundle = deployer.getBundle(info);
+ Bundle bundle = getBundle(dep);
int state = bundle.getState();
if (state == Bundle.INSTALLED || state == Bundle.RESOLVED || state == Bundle.ACTIVE)
{
- bundleInfoCache.remove(info.getLocation().toExternalForm());
- diff.add(info);
+ deploymentCache.remove(dep.getLocation().toExternalForm());
+ diff.add(dep);
}
}
}
if (traceBundles)
- logBundleInfos("OLD diff", diff);
+ logBundleDeployments("OLD diff", diff);
// Undeploy the bundles through the DeployerService
try
{
- BundleInfo[] infoArr = diff.toArray(new BundleInfo[diff.size()]);
- deployer.undeploy(infoArr);
+ BundleDeployment[] depArr = diff.toArray(new BundleDeployment[diff.size()]);
+ deployer.undeploy(depArr);
}
catch (Exception ex)
{
@@ -204,27 +211,27 @@
return diff.size();
}
- private int processNewDeployments(List<BundleInfo> currScan)
+ private int processNewDeployments(List<BundleDeployment> currScan)
{
- List<BundleInfo> diff = new ArrayList<BundleInfo>();
+ List<BundleDeployment> diff = new ArrayList<BundleDeployment>();
// Detect NEW bundles that are not in the last scan
- for (BundleInfo info : currScan)
+ for (BundleDeployment dep : currScan)
{
- if (lastScan.contains(info) == false && deployer.getBundle(info) == null)
+ if (lastScan.contains(dep) == false && getBundle(dep) == null)
{
- diff.add(info);
+ diff.add(dep);
}
}
if (traceBundles)
- logBundleInfos("NEW diff", diff);
+ logBundleDeployments("NEW diff", diff);
// Deploy the bundles through the DeployerService
try
{
- BundleInfo[] infoArr = diff.toArray(new BundleInfo[diff.size()]);
- deployer.deploy(infoArr);
+ BundleDeployment[] depArr = diff.toArray(new BundleDeployment[diff.size()]);
+ deployer.deploy(depArr);
}
catch (Exception ex)
{
@@ -234,9 +241,9 @@
return diff.size();
}
- public BundleInfo[] getBundleInfos()
+ public BundleDeployment[] getBundleDeployments()
{
- List<BundleInfo> bundles = new ArrayList<BundleInfo>();
+ List<BundleDeployment> bundles = new ArrayList<BundleDeployment>();
File[] listFiles = scanLocation.listFiles();
if (listFiles == null)
@@ -247,24 +254,27 @@
for (File file : listFiles)
{
URL bundleURL = toURL(file);
- BundleInfo info = bundleInfoCache.get(bundleURL.toExternalForm());
- if (info == null)
+ BundleDeployment dep = deploymentCache.get(bundleURL.toExternalForm());
+ if (dep == null)
{
try
{
- info = deployer.getBundleInfo(bundleURL);
- bundleInfoCache.put(bundleURL.toExternalForm(), info);
+ // hot-deploy bundles are started automatically
+ dep = registry.createBundleDeployment(bundleURL);
+ dep.setAutoStart(true);
+
+ deploymentCache.put(bundleURL.toExternalForm(), dep);
}
catch (BundleException ex)
{
- log.log(LogService.LOG_WARNING, "Cannot obtain bundle info for: " + file);
+ log.log(LogService.LOG_WARNING, "Cannot obtain bundle deployment for: " + file);
}
}
- bundles.add(info);
+ bundles.add(dep);
}
}
- BundleInfo[] arr = new BundleInfo[bundles.size()];
+ BundleDeployment[] arr = new BundleDeployment[bundles.size()];
return bundles.toArray(arr);
}
@@ -303,6 +313,27 @@
scanLocation = scanFile;
}
+ private Bundle getBundle(BundleDeployment dep)
+ {
+ String symbolicName = dep.getSymbolicName();
+ String version = dep.getVersion();
+
+ Bundle bundle = null;
+ for (Bundle aux : context.getBundles())
+ {
+ if (aux.getSymbolicName().equals(symbolicName))
+ {
+ String auxVersion = (String)aux.getHeaders().get(Constants.BUNDLE_VERSION);
+ if (version == null || version.equals(auxVersion))
+ {
+ bundle = aux;
+ break;
+ }
+ }
+ }
+ return bundle;
+ }
+
private URL toURL(File file)
{
try
Modified: projects/jboss-osgi/projects/bundles/webconsole/trunk/src/main/java/org/jboss/osgi/service/webconsole/internal/plugins/BundlesPlugin.java
===================================================================
--- projects/jboss-osgi/projects/bundles/webconsole/trunk/src/main/java/org/jboss/osgi/service/webconsole/internal/plugins/BundlesPlugin.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/bundles/webconsole/trunk/src/main/java/org/jboss/osgi/service/webconsole/internal/plugins/BundlesPlugin.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -29,10 +29,12 @@
import org.apache.felix.webconsole.internal.core.BundlesServlet;
import org.jboss.osgi.spi.service.DeployerService;
-import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.osgi.spi.service.DeploymentRegistryService;
+import org.jboss.osgi.spi.util.BundleDeployment;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
@@ -62,18 +64,23 @@
getLog().log(LogService.LOG_WARNING, "Cannot obtain service: " + DeployerService.class.getName());
return super.actionUninstall(bundle);
}
-
DeployerService service = (DeployerService)context.getService(sref);
- BundleInfo info = service.getBundleInfo(bundle);
- if (info == null)
+
+ sref = context.getServiceReference(DeploymentRegistryService.class.getName());
+ DeploymentRegistryService registry = (DeploymentRegistryService)context.getService(sref);
+
+ String symbolicName = bundle.getSymbolicName();
+ String version = (String)bundle.getHeaders().get(Constants.BUNDLE_VERSION);
+ BundleDeployment dep = registry.getBundleDeployment(symbolicName, version);
+ if (dep == null)
{
- getLog().log(LogService.LOG_WARNING, "Cannot find bundle info for: " + bundle);
+ getLog().log(LogService.LOG_WARNING, "Cannot find bundle deployment for: " + bundle);
return super.actionUninstall(bundle);
}
try
{
- service.undeploy(new BundleInfo[] { info });
+ service.undeploy(new BundleDeployment[] { dep });
return true;
}
catch (BundleException be)
Modified: projects/jboss-osgi/projects/bundles/webconsole/trunk/src/main/java/org/jboss/osgi/service/webconsole/internal/plugins/InstallActionExt.java
===================================================================
--- projects/jboss-osgi/projects/bundles/webconsole/trunk/src/main/java/org/jboss/osgi/service/webconsole/internal/plugins/InstallActionExt.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/bundles/webconsole/trunk/src/main/java/org/jboss/osgi/service/webconsole/internal/plugins/InstallActionExt.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -30,13 +30,14 @@
import org.apache.felix.webconsole.internal.core.InstallAction;
import org.jboss.osgi.spi.service.DeployerService;
-import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.osgi.spi.service.DeploymentRegistryService;
+import org.jboss.osgi.spi.util.BundleDeployment;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;
-import org.osgi.service.startlevel.StartLevel;
/**
* A Console plugin
@@ -49,42 +50,35 @@
@Override
protected void installBackground(final File bundleFile, final String location, final int startlevel, final boolean doStart, boolean refreshPackages)
{
- final BundleContext context = getBundleContext();
- final ServiceReference sref = context.getServiceReference(DeployerService.class.getName());
+ BundleContext context = getBundleContext();
+ ServiceReference sref = context.getServiceReference(DeployerService.class.getName());
if (sref == null)
{
getLog().log(LogService.LOG_WARNING, "Cannot obtain service: " + DeployerService.class.getName());
super.installBackground(bundleFile, location, startlevel, doStart, refreshPackages);
return;
}
-
+ final DeployerService deployer = (DeployerService)context.getService(sref);
+
+ sref = context.getServiceReference(DeploymentRegistryService.class.getName());
+ final DeploymentRegistryService registry = (DeploymentRegistryService)context.getService(sref);
+
Thread t = new InstallHelper(this, "Background Install " + bundleFile, bundleFile, refreshPackages)
{
protected Bundle doRun(InputStream bundleStream) throws BundleException
{
- DeployerService service = (DeployerService)context.getService(sref);
URL bundleURL = getBundleURL(bundleFile);
- BundleInfo info = service.getBundleInfo(bundleURL);
+
+ BundleDeployment dep = registry.createBundleDeployment(bundleURL);
+ dep.setStartLevel(startlevel);
+ dep.setAutoStart(doStart);
- service.deploy(new BundleInfo[] { info });
- Bundle bundle = service.getBundle(info);
+ deployer.deploy(new BundleDeployment[] { dep });
+
+ Bundle bundle = getBundle(dep);
if (bundle == null)
- throw new IllegalStateException("Cannot obtain installed bundle: " + info);
+ throw new IllegalStateException("Cannot obtain installed bundle: " + dep);
- if (startlevel > 0)
- {
- StartLevel sl = getStartLevel();
- if (sl != null)
- {
- sl.setBundleStartLevel(bundle, startlevel);
- }
- }
-
- if (doStart)
- {
- bundle.start();
- }
-
return bundle;
}
@@ -93,6 +87,27 @@
t.start();
}
+ private Bundle getBundle(BundleDeployment info)
+ {
+ String symbolicName = info.getSymbolicName();
+ String version = info.getVersion();
+
+ Bundle bundle = null;
+ for (Bundle aux : getBundleContext().getBundles())
+ {
+ if (aux.getSymbolicName().equals(symbolicName))
+ {
+ String auxVersion = (String)aux.getHeaders().get(Constants.BUNDLE_VERSION);
+ if (version == null || version.equals(auxVersion))
+ {
+ bundle = aux;
+ break;
+ }
+ }
+ }
+ return bundle;
+ }
+
private URL getBundleURL(final File bundleFile) throws BundleException
{
URL bundleURL;
Added: projects/jboss-osgi/projects/integration/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartLevelDeployer.java
===================================================================
--- projects/jboss-osgi/projects/integration/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartLevelDeployer.java (rev 0)
+++ projects/jboss-osgi/projects/integration/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartLevelDeployer.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.deployer;
+
+// $Id: $
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.spi.Constants;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.startlevel.StartLevel;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * This is the Bundle start level Deployer
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 08-Jul-2009
+ */
+public class BundleStartLevelDeployer extends AbstractSimpleRealDeployer<Bundle>
+{
+ private BundleContext systemContext;
+ private ServiceTracker startLevelTracker;
+
+ public BundleStartLevelDeployer()
+ {
+ super(Bundle.class);
+ addOutput(Constants.PROPERTY_START_LEVEL);
+ }
+
+ public void setSystemContext(BundleContext systemContext)
+ {
+ this.systemContext = systemContext;
+ }
+
+ public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
+ {
+ Integer propStart = unit.getAttachment(Constants.PROPERTY_START_LEVEL, Integer.class);
+ StartLevel startLevel = getStartLevel();
+ if (propStart != null && startLevel != null)
+ {
+ startLevel.setBundleStartLevel(bundle, propStart);
+ }
+ }
+
+ private StartLevel getStartLevel()
+ {
+ if (startLevelTracker == null)
+ {
+ startLevelTracker = new ServiceTracker(systemContext, StartLevel.class.getName(), null);
+ startLevelTracker.open();
+ }
+ return (StartLevel)startLevelTracker.getService();
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/integration/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/projects/integration/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/integration/deployers/trunk/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -56,6 +56,7 @@
public BundleStartStopDeployer()
{
super(Bundle.class);
+ addInput(Constants.PROPERTY_START_LEVEL);
}
public void setSystemContext(BundleContext systemContext)
@@ -65,15 +66,19 @@
public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
{
- String propStart = systemContext.getProperty(Constants.PROPERTY_DEFERRED_START);
- if (Boolean.parseBoolean(propStart != null ? propStart : "true") == true)
+ Boolean propAutoStart = unit.getAttachment(Constants.PROPERTY_AUTO_START, Boolean.class);
+ if (propAutoStart == Boolean.TRUE)
{
- deferredStart(unit, bundle);
+ String propDeferredStart = systemContext.getProperty(Constants.PROPERTY_DEFERRED_START);
+ if (Boolean.parseBoolean(propDeferredStart != null ? propDeferredStart : "true") == true)
+ {
+ deferredStart(unit, bundle);
+ }
+ else
+ {
+ simpleStart(unit, bundle);
+ }
}
- else
- {
- simpleStart(unit, bundle);
- }
}
@Override
Modified: projects/jboss-osgi/projects/integration/jbossas/trunk/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java
===================================================================
--- projects/jboss-osgi/projects/integration/jbossas/trunk/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/integration/jbossas/trunk/src/main/java/org/jboss/osgi/integration/jbossas/AbstractMicrocontainerService.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -25,17 +25,10 @@
import static org.jboss.osgi.spi.management.MicrocontainerServiceMBean.MBEAN_MICROCONTAINER_SERVICE;
-import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
import javax.management.MBeanServer;
import javax.management.StandardMBean;
@@ -49,21 +42,23 @@
import org.jboss.dependency.spi.ControllerState;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
import org.jboss.deployers.vfs.spi.client.VFSDeployment;
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.osgi.spi.Constants;
import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
import org.jboss.osgi.spi.service.DeployerService;
+import org.jboss.osgi.spi.service.DeploymentRegistryService;
import org.jboss.osgi.spi.service.MicrocontainerService;
-import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.osgi.spi.util.BundleDeployment;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
+import org.osgi.util.tracker.ServiceTracker;
/**
* An OSGi Service the gives access to the Kernel.
@@ -74,7 +69,7 @@
public abstract class AbstractMicrocontainerService implements DeployerService, MicrocontainerService
{
private VFSDeploymentFactory deploymentFactory = VFSDeploymentFactory.getInstance();
- private Map<String, BundleDeployment> deployments = Collections.synchronizedMap(new HashMap<String, BundleDeployment>());
+ private ServiceTracker registryTracker;
public abstract Kernel getKernel();
@@ -113,88 +108,17 @@
return (T)getRegisteredBean(beanName);
}
- public BundleInfo getBundleInfo(URL url) throws BundleException
- {
- Manifest manifest;
- try
- {
- JarFile jarFile = new JarFile(url.getPath());
- manifest = jarFile.getManifest();
- jarFile.close();
- }
- catch (IOException ex)
- {
- throw new BundleException("Cannot get manifest from: " + url);
-
- }
-
- Attributes attribs = manifest.getMainAttributes();
- String symbolicName = attribs.getValue(Constants.BUNDLE_SYMBOLICNAME);
- if (symbolicName == null)
- throw new BundleException("Cannot obtain Bundle-SymbolicName for: " + url);
-
- String version = attribs.getValue(Constants.BUNDLE_VERSION);
- return new BundleInfo(url, symbolicName, version);
- }
-
- public BundleInfo getBundleInfo(Bundle bundle)
- {
- if (bundle == null)
- throw new IllegalArgumentException("Cannot obtain bundle info for: null");
-
- String sname = bundle.getSymbolicName();
- String version = (String)bundle.getHeaders().get(Constants.BUNDLE_VERSION);
-
- URL location = null;
- for (String auxLoc : deployments.keySet())
- {
- BundleDeployment auxDep = deployments.get(auxLoc);
- BundleInfo auxInfo = auxDep.getBundleInfo();
- if (sname.equals(auxInfo.getSymbolicName()) && version.equals(auxInfo.getVersion()))
- {
- location = toURL(auxLoc);
- break;
- }
- }
-
- BundleInfo info = null;
- if (location != null)
- {
- info = new BundleInfo(location, sname, version);
- }
- return info;
- }
-
- public Bundle getBundle(BundleInfo info)
- {
- BundleContext context = getRegisteredBean(BundleContext.class, BEAN_SYSTEM_BUNDLE_CONTEXT);
- String symbolicName = info.getSymbolicName();
- String version = info.getVersion();
-
- Bundle bundle = null;
- for (Bundle aux : context.getBundles())
- {
- if (aux.getSymbolicName().equals(symbolicName))
- {
- String auxVersion = (String)aux.getHeaders().get(Constants.BUNDLE_VERSION);
- if (version == null || version.equals(auxVersion))
- {
- bundle = aux;
- break;
- }
- }
- }
- return bundle;
- }
-
public void deploy(URL url) throws BundleException
{
- deployInternal(new URL[] { url });
+ DeploymentRegistryService registry = getDeploymentRegistry();
+ BundleDeployment dep = registry.createBundleDeployment(url);
+ deploy(new BundleDeployment[] { dep });
}
public boolean undeploy(URL url) throws BundleException
{
- BundleDeployment dep = deployments.remove(url.toExternalForm());
+ DeploymentRegistryService registry = getDeploymentRegistry();
+ BundleDeployment dep = registry.getBundleDeployment(url);
if (dep == null)
{
logWarning("Package not deployed: " + url);
@@ -204,7 +128,7 @@
try
{
MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
- mainDeployer.removeDeployment(dep.getName());
+ mainDeployer.removeDeployment((String)dep.getMetadata());
mainDeployer.process();
return true;
}
@@ -215,17 +139,8 @@
}
}
- public void deploy(BundleInfo[] bundles) throws BundleException
+ public void deploy(BundleDeployment[] depArr) throws BundleException
{
- URL[] urls = new URL[bundles.length];
- for (int i = 0; i < bundles.length; i++)
- urls[i] = bundles[i].getLocation();
-
- deployInternal(urls);
- }
-
- private void deployInternal(URL[] urls) throws BundleException
- {
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
try
{
@@ -233,26 +148,29 @@
List<Deployment> depList = new ArrayList<Deployment>();
MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
- for (URL location : urls)
+ DeploymentRegistryService registry = getDeploymentRegistry();
+
+ for (BundleDeployment dep : depArr)
{
- BundleInfo info = getBundleInfo(location);
-
- VirtualFile file = VFS.createNewRoot(location);
+ VirtualFile file = VFS.createNewRoot(dep.getLocation());
VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
- mainDeployer.addDeployment(deployment);
-
- String depName = deployment.getName();
- BundleDeployment dep = new BundleDeployment(depName, info);
- deployments.put(location.toExternalForm(), dep);
+ dep.setMetadata(deployment.getName());
+ registry.registerBundleDeployment(dep);
depList.add(deployment);
+
+ MutableAttachments att = (MutableAttachments)deployment.getPredeterminedManagedObjects();
+ att.addAttachment(Constants.PROPERTY_START_LEVEL, new Integer(dep.getStartLevel()));
+ att.addAttachment(Constants.PROPERTY_AUTO_START, new Boolean(dep.isAutoStart()));
+
+ mainDeployer.addDeployment(deployment);
}
// Process the deployments
mainDeployer.process();
// Check for completeness
- Deployment[] depArr = depList.toArray(new Deployment[depList.size()]);
- mainDeployer.checkComplete(depArr);
+ Deployment[] deploymentArr = depList.toArray(new Deployment[depList.size()]);
+ mainDeployer.checkComplete(deploymentArr);
}
catch (RuntimeException rte)
{
@@ -268,23 +186,17 @@
}
}
- public void undeploy(BundleInfo[] infos) throws BundleException
+ public void undeploy(BundleDeployment[] depArr) throws BundleException
{
try
{
MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
- for (BundleInfo info : infos)
+ DeploymentRegistryService registry = getDeploymentRegistry();
+
+ for (BundleDeployment dep : depArr)
{
- URL location = info.getLocation();
- BundleDeployment dep = deployments.remove(location.toExternalForm());
- if (dep != null)
- {
- mainDeployer.removeDeployment(dep.getName());
- }
- else
- {
- logWarning("Package not deployed: " + location);
- }
+ registry.unregisterBundleDeployment(dep);
+ mainDeployer.removeDeployment((String)dep.getMetadata());
}
mainDeployer.process();
}
@@ -344,40 +256,17 @@
}
}
- private URL toURL(String location)
+ private DeploymentRegistryService getDeploymentRegistry()
{
- try
+ if (registryTracker == null)
{
- return new URL(location);
+ BundleContext context = getRegisteredBean(BundleContext.class, BEAN_SYSTEM_BUNDLE_CONTEXT);
+ registryTracker = new ServiceTracker(context, DeploymentRegistryService.class.getName(), null);
+ registryTracker.open();
}
- catch (MalformedURLException e)
- {
- throw new IllegalArgumentException("Invalid URL location: " + location);
- }
+ return (DeploymentRegistryService)registryTracker.getService();
}
-
- static class BundleDeployment
- {
- private String name;
- private BundleInfo info;
-
- public BundleDeployment(String depName, BundleInfo bundleInfo)
- {
- this.name = depName;
- this.info = bundleInfo;
- }
-
- public String getName()
- {
- return name;
- }
-
- public BundleInfo getBundleInfo()
- {
- return info;
- }
- }
-
+
static class PreInstalledControllerContext extends AbstractControllerContext
{
public PreInstalledControllerContext(Object name, ControllerContextActions actions, Object target)
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/Constants.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/Constants.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/Constants.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -43,6 +43,20 @@
String PROPERTY_DEFERRED_START = "org.jboss.osgi.deferred.start";
/**
+ * If set to 'true' bundles are started automatically.
+ *
+ * The default is 'false'
+ */
+ String PROPERTY_AUTO_START = "org.jboss.osgi.auto.start";
+
+ /**
+ * Specifies the start level for a bundle.
+ *
+ * The default is '0'
+ */
+ String PROPERTY_START_LEVEL = "org.jboss.osgi.start.level";
+
+ /**
* The JBossOSGi runtime system property that denotes the path to the runtime
*/
String OSGI_HOME = "osgi.home";
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeployerService.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeployerService.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeployerService.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -21,17 +21,16 @@
*/
package org.jboss.osgi.spi.service;
+//$Id$
+
import java.net.URL;
import javax.management.ObjectName;
import org.jboss.osgi.spi.management.ObjectNameFactory;
-import org.jboss.osgi.spi.util.BundleInfo;
-import org.osgi.framework.Bundle;
+import org.jboss.osgi.spi.util.BundleDeployment;
import org.osgi.framework.BundleException;
-//$Id$
-
/**
* A Service that can be used to deploy/undeploy bundles or archives to/from the runtime.
*
@@ -46,31 +45,14 @@
ObjectName MBEAN_DEPLOYER_SERVICE = ObjectNameFactory.create("jboss.osgi:service=DeployerService");
/**
- * Get the bundle info for the given bundle URL
- */
- BundleInfo getBundleInfo(URL url) throws BundleException;
-
- /**
- * Get the bundle info for the given bundle
- * @return null, if this service does not maintain the bundle info
- */
- BundleInfo getBundleInfo(Bundle bundle);
-
- /**
- * Get the installed bundle for the given bundle info
- * @return null, if there is no bundle that matches the given bundle info
- */
- Bundle getBundle(BundleInfo info);
-
- /**
* Deploy an array of bundles
*/
- void deploy(BundleInfo[] bundles) throws BundleException;
+ void deploy(BundleDeployment[] bundleDeps) throws BundleException;
/**
* Undeploy an array of bundles
*/
- void undeploy(BundleInfo[] bundles) throws BundleException;
+ void undeploy(BundleDeployment[] bundleDeps) throws BundleException;
/**
* Deploy bundle from URL
Added: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentRegistryService.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentRegistryService.java (rev 0)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentRegistryService.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.service;
+
+//$Id: DeployerService.java 90894 2009-07-07 11:58:40Z thomas.diesler at jboss.com $
+
+import java.net.URL;
+
+import org.jboss.osgi.spi.util.BundleDeployment;
+import org.osgi.framework.BundleException;
+
+/**
+ * A Service to register/unregister bundle deployments.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2009
+ */
+public interface DeploymentRegistryService
+{
+ /**
+ * Create a bundle deployment from the given bundle URL
+ */
+ BundleDeployment createBundleDeployment(URL url) throws BundleException;
+
+ /**
+ * Create a bundle deployment from the given bundle URL
+ * @return null, if this service does not maintain the bundle deployment
+ */
+ BundleDeployment getBundleDeployment(URL url);
+
+ /**
+ * Get the bundle deployment for the given bundle symbolicName and version
+ * @return null, if this service does not maintain the bundle deployment
+ */
+ BundleDeployment getBundleDeployment(String symbolicName, String version);
+
+ /**
+ * Register a bundle deployment
+ */
+ void registerBundleDeployment(BundleDeployment dep);
+
+ /**
+ * Unregister a bundle deployment
+ */
+ void unregisterBundleDeployment(BundleDeployment dep);
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentScannerService.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentScannerService.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/service/DeploymentScannerService.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -25,7 +25,7 @@
import java.net.URL;
-import org.jboss.osgi.spi.util.BundleInfo;
+import org.jboss.osgi.spi.util.BundleDeployment;
/**
* A service that scans a directory location for new/removed bundles.
@@ -76,7 +76,7 @@
/**
* Returns the array of bundles currently known to the deployemtn scanner.
*/
- BundleInfo[] getBundleInfos();
+ BundleDeployment[] getBundleDeployments();
/**
* Add a scan listener to this service
Copied: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleDeployment.java (from rev 90894, projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java)
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleDeployment.java (rev 0)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleDeployment.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.util;
+
+import java.io.Serializable;
+import java.net.URL;
+
+//$Id$
+
+/**
+ * An abstraction of a bundle deployment
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 27-May-2009
+ */
+public class BundleDeployment implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private URL location;
+ private String symbolicName;
+ private String version;
+ private int startLevel;
+ private boolean autoStart;
+ private Object metadata;
+
+ public BundleDeployment(URL location, String symbolicName, String version)
+ {
+ if (location == null)
+ throw new IllegalArgumentException("Location cannot be null");
+ if (symbolicName == null)
+ throw new IllegalArgumentException("Symbolic name cannot be null");
+
+ this.symbolicName = symbolicName;
+ this.location = location;
+
+ this.version = (version != null ? version : "0.0.0");
+ }
+
+ /**
+ * Get the bundle location
+ */
+ public URL getLocation()
+ {
+ return location;
+ }
+
+ /**
+ * Get the bundle symbolic name
+ */
+ public String getSymbolicName()
+ {
+ return symbolicName;
+ }
+
+ /**
+ * Get the bundle version
+ */
+ public String getVersion()
+ {
+ return version;
+ }
+
+ /**
+ * Get the start level associated with this deployment
+ */
+ public int getStartLevel()
+ {
+ return startLevel;
+ }
+
+ /**
+ * Set the start level associated with this deployment
+ */
+ public void setStartLevel(int startLevel)
+ {
+ this.startLevel = startLevel;
+ }
+
+ /**
+ * Get the autostart flag associated with this deployment
+ */
+ public boolean isAutoStart()
+ {
+ return autoStart;
+ }
+
+ /**
+ * Set the autostart flag associated with this deployment
+ */
+ public void setAutoStart(boolean autoStart)
+ {
+ this.autoStart = autoStart;
+ }
+
+ /**
+ * Get extra meta data associated with this deployment
+ */
+ public Object getMetadata()
+ {
+ return metadata;
+ }
+
+ /**
+ * Set extra meta data associated with this deployment
+ */
+ public void setMetadata(Object metadata)
+ {
+ this.metadata = metadata;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (!(obj instanceof BundleDeployment))
+ return false;
+
+ BundleDeployment other = (BundleDeployment)obj;
+ return symbolicName.equals(other.symbolicName) && version.equals(other.version);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return toString().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "[" + symbolicName + ":" + version + "]";
+ }
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.spi.util;
-
-import java.net.URL;
-
-//$Id$
-
-/**
- * An abstraction of a bundle
- *
- * @author thomas.diesler at jboss.com
- * @since 27-May-2009
- */
-public class BundleInfo
-{
- private URL location;
- private String symbolicName;
- private String version;
-
- public BundleInfo(URL location, String symbolicName, String version)
- {
- if (location == null)
- throw new IllegalArgumentException("Location cannot be null");
- if (symbolicName == null)
- throw new IllegalArgumentException("Symbolic name cannot be null");
-
- this.symbolicName = symbolicName;
- this.location = location;
-
- this.version = (version != null ? version : "0.0.0");
- }
-
- /**
- * Get the bundle location
- */
- public URL getLocation()
- {
- return location;
- }
-
- /**
- * Get the bundle symbolic name
- */
- public String getSymbolicName()
- {
- return symbolicName;
- }
-
- /**
- * Get the bundle version
- */
- public String getVersion()
- {
- return version;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (!(obj instanceof BundleInfo))
- return false;
-
- BundleInfo other = (BundleInfo)obj;
- return symbolicName.equals(other.symbolicName) && version.equals(other.version);
- }
-
- @Override
- public int hashCode()
- {
- return toString().hashCode();
- }
-
- @Override
- public String toString()
- {
- return "[" + symbolicName + ":" + version + "]";
- }
-}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml 2009-07-08 09:26:46 UTC (rev 90924)
+++ projects/jboss-osgi/trunk/testsuite/functional/scripts/antrun-test-jars.xml 2009-07-08 10:12:31 UTC (rev 90925)
@@ -78,6 +78,9 @@
<!-- jbosgi41 -->
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi41-bundleA.jar" files="${tests.resources.dir}/jbosgi41/jbosgi41-bundleA.bnd" />
+ <!-- jbosgi99 -->
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi99-bundleA.jar" files="${tests.resources.dir}/jbosgi99/jbosgi99-bundleA.bnd" />
+
<!-- jbosgi108 -->
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi108-bundleA.jar" files="${tests.resources.dir}/jbosgi108/jbosgi108-bundleA.bnd" />
<bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/jbosgi108-bundleB.jar" files="${tests.resources.dir}/jbosgi108/jbosgi108-bundleB.bnd" />
Copied: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99 (from rev 90880, projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi108)
Deleted: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI108TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi108/OSGI108TestCase.java 2009-07-07 07:31:04 UTC (rev 90880)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI108TestCase.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -1,176 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.osgi.jbosgi108;
-
-//$Id: OSGI39TestCase.java 87103 2009-04-09 22:18:31Z thomas.diesler at jboss.com $
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.List;
-
-import org.jboss.osgi.spi.capability.JMXCapability;
-import org.jboss.osgi.spi.management.MBeanProxy;
-import org.jboss.osgi.spi.testing.OSGiBundle;
-import org.jboss.osgi.spi.testing.OSGiPackageAdmin;
-import org.jboss.osgi.spi.testing.OSGiRuntime;
-import org.jboss.osgi.spi.testing.OSGiTestHelper;
-import org.jboss.test.osgi.jbosgi108.bundleA.SomeBeanMBean;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.osgi.framework.BundleException;
-
-/**
- * [JBOSGI-108] Investigate statics on PackageAdmin.refresh
- *
- * https://jira.jboss.org/jira/browse/JBOSGI-108
- *
- * @author thomas.diesler at jboss.com
- * @since 19-Jun-2009
- */
-public class OSGI108TestCase
-{
- private static OSGiRuntime runtime;
-
- @BeforeClass
- public static void beforeClass() throws BundleException
- {
- runtime = new OSGiTestHelper().getDefaultRuntime();
- runtime.addCapability(new JMXCapability());
- }
-
- @AfterClass
- public static void afterClass() throws BundleException
- {
- if (runtime != null)
- runtime.shutdown();
- }
-
- @Before
- public void setUp()
- {
- OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
- packageAdmin.refreshPackages(null);
- }
-
- @Test
- public void testRedeploySingle() throws Exception
- {
- OSGiBundle bundleA = runtime.installBundle("jbosgi108-bundleA.jar");
-
- bundleA.start();
-
- SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
- List<String> messages = report(someBean.getMessages());
- assertEquals("Start messages", 1, messages.size());
-
- bundleA.uninstall();
-
- // Reinstall bundleA
- bundleA = runtime.installBundle("jbosgi108-bundleA.jar");
- bundleA.start();
-
- // The static in bundleA.SomeBean is expected to be recreated
-
- messages = report(someBean.getMessages());
- assertEquals("Start messages", 1, messages.size());
-
- bundleA.uninstall();
- }
-
- @Test
- public void testRedeployWithReference() throws Exception
- {
- OSGiBundle bundleA = runtime.installBundle("jbosgi108-bundleA.jar");
- OSGiBundle bundleB = runtime.installBundle("jbosgi108-bundleB.jar");
-
- bundleA.start();
- bundleB.start();
-
- SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
- List<String> messages = report(someBean.getMessages());
- assertEquals("Start messages", 2, messages.size());
-
- bundleA.uninstall();
-
- // After uninstall bundleA, bundleB still holds a reference on
- // bundleA.SomeBean
-
- // Reinstall bundleA
- bundleA = runtime.installBundle("jbosgi108-bundleA.jar");
- bundleA.start();
-
- // The static in bundleA.SomeBean is expected to be reused
-
- messages = report(someBean.getMessages());
- assertEquals("Start messages", 4, messages.size());
-
- bundleB.uninstall();
- bundleA.uninstall();
- }
-
- @Test
- public void testRedeployWithReferenceAndRefresh() throws Exception
- {
- OSGiBundle bundleA = runtime.installBundle("jbosgi108-bundleA.jar");
- OSGiBundle bundleB = runtime.installBundle("jbosgi108-bundleB.jar");
-
- bundleA.start();
- bundleB.start();
-
- SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
- List<String> messages = report(someBean.getMessages());
- assertEquals("Start messages", 2, messages.size());
-
- bundleA.uninstall();
-
- // After uninstall bundleA, bundleB still holds a reference on
- // bundleA.SomeBean
-
- // Refresh all packages
- OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
- packageAdmin.refreshPackages(null);
-
- // Reinstall bundleA
- bundleA = runtime.installBundle("jbosgi108-bundleA.jar");
- bundleA.start();
-
- // The static in bundleA.SomeBean is expected to be recreated
-
- messages = report(someBean.getMessages());
- assertEquals("Start messages", 1, messages.size());
-
- bundleB.uninstall();
- bundleA.uninstall();
- }
-
- private List<String> report(List<String> messages)
- {
- // System.out.println(">>>>>>>>>>>>");
- // for (String aux : messages)
- // System.out.println(aux);
- // System.out.println("<<<<<<<<<<<");
-
- return messages;
- }
-}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java (from rev 90880, projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi108/OSGI108TestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/OSGI99TestCase.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -0,0 +1,73 @@
+/*
+ * 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.jbosgi99;
+
+//$Id: OSGI39TestCase.java 87103 2009-04-09 22:18:31Z thomas.diesler at jboss.com $
+
+import static org.junit.Assert.assertEquals;
+
+import org.jboss.osgi.spi.testing.OSGiBundle;
+import org.jboss.osgi.spi.testing.OSGiRuntime;
+import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * [JBOSGI-99] No explicit control over bundle.start()
+ *
+ * https://jira.jboss.org/jira/browse/JBOSGI-99
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 08-Jul-2009
+ */
+public class OSGI99TestCase
+{
+ private static OSGiRuntime runtime;
+
+ @BeforeClass
+ public static void beforeClass() throws BundleException
+ {
+ runtime = new OSGiTestHelper().getDefaultRuntime();
+ }
+
+ @AfterClass
+ public static void afterClass() throws BundleException
+ {
+ if (runtime != null)
+ runtime.shutdown();
+ }
+
+ @Test
+ public void testInstallOnly() throws Exception
+ {
+ OSGiBundle bundleA = runtime.installBundle("jbosgi99-bundleA.jar");
+ assertEquals("Bundle installed", Bundle.INSTALLED, bundleA.getState());
+
+ bundleA.start();
+ assertEquals("Bundle active", Bundle.ACTIVE, bundleA.getState());
+
+ bundleA.uninstall();
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/ActivatorBundleA.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi108/bundleA/ActivatorBundleA.java 2009-07-07 07:31:04 UTC (rev 90880)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/ActivatorBundleA.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -19,57 +19,20 @@
* 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.jbosgi108.bundleA;
+package org.jboss.test.osgi.jbosgi99.bundleA;
//$Id: ServiceActivator.java 87064 2009-04-09 11:08:56Z thomas.diesler at jboss.com $
-import javax.management.MBeanServer;
-
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
public class ActivatorBundleA implements BundleActivator
{
- private SomeBean bean;
-
public void start(BundleContext context)
{
- bean = new SomeBean();
-
- // Register the MBean
- try
- {
- ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
- MBeanServer service = (MBeanServer)context.getService(sref);
- service.registerMBean(bean, SomeBean.MBEAN_NAME);
- }
- catch (Exception ex)
- {
- throw new IllegalStateException(ex);
- }
-
- ClassLoader cl = getClass().getClassLoader();
- String msg = "start with " + cl + " - hashCode: " + cl.hashCode();
- bean.addMessage(msg);
}
public void stop(BundleContext context)
{
- ClassLoader cl = getClass().getClassLoader();
- String msg = "stop with " + cl + " - hashCode: " + cl.hashCode();
- bean.addMessage(msg);
-
- // Register the MBean
- try
- {
- ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
- MBeanServer service = (MBeanServer)context.getService(sref);
- service.unregisterMBean(SomeBean.MBEAN_NAME);
- }
- catch (Exception ex)
- {
- throw new IllegalStateException(ex);
- }
}
}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/SomeBean.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi108/bundleA/SomeBean.java 2009-07-07 07:31:04 UTC (rev 90880)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/SomeBean.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -1,43 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.osgi.jbosgi108.bundleA;
-
-//$Id$
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class SomeBean implements SomeBeanMBean
-{
- private static List<String> messages = new ArrayList<String>();
-
- public void addMessage(String msg)
- {
- messages.add(msg);
- }
-
- public List<String> getMessages()
- {
- return Collections.unmodifiableList(messages);
- }
-}
Deleted: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/SomeBeanMBean.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi108/bundleA/SomeBeanMBean.java 2009-07-07 07:31:04 UTC (rev 90880)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi99/bundleA/SomeBeanMBean.java 2009-07-08 10:12:31 UTC (rev 90925)
@@ -1,37 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.osgi.jbosgi108.bundleA;
-
-import java.util.List;
-
-import javax.management.ObjectName;
-
-import org.jboss.osgi.spi.management.ObjectNameFactory;
-
-//$Id$
-
-public interface SomeBeanMBean
-{
- ObjectName MBEAN_NAME = ObjectNameFactory.create("jboss.osgi:bean=SomeBean");
-
- List<String> getMessages();
-}
Copied: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99 (from rev 90880, projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi108)
Deleted: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi108-bundleA.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi108/jbosgi108-bundleA.bnd 2009-07-07 07:31:04 UTC (rev 90880)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi108-bundleA.bnd 2009-07-08 10:12:31 UTC (rev 90925)
@@ -1,6 +0,0 @@
-# bnd build -classpath target/test-classes -output target/test-libs/jbosgi108-bundleA.jar src/test/resources/jbosgi108/jbosgi108-bundleA.bnd
-
-Bundle-SymbolicName: jbosgi108-bundleA
-Bundle-Activator: org.jboss.test.osgi.jbosgi108.bundleA.ActivatorBundleA
-Export-Package: org.jboss.test.osgi.jbosgi108.bundleA
-
Deleted: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi108-bundleB.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi108/jbosgi108-bundleB.bnd 2009-07-07 07:31:04 UTC (rev 90880)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi108-bundleB.bnd 2009-07-08 10:12:31 UTC (rev 90925)
@@ -1,7 +0,0 @@
-# bnd build -classpath target/test-classes -output target/test-libs/jbosgi108-bundleB.jar src/test/resources/jbosgi108/jbosgi108-bundleB.bnd
-
-Bundle-SymbolicName: jbosgi108-bundleB
-Bundle-Activator: org.jboss.test.osgi.jbosgi108.bundleB.ActivatorBundleB
-Export-Package: org.jboss.test.osgi.jbosgi108.bundleB
-Import-Package: org.osgi.framework, org.jboss.test.osgi.jbosgi108.bundleA
-
Copied: projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd (from rev 90880, projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi108/jbosgi108-bundleA.bnd)
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/jbosgi99/jbosgi99-bundleA.bnd 2009-07-08 10:12:31 UTC (rev 90925)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/jbosgi99-bundleA.jar src/test/resources/jbosgi99/jbosgi99-bundleA.bnd
+
+Bundle-SymbolicName: jbosgi99-bundleA
+Bundle-Activator: org.jboss.test.osgi.jbosgi99.bundleA.ActivatorBundleA
+Export-Package: org.jboss.test.osgi.jbosgi99.bundleA
+
More information about the jboss-cvs-commits
mailing list