this.bundleStateListenerFactories = bundleStateListenerFactories;
}
protected Object doExecute() throws Exception {
ServiceReference ref = getBundleContext().getServiceReference(StartLevel.class.getName());
StartLevel sl = null;
if (ref != null) {
sl = (StartLevel) getBundleContext().getService(ref);
}
if (sl == null) {
System.out.println("StartLevel service is unavailable.");
}
ServiceReference pkgref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
PackageAdmin admin = null;
if (pkgref != null) {
admin = (PackageAdmin) getBundleContext().getService(pkgref);
if (admin == null) {
System.out.println("PackageAdmin service is unavailable.");
}
}
Bundle[] bundles = getBundleContext().getBundles();
if (bundles != null) {
// Determine threshold
final String sbslProp = bundleContext.getProperty("karaf.systemBundlesStartLevel");
if (sbslProp != null) {
try {
if (bundleLevelThreshold < 0) {
bundleLevelThreshold = Integer.valueOf( sbslProp );
}
}
catch( Exception ignore ) {
// ignore
}
}
// Display active start level.
if (sl != null) {
System.out.println("START LEVEL " + sl.getStartLevel() +
" , List Threshold: " + bundleLevelThreshold);
}
// Print column headers.
String msg = " Name";
if (showLoc) {
msg = " Location";
}
else if (showSymbolic) {
msg = " Symbolic name";
}
else if (showUpdate) {
msg = " Update location";
}
String level = (sl == null) ? "" : " Level ";
String headers = " ID State ";
for (BundleStateListener.Factory factory : bundleStateListenerFactories) {
BundleStateListener listener = factory.getListener();
if (listener != null) {
headers += " " + listener.getName() + " ";
}
}
headers += level + msg;
System.out.println(headers);
for (int i = 0; i < bundles.length; i++) {
if (sl.getBundleStartLevel(bundles[i]) >= bundleLevelThreshold) {
// Get the bundle name or location.
String name = (String) bundles[i].getHeaders().get(Constants.BUNDLE_NAME);
// If there is no name, then default to symbolic name.
name = (name == null) ? bundles[i].getSymbolicName() : name;
// If there is no symbolic name, resort to location.
name = (name == null) ? bundles[i].getLocation() : name;
// Overwrite the default value is the user specifically
// requested to display one or the other.
if (showLoc) {
name = bundles[i].getLocation();
}
else if (showSymbolic) {
name = bundles[i].getSymbolicName();
name = (name == null) ? "<no symbolic name>" : name;
}
else if (showUpdate) {
name = (String) bundles[i].getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
name = (name == null) ? bundles[i].getLocation() : name;
}
// Show bundle version if not showing location.
String version = (String) bundles[i].getHeaders().get(Constants.BUNDLE_VERSION);
name = (!showLoc && !showUpdate && (version != null)) ? name + " (" + version + ")" : name;
long l = bundles[i].getBundleId();
String id = String.valueOf(l);
if (sl == null) {
level = "1";
}
else {
level = String.valueOf(sl.getBundleStartLevel(bundles[i]));
}
while (level.length() < 5) {
level = " " + level;
}
while (id.length() < 4) {