You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/04/27 22:31:21 UTC
svn commit: r1590486 -
/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
Author: mattsicker
Date: Sun Apr 27 20:31:21 2014
New Revision: 1590486
URL: http://svn.apache.org/r1590486
Log:
Update bundle activator to check installed bundles for plugins.
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java?rev=1590486&r1=1590485&r2=1590486&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/osgi/Activator.java Sun Apr 27 20:31:21 2014
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.imp
import org.apache.logging.log4j.simple.SimpleLoggerContextFactory;
import org.apache.logging.log4j.spi.LoggerContextFactory;
import org.apache.logging.log4j.status.StatusLogger;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
@@ -40,15 +41,33 @@ public class Activator implements org.os
public void start(final BundleContext context) throws Exception {
registerLoggerContextFactory();
context.addBundleListener(new Listener());
+ // done after the BundleListener as to not miss any new bundle installs in the interim
+ scanInstalledBundlesForPlugins(context);
}
private void registerLoggerContextFactory() {
final LoggerContextFactory current = LogManager.getFactory();
if (!(current instanceof Log4jContextFactory)) {
+ LOGGER.debug("Replacing LogManager LoggerContextFactory.");
LogManager.setFactory(new Log4jContextFactory());
}
}
+ private void scanInstalledBundlesForPlugins(final BundleContext context) {
+ final Bundle[] bundles = context.getBundles();
+ for (final Bundle bundle : bundles) {
+ if (bundle.getState() == Bundle.ACTIVE) {
+ // TODO: bundle state can change during this
+ scanBundleForPlugins(bundle);
+ }
+ }
+ }
+
+ private static void scanBundleForPlugins(final Bundle bundle) {
+ LOGGER.debug("Scanning bundle [{}] for plugins.", bundle.getSymbolicName());
+ PluginManager.loadPlugins(new BundleResourceLoader(bundle));
+ }
+
@Override
public void stop(final BundleContext context) throws Exception {
unregisterLoggerContextFactory();
@@ -64,7 +83,7 @@ public class Activator implements org.os
public void bundleChanged(final BundleEvent event) {
switch (event.getType()) {
case BundleEvent.STARTED:
- PluginManager.loadPlugins(new BundleResourceLoader(event.getBundle()));
+ scanBundleForPlugins(event.getBundle());
break;
default: