You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/09/13 16:43:48 UTC

svn commit: r996561 - in /sling/trunk/installer/osgi/installer/src: main/java/org/apache/sling/osgi/installer/impl/ main/java/org/apache/sling/osgi/installer/impl/config/ main/java/org/apache/sling/osgi/installer/impl/tasks/ test/java/org/apache/sling/...

Author: cziegeler
Date: Mon Sep 13 14:43:47 2010
New Revision: 996561

URL: http://svn.apache.org/viewvc?rev=996561&view=rev
Log:
SLING-1737 : Add state management for resources

Modified:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleInstallTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ChangeStateTask.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SystemBundleUpdateTask.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/TaskOrderingTest.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/EntityResourceList.java Mon Sep 13 14:43:47 2010
@@ -45,8 +45,49 @@ public class EntityResourceList implemen
         return resources.isEmpty();
     }
 
-    public RegisteredResource getFirst() {
-        return resources.first();
+    /**
+     * Return the first resource if it either needs to be installed or uninstalled.
+     */
+    public RegisteredResource getActiveResource() {
+        if ( !resources.isEmpty() ) {
+            final RegisteredResource r = resources.first();
+            if ( r.getState() == RegisteredResource.State.INSTALL
+              || r.getState() == RegisteredResource.State.UNINSTALL ) {
+                return r;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Set the finish state for the resource.
+     * If this resource has been uninstalled, check the next in the list if it needs to
+     * be reactivated.
+     */
+    public void setFinishState(final RegisteredResource.State state) {
+        final RegisteredResource toActivate = getActiveResource();
+        if ( toActivate != null
+             && toActivate.getState() == RegisteredResource.State.UNINSTALL
+             && this.resources.size() > 1 ) {
+
+            // to get the second item in the set we have to use an iterator!
+            final Iterator<RegisteredResource> i = this.resources.iterator();
+            i.next(); // skip first
+            final RegisteredResource second = i.next();
+            if ( state == RegisteredResource.State.UNINSTALLED ) {
+                // first resource got uninstalled, go back to second
+                if (second.getState() == RegisteredResource.State.IGNORED || second.getState() == RegisteredResource.State.INSTALLED) {
+                    LOGGER.debug("Reactivating for next cycle: {}", second);
+                    second.setState(RegisteredResource.State.INSTALL);
+                }
+            } else {
+                // don't install as the first did not get uninstalled
+                if ( second.getState() == RegisteredResource.State.INSTALL ) {
+                    second.setState(RegisteredResource.State.IGNORED);
+                }
+            }
+        }
+        toActivate.setState(state);
     }
 
     public Collection<RegisteredResource> getResources() {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java Mon Sep 13 14:43:47 2010
@@ -138,6 +138,7 @@ public class OsgiInstallerImpl
     public void run() {
         this.init();
         while (active) {
+            this.mergeNewResources();
             final boolean tasksToDo = this.hasOpenTasks();
             final SortedSet<OsgiInstallerTask> tasks = this.computeTasks();
 
@@ -347,45 +348,8 @@ public class OsgiInstallerImpl
             }
             urlsToRemove.clear();
 
-            // if we have changes we have to process the resources per entity to update states
             if ( changed ) {
                 printResources("Merged");
-                for(final String entityId : this.persistentList.getEntityIds()) {
-                    final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
-                    if ( !group.isEmpty() ) {
-
-                        // The first resource in each group defines what should be done within this group.
-                        // This is based on the state of the first resource:
-                        // INSTALL : Install this resource and ignore all others in the group
-                        // UNINSTALL : Uninstall this resource and set the next resource in the group to INSTALL
-                        //             if it has either state IGNORE or INSTALLED
-                        // INSTALLED : Nothing to do
-                        // IGNORED   : Nothing to do
-                        // UNINSTALLED : This can't happen - but we do nothing in this case anyway
-
-                        final Iterator<RegisteredResource> i = group.getResources().iterator();
-                        final RegisteredResource first = i.next();
-
-                        RegisteredResource toActivate = null;
-                        switch ( first.getState() ) {
-                            case UNINSTALL : toActivate = first;
-                                             break;
-                            case INSTALL   : toActivate = first;
-                                             break;
-                        }
-                        if ( toActivate != null ) {
-                            logger.debug("Activating {}", toActivate);
-                            if ( toActivate.getState() == RegisteredResource.State.UNINSTALL && i.hasNext() ) {
-                                final RegisteredResource r = i.next();;
-                                if (r.getState() == RegisteredResource.State.IGNORED || r.getState() == RegisteredResource.State.INSTALLED) {
-                                    logger.debug("Reactivating for next cycle {}", r);
-                                    r.setState(RegisteredResource.State.INSTALL);
-                                }
-                            }
-                        }
-                    }
-                }
-                printResources("Prepared");
                 // persist list
                 this.persistentList.save();
             }
@@ -396,13 +360,8 @@ public class OsgiInstallerImpl
         // check if there is something to do
         for(final String entityId : this.persistentList.getEntityIds()) {
             final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
-            if ( !group.isEmpty() ) {
-                final RegisteredResource first = group.getFirst();
-
-                if ( first != null &&
-                     (first.getState() == RegisteredResource.State.UNINSTALL || first.getState() == RegisteredResource.State.INSTALL) ) {
-                    return true;
-                }
+            if ( group.getActiveResource() != null ) {
+                return true;
             }
         }
         return false;
@@ -448,12 +407,9 @@ public class OsgiInstallerImpl
         // Walk the list of entities, and create appropriate OSGi tasks for each group
         for(final String entityId : this.persistentList.getEntityIds()) {
             final EntityResourceList group = this.persistentList.getEntityResourceList(entityId);
-            if ( !group.isEmpty() ) {
-
-                // Check the first resource in each group
-                final Iterator<RegisteredResource> i = group.getResources().iterator();
-                final RegisteredResource first = i.next();
-
+            // Check the first resource in each group
+            final RegisteredResource first = group.getActiveResource();
+            if ( first != null ) {
                 RegisteredResource toActivate = null;
                 switch ( first.getState() ) {
                     case UNINSTALL : toActivate = first;
@@ -465,9 +421,9 @@ public class OsgiInstallerImpl
                     final String rt = toActivate.getType();
                     final OsgiInstallerTask task;
                     if ( InstallableResource.TYPE_BUNDLE.equals(rt) ) {
-                        task = bundleTaskCreator.createTask(toActivate);
+                        task = bundleTaskCreator.createTask(group);
                     } else if ( InstallableResource.TYPE_CONFIG.equals(rt) ) {
-                        task = configTaskCreator.createTask(toActivate);
+                        task = configTaskCreator.createTask(group);
                     } else {
                         task = null;
                     }

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java Mon Sep 13 14:43:47 2010
@@ -27,19 +27,29 @@ import org.slf4j.LoggerFactory;
  */
 public abstract class OsgiInstallerTask implements Comparable<OsgiInstallerTask> {
 
-    private final RegisteredResource resource;
+    private final EntityResourceList entityResourceList;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
-    public OsgiInstallerTask(final RegisteredResource r) {
-        this.resource = r;
+    public OsgiInstallerTask(final EntityResourceList erl) {
+        this.entityResourceList = erl;
     }
 
     /**
      * Return the corresponding resource - depending on the task this might be null.
      */
     public RegisteredResource getResource() {
-        return this.resource;
+        if ( this.entityResourceList != null ) {
+            return this.entityResourceList.getActiveResource();
+        }
+        return null;
+    }
+
+    /**
+     * Return the corresponding resource - depending on the task this might be null.
+     */
+    public EntityResourceList getEntityResourceList() {
+        return this.entityResourceList;
     }
 
     public Logger getLogger() {
@@ -56,9 +66,13 @@ public abstract class OsgiInstallerTask 
 		return getSortKey().compareTo(o.getSortKey());
 	}
 
+	public void setFinishedState(final RegisteredResource.State state) {
+	    this.entityResourceList.setFinishState(state);
+	}
+
     @Override
     public String toString() {
-        return getClass().getSimpleName() + ": " + resource;
+        return getClass().getSimpleName() + ": " + this.getResource();
     }
 
     @Override

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/AbstractConfigTask.java Mon Sep 13 14:43:47 2010
@@ -24,8 +24,8 @@ import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
-import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
@@ -48,11 +48,11 @@ abstract class AbstractConfigTask extend
     /** Tracker for the configuration admin. */
     private final ServiceTracker configAdminServiceTracker;
 
-    AbstractConfigTask(final RegisteredResource r, final ServiceTracker configAdminServiceTracker) {
+    AbstractConfigTask(final EntityResourceList r, final ServiceTracker configAdminServiceTracker) {
         super(r);
         this.configAdminServiceTracker = configAdminServiceTracker;
-        this.configPid = (String)r.getAttributes().get(Constants.SERVICE_PID);
-        this.factoryPid = (String)r.getAttributes().get(ConfigurationAdmin.SERVICE_FACTORYPID);
+        this.configPid = (String)getResource().getAttributes().get(Constants.SERVICE_PID);
+        this.factoryPid = (String)getResource().getAttributes().get(ConfigurationAdmin.SERVICE_FACTORYPID);
     }
 
     /**

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigInstallTask.java Mon Sep 13 14:43:47 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl.config;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.service.cm.Configuration;
@@ -31,7 +32,7 @@ public class ConfigInstallTask extends A
 
     private static final String CONFIG_INSTALL_ORDER = "20-";
 
-    public ConfigInstallTask(final RegisteredResource r, final ServiceTracker configAdminServiceTracker) {
+    public ConfigInstallTask(final EntityResourceList r, final ServiceTracker configAdminServiceTracker) {
         super(r, configAdminServiceTracker);
     }
 
@@ -71,12 +72,12 @@ public class ConfigInstallTask extends A
                 }
                 config.update(getResource().getDictionary());
                 ctx.log("Installed configuration {} from resource {}", config.getPid(), getResource());
-                this.getResource().setState(RegisteredResource.State.INSTALLED);
+                this.setFinishedState(RegisteredResource.State.INSTALLED);
                 this.getLogger().debug("Configuration " + config.getPid()
                             + " " + (created ? "created" : "updated")
                             + " from " + getResource());
             } else {
-                this.getResource().setState(RegisteredResource.State.IGNORED);
+                this.setFinishedState(RegisteredResource.State.IGNORED);
             }
         } catch (Exception e) {
             this.getLogger().debug("Exception during installation of config " + this.getResource() + " : " + e.getMessage() + ". Retrying later.", e);

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigRemoveTask.java Mon Sep 13 14:43:47 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl.config;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.service.cm.Configuration;
@@ -29,7 +30,7 @@ public class ConfigRemoveTask extends Ab
 
     private static final String CONFIG_REMOVE_ORDER = "10-";
 
-    public ConfigRemoveTask(final RegisteredResource r,
+    public ConfigRemoveTask(final EntityResourceList r,
             final ServiceTracker configAdminServiceTracker) {
         super(r, configAdminServiceTracker);
     }
@@ -54,19 +55,19 @@ public class ConfigRemoveTask extends Ab
             final Configuration cfg = getConfiguration(ca, false);
             if (cfg == null) {
                 this.getLogger().debug("Cannot delete config , pid={} not found, ignored ({})", getCompositePid(), getResource());
-                this.getResource().setState(RegisteredResource.State.IGNORED);
+                this.setFinishedState(RegisteredResource.State.IGNORED);
             } else {
                 if ( cfg.getProperties().get(ConfigTaskCreator.CONFIG_PATH_KEY) == null ) {
                     this.getLogger().debug("Configuration has not been installed by this resource. Not removing!");
-                    this.getResource().setState(RegisteredResource.State.IGNORED);
+                    this.setFinishedState(RegisteredResource.State.IGNORED);
                 } else if ( !isSameData(cfg.getProperties(), this.getResource().getDictionary()) ) {
                     this.getLogger().debug("Configuration has changed after is has been installed. Not removing!");
-                    this.getResource().setState(RegisteredResource.State.IGNORED);
+                    this.setFinishedState(RegisteredResource.State.IGNORED);
                 } else {
                     this.getLogger().debug("Deleting config {} ({})", getCompositePid(), getResource());
                     cfg.delete();
                     ctx.log("Deleted configuration {} from resource {}", getCompositePid(), getResource());
-                    this.getResource().setState(RegisteredResource.State.UNINSTALLED);
+                    this.setFinishedState(RegisteredResource.State.UNINSTALLED);
                 }
             }
         } catch (Exception e) {

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/config/ConfigTaskCreator.java Mon Sep 13 14:43:47 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl.config;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.framework.BundleContext;
@@ -57,13 +58,13 @@ public class ConfigTaskCreator {
 	/**
      * Create a task to install or uninstall a configuration.
 	 */
-	public OsgiInstallerTask createTask(final RegisteredResource toActivate) {
+	public OsgiInstallerTask createTask(final EntityResourceList toActivate) {
 	    // if there is no config admin, just return
 	    if ( this.configAdminServiceTracker.getService() == null ) {
             return null;
 	    }
 	    final OsgiInstallerTask result;
-		if (toActivate.getState() == RegisteredResource.State.UNINSTALL) {
+		if (toActivate.getActiveResource().getState() == RegisteredResource.State.UNINSTALL) {
 		    result = new ConfigRemoveTask(toActivate, this.configAdminServiceTracker);
 		} else {
 	        result = new ConfigInstallTask(toActivate, this.configAdminServiceTracker);

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=996561&r1=996560&r2=996561&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 Mon Sep 13 14:43:47 2010
@@ -19,9 +19,9 @@
 package org.apache.sling.osgi.installer.impl.tasks;
 
 import org.apache.sling.osgi.installer.InstallableResource;
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 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.service.startlevel.StartLevel;
 
@@ -33,7 +33,7 @@ public class BundleInstallTask extends O
 
     private final BundleTaskCreator creator;
 
-    public BundleInstallTask(final RegisteredResource r,
+    public BundleInstallTask(final EntityResourceList r,
             final BundleTaskCreator creator) {
         super(r);
         this.creator = creator;
@@ -70,7 +70,7 @@ public class BundleInstallTask extends O
 
             // mark this resource as installed and to be started
             this.getResource().getAttributes().put(BundleTaskCreator.ATTR_START, "true");
-            ctx.addTaskToCurrentCycle(new BundleStartTask(getResource(), b.getBundleId(), this.creator));
+            ctx.addTaskToCurrentCycle(new BundleStartTask(getEntityResourceList(), b.getBundleId(), this.creator));
         } catch (Exception ex) {
             // if something goes wrong we simply try it again
             this.getLogger().debug("Exception during install of bundle " + this.getResource() + " : " + ex.getMessage() + ". Retrying later.", ex);

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleRemoveTask.java Mon Sep 13 14:43:47 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl.tasks;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
@@ -35,7 +36,7 @@ public class BundleRemoveTask extends Os
 
     private final BundleTaskCreator creator;
 
-    public BundleRemoveTask(final RegisteredResource r,
+    public BundleRemoveTask(final EntityResourceList r,
                             final BundleTaskCreator creator) {
         super(r);
         this.creator = creator;
@@ -49,7 +50,7 @@ public class BundleRemoveTask extends Os
         final Bundle b = this.creator.getMatchingBundle(symbolicName);
         if (b == null) {
             // nothing to do, so just stop
-            this.getResource().setState(RegisteredResource.State.UNINSTALLED);
+            this.setFinishedState(RegisteredResource.State.UNINSTALLED);
             return;
         }
         final int state = b.getState();
@@ -59,7 +60,7 @@ public class BundleRemoveTask extends Os
             }
             b.uninstall();
             ctx.log("Uninstalled bundle {} from resource {}", b, getResource());
-            this.getResource().setState(RegisteredResource.State.UNINSTALLED);
+            this.setFinishedState(RegisteredResource.State.UNINSTALLED);
             ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.creator));
         } catch (final BundleException be) {
             this.getLogger().debug("Exception during removal of bundle " + this.getResource() + " : " + be.getMessage() + ". Retrying later.", be);

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java Mon Sep 13 14:43:47 2010
@@ -20,6 +20,7 @@ package org.apache.sling.osgi.installer.
 
 import java.text.DecimalFormat;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerImpl;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
@@ -43,7 +44,7 @@ public class BundleStartTask extends Osg
 
 	private final BundleTaskCreator creator;
 
-	public BundleStartTask(final RegisteredResource r, final long bundleId, final BundleTaskCreator btc) {
+	public BundleStartTask(final EntityResourceList r, final long bundleId, final BundleTaskCreator btc) {
 	    super(r);
 		this.bundleId = bundleId;
 		this.creator = btc;
@@ -68,7 +69,7 @@ public class BundleStartTask extends Osg
         if (bundleId == 0) {
             this.getLogger().debug("Bundle 0 is the framework bundle, ignoring request to start it");
             if ( this.getResource() != null ) {
-                this.getResource().setState(RegisteredResource.State.INSTALLED);
+                this.setFinishedState(RegisteredResource.State.INSTALLED);
             }
             return;
         }
@@ -93,7 +94,7 @@ public class BundleStartTask extends Osg
         if (b.getState() == Bundle.ACTIVE) {
             this.getLogger().debug("Bundle already started, no action taken: {}/{}", bundleId, b.getSymbolicName());
             if ( this.getResource() != null ) {
-                this.getResource().setState(RegisteredResource.State.INSTALLED);
+                this.setFinishedState(RegisteredResource.State.INSTALLED);
             }
             return;
         }
@@ -101,7 +102,7 @@ public class BundleStartTask extends Osg
         try {
             b.start();
             if ( this.getResource() != null ) {
-                this.getResource().setState(RegisteredResource.State.INSTALLED);
+                this.setFinishedState(RegisteredResource.State.INSTALLED);
             }
             this.getLogger().info("Bundle started (retry count={}, bundle ID={}) : {}",
                     new Object[] {retryCount, bundleId, b.getSymbolicName()});

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreator.java Mon Sep 13 14:43:47 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl.tasks;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
 import org.osgi.framework.Bundle;
@@ -115,7 +116,8 @@ public class BundleTaskCreator {
 	/**
      * Create a bundle task - install, update or remove
 	 */
-	public OsgiInstallerTask createTask(final RegisteredResource toActivate) {
+	public OsgiInstallerTask createTask(final EntityResourceList resourceList) {
+	    final RegisteredResource toActivate = resourceList.getActiveResource();
 	    final OsgiInstallerTask result;
 
         final String symbolicName = (String)toActivate.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
@@ -126,10 +128,10 @@ public class BundleTaskCreator {
 		    // Remove corresponding bundle if present and if we installed it
 		    if (info != null
 		        && info.version.equals(new Version((String)toActivate.getAttributes().get(Constants.BUNDLE_VERSION))) ) {
-		        result = new BundleRemoveTask(toActivate, this);
+		        result = new BundleRemoveTask(resourceList, this);
 		    } else {
 	            logger.info("Bundle {} was not installed by this module, not removed", symbolicName);
-	            result = new ChangeStateTask(toActivate, RegisteredResource.State.UNINSTALLED);
+	            result = new ChangeStateTask(resourceList, RegisteredResource.State.UNINSTALLED);
 	        }
 
 		// Install
@@ -137,9 +139,9 @@ public class BundleTaskCreator {
 		    // check if we should start the bundle as we installed it in the previous run
 		    if (info == null) {
 			    // bundle is not installed yet: install
-			    result = new BundleInstallTask(toActivate, this);
+			    result = new BundleInstallTask(resourceList, this);
 		    } else if ( toActivate.getAttributes().get(ATTR_START) != null ) {
-	            result = new BundleStartTask(toActivate, info.id, this);
+	            result = new BundleStartTask(resourceList, info.id, this);
 			} else {
 	            boolean doUpdate = false;
 
@@ -159,13 +161,13 @@ public class BundleTaskCreator {
 
                     logger.debug("Scheduling update of {}", toActivate);
                     if ( Constants.SYSTEM_BUNDLE_SYMBOLICNAME.equals(symbolicName) ) {
-                        result = new SystemBundleUpdateTask(toActivate, this);
+                        result = new SystemBundleUpdateTask(resourceList, this);
                     } else {
-                        result = new BundleUpdateTask(toActivate, this);
+                        result = new BundleUpdateTask(resourceList, this);
                     }
                 } else {
                     logger.debug("Nothing to install for {}, same version {} already installed.", toActivate, newVersion);
-                    result = new ChangeStateTask(toActivate, RegisteredResource.State.IGNORED);
+                    result = new ChangeStateTask(resourceList, RegisteredResource.State.IGNORED);
                 }
 			}
 		}

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java Mon Sep 13 14:43:47 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl.tasks;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
@@ -37,7 +38,7 @@ public class BundleUpdateTask extends Os
 
     private final BundleTaskCreator creator;
 
-    public BundleUpdateTask(final RegisteredResource r,
+    public BundleUpdateTask(final EntityResourceList r,
                             final BundleTaskCreator creator) {
         super(r);
         this.creator = creator;
@@ -51,7 +52,7 @@ public class BundleUpdateTask extends Os
         final Bundle b = this.creator.getMatchingBundle(symbolicName);
         if (b == null) {
             this.getLogger().debug("Bundle to update ({}) not found", symbolicName);
-            this.getResource().setState(RegisteredResource.State.IGNORED);
+            this.setFinishedState(RegisteredResource.State.IGNORED);
             return;
         }
 
@@ -64,7 +65,7 @@ public class BundleUpdateTask extends Os
     	if (currentVersion.equals(newVersion) && !snapshot) {
     	    // TODO : Isn't this already checked in the task creator?
     	    this.getLogger().debug("Same version is already installed, and not a snapshot, ignoring update: {}", getResource());
-            this.getResource().setState(RegisteredResource.State.INSTALLED);
+    	    this.setFinishedState(RegisteredResource.State.INSTALLED);
     		return;
     	}
 
@@ -79,16 +80,16 @@ public class BundleUpdateTask extends Os
 
             if (reactivate) {
                 this.getResource().getAttributes().put(BundleTaskCreator.ATTR_START, "true");
-                ctx.addTaskToCurrentCycle(new BundleStartTask(getResource(), b.getBundleId(), this.creator));
+                ctx.addTaskToCurrentCycle(new BundleStartTask(this.getEntityResourceList(), b.getBundleId(), this.creator));
             } else {
-                this.getResource().setState(RegisteredResource.State.INSTALLED);
+                this.setFinishedState(RegisteredResource.State.INSTALLED);
             }
             ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask(this.creator));
             this.getLogger().debug("Bundle updated: {}/{}", b.getBundleId(), b.getSymbolicName());
     	} catch (Exception e) {
             if ( !canRetry ) {
                 this.getLogger().warn("Removing failing tasks - unable to retry: " + this, e);
-                this.getResource().setState(RegisteredResource.State.IGNORED);
+                this.setFinishedState(RegisteredResource.State.IGNORED);
             }
     	}
     }

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ChangeStateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ChangeStateTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ChangeStateTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ChangeStateTask.java Mon Sep 13 14:43:47 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.osgi.installer.impl.tasks;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
@@ -31,8 +32,8 @@ public class ChangeStateTask extends Osg
 
     private final RegisteredResource.State state;
 
-    public ChangeStateTask(final RegisteredResource r,
-                          final RegisteredResource.State s) {
+    public ChangeStateTask(final EntityResourceList r,
+                           final RegisteredResource.State s) {
         super(r);
         this.state = s;
     }
@@ -41,7 +42,7 @@ public class ChangeStateTask extends Osg
      * @see org.apache.sling.osgi.installer.impl.OsgiInstallerTask#execute(org.apache.sling.osgi.installer.impl.OsgiInstallerContext)
      */
     public void execute(final OsgiInstallerContext ctx) {
-        this.getResource().setState(this.state);
+        this.setFinishedState(this.state);
     }
 
     @Override

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SystemBundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SystemBundleUpdateTask.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SystemBundleUpdateTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SystemBundleUpdateTask.java Mon Sep 13 14:43:47 2010
@@ -21,9 +21,9 @@ package org.apache.sling.osgi.installer.
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 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.BundleException;
 import org.osgi.framework.Constants;
@@ -37,7 +37,7 @@ public class SystemBundleUpdateTask exte
 
     private final BundleTaskCreator creator;
 
-    public SystemBundleUpdateTask(final RegisteredResource r,
+    public SystemBundleUpdateTask(final EntityResourceList r,
             final BundleTaskCreator creator) {
         super(r);
         this.creator = creator;

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=996561&r1=996560&r2=996561&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 Mon Sep 13 14:43:47 2010
@@ -48,10 +48,12 @@ public class TaskOrderingTest {
 		taskSet = new TreeSet<OsgiInstallerTask>();
 	}
 
-	private static RegisteredResource getRegisteredResource(String url) throws IOException {
-		return RegisteredResourceImpl.create(null,
+	private static EntityResourceList getRegisteredResource(String url) throws IOException {
+	    final EntityResourceList erl = new EntityResourceList();
+	    erl.addOrUpdate(RegisteredResourceImpl.create(null,
 		        new InstallableResource(url, null, new Hashtable<String, Object>(), null, null, null),
-		        "test");
+		        "test"));
+	    return erl;
 	}
 
 	private void assertOrder(int testId, Collection<OsgiInstallerTask> actual, OsgiInstallerTask [] expected) {

Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java?rev=996561&r1=996560&r2=996561&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java (original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/tasks/BundleTaskCreatorTest.java Mon Sep 13 14:43:47 2010
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import org.apache.sling.osgi.installer.impl.EntityResourceList;
 import org.apache.sling.osgi.installer.impl.MockBundleResource;
 import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
 import org.apache.sling.osgi.installer.impl.RegisteredResource;
@@ -42,7 +43,9 @@ public class BundleTaskCreatorTest {
 	    }
 		final SortedSet<OsgiInstallerTask> tasks = new TreeSet<OsgiInstallerTask>();
         for(final RegisteredResource r : sortedResources) {
-  		    tasks.add(btc.createTask(r));
+            final EntityResourceList erl = new EntityResourceList();
+            erl.addOrUpdate(r);
+  		    tasks.add(btc.createTask(erl));
         }
 		return tasks;
 	}