/**
* @see org.apache.sling.installer.api.tasks.TaskResourceGroup#setFinishState(org.apache.sling.installer.api.tasks.ResourceState)
*/
public void setFinishState(ResourceState state) {
final TaskResource toActivate = getActiveResource();
if ( toActivate != null ) {
if ( toActivate.getState() == ResourceState.UNINSTALL
&& this.resources.size() > 1 ) {
final TaskResource second = this.getNextActiveResource();
if ( state == ResourceState.UNINSTALLED ) {
// first resource got uninstalled, go back to second
if (second.getState() == ResourceState.IGNORED || second.getState() == ResourceState.INSTALLED) {
LOGGER.debug("Reactivating for next cycle: {}", second);
((RegisteredResourceImpl)second).setState(ResourceState.INSTALL);
}
} else {
// don't install as the first did not get uninstalled
if ( second.getState() == ResourceState.INSTALL ) {
((RegisteredResourceImpl)second).setState(ResourceState.IGNORED);
}
// and now set resource to uninstalled
state = ResourceState.UNINSTALLED;
}
} else if ( state == ResourceState.INSTALLED ) {
// make sure that no other resource has state INSTALLED
if ( this.resources.size() > 1 ) {
// to get the second item in the set we have to use an iterator!
final Iterator<RegisteredResourceImpl> i = this.resources.iterator();
i.next(); // skip first
while ( i.hasNext() ) {
final TaskResource rsrc = i.next();
if ( rsrc.getState() == ResourceState.INSTALLED ) {
((RegisteredResourceImpl)rsrc).setState(ResourceState.INSTALL);
}
}
}
}
((RegisteredResourceImpl)toActivate).setState(state);
if ( state != ResourceState.INSTALLED ) {
// make sure to remove all install info attributes if the resource is not
// installed anymore
toActivate.setAttribute(TaskResource.ATTR_INSTALL_EXCLUDED, null);
toActivate.setAttribute(TaskResource.ATTR_INSTALL_INFO, null);
}
// remove install info attributes on all other resources in the group
final Iterator<RegisteredResourceImpl> tri = this.resources.iterator();
tri.next(); // skip first
while ( tri.hasNext() ) {
final TaskResource rsrc = tri.next();
rsrc.setAttribute(TaskResource.ATTR_INSTALL_EXCLUDED, null);
rsrc.setAttribute(TaskResource.ATTR_INSTALL_INFO, null);
}
this.listener.onEvent(new InstallationEvent() {
public TYPE getType() {