FELIX-4167: do not try to start or stop fragment bundles.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1504843 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
index 8ecd9d8..08bb2e0 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
@@ -22,6 +22,8 @@
import java.util.List;
import java.util.ListIterator;
+import org.apache.felix.deploymentadmin.Constants;
+import org.osgi.framework.Bundle;
import org.osgi.service.deploymentadmin.DeploymentException;
/**
@@ -105,7 +107,7 @@
protected void addCommit(Runnable runnable) {
m_commit.add(runnable);
}
-
+
/**
* Sets the command to being cancelled, this does not have an immediate effect. Commands that are executing should
* check regularly if they were cancelled and if so they should make an effort to stop their operations as soon as possible
@@ -114,4 +116,14 @@
public void cancel() {
m_cancelled = true;
}
+
+ /**
+ * Determines whether a given bundle is actually a fragment bundle.
+ * @param bundle the bundle to test, cannot be <code>null</code>.
+ * @return <code>true</code> if the given bundle is actually a fragment bundle, <code>false</code> otherwise.
+ */
+ static final boolean isFragmentBundle(Bundle bundle) {
+ Object fragmentHost = bundle.getHeaders().get(Constants.FRAGMENT_HOST);
+ return fragmentHost != null;
+ }
}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
index 202cde3..3df2169 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
@@ -48,14 +48,18 @@
BundleInfoImpl[] bundleInfos = source.getOrderedBundleInfos();
for (int i = 0; i < bundleInfos.length; i++) {
BundleInfoImpl bundleInfoImpl = bundleInfos[i];
- if(!bundleInfoImpl.isCustomizer()) {
+ if (!bundleInfoImpl.isCustomizer()) {
Bundle bundle = source.getBundle(bundleInfoImpl.getSymbolicName());
if (bundle != null) {
- try {
- bundle.start();
- }
- catch (BundleException be) {
- log.log(LogService.LOG_WARNING, "Could not start bundle '" + bundle.getSymbolicName() + "'", be);
+ if (isFragmentBundle(bundle)) {
+ log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + bundle.getSymbolicName() + "'");
+ } else {
+ try {
+ bundle.start();
+ }
+ catch (BundleException be) {
+ log.log(LogService.LOG_WARNING, "Could not start bundle '" + bundle.getSymbolicName() + "'", be);
+ }
}
}
else {
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
index ca1258d..164f4d7 100644
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
+++ b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
@@ -39,6 +39,8 @@
public void execute(DeploymentSessionImpl session) throws DeploymentException {
String stopUnaffectedBundle = System.getProperty("org.apache.felix.deploymentadmin.stopunaffectedbundle", "true");
+
+ LogService log = session.getLog();
AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
BundleInfo[] bundleInfos = target.getOrderedBundleInfos();
@@ -52,16 +54,20 @@
if ("false".equalsIgnoreCase(stopUnaffectedBundle) && omitBundleStop(session, symbolicName)) {
continue;
}
- addRollback(new StartBundleRunnable(session, bundle));
- try {
- bundle.stop();
- }
- catch (BundleException e) {
- session.getLog().log(LogService.LOG_WARNING, "Could not stop bundle '" + bundle.getSymbolicName() + "'", e);
- }
+ if (isFragmentBundle(bundle)) {
+ log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + bundle.getSymbolicName() + "'");
+ } else {
+ addRollback(new StartBundleRunnable(session, bundle));
+ try {
+ bundle.stop();
+ }
+ catch (BundleException e) {
+ log.log(LogService.LOG_WARNING, "Could not stop bundle '" + bundle.getSymbolicName() + "'", e);
+ }
+ }
}
else {
- session.getLog().log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "' because it was not defined int he framework");
+ log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "' because it was not defined int he framework");
}
}
}