incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1058472 - in /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl: Activator.java console/OsgiInstallerWebConsolePlugin.java
Date Thu, 13 Jan 2011 09:25:14 GMT
Author: cziegeler
Date: Thu Jan 13 09:25:14 2011
New Revision: 1058472

URL: http://svn.apache.org/viewvc?rev=1058472&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/Activator.java
    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/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java?rev=1058472&r1=1058471&r2=1058472&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java
Thu Jan 13 09:25:14 2011
@@ -40,7 +40,7 @@ import org.osgi.framework.ServiceRegistr
 public class Activator implements BundleActivator {
 
     /** Vendor of all registered services. */
-    private static final String VENDOR = "The Apache Software Foundation";
+    public static final String VENDOR = "The Apache Software Foundation";
 
     private List<InternalService> services = new ArrayList<InternalService>();
     private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();

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=1058472&r1=1058471&r2=1058472&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 09:25:14 2011
@@ -20,6 +20,7 @@ package org.apache.sling.installer.core.
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Hashtable;
 import java.util.List;
@@ -30,6 +31,7 @@ import javax.servlet.ServletResponse;
 
 import org.apache.sling.installer.api.tasks.RegisteredResource;
 import org.apache.sling.installer.api.tasks.TaskResource;
+import org.apache.sling.installer.core.impl.Activator;
 import org.apache.sling.installer.core.impl.EntityResourceList;
 import org.apache.sling.installer.core.impl.OsgiInstallerImpl;
 import org.osgi.framework.BundleContext;
@@ -49,7 +51,7 @@ public class OsgiInstallerWebConsolePlug
         props.put("felix.webconsole.label", "osgi-installer");
         props.put("felix.webconsole.title", "OSGi Installer");
         props.put("felix.webconsole.configprinter.modes", new String[] {"zip", "txt"});
-        props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
+        props.put(Constants.SERVICE_VENDOR, Activator.VENDOR);
         props.put(Constants.SERVICE_DESCRIPTION,
             "OSGi Installer Web Console Plugin");
         return bundleContext.registerService("javax.servlet.Servlet", plugin,
@@ -61,27 +63,60 @@ public class OsgiInstallerWebConsolePlug
         this.installer = installer;
     }
 
+    /**
+     * Internal class to collect the current state.
+     */
+    private static final class State {
+        public final List<EntityResourceList> activeResources = new ArrayList<EntityResourceList>();
+        public final List<EntityResourceList> installedResources = new ArrayList<EntityResourceList>();
+        public final List<RegisteredResource> untransformedResources = new ArrayList<RegisteredResource>();
+    }
+
+    /**
+     * Get the current installer state.
+     * This method should be called from within a synchronized block for the resources!
+     */
+    private State getCurrentState() {
+        final State state = new State();
+
+        for(final String entityId : this.installer.getPersistentResourceList().getEntityIds())
{
+            final EntityResourceList group = this.installer.getPersistentResourceList().getEntityResourceList(entityId);
+            if ( group.getActiveResource() != null ) {
+                state.activeResources.add(group);
+            } else {
+                state.installedResources.add(group);
+            }
+        }
+        state.untransformedResources.addAll(this.installer.getPersistentResourceList().getUntransformedResources());
+
+        return state;
+    }
+
     @Override
     public void service(ServletRequest req, ServletResponse res)
     throws IOException {
 
         final PrintWriter pw = res.getWriter();
 
-        pw.println("<h1>Entities</h1>");
-        pw.println("<ul>");
         synchronized ( this.installer.getResourcesLock() ) {
-            Collection<String> entities = this.installer.getPersistentResourceList().getEntityIds();
-            for (String entityId : entities) {
-                EntityResourceList erl = this.installer.getPersistentResourceList().getEntityResourceList(entityId);
-                TaskResource registeredResource = erl.getActiveResource();
-                if (registeredResource != null) {
-                    pw.printf("<li>%s: %s, %s, %s%n",
-                        registeredResource.getEntityId(),
-                        registeredResource.getDigest(),
-                        registeredResource.getScheme(),
-                        registeredResource.getState());
-                }
-                Collection<TaskResource> resources = erl.getResources();
+            final State state = this.getCurrentState();
+
+            pw.println("<h1>Active Resources</h1>");
+            pw.println("<ul>");
+            for(final EntityResourceList group : state.activeResources) {
+                final TaskResource toActivate = group.getActiveResource();
+                pw.printf("<li>%s: %s, %s, %s</li>%n",
+                        toActivate.getEntityId(),
+                        toActivate.getDigest(),
+                        toActivate.getScheme(),
+                        toActivate.getState());
+            }
+            pw.println("</ul>");
+
+            pw.println("<h1>Installed Resources</h1>");
+            pw.println("<ul>");
+            for(final EntityResourceList group : state.installedResources) {
+                final Collection<TaskResource> resources = group.getResources();
                 if (resources.size() > 0) {
                     pw.println("<ul>");
                     for (TaskResource resource : resources) {
@@ -91,11 +126,17 @@ public class OsgiInstallerWebConsolePlug
                     }
                     pw.println("</ul>");
                 }
-                pw.println("</li>");
             }
             pw.println("</ul>");
 
-            printUnknownResources(pw, this.installer.getPersistentResourceList().getUntransformedResources());
+            pw.println("<h1>Untransformed Resources</h1>");
+            pw.println("<ul>");
+            for(final RegisteredResource registeredResource : state.untransformedResources)
{
+                pw.printf("<li>%s: %s, %s</li>%n",
+                    registeredResource.getEntityId(),
+                    registeredResource.getDigest(), registeredResource.getScheme());
+            }
+            pw.println("</ul>");
         }
     }
 
@@ -108,48 +149,40 @@ public class OsgiInstallerWebConsolePlug
         }
         pw.println("Apache Sling OSGi Installer");
         pw.println("===========================");
-        pw.println("Entities:");
         synchronized ( this.installer.getResourcesLock() ) {
-            Collection<String> entities = this.installer.getPersistentResourceList().getEntityIds();
-            for (String entityId : entities) {
-                EntityResourceList erl = this.installer.getPersistentResourceList().getEntityResourceList(entityId);
-                TaskResource registeredResource = erl.getActiveResource();
-                if (registeredResource != null) {
-                    pw.printf("- %s: %s, %s, %s%n",
-                        registeredResource.getEntityId(),
-                        registeredResource.getDigest(),
-                        registeredResource.getScheme(),
-                        registeredResource.getState());
-                }
-                Collection<TaskResource> resources = erl.getResources();
+            final State state = this.getCurrentState();
+            pw.println("Active Resources:");
+            for(final EntityResourceList group : state.activeResources) {
+                final TaskResource toActivate = group.getActiveResource();
+                pw.printf("- %s: %s, %s, %s%n",
+                        toActivate.getEntityId(),
+                        toActivate.getDigest(),
+                        toActivate.getScheme(),
+                        toActivate.getState());
+            }
+            pw.println();
+
+            pw.println("Installed Resources:");
+            for(final EntityResourceList group : state.installedResources) {
+                final Collection<TaskResource> resources = group.getResources();
                 if (resources.size() > 0) {
+                    pw.print("* ");
                     for (TaskResource resource : resources) {
                         pw.printf("- %s: %s, %s, %s%n",
                             resource.getEntityId(), resource.getDigest(),
                             resource.getScheme(), resource.getState());
                     }
+                    pw.println("</ul>");
                 }
             }
-
             pw.println();
+
             pw.println("Untransformed Resources:");
-            for (RegisteredResource registeredResource : this.installer.getPersistentResourceList().getUntransformedResources())
{
+            for(final RegisteredResource registeredResource : state.untransformedResources)
{
                 pw.printf("- %s: %s, %s%n",
                     registeredResource.getEntityId(),
                     registeredResource.getDigest(), registeredResource.getScheme());
             }
         }
     }
-
-    private void printUnknownResources(final PrintWriter pw,
-            final List<RegisteredResource> unknown) {
-        pw.println("<h1>Untransformed Resources</h1>");
-        pw.println("<ul>");
-        for (RegisteredResource registeredResource : unknown) {
-            pw.printf("<li>%s: %s, %s</li>%n",
-                registeredResource.getEntityId(),
-                registeredResource.getDigest(), registeredResource.getScheme());
-        }
-        pw.println("</ul>");
-    }
 }



Mime
View raw message