The Kit Manager Service supports installing/uninstalling bundles by using scripts.
Overview
The Kit Manager Service supports installing/uninstalling bundles by using scripts. This allows you to specify all necessary bundles to form a kit and the correct order for installing them. The service is represented by the com.prosyst.mbs.services.kitmanager.KitManagerService interface.
Registering Bundle
This service is registered by Util Kit Manager Bundle.
Installing Kits
By calling the installKit method of the Kit Manager Service (com.prosyst.mbs.services.kitmanager.KitManagerService) you can install kits in the framework. This method takes two parameters:
The installKit method returns an InstallStatus object that contains an eventual message about installation failure.
The example that follows loads in the Kit Manager Service an install script, called install.txt. Supposing that the install script and kitbundle.jar are placed in the c:/kit/ local directory, the mbs.script.base property is preliminary set to file:///c:/kit/ so that the service can find the script and forward its commands for execution. To avoid appending the bundle base URL to the script base URL, a "/" is placed in front of the bundle JAR location (see "Writing Your Own Scripts" section from the Util Kit Manager Bundle). An example code that loads install.txt with repair on can be:
Using the Kit Manager Service for installing kits is shown below:
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import com.prosyst.mbs.services.kitmanager.KitManagerService;
public class KitManTester implements BundleActivator {
ServiceReference kitManRef = null;
KitManagerService kitMan;
String location = "install.txt";
public void start(BundleContext bc) {
kitManRef = bc.getServiceReference(KitManagerService.class.getName());
if(kitManRef != null) {
kitMan = (KitManagerService)bc.getService(kitManRef);
}
try {
kitMan.installKit(location, true);
} catch(java.io.IOException ioexc) {
ioexc.printStackTrace();
}
}
public void stop(BundleContext bc) {
bc.ungetService(kitManRef);
}
}
Uninstalling Kits
If you want to uninstall a kit, you can use the uninstallKit method of the Kit Manager Service specifying the install script of the kit. The service retrieves the IDs of the kit's bundles from a custom database, called "KITMAN", in the DB Bundle. Next, a dependence analysis is performed to find out whether some external bundle depends on a bundle included in the kit or not. If such relation is discovered, no uninstallation is performed. Instead, the DependencyList object returned by the uninstallKit method lists all found dependencies.
The doUninstall flag of the uninstallKit method allows you to:
When the Kit Manager discovers kit dependencies, the bundle using it can prompt its users for the correct behavior, that is, whether to uninstall all bundles or to uninstall only independent bundles.
For example supposing that kit B depends on a bundle from kit A and the user wants to uninstall kit A. Consider the cases:
Listing Available Kits
You make the Kit Manager Service list the currently available kits by calling the listKits method. You receive a Vector of strings, which contains a kits' list formed using the rules discussed in "Adding Kits to the Kit Manager" section from the Util Kit Manager Bundle.
Viewing Kit's Status
Developers can also examine the status of a kit through the analyseKit method of the Kit Manager Service. The result is represented by a KitStatus object that wraps the status of the kit, which can be "installed", "not installed", "present" and with "bad script". You can also get the status of the kit's bundles.