This is an automated email from the ASF dual-hosted git repository. mattsicker pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 060264c9b09c94f1986ba1ca28107f9f605393b4 Author: Matt Sicker <[email protected]> AuthorDate: Tue Mar 29 20:26:12 2022 -0500 Remove PluginContext Signed-off-by: Matt Sicker <[email protected]> --- .../logging/log4j/plugins/util/PluginContext.java | 45 ---------------------- .../logging/log4j/plugins/util/PluginRegistry.java | 16 ++++---- 2 files changed, 7 insertions(+), 54 deletions(-) diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginContext.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginContext.java deleted file mode 100644 index ccee554..0000000 --- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginContext.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ - -package org.apache.logging.log4j.plugins.util; - -import org.apache.logging.log4j.util.LoaderUtil; - -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodHandles.Lookup; - -public class PluginContext { - private final ClassLoader classLoader; - private final Lookup lookup; - - public PluginContext() { - this(LoaderUtil.getClassLoader(), MethodHandles.lookup()); - } - - public PluginContext(final ClassLoader classLoader, final Lookup lookup) { - this.classLoader = classLoader; - this.lookup = lookup; - } - - public ClassLoader getClassLoader() { - return classLoader; - } - - public Lookup getLookup() { - return lookup; - } -} diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginRegistry.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginRegistry.java index 413f9e1..e68bfdb 100644 --- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginRegistry.java +++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/PluginRegistry.java @@ -29,7 +29,6 @@ import org.apache.logging.log4j.util.LoaderUtil; import org.apache.logging.log4j.util.Strings; import java.io.IOException; -import java.lang.invoke.MethodHandles; import java.net.URI; import java.net.URL; import java.text.DecimalFormat; @@ -117,7 +116,7 @@ public class PluginRegistry { // already loaded return existing; } - final Map<String, List<PluginType<?>>> newPluginsByCategory = decodeCacheFiles(new PluginContext()); + final Map<String, List<PluginType<?>>> newPluginsByCategory = decodeCacheFiles(LoaderUtil.getClassLoader()); loadPlugins(newPluginsByCategory); // Note multiple threads could be calling this method concurrently. Both will do the work, @@ -151,7 +150,7 @@ public class PluginRegistry { // already loaded from this classloader return existing; } - final Map<String, List<PluginType<?>>> newPluginsByCategory = decodeCacheFiles(new PluginContext(loader, MethodHandles.lookup())); + final Map<String, List<PluginType<?>>> newPluginsByCategory = decodeCacheFiles(loader); loadPlugins(loader, newPluginsByCategory); // Note multiple threads could be calling this method concurrently. Both will do the work, @@ -231,14 +230,13 @@ public class PluginRegistry { }); } - private Map<String, List<PluginType<?>>> decodeCacheFiles(final PluginContext context) { + private Map<String, List<PluginType<?>>> decodeCacheFiles(final ClassLoader classLoader) { final long startTime = System.nanoTime(); final PluginCache cache = new PluginCache(); try { - final ClassLoader loader = context.getClassLoader(); - final Enumeration<URL> resources = loader.getResources(PluginManager.PLUGIN_CACHE_FILE); + final Enumeration<URL> resources = classLoader.getResources(PluginManager.PLUGIN_CACHE_FILE); if (resources == null) { - LOGGER.info("Plugin preloads not available from class loader {}", loader); + LOGGER.info("Plugin preloads not available from class loader {}", classLoader); } else { cache.loadCacheFiles(resources); } @@ -253,7 +251,7 @@ public class PluginRegistry { newPluginsByCategory.put(categoryLowerCase, types); for (final Map.Entry<String, PluginEntry> inner : outer.getValue().entrySet()) { final PluginEntry entry = inner.getValue(); - final PluginType<?> type = new PluginType<>(entry, context.getClassLoader()); + final PluginType<?> type = new PluginType<>(entry, classLoader); types.add(type); ++pluginCount; } @@ -263,7 +261,7 @@ public class PluginRegistry { final long endTime = System.nanoTime(); final DecimalFormat numFormat = new DecimalFormat("#0.000000"); return "Took " + numFormat.format((endTime - startTime) * 1e-9) + - " seconds to load " + numPlugins + " plugins from " + context.getClassLoader(); + " seconds to load " + numPlugins + " plugins from " + classLoader; }); return newPluginsByCategory; }
