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/08/23 18:38:20 UTC

svn commit: r1376582 - in /sling/trunk: installer/console/ installer/console/src/ installer/console/src/main/ installer/console/src/main/java/ installer/console/src/main/java/org/ installer/console/src/main/java/org/apache/ installer/console/src/main/j...

Author: cziegeler
Date: Thu Aug 23 16:38:20 2012
New Revision: 1376582

URL: http://svn.apache.org/viewvc?rev=1376582&view=rev
Log:
SLING-2568 : Move webconsole plugin into separate bundle

Added:
    sling/trunk/installer/console/   (with props)
    sling/trunk/installer/console/pom.xml   (with props)
    sling/trunk/installer/console/src/
    sling/trunk/installer/console/src/main/
    sling/trunk/installer/console/src/main/java/
    sling/trunk/installer/console/src/main/java/org/
    sling/trunk/installer/console/src/main/java/org/apache/
    sling/trunk/installer/console/src/main/java/org/apache/sling/
    sling/trunk/installer/console/src/main/java/org/apache/sling/installer/
    sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/
    sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/
    sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/
    sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java   (with props)
Removed:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/console/
Modified:
    sling/trunk/installer/core/pom.xml
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/Activator.java
    sling/trunk/launchpad/builder/src/main/bundles/list.xml

Propchange: sling/trunk/installer/console/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 23 16:38:20 2012
@@ -0,0 +1,12 @@
+target
+bin
+derby.log
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+

Added: sling/trunk/installer/console/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/console/pom.xml?rev=1376582&view=auto
==============================================================================
--- sling/trunk/installer/console/pom.xml (added)
+++ sling/trunk/installer/console/pom.xml Thu Aug 23 16:38:20 2012
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>13</version>
+        <relativePath>../../parent/pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.sling.installer.console</artifactId>
+    <version>0.9.0-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Sling Installer WebConsole Plugin</name>
+    <description> 
+        Provides a web console plugin for the OSGi installer
+    </description>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/installer/console</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/installer/console</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/installer/console</url>
+    </scm>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-scr-plugin</artifactId>
+		    </plugin>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Private-Package>
+						    org.apache.sling.installer.core.impl.console
+						</Private-Package>
+					</instructions>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.installer.core</artifactId>
+            <version>3.3.8</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+        </dependency>
+    </dependencies>
+</project>

Propchange: sling/trunk/installer/console/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/console/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: sling/trunk/installer/console/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java?rev=1376582&view=auto
==============================================================================
--- sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java (added)
+++ sling/trunk/installer/console/src/main/java/org/apache/sling/installer/core/impl/console/OsgiInstallerWebConsolePlugin.java Thu Aug 23 16:38:20 2012
@@ -0,0 +1,284 @@
+/*
+ * 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.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+
+import javax.servlet.GenericServlet;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.installer.api.InstallableResource;
+import org.apache.sling.installer.api.info.InfoProvider;
+import org.apache.sling.installer.api.info.InstallationState;
+import org.apache.sling.installer.api.info.Resource;
+import org.apache.sling.installer.api.info.ResourceGroup;
+import org.apache.sling.installer.api.tasks.RegisteredResource;
+import org.apache.sling.installer.api.tasks.ResourceState;
+import org.osgi.framework.Constants;
+
+
+@Component
+@Service(value=javax.servlet.Servlet.class)
+@Properties({
+    @Property(name=Constants.SERVICE_DESCRIPTION, value="Apache Sling OSGi Installer Web Console Plugin"),
+    @Property(name="felix.webconsole.label", value="osgi-installer"),
+    @Property(name="felix.webconsole.title", value="OSGi Installer"),
+    @Property(name="felix.webconsole.configprinter.modes", value={"zip", "txt"})
+})
+@SuppressWarnings("serial")
+public class OsgiInstallerWebConsolePlugin extends GenericServlet {
+
+    @Reference
+    private InfoProvider installer;
+
+    private String getType(final RegisteredResource rsrc) {
+        final String type = rsrc.getType();
+        if ( type.equals(InstallableResource.TYPE_BUNDLE) ) {
+            return "Bundles";
+        } else if ( type.equals(InstallableResource.TYPE_CONFIG) ) {
+            return "Configurations";
+        } else if ( type.equals(InstallableResource.TYPE_FILE) ) {
+            return "Files";
+        } else if ( type.equals(InstallableResource.TYPE_PROPERTIES) ) {
+            return "Properties";
+        }
+        return type;
+    }
+
+    private String getEntityId(final RegisteredResource rsrc, String alias) {
+        String id = rsrc.getEntityId();
+        final int pos = id.indexOf(':');
+        if ( pos != -1 ) {
+            id = id.substring(pos + 1);
+        }
+        return (alias == null ? id : id + '\n' + alias);
+    }
+
+    private String getURL(final Resource rsrc) {
+        if ( rsrc.getVersion() != null ) {
+            return rsrc.getURL() + " (" + rsrc.getVersion() + ")";
+        }
+        return rsrc.getURL();
+    }
+
+    private String getInfo(final RegisteredResource rsrc) {
+        return rsrc.getDigest() + '/' + String.valueOf(rsrc.getPriority());
+    }
+
+    /** Default date format used. */
+    private final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSS yyyy-MMM-dd");
+
+    /**
+     * Format a date
+     */
+    private synchronized String formatDate(final long time) {
+        if ( time == -1 ) {
+            return "-";
+        }
+        final Date d = new Date(time);
+        return dateFormat.format(d);
+    }
+
+    @Override
+    public void service(final ServletRequest req, final ServletResponse res)
+    throws IOException {
+        final PrintWriter pw = res.getWriter();
+
+        final InstallationState state = this.installer.getInstallationState();
+        pw.print("<p class='statline ui-state-highlight'>Apache Sling OSGi Installer");
+        if ( state.getActiveResources().size() == 0 && state.getInstalledResources().size() == 0 && state.getUntransformedResources().size() == 0 ) {
+            pw.print(" - no resources registered.");
+        }
+        pw.print("</p>");
+
+        String rt = null;
+        for(final ResourceGroup group : state.getActiveResources()) {
+            final Resource toActivate = group.getResources().get(0);
+            if ( !toActivate.getType().equals(rt) ) {
+                if ( rt != null ) {
+                    pw.println("</tbody></table>");
+                }
+                pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
+                pw.printf("<span style='float: left; margin-left: 1em;'>Active Resources - %s</span>", getType(toActivate));
+                pw.println("</div>");
+                pw.println("<table class='nicetable'><tbody>");
+                pw.printf("<tr><th>Entity ID</th><th>Digest/Priority</th><th>URL (Version)</th><th>State</th></tr>");
+                rt = toActivate.getType();
+            }
+            pw.printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
+                    getEntityId(toActivate, group.getAlias()),
+                    getInfo(toActivate),
+                    getURL(toActivate),
+                    toActivate.getState());
+        }
+        if ( rt != null ) {
+            pw.println("</tbody></table>");
+        }
+        rt = null;
+
+        for(final ResourceGroup group : state.getInstalledResources()) {
+            final Collection<Resource> resources = group.getResources();
+            if (resources.size() > 0) {
+                final Iterator<Resource> iter = resources.iterator();
+                final Resource first = iter.next();
+                if ( !first.getType().equals(rt) ) {
+                    if ( rt != null ) {
+                        pw.println("</tbody></table>");
+                    }
+                    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
+                    pw.printf("<span style='float: left; margin-left: 1em;'>Processed Resources - %s</span>", getType(first));
+                    pw.println("</div>");
+                    pw.println("<table class='nicetable'><tbody>");
+                    pw.printf("<tr><th>Entity ID</th><th>Digest/Priority</th><th>URL (Version)</th><th>State</th></tr>");
+                    rt = first.getType();
+                }
+                pw.print("<tr><td>");
+                pw.print(getEntityId(first, group.getAlias()));
+                pw.print("</td><td>");
+                pw.print(getInfo(first));
+                pw.print("</td><td>");
+                pw.print(getURL(first));
+                pw.print("</td><td>");
+                pw.print(first.getState());
+                if ( first.getState() == ResourceState.INSTALLED ) {
+                    final long lastChange = first.getLastChange();
+                    if ( lastChange > 0 ) {
+                        pw.print("<br/>");
+                        pw.print(formatDate(lastChange));
+                    }
+                }
+                pw.print("</td></tr>");
+
+                while ( iter.hasNext() ) {
+                    final Resource resource = iter.next();
+                    pw.printf("<tr><td></td><td>%s</td><td>%s</td><td>%s</td></tr>",
+                        getInfo(resource),
+                        getURL(resource),
+                        resource.getState());
+                }
+            }
+        }
+        if ( rt != null ) {
+            pw.println("</tbody></table>");
+        }
+
+        rt = null;
+        for(final RegisteredResource registeredResource : state.getUntransformedResources()) {
+            if ( !registeredResource.getType().equals(rt) ) {
+                if ( rt != null ) {
+                    pw.println("</tbody></table>");
+                }
+                pw.println("<div class='ui-widget-header ui-corner-top buttonGroup' style='height: 15px;'>");
+                pw.printf("<span style='float: left; margin-left: 1em;'>Untransformed Resources - %s</span>", getType(registeredResource));
+                pw.println("</div>");
+                pw.println("<table class='nicetable'><tbody>");
+                pw.printf("<tr><th>Digest/Priority</th><th>URL</th></tr>");
+
+                rt = registeredResource.getType();
+            }
+            pw.printf("<tr><td>%s</td><td>%s</td></tr>",
+                getInfo(registeredResource),
+                registeredResource.getURL());
+        }
+        if ( rt != null ) {
+            pw.println("</tbody></table>");
+        }
+    }
+
+    /**
+     * 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("===========================");
+        final InstallationState state = this.installer.getInstallationState();
+        pw.println("Active Resources");
+        pw.println("----------------");
+        String rt = null;
+        for(final ResourceGroup group : state.getActiveResources()) {
+            final Resource toActivate = group.getResources().get(0);
+            if ( !toActivate.getType().equals(rt) ) {
+                pw.printf("%s:%n", getType(toActivate));
+                rt = toActivate.getType();
+            }
+            pw.printf("- %s: %s, %s, %s%n",
+                    getEntityId(toActivate, group.getAlias()),
+                    getInfo(toActivate),
+                    getURL(toActivate),
+                    toActivate.getState());
+        }
+        pw.println();
+
+        pw.println("Processed Resources");
+        pw.println("-------------------");
+        rt = null;
+        for(final ResourceGroup group : state.getInstalledResources()) {
+            final Collection<Resource> resources = group.getResources();
+            if (resources.size() > 0) {
+                final Iterator<Resource> iter = resources.iterator();
+                final Resource first = iter.next();
+                if ( !first.getType().equals(rt) ) {
+                    pw.printf("%s:%n", getType(first));
+                    rt = first.getType();
+                }
+                pw.printf("* %s: %s, %s, %s%n",
+                        getEntityId(first, group.getAlias()),
+                        getInfo(first),
+                        getURL(first),
+                        first.getState());
+                while ( iter.hasNext() ) {
+                    final Resource resource = iter.next();
+                    pw.printf("  - %s, %s, %s%n",
+                        getInfo(resource),
+                        getURL(resource),
+                        resource.getState());
+                }
+            }
+        }
+        pw.println();
+
+        pw.println("Untransformed Resources");
+        pw.println("-----------------------");
+        rt = null;
+        for(final RegisteredResource registeredResource : state.getUntransformedResources()) {
+            if ( !registeredResource.getType().equals(rt) ) {
+                pw.printf("%s:%n", getType(registeredResource));
+                rt = registeredResource.getType();
+            }
+            pw.printf("- %s, %s%n",
+                    getInfo(registeredResource),
+                    registeredResource.getURL());
+        }
+    }
+}

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

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

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

Modified: sling/trunk/installer/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/pom.xml?rev=1376582&r1=1376581&r2=1376582&view=diff
==============================================================================
--- sling/trunk/installer/core/pom.xml (original)
+++ sling/trunk/installer/core/pom.xml Thu Aug 23 16:38:20 2012
@@ -54,11 +54,6 @@
 						<Bundle-Activator>
 							org.apache.sling.installer.core.impl.Activator
                         </Bundle-Activator>
-                        <DynamicImport-Package>
-                            <!-- plug into the web console -->
-                            javax.servlet;
-                            javax.servlet.http;version="[2.3,3)"
-                        </DynamicImport-Package>
 						<Export-Package>
 							org.apache.sling.installer.api;version=3.1.0,
                             org.apache.sling.installer.api.info;version=1.0.0,
@@ -137,10 +132,6 @@
             <artifactId>slf4j-api</artifactId>
         </dependency>
         <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>servlet-api</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.osgi</artifactId>
             <version>2.1.0</version>

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=1376582&r1=1376581&r2=1376582&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 Aug 23 16:38:20 2012
@@ -29,13 +29,10 @@ import org.apache.sling.installer.api.in
 import org.apache.sling.installer.api.tasks.InstallTaskFactory;
 import org.apache.sling.installer.api.tasks.ResourceTransformer;
 import org.apache.sling.installer.api.tasks.RetryHandler;
-import org.apache.sling.installer.core.impl.console.OsgiInstallerWebConsolePlugin;
 import org.apache.sling.installer.core.impl.tasks.BundleTaskCreator;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
 
 /**
@@ -53,9 +50,6 @@ 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)
      */
@@ -79,40 +73,12 @@ public class Activator implements Bundle
                 RetryHandler.class.getName()
         };
         osgiControllerServiceReg = context.registerService(serviceInterfaces, osgiControllerService, props);
-
-        // register service factory for the web console plugin
-        final Hashtable<String, Object> consoleProps = new Hashtable<String, Object>();
-        consoleProps.put("felix.webconsole.label", "osgi-installer");
-        consoleProps.put("felix.webconsole.title", "OSGi Installer");
-        consoleProps.put("felix.webconsole.configprinter.modes", new String[] {"zip", "txt"});
-        consoleProps.put(Constants.SERVICE_VENDOR, Activator.VENDOR);
-        consoleProps.put(Constants.SERVICE_DESCRIPTION,
-            "OSGi Installer Web Console Plugin");
-        this.webReg = context.registerService("javax.servlet.Servlet",
-                new ServiceFactory() {
-
-                    public void ungetService(final Bundle bundle,
-                            final ServiceRegistration reg,
-                            final Object consoleObject) {
-                        // nothing to do
-                    }
-
-                    public Object getService(final Bundle bundle,
-                            final ServiceRegistration reg) {
-                        return new OsgiInstallerWebConsolePlugin(osgiControllerService);
-                    }
-                }, consoleProps);
     }
 
     /**
      * @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/launchpad/builder/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/builder/src/main/bundles/list.xml?rev=1376582&r1=1376581&r2=1376582&view=diff
==============================================================================
--- sling/trunk/launchpad/builder/src/main/bundles/list.xml (original)
+++ sling/trunk/launchpad/builder/src/main/bundles/list.xml Thu Aug 23 16:38:20 2012
@@ -233,7 +233,12 @@
         <bundle>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.installer.core</artifactId>
-            <version>3.3.8</version>
+            <version>3.3.9-SNAPSHOT</version>
+        </bundle>
+        <bundle>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.installer.console</artifactId>
+            <version>0.9.0-SNAPSHOT</version>
         </bundle>
         <bundle>
             <groupId>org.apache.sling</groupId>