jvz commented on code in PR #1136:
URL: https://github.com/apache/logging-log4j2/pull/1136#discussion_r1015851903
##########
log4j-api/src/main/java/org/apache/logging/log4j/util/Activator.java:
##########
@@ -101,64 +100,52 @@ private String toStateString(final int state) {
}
private void loadProvider(final BundleContext bundleContext, final
BundleWiring bundleWiring) {
- final String filter = "(APIVersion>=2.6.0)";
- try {
- final Collection<ServiceReference<Provider>> serviceReferences =
bundleContext.getServiceReferences(Provider.class, filter);
- Provider maxProvider = null;
- for (final ServiceReference<Provider> serviceReference :
serviceReferences) {
- final Provider provider =
bundleContext.getService(serviceReference);
- if (maxProvider == null || provider.getPriority() >
maxProvider.getPriority()) {
- maxProvider = provider;
- }
- }
- if (maxProvider != null) {
- ProviderUtil.addProvider(maxProvider);
+ final List<Provider> providers = loadProviders(bundleWiring);
+ if (!providers.isEmpty()) {
+
ServiceRegistry.getInstance().registerBundleServices(Provider.class,
bundleContext.getBundle().getBundleId(), providers);
+ if (hasLoggingSystemInitializationLock) {
+ LoggingSystem.getInstance().releaseInitializationLock();
+ hasLoggingSystemInitializationLock = false;
}
- } catch (final InvalidSyntaxException ex) {
- LOGGER.error("Invalid service filter: " + filter, ex);
}
- final List<URL> urls = bundleWiring.findEntries("META-INF",
"log4j-provider.properties", 0);
- for (final URL url : urls) {
- ProviderUtil.loadProvider(url, bundleWiring.getClassLoader());
+ }
+
+ private List<Provider> loadProviders(final BundleWiring bundleWiring) {
+ final List<Provider> providers = new ArrayList<>();
+ final ClassLoader classLoader = bundleWiring.getClassLoader();
+ final Iterator<Provider> iterator = ServiceLoader.load(Provider.class,
classLoader).iterator();
Review Comment:
This approach seems to be the easiest way to support OSGi without requiring
extra metadata or similar to make it work. Only disadvantage, as I mentioned on
the dev list, is that this requires a couple admin permissions in OSGi to
obtain different bundles' ClassLoader and similar private-ish objects. On the
other hand, this makes it so we don't need to use anything outside the core
OSGi API (which includes bundles and services basically, the latter we don't
need to support anymore).
I'll note that I removed support for loading legacy providers here as they'd
be unlikely to work properly in OSGi anyways, and we bumped the API
compatibility version to 3.0.0 anyways.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]