incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1060490 - in /sling/trunk/bundles/extensions/bundleresource: ./ src/main/java/org/apache/sling/bundleresource/impl/
Date Tue, 18 Jan 2011 18:02:03 GMT
Author: cziegeler
Date: Tue Jan 18 18:02:03 2011
New Revision: 1060490

URL: http://svn.apache.org/viewvc?rev=1060490&view=rev
Log:
SLING-1935 :  Remove dependency to web console

Modified:
    sling/trunk/bundles/extensions/bundleresource/pom.xml
    sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
    sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java
    sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java

Modified: sling/trunk/bundles/extensions/bundleresource/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/pom.xml?rev=1060490&r1=1060489&r2=1060490&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/pom.xml (original)
+++ sling/trunk/bundles/extensions/bundleresource/pom.xml Tue Jan 18 18:02:03 2011
@@ -67,9 +67,6 @@
                             org.apache.sling.api.resource;version="[$(version;==;$(@)),$(version;=+;$(@)))",
                             *
                         </Import-Package>
-                        <DynamicImport-Package>
-                            org.apache.felix.webconsole
-                        </DynamicImport-Package>
                     </instructions>
                 </configuration>
             </plugin>
@@ -101,15 +98,18 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.jcr.resource</artifactId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
             <version>2.0.6</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.webconsole</artifactId>
-            <version>1.2.0</version>
-            <scope>provided</scope>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>compile</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>
@@ -118,13 +118,8 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.compendium</artifactId>
-            <scope>compile</scope>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>

Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java?rev=1060490&r1=1060489&r2=1060490&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
(original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
Tue Jan 18 18:02:03 2011
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.bundleresource.impl;
 
-import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -38,26 +37,6 @@ public class Activator implements Bundle
      */
     public static final String BUNDLE_RESOURCE_ROOTS = "Sling-Bundle-Resources";
 
-    /**
-     * Fully qualified name of the Web Console Plugin class. This class will be
-     * loaded dynamically to prevent issues if the Felix Web Console is not
-     * installed in the system (value is
-     * "org.apache.sling.bundleresource.impl.BundleResourceWebConsolePlugin").
-     */
-    private static final String CONSOLE_PLUGIN_CLASS = "org.apache.sling.bundleresource.impl.BundleResourceWebConsolePlugin";
-
-    /**
-     * Name of the initialization method to call on the Web Console Plugin class
-     * (value is "initPlugin").
-     */
-    private static final String METHOD_INIT = "initPlugin";
-
-    /**
-     * Name of the shutdown method to call on the Web Console Plugin class
-     * (value is "destroyPlugin").
-     */
-    private static final String METHOD_DESTROY = "destroyPlugin";
-
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -65,7 +44,10 @@ public class Activator implements Bundle
 
     private BundleContext bundleContext;
 
-    public void start(BundleContext context) throws Exception {
+    /**
+     * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+     */
+    public void start(final BundleContext context) throws Exception {
 
         this.bundleContext = context;
 
@@ -85,15 +67,14 @@ public class Activator implements Bundle
                 t);
         }
 
-        // hackery thing to prevent problems if the web console is not present
-        callMethod(CONSOLE_PLUGIN_CLASS, METHOD_INIT,
-            new Class<?>[] { BundleContext.class }, new Object[] { context });
-
+        BundleResourceWebConsolePlugin.initPlugin(context);
     }
 
-    public void stop(BundleContext context) throws Exception {
-        // hackery thing to prevent problems if the web console is not present
-        callMethod(CONSOLE_PLUGIN_CLASS, METHOD_DESTROY, null, null);
+    /**
+     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+     */
+    public void stop(final BundleContext context) throws Exception {
+        BundleResourceWebConsolePlugin.destroyPlugin();
 
         context.removeBundleListener(this);
         this.bundleContext = null;
@@ -103,7 +84,7 @@ public class Activator implements Bundle
      * Loads and unloads any components provided by the bundle whose state
      * changed. If the bundle has been started, the components are loaded. If
      * the bundle is about to stop, the components are unloaded.
-     * 
+     *
      * @param event The <code>BundleEvent</code> representing the bundle state
      *            change.
      */
@@ -150,37 +131,4 @@ public class Activator implements Bundle
             brp.unregisterService();
         }
     }
-
-    /**
-     * Helper method to call the static method <code>methodName</code> on the
-     * class <code>clazzName</code> with the given <code>args</code>.
This
-     * method operates exclusively using reflection to prevent any issues if the
-     * class cannot be loaded.
-     * <p>
-     * The goal is to enable running the bundle resource provider without a hard
-     * dependency on the Felix Web Console.
-     * 
-     * @param clazzName The fully qualified name of the class whose static
-     *            method is to be called.
-     * @param methodName The name of the method to call. This method must be
-     *            declared in the given class.
-     * @param argTypes The types of arguments of the methods to be able to find
-     *            the method. This may be <code>null</code> if the method has
-     *            no arguments.
-     * @param args The actual arguments to the method. This may be
-     *            <code>null</code> if the method has no arguments.
-     */
-    private void callMethod(String clazzName, String methodName,
-            Class<?>[] argTypes, Object[] args) {
-        try {
-            Class<?> clazz = getClass().getClassLoader().loadClass(clazzName);
-            Method method = clazz.getDeclaredMethod(methodName, argTypes);
-            if (!method.isAccessible()) {
-                method.setAccessible(true);
-            }
-            method.invoke(null, args);
-        } catch (Throwable t) {
-            // ignore anything
-        }
-    }
 }

Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java?rev=1060490&r1=1060489&r2=1060490&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java
(original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java
Tue Jan 18 18:02:03 2011
@@ -232,6 +232,8 @@ class BundleResourceCache {
     private static class BundleResourceMap<K, V> extends
             LinkedHashMap<String, V> {
 
+        private static final long serialVersionUID = 7455098291380945276L;
+
         /**
          * The default size of a bundle resource cache (value is 20).
          */

Modified: sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java?rev=1060490&r1=1060489&r2=1060490&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java
(original)
+++ sling/trunk/bundles/extensions/bundleresource/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java
Tue Jan 18 18:02:03 2011
@@ -25,11 +25,12 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.List;
 
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.felix.webconsole.AbstractWebConsolePlugin;
-import org.apache.felix.webconsole.WebConsoleConstants;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -38,7 +39,9 @@ import org.osgi.framework.ServiceReferen
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.util.tracker.ServiceTracker;
 
-class BundleResourceWebConsolePlugin extends AbstractWebConsolePlugin {
+class BundleResourceWebConsolePlugin extends HttpServlet {
+
+    private static final long serialVersionUID = 566337139719695235L;
 
     private static final String LABEL = "bundleresources";
 
@@ -51,7 +54,7 @@ class BundleResourceWebConsolePlugin ext
     //--------- setup and shutdown
 
     private static BundleResourceWebConsolePlugin INSTANCE;
-    
+
     static void initPlugin(BundleContext context) {
         if (INSTANCE == null) {
             BundleResourceWebConsolePlugin tmp = new BundleResourceWebConsolePlugin();
@@ -59,7 +62,7 @@ class BundleResourceWebConsolePlugin ext
             INSTANCE = tmp;
         }
     }
-    
+
     static void destroyPlugin() {
         if (INSTANCE != null) {
             try {
@@ -69,27 +72,14 @@ class BundleResourceWebConsolePlugin ext
             }
         }
     }
-    
+
     // private constructor to force using static setup and shutdown
     private BundleResourceWebConsolePlugin() {
     }
 
-    //---------- AbstractWebConsolePlugin implementation
-    
-    @Override
-    public String getLabel() {
-        return LABEL;
-    }
-
     @Override
-    public String getTitle() {
-        return "Bundle Resource Provider";
-    }
-
-    @Override
-    protected void renderContent(HttpServletRequest req, HttpServletResponse res)
-            throws IOException {
-
+    protected void doGet(final HttpServletRequest req, final HttpServletResponse res)
+    throws ServletException, IOException {
         PrintWriter pw = res.getWriter();
 
         pw.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");
@@ -160,8 +150,6 @@ class BundleResourceWebConsolePlugin ext
     }
 
     public void activate(BundleContext context) {
-        super.activate(context);
-
         providerTracker = new ServiceTracker(context,
             ResourceProvider.SERVICE_NAME, null) {
             @Override
@@ -189,10 +177,11 @@ class BundleResourceWebConsolePlugin ext
             "Web Console Plugin for Bundle Resource Providers");
         props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
         props.put(Constants.SERVICE_PID, getClass().getName());
-        props.put(WebConsoleConstants.PLUGIN_LABEL, LABEL);
+        props.put("felix.webconsole.label", LABEL);
+        props.put("felix.webconsole.title", "Bundle Resource Provider");
 
         serviceRegistration = context.registerService(
-            WebConsoleConstants.SERVICE_NAME, this, props);
+            Servlet.class.getName(), this, props);
     }
 
     public void deactivate() {
@@ -205,8 +194,6 @@ class BundleResourceWebConsolePlugin ext
             providerTracker.close();
             providerTracker = null;
         }
-
-        super.deactivate();
     }
 
     private String getName(Bundle bundle) {



Mime
View raw message