*
* @see org.apache.sling.installer.api.tasks.InstallTaskFactory#createTask(org.apache.sling.installer.api.tasks.TaskResourceGroup)
*/
public InstallTask createTask(final TaskResourceGroup resourceList) {
// quick check of the resource type.
final TaskResource toActivate = resourceList.getActiveResource();
if ( toActivate.getType().equals(PersistentResourceList.RESTART_ACTIVE_BUNDLES_TYPE) ) {
return new RestartActiveBundlesTask(resourceList, this.taskSupport);
}
if ( !toActivate.getType().equals(InstallableResource.TYPE_BUNDLE) ) {
return null;
}
// check if symbolic name and version is provided in the attributes
if ( toActivate.getAttribute(Constants.BUNDLE_SYMBOLICNAME) == null ) {
final Util.BundleHeaders headers = Util.readBundleHeaders(toActivate, logger);
if ( headers == null ) {
logger.info("Resource of type bundle {} is not really a bundle - manifest entries are missing.", toActivate);
return new ChangeStateTask(resourceList, ResourceState.IGNORED);
}
toActivate.setAttribute(Constants.BUNDLE_SYMBOLICNAME, headers.symbolicName);
toActivate.setAttribute(Constants.BUNDLE_VERSION, headers.version);
if ( headers.activationPolicy != null ) {
toActivate.setAttribute(Constants.BUNDLE_ACTIVATIONPOLICY, headers.activationPolicy);
}
}
final String symbolicName = (String)toActivate.getAttribute(Constants.BUNDLE_SYMBOLICNAME);
final boolean isInstallerCoreBundle = this.bundleContext.getBundle().getSymbolicName().equals(symbolicName);
// Uninstall
final InstallTask result;
if (toActivate.getState() == ResourceState.UNINSTALL) {
// find the info with the exact version
final BundleInfo info = this.getBundleInfo(
symbolicName,
(String)toActivate.getAttribute(Constants.BUNDLE_VERSION));
// Remove corresponding bundle if present and if we installed it
if ( info != null ) {
// if this is an uninstall, check if we have to install an older version
// in this case we should do an update instead of uninstall/install (!)
final TaskResource second = resourceList.getNextActiveResource();
if ( second != null &&
( second.getState() == ResourceState.IGNORED || second.getState() == ResourceState.INSTALLED || second.getState() == ResourceState.INSTALL ) ) {
second.setAttribute(FORCE_INSTALL_VERSION, info.version.toString());
BundleUtil.clearBundleStart(second);
logger.debug("Detected downgrade of bundle {}", symbolicName);
result = new ChangeStateTask(resourceList, ResourceState.UNINSTALLED);
} else {
// prevent uninstalling the installer itself!