logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1612996 - /logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/Activator.java
Date Thu, 24 Jul 2014 05:02:17 GMT
Author: mattsicker
Date: Thu Jul 24 05:02:16 2014
New Revision: 1612996

URL: http://svn.apache.org/r1612996
Log:
Use list of required bundle wires first in Activator to find log4j providers specifying the
capability first.

Modified:
    logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/Activator.java

Modified: logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/Activator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/Activator.java?rev=1612996&r1=1612995&r2=1612996&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/Activator.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-api/src/main/java/org/apache/logging/log4j/util/Activator.java
Thu Jul 24 05:02:16 2014
@@ -18,8 +18,10 @@ package org.apache.logging.log4j.util;
 
 import java.net.URL;
 import java.security.Permission;
+import java.util.List;
 
 import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.spi.LoggerContextFactory;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.osgi.framework.AdaptPermission;
 import org.osgi.framework.AdminPermission;
@@ -28,6 +30,7 @@ import org.osgi.framework.BundleActivato
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
 import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
 
 /**
@@ -54,24 +57,29 @@ public class Activator implements Bundle
         }
         try {
             checkPermission(new AdminPermission(bundle, AdminPermission.RESOURCE));
-            final URL url = bundle.getEntry(ProviderUtil.PROVIDER_RESOURCE);
-            if (url != null) {
-                checkPermission(new AdminPermission(bundle, AdminPermission.CLASS));
-                checkPermission(new AdaptPermission(BundleWiring.class.getName(), bundle,
AdaptPermission.ADAPT));
-                ProviderUtil.loadProvider(url, getBundleClassLoader(bundle));
-            }
+            checkPermission(new AdaptPermission(BundleWiring.class.getName(), bundle, AdaptPermission.ADAPT));
+            loadProvider(bundle.adapt(BundleWiring.class));
+        } catch (final SecurityException e) {
+            LOGGER.debug("Cannot access bundle [{}] contents. Ignoring.", bundle.getSymbolicName(),
e);
         } catch (final Exception e) {
             LOGGER.warn("Problem checking bundle {} for Log4j 2 provider.", bundle.getSymbolicName(),
e);
         }
     }
 
-    private static ClassLoader getBundleClassLoader(Bundle bundle) {
-        final BundleWiring wiring = bundle.adapt(BundleWiring.class);
-        return wiring.getClassLoader();
+    private void loadProvider(BundleWiring provider) {
+        final List<URL> urls = provider.findEntries("META-INF", "log4j-provider.properties",
0);
+        for (final URL url : urls) {
+            ProviderUtil.loadProvider(url, provider.getClassLoader());
+        }
     }
 
     @Override
     public void start(final BundleContext context) throws Exception {
+        final BundleWiring self = context.getBundle().adapt(BundleWiring.class);
+        final List<BundleWire> required = self.getRequiredWires(LoggerContextFactory.class.getName());
+        for (BundleWire wire : required) {
+            loadProvider(wire.getProviderWiring());
+        }
         context.addBundleListener(this);
         final Bundle[] bundles = context.getBundles();
         for (final Bundle bundle : bundles) {



Mime
View raw message