Author: cziegeler
Date: Thu Aug 12 07:09:59 2010
New Revision: 984661
URL: http://svn.apache.org/viewvc?rev=984661&view=rev
Log:
SLING-1643 : Add start level support
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java?rev=984661&r1=984660&r2=984661&view=diff
==============================================================================
---
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
(original)
+++
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
Thu Aug 12 07:09:59 2010
@@ -49,6 +49,12 @@ public class InstallableResource {
*/
public static final String TYPE_CONFIG = "config";
+ /**
+ * Optional parameter in the dictionary if a bundle is installed. If this
+ * is set with a valid start level, the bundle is installed in that start
level.
+ */
+ public static final String BUNDLE_START_LEVEL = "bundle.startlevel";
+
/** Default resource priority */
public static final int DEFAULT_PRIORITY = 100;
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java?rev=984661&r1=984660&r2=984661&view=diff
==============================================================================
---
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
(original)
+++
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
Thu Aug 12 07:09:59 2010
@@ -31,6 +31,7 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
import org.osgi.util.tracker.ServiceTracker;
/** TaskCreator that processes a list of bundle RegisteredResources */
@@ -39,9 +40,15 @@ class BundleTaskCreator {
/** Interface of the package admin */
private static String PACKAGE_ADMIN_NAME = PackageAdmin.class.getName();
+ /** Interface of the start level */
+ private static String START_LEVEL_NAME = StartLevel.class.getName();
+
/** Tracker for the package admin. */
private final ServiceTracker packageAdminTracker;
+ /** Tracker for the start level service. */
+ private final ServiceTracker startLevelTracker;
+
/** Store the digests of the bundles for which we create update tasks,
* keyed by symbolic name, to avoid generating repated updates
* for snapshot bundles
@@ -52,10 +59,13 @@ class BundleTaskCreator {
// create and start tracker
this.packageAdminTracker = new ServiceTracker(bc, PACKAGE_ADMIN_NAME,
null);
this.packageAdminTracker.open();
+ this.startLevelTracker = new ServiceTracker(bc, START_LEVEL_NAME,
null);
+ this.startLevelTracker.open();
}
public void deactivate() {
this.packageAdminTracker.close();
+ this.startLevelTracker.close();
}
/** Holds the bundle info that we need, makes it easier to test
@@ -119,7 +129,7 @@ class BundleTaskCreator {
if (info == null) {
// bundle is not installed yet: install and save
digest to avoid
// unnecessary updates
- tasks.add(new BundleInstallTask(toActivate));
+ tasks.add(new BundleInstallTask(toActivate,
this.startLevelTracker));
digestToSave = toActivate.getDigest();
} else {
final int compare =
info.version.compareTo(newVersion);
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java?rev=984661&r1=984660&r2=984661&view=diff
==============================================================================
---
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
(original)
+++
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
Thu Aug 12 07:09:59 2010
@@ -96,7 +96,7 @@ public class RegisteredResourceImpl impl
throw new IllegalArgumentException("InputStream is required
for BUNDLE resource type: " + input);
}
try {
- dictionary = null;
+ dictionary = copy(input.getDictionary());
final File f = getDataFile();
Logger.logDebug("Copying data to local storage " +
f.getAbsolutePath());
copyToLocalStorage(input.getInputStream(), f);
@@ -193,7 +193,10 @@ public class RegisteredResourceImpl impl
}
/** Copy given Dictionary, sorting keys */
- static Dictionary<String, Object> copy(Dictionary<String, Object> d) {
+ static Dictionary<String, Object> copy(final Dictionary<String, Object>
d) {
+ if ( d == null ) {
+ return null;
+ }
final Dictionary<String, Object> result = new Hashtable<String,
Object>();
final List<String> keys = new ArrayList<String>();
final Enumeration<String> e = d.keys();
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java?rev=984661&r1=984660&r2=984661&view=diff
==============================================================================
---
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
(original)
+++
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
Thu Aug 12 07:09:59 2010
@@ -18,12 +18,16 @@
*/
package org.apache.sling.osgi.installer.impl.tasks;
+import org.apache.sling.osgi.installer.InstallableResource;
+import org.apache.sling.osgi.installer.impl.Logger;
import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
import org.apache.sling.osgi.installer.impl.RegisteredResource;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
+import org.osgi.service.startlevel.StartLevel;
+import org.osgi.util.tracker.ServiceTracker;
/** Install a bundle supplied as a RegisteredResource.
* Creates a BundleStartTask to start the bundle */
@@ -33,8 +37,11 @@ public class BundleInstallTask extends O
private final RegisteredResource resource;
- public BundleInstallTask(RegisteredResource r) {
+ private final ServiceTracker startLevelServiceTracker;
+
+ public BundleInstallTask(final RegisteredResource r, final ServiceTracker
startLevelServiceTracker) {
this.resource = r;
+ this.startLevelServiceTracker = startLevelServiceTracker;
}
@Override
@@ -45,9 +52,27 @@ public class BundleInstallTask extends O
/**
* @see
org.apache.sling.osgi.installer.impl.OsgiInstallerTask#execute(org.apache.sling.osgi.installer.impl.OsgiInstallerContext)
*/
- public Result execute(OsgiInstallerContext ctx) {
+ public Result execute(final OsgiInstallerContext ctx) {
+ int startLevel = 0;
+ final Object providedLevel = (this.resource.getDictionary() != null
+ ?
this.resource.getDictionary().get(InstallableResource.BUNDLE_START_LEVEL) :
null);
+ if ( providedLevel != null ) {
+ if ( providedLevel instanceof Number ) {
+ startLevel = ((Number)providedLevel).intValue();
+ } else {
+ startLevel = Integer.valueOf(providedLevel.toString());
+ }
+ }
+ // get the start level service (if possible) so we can set the initial
start level
+ final StartLevel startLevelService = (StartLevel)
startLevelServiceTracker.getService();
try {
final Bundle b =
ctx.getBundleContext().installBundle(resource.getURL(),
resource.getInputStream());
+ // optionally set the start level
+ if (startLevelService != null && startLevel > 0) {
+ startLevelService.setBundleStartLevel(b, startLevel);
+ } else {
+ Logger.logWarn("Ignoring start level " + startLevel + " for
bundle " + b + " - start level service not available.");
+ }
final Version newVersion = new
Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
ctx.saveInstalledBundleInfo(b, resource.getDigest(),
newVersion.toString());
logExecution();
Modified:
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java?rev=984661&r1=984660&r2=984661&view=diff
==============================================================================
---
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java
(original)
+++
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java
Thu Aug 12 07:09:59 2010
@@ -72,7 +72,7 @@ public class TaskOrderingTest {
new ConfigInstallTask(getRegisteredResource("test:a"), null),
new BundleRemoveTask(getRegisteredResource("test:url"),
null),
new BundleUpdateTask(getRegisteredResource("test:url"),
null),
- new BundleInstallTask(getRegisteredResource("test:url")),
+ new BundleInstallTask(getRegisteredResource("test:url"),
null),
new SynchronousRefreshPackagesTask(null),
new BundleStartTask(0),
};
@@ -126,8 +126,8 @@ public class TaskOrderingTest {
public void testMultipleConfigAndBundles() throws Exception {
int testIndex = 1;
final OsgiInstallerTask [] tasksInOrder = {
- new
BundleInstallTask(getRegisteredResource("test:someURIa.nothing")),
- new
BundleInstallTask(getRegisteredResource("test:someURIb.nothing")),
+ new
BundleInstallTask(getRegisteredResource("test:someURIa.nothing"), null),
+ new
BundleInstallTask(getRegisteredResource("test:someURIb.nothing"), null),
new SynchronousRefreshPackagesTask(null),
new BundleStartTask(0),
};