incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1058154 - in /sling/trunk/installer/core: ./ src/main/java/org/apache/sling/installer/core/impl/ src/main/java/org/apache/sling/installer/core/impl/console/
Date Wed, 12 Jan 2011 14:24:08 GMT
Author: cziegeler
Date: Wed Jan 12 14:24:08 2011
New Revision: 1058154

URL: http://svn.apache.org/viewvc?rev=1058154&view=rev
Log:
SLING-755 : jcrinstall console plugin

Added:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
  (with props)
Modified:
    sling/trunk/installer/core/pom.xml
    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/OsgiInstallerImpl.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java

Modified: sling/trunk/installer/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/pom.xml?rev=1058154&r1=1058153&r2=1058154&view=diff
==============================================================================
--- sling/trunk/installer/core/pom.xml (original)
+++ sling/trunk/installer/core/pom.xml Wed Jan 12 14:24:08 2011
@@ -54,6 +54,9 @@
 						<Bundle-Activator>
 							org.apache.sling.installer.core.impl.Activator
                         </Bundle-Activator>
+                        <Import-Package>
+                            javax.servlet;javax.servlet.http;resolution:=optional,*
+                        </Import-Package>
 						<Export-Package>
 							org.apache.sling.installer.api;version=3.0.0,
                             org.apache.sling.installer.api.tasks;version=1.0.0
@@ -125,6 +128,10 @@
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
       <!-- We use a class from the config admin implementation to read config files -->
         <dependency>
             <groupId>org.apache.felix</groupId>

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=1058154&r1=1058153&r2=1058154&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
Wed Jan 12 14:24:08 2011
@@ -26,6 +26,7 @@ import org.apache.sling.installer.api.Os
 import org.apache.sling.installer.api.tasks.InstallTaskFactory;
 import org.apache.sling.installer.api.tasks.ResourceTransformer;
 import org.apache.sling.installer.core.impl.config.ConfigTaskCreator;
+import org.apache.sling.installer.core.impl.console.OsgiInstallerWebConsolePlugin;
 import org.apache.sling.installer.core.impl.tasks.BundleTaskCreator;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -47,6 +48,9 @@ public class Activator implements Bundle
     private OsgiInstallerImpl osgiControllerService;
     private ServiceRegistration osgiControllerServiceReg;
 
+    /** Registration for the web console plugin. */
+    private ServiceRegistration webReg;
+
     /**
      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
      */
@@ -66,12 +70,24 @@ public class Activator implements Bundle
                 OsgiInstaller.class.getName()
         };
         osgiControllerServiceReg = context.registerService(serviceInterfaces, osgiControllerService,
props);
+
+        try {
+            this.webReg = OsgiInstallerWebConsolePlugin.register(context,
+                    this.osgiControllerService);
+        } catch (final Throwable ignore) {
+            // ignore this
+        }
     }
 
     /**
      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
      */
     public void stop(final BundleContext context) {
+        // stop web console plugin
+        if ( this.webReg != null ) {
+            this.webReg.unregister();
+            this.webReg = null;
+        }
         // stop osgi installer service
         if ( this.osgiControllerService != null ) {
             this.osgiControllerService.deactivate();

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1058154&r1=1058153&r2=1058154&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
Wed Jan 12 14:24:08 2011
@@ -221,6 +221,14 @@ public class OsgiInstallerImpl
         }
     }
 
+    public Object getResourcesLock() {
+        return this.resourcesLock;
+    }
+
+    public PersistentResourceList getPersistentResourceList() {
+        return this.persistentList;
+    }
+
     /**
      * Create new installable resources for all installable resources.
      * The new versions has a set resource type.

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java?rev=1058154&r1=1058153&r2=1058154&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
Wed Jan 12 14:24:08 2011
@@ -200,6 +200,7 @@ public class PersistentResourceList {
     public List<RegisteredResource> getUnknownResources() {
         return this.unknownResources;
     }
+
     /**
      * Remove a resource by url
      * @param url The url to remove

Added: 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=1058154&view=auto
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
(added)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
Wed Jan 12 14:24:08 2011
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.installer.core.impl.console;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.sling.installer.api.tasks.RegisteredResource;
+import org.apache.sling.installer.core.impl.EntityResourceList;
+import org.apache.sling.installer.core.impl.OsgiInstallerImpl;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+
+@SuppressWarnings("serial")
+public class OsgiInstallerWebConsolePlugin extends GenericServlet {
+
+    private final OsgiInstallerImpl installer;
+
+    public static ServiceRegistration register(final BundleContext bundleContext,
+            final OsgiInstallerImpl installer) {
+        final OsgiInstallerWebConsolePlugin plugin = new OsgiInstallerWebConsolePlugin(
+                installer);
+        final Hashtable<String, Object> props = new Hashtable<String, Object>();
+        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_DESCRIPTION,
+            "OSGi Installer Web Console Plugin");
+        return bundleContext.registerService("javax.servlet.Servlet", plugin,
+            props);
+    }
+
+    private OsgiInstallerWebConsolePlugin(
+            final OsgiInstallerImpl installer) {
+        this.installer = installer;
+    }
+
+    @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);
+                RegisteredResource registeredResource = erl.getActiveResource();
+                if (registeredResource != null) {
+                    pw.printf("<li>%s: %s, %s, %s%n",
+                        registeredResource.getEntityId(),
+                        registeredResource.getDigest(),
+                        registeredResource.getScheme(),
+                        registeredResource.getState());
+                }
+                Collection<RegisteredResource> resources = erl.getResources();
+                if (resources.size() > 0) {
+                    pw.println("<ul>");
+                    for (RegisteredResource resource : resources) {
+                        pw.printf("<li>%s: %s, %s, %s</li>%n",
+                            resource.getEntityId(), resource.getDigest(),
+                            resource.getScheme(), resource.getState());
+                    }
+                    pw.println("</ul>");
+                }
+                pw.println("</li>");
+            }
+            pw.println("</ul>");
+
+            printUnknownResources(pw, this.installer.getPersistentResourceList().getUnknownResources());
+        }
+    }
+
+    /**
+     * Method for the configuration printer.
+     */
+    public void printConfiguration(final PrintWriter pw, final String mode) {
+        if ( !"zip".equals(mode) && !"txt".equals(mode) ) {
+            return;
+        }
+        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);
+                RegisteredResource registeredResource = erl.getActiveResource();
+                if (registeredResource != null) {
+                    pw.printf("- %s: %s, %s, %s%n",
+                        registeredResource.getEntityId(),
+                        registeredResource.getDigest(),
+                        registeredResource.getScheme(),
+                        registeredResource.getState());
+                }
+                Collection<RegisteredResource> resources = erl.getResources();
+                if (resources.size() > 0) {
+                    for (RegisteredResource resource : resources) {
+                        pw.printf("- %s: %s, %s, %s%n",
+                            resource.getEntityId(), resource.getDigest(),
+                            resource.getScheme(), resource.getState());
+                    }
+                }
+            }
+
+            pw.println();
+            pw.println("Unknown Resources:");
+            for (RegisteredResource registeredResource : this.installer.getPersistentResourceList().getUnknownResources())
{
+                pw.printf("- %s: %s, %s, %s</li>%n",
+                    registeredResource.getEntityId(),
+                    registeredResource.getDigest(), registeredResource.getScheme(),
+                    registeredResource.getState());
+            }
+        }
+    }
+
+    private void printUnknownResources(final PrintWriter pw,
+            final List<RegisteredResource> unknown) {
+        pw.println("<h1>Unknown Resources</h1>");
+        pw.println("<ul>");
+        for (RegisteredResource registeredResource : unknown) {
+            pw.printf("<li>%s: %s, %s, %s</li>%n",
+                registeredResource.getEntityId(),
+                registeredResource.getDigest(), registeredResource.getScheme(),
+                registeredResource.getState());
+        }
+        pw.println("</ul>");
+    }
+}

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message