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 2012/02/09 21:39:15 UTC

svn commit: r1242512 - in /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks: AbstractBundleTask.java BundleInstallTask.java BundleUpdateTask.java

Author: cziegeler
Date: Thu Feb  9 20:39:15 2012
New Revision: 1242512

URL: http://svn.apache.org/viewvc?rev=1242512&view=rev
Log:
SLING-2414 : Install bundles in the order of their start level

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/AbstractBundleTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/AbstractBundleTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/AbstractBundleTask.java?rev=1242512&r1=1242511&r2=1242512&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/AbstractBundleTask.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/AbstractBundleTask.java Thu Feb  9 20:39:15 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.installer.core.impl.tasks;
 
+import org.apache.sling.installer.api.InstallableResource;
 import org.apache.sling.installer.api.tasks.TaskResourceGroup;
 import org.apache.sling.installer.core.impl.AbstractInstallTask;
 import org.osgi.framework.Bundle;
@@ -55,6 +56,51 @@ public abstract class AbstractBundleTask
     }
 
     /**
+     * Detect the start level for the resource.
+     */
+    protected int getBundleStartLevel() {
+        int startLevel = 0;
+        final Object providedLevel;
+
+        if (this.getResource().getDictionary() != null) {
+            if ( this.getResource().getDictionary().get(InstallableResource.BUNDLE_START_LEVEL) != null ) {
+                providedLevel = this.getResource().getDictionary().get(InstallableResource.BUNDLE_START_LEVEL);
+            } else {
+                providedLevel = this.getResource().getDictionary().get(InstallableResource.INSTALLATION_HINT);
+            }
+        } else {
+            providedLevel = null;
+        }
+        if ( providedLevel != null ) {
+            if ( providedLevel instanceof Number ) {
+                startLevel = ((Number)providedLevel).intValue();
+            } else {
+                try {
+                    startLevel = Integer.valueOf(providedLevel.toString());
+                } catch (final NumberFormatException nfe) {
+                    // ignore this
+                }
+            }
+        }
+        return startLevel;
+    }
+
+    /**
+     * Get sortable start level - low levels before high levels
+     */
+    protected String getSortableStartLevel() {
+        final int startLevel = this.getBundleStartLevel();
+        if ( startLevel == 0 ) {
+            return "999";
+        } else if ( startLevel < 10 ) {
+            return "00" + String.valueOf(startLevel);
+        } else if ( startLevel < 100 ) {
+            return "0" + String.valueOf(startLevel);
+        }
+        return String.valueOf(startLevel);
+    }
+
+    /**
      * Check if the bundle is active.
      * This is true if the bundle has the active state or of the bundle
      * is in the starting state and has the lazy activation policy.

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java?rev=1242512&r1=1242511&r2=1242512&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleInstallTask.java Thu Feb  9 20:39:15 2012
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.installer.core.impl.tasks;
 
-import org.apache.sling.installer.api.InstallableResource;
 import org.apache.sling.installer.api.tasks.InstallationContext;
 import org.apache.sling.installer.api.tasks.TaskResourceGroup;
 import org.osgi.framework.Bundle;
@@ -41,36 +40,14 @@ public class BundleInstallTask extends A
      * @see org.apache.sling.installer.api.tasks.InstallTask#execute(org.apache.sling.installer.api.tasks.InstallationContext)
      */
     public void execute(final InstallationContext ctx) {
-        int startLevel = 0;
-        final Object providedLevel;
-
-        if (this.getResource().getDictionary() != null) {
-            if ( this.getResource().getDictionary().get(InstallableResource.BUNDLE_START_LEVEL) != null ) {
-                providedLevel = this.getResource().getDictionary().get(InstallableResource.BUNDLE_START_LEVEL);
-            } else {
-                providedLevel = this.getResource().getDictionary().get(InstallableResource.INSTALLATION_HINT);
-            }
-        } else {
-            providedLevel = null;
-        }
-        if ( providedLevel != null ) {
-            if ( providedLevel instanceof Number ) {
-                startLevel = ((Number)providedLevel).intValue();
-            } else {
-                try {
-                    startLevel = Integer.valueOf(providedLevel.toString());
-                } catch (final NumberFormatException nfe) {
-                    // ignore this
-                }
-            }
-        }
-        // get the start level service (if possible) so we can set the initial start level
-        final StartLevel startLevelService = this.getStartLevel();
+        final int startLevel = this.getBundleStartLevel();
         try {
             final Bundle b = this.getBundleContext().installBundle(getResource().getURL(), getResource().getInputStream());
             ctx.log("Installed bundle {} from resource {}", b, getResource());
             // optionally set the start level
             if ( startLevel > 0 ) {
+                // get the start level service (if possible) so we can set the initial start level
+                final StartLevel startLevelService = this.getStartLevel();
                 if (startLevelService != null) {
                     startLevelService.setBundleStartLevel(b, startLevel);
                 } else {
@@ -90,6 +67,6 @@ public class BundleInstallTask extends A
 
     @Override
     public String getSortKey() {
-        return BUNDLE_INSTALL_ORDER + getResource().getURL();
+        return BUNDLE_INSTALL_ORDER + getSortableStartLevel() + "-" + getResource().getURL();
     }
 }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java?rev=1242512&r1=1242511&r2=1242512&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleUpdateTask.java Thu Feb  9 20:39:15 2012
@@ -120,7 +120,7 @@ public class BundleUpdateTask extends Ab
 
     @Override
     public String getSortKey() {
-        return BUNDLE_UPDATE_ORDER + getResource().getEntityId();
+        return BUNDLE_UPDATE_ORDER + getSortableStartLevel() + "-" + getResource().getEntityId();
     }
 
     private boolean isSystemBundleFragment(final Bundle installedBundle) {