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 2011/01/13 17:41:07 UTC

svn commit: r1058656 - /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java

Author: cziegeler
Date: Thu Jan 13 16:41:07 2011
New Revision: 1058656

URL: http://svn.apache.org/viewvc?rev=1058656&view=rev
Log:
SLING-755 : Web Console Plugin for the OSGi Installer

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java?rev=1058656&r1=1058655&r2=1058656&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java Thu Jan 13 16:41:07 2011
@@ -22,6 +22,8 @@ import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
@@ -74,6 +76,35 @@ public class OsgiInstallerWebConsolePlug
         public final List<RegisteredResource> untransformedResources = new ArrayList<RegisteredResource>();
     }
 
+    private static final Comparator<EntityResourceList> COMPARATOR = new Comparator<EntityResourceList>() {
+
+        public int compare(EntityResourceList o1, EntityResourceList o2) {
+            RegisteredResource r1 = null;
+            RegisteredResource r2 = null;
+            if ( o1.getResources().size() > 0 ) {
+                r1 = o1.getResources().iterator().next();
+            }
+            if ( o2.getResources().size() > 0 ) {
+                r2 = o2.getResources().iterator().next();
+            }
+            int result;
+            if ( r1 == null && r2 == null ) {
+                result = 0;
+            } else if ( r1 == null ) {
+                result = -1;
+            } else if ( r2 == null ) {
+                result = 1;
+            } else {
+                result = r1.getType().compareTo(r2.getType());
+                if ( result == 0 ) {
+                    result = r1.getEntityId().compareTo(r2.getEntityId());
+                }
+            }
+            return result;
+        }
+
+    };
+
     /**
      * Get the current installer state.
      * This method should be called from within a synchronized block for the resources!
@@ -89,6 +120,8 @@ public class OsgiInstallerWebConsolePlug
                 state.installedResources.add(group);
             }
         }
+        Collections.sort(state.activeResources, COMPARATOR);
+        Collections.sort(state.installedResources, COMPARATOR);
         state.untransformedResources.addAll(this.installer.getPersistentResourceList().getUntransformedResources());
 
         return state;
@@ -97,17 +130,26 @@ public class OsgiInstallerWebConsolePlug
     private String getType(final RegisteredResource rsrc) {
         final String type = rsrc.getType();
         if ( type.equals(InstallableResource.TYPE_BUNDLE) ) {
-            return "Bundle";
+            return "Bundles";
         } else if ( type.equals(InstallableResource.TYPE_CONFIG) ) {
-            return "Configuration";
+            return "Configurations";
         } else if ( type.equals(InstallableResource.TYPE_FILE) ) {
-            return "File";
+            return "Files";
         } else if ( type.equals(InstallableResource.TYPE_PROPERTIES) ) {
             return "Properties";
         }
         return type;
     }
 
+    private String getEntityId(final RegisteredResource rsrc) {
+        String id = rsrc.getEntityId();
+        final int pos = id.indexOf(':');
+        if ( pos != -1 ) {
+            id = id.substring(pos + 1);
+        }
+        return id;
+    }
+
     @Override
     public void service(ServletRequest req, ServletResponse res)
     throws IOException {
@@ -118,29 +160,43 @@ public class OsgiInstallerWebConsolePlug
             final State state = this.getCurrentState();
 
             pw.println("<h1>Active Resources</h1>");
-            pw.println("<ul>");
+            String rt = null;
             for(final EntityResourceList group : state.activeResources) {
                 final TaskResource toActivate = group.getActiveResource();
-                pw.printf("<li>%s %s: %s, %s, %s</li>%n",
-                        getType(toActivate),
-                        toActivate.getEntityId(),
+                if ( !toActivate.getType().equals(rt) ) {
+                    if ( rt != null ) {
+                        pw.println("</ul>");
+                    }
+                    pw.printf("<h2>%s</h2>%n", getType(toActivate));
+                    pw.println("<ul>");
+                    rt = toActivate.getType();
+                }
+                pw.printf("<li>%s: %s, %s, %s</li>%n",
+                        getEntityId(toActivate),
                         toActivate.getDigest(),
                         toActivate.getURL(),
                         toActivate.getState());
             }
             pw.println("</ul>");
+            rt = null;
 
             pw.println("<h1>Processed Resources</h1>");
-            pw.println("<ul>");
             for(final EntityResourceList group : state.installedResources) {
                 final Collection<TaskResource> resources = group.getResources();
                 if (resources.size() > 0) {
                     final Iterator<TaskResource> iter = resources.iterator();
                     final TaskResource first = iter.next();
+                    if ( !first.getType().equals(rt) ) {
+                        if ( rt != null ) {
+                            pw.println("</ul>");
+                        }
+                        pw.printf("<h2>%s</h2>%n", getType(first));
+                        rt = first.getType();
+                        pw.println("<ul>");
+                    }
                     pw.println("<ul>");
-                    pw.printf("<li>%s %s: %s, %s, %s</li>%n",
-                            getType(first),
-                            first.getEntityId(),
+                    pw.printf("<li>%s: %s, %s, %s</li>%n",
+                            getEntityId(first),
                             first.getDigest(),
                             first.getURL(),
                             first.getState());
@@ -154,17 +210,28 @@ public class OsgiInstallerWebConsolePlug
                     pw.println("</ul>");
                 }
             }
-            pw.println("</ul>");
+            if ( rt != null ) {
+                pw.println("</ul>");
+            }
 
             pw.println("<h1>Untransformed Resources</h1>");
-            pw.println("<ul>");
+            rt = null;
             for(final RegisteredResource registeredResource : state.untransformedResources) {
-                pw.printf("<li>%s: %s, %s</li>%n",
-                    getType(registeredResource),
+                if ( !registeredResource.getType().equals(rt) ) {
+                    if ( rt != null ) {
+                        pw.println("</ul>");
+                    }
+                    pw.printf("<h2>%s</h2>%n", getType(registeredResource));
+                    rt = registeredResource.getType();
+                    pw.println("<ul>");
+                }
+                pw.printf("<li>%s, %s</li>%n",
                     registeredResource.getDigest(),
                     registeredResource.getURL());
             }
-            pw.println("</ul>");
+            if ( rt != null ) {
+                pw.println("</ul>");
+            }
         }
     }
 
@@ -179,27 +246,37 @@ public class OsgiInstallerWebConsolePlug
         pw.println("===========================");
         synchronized ( this.installer.getResourcesLock() ) {
             final State state = this.getCurrentState();
-            pw.println("Active Resources:");
+            pw.println("Active Resources");
+            pw.println("----------------");
+            String rt = null;
             for(final EntityResourceList group : state.activeResources) {
                 final TaskResource toActivate = group.getActiveResource();
-                pw.printf("- %s %s: %s, %s, %s%n",
-                        getType(toActivate),
-                        toActivate.getEntityId(),
+                if ( !toActivate.getType().equals(rt) ) {
+                    pw.printf("%s:%n", getType(toActivate));
+                    rt = toActivate.getType();
+                }
+                pw.printf("- %s: %s, %s, %s%n",
+                        getEntityId(toActivate),
                         toActivate.getDigest(),
                         toActivate.getURL(),
                         toActivate.getState());
             }
             pw.println();
 
-            pw.println("Processed Resources:");
+            pw.println("Processed Resources");
+            pw.println("-------------------");
+            rt = null;
             for(final EntityResourceList group : state.installedResources) {
                 final Collection<TaskResource> resources = group.getResources();
                 if (resources.size() > 0) {
                     final Iterator<TaskResource> iter = resources.iterator();
                     final TaskResource first = iter.next();
-                    pw.printf("* %s %s: %s, %s, %s%n",
-                            getType(first),
-                            first.getEntityId(),
+                    if ( !first.getType().equals(rt) ) {
+                        pw.printf("%s:%n", getType(first));
+                        rt = first.getType();
+                    }
+                    pw.printf("* %s: %s, %s, %s%n",
+                            getEntityId(first),
                             first.getDigest(),
                             first.getURL(),
                             first.getState());
@@ -214,10 +291,15 @@ public class OsgiInstallerWebConsolePlug
             }
             pw.println();
 
-            pw.println("Untransformed Resources:");
+            pw.println("Untransformed Resources");
+            pw.println("-----------------------");
+            rt = null;
             for(final RegisteredResource registeredResource : state.untransformedResources) {
-                pw.printf("- %s: %s, %s%n",
-                        getType(registeredResource),
+                if ( !registeredResource.getType().equals(rt) ) {
+                    pw.printf("%s:%n", getType(registeredResource));
+                    rt = registeredResource.getType();
+                }
+                pw.printf("- %s, %s%n",
                         registeredResource.getDigest(),
                         registeredResource.getURL());
             }