You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:19:44 UTC
[sling-org-apache-sling-bundleresource-impl] 27/30: SLING-1935 :
Remove dependency to web console
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.bundleresource.impl-2.0.6
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-bundleresource-impl.git
commit 98840cb5b94bd2642cd7d83596c05f69773bf196
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Jan 18 18:02:03 2011 +0000
SLING-1935 : Remove dependency to web console
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/extensions/bundleresource@1060490 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 25 +++-----
.../sling/bundleresource/impl/Activator.java | 74 ++++------------------
.../bundleresource/impl/BundleResourceCache.java | 2 +
.../impl/BundleResourceWebConsolePlugin.java | 41 ++++--------
4 files changed, 37 insertions(+), 105 deletions(-)
diff --git a/pom.xml b/pom.xml
index f9ff470..649bcf8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git a/src/main/java/org/apache/sling/bundleresource/impl/Activator.java b/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
index 2eb1821..919921d 100644
--- a/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
+++ b/src/main/java/org/apache/sling/bundleresource/impl/Activator.java
@@ -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 BundleActivator, BundleListener {
*/
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 BundleActivator, BundleListener {
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 BundleActivator, BundleListener {
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 BundleActivator, BundleListener {
* 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 BundleActivator, BundleListener {
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
- }
- }
}
diff --git a/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java b/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java
index fab1d11..ba9d1f5 100644
--- a/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java
+++ b/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceCache.java
@@ -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).
*/
diff --git a/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java b/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java
index 19dd77a..3aead53 100644
--- a/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java
+++ b/src/main/java/org/apache/sling/bundleresource/impl/BundleResourceWebConsolePlugin.java
@@ -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.ServiceReference;
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 extends AbstractWebConsolePlugin {
//--------- 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 extends AbstractWebConsolePlugin {
INSTANCE = tmp;
}
}
-
+
static void destroyPlugin() {
if (INSTANCE != null) {
try {
@@ -69,27 +72,14 @@ class BundleResourceWebConsolePlugin extends AbstractWebConsolePlugin {
}
}
}
-
+
// 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 extends AbstractWebConsolePlugin {
}
public void activate(BundleContext context) {
- super.activate(context);
-
providerTracker = new ServiceTracker(context,
ResourceProvider.SERVICE_NAME, null) {
@Override
@@ -189,10 +177,11 @@ class BundleResourceWebConsolePlugin extends AbstractWebConsolePlugin {
"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 extends AbstractWebConsolePlugin {
providerTracker.close();
providerTracker = null;
}
-
- super.deactivate();
}
private String getName(Bundle bundle) {
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.