You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2021/12/13 11:50:16 UTC

[logging-log4j2] branch master updated: Remove SetUtils from core.

This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ce7eac  Remove SetUtils from core.
6ce7eac is described below

commit 6ce7eac75cb3a28b6e17ad0321a0bf2bbe9f9803
Author: Volkan Yazici <vo...@yazi.ci>
AuthorDate: Sun Dec 12 21:14:12 2021 +0100

    Remove SetUtils from core.
---
 .../org/apache/logging/log4j/util/Strings.java     |  5 +++
 .../apache/logging/log4j/core/util/SetUtils.java   | 47 ----------------------
 .../logging/log4j/web/Log4jWebInitializerImpl.java | 41 ++++++++++++-------
 .../logging/log4j/web/Log4jWebInitializerImpl.java | 43 +++++++++++++-------
 4 files changed, 60 insertions(+), 76 deletions(-)

diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java
index 09168d8..736ef32 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java
@@ -34,6 +34,11 @@ public final class Strings {
      * The empty string.
      */
     public static final String EMPTY = "";
+
+    /**
+     * The empty string array.
+     */
+    public static final String[] EMPTY_ARRAY = {};
     
     /**
      * OS-dependent line separator, defaults to {@code "\n"} if the system property {@code ""line.separator"} cannot be
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java
deleted file mode 100644
index e1a5218..0000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/SetUtils.java
+++ /dev/null
@@ -1,47 +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.core.util;
-
-import java.util.Set;
-
-/**
- * Set-related convenience methods.
- */
-public final class SetUtils {
-
-    private static final String[] EMPTY_STRINGS = new String[0];
-
-    private SetUtils() {}
-
-    /**
-     * Collects strings starting with the given {@code prefix} from the given {@code set}.
-     *
-     * @param set a (nullable) set of strings
-     * @param prefix a prefix to look for in the string set
-     * @return an array of the matching strings from the given set
-     */
-    public static String[] prefixSet(final Set<String> set, final String prefix) {
-        if (set == null) {
-            return EMPTY_STRINGS;
-        }
-        return set
-                .stream()
-                .filter(string -> string.startsWith(prefix))
-                .toArray(String[]::new);
-    }
-
-}
diff --git a/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java b/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
index 3ecbe14..bb5d51d 100644
--- a/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
+++ b/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
@@ -16,19 +16,7 @@
  */
 package org.apache.logging.log4j.web;
 
-import java.net.URI;
-import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-
 import jakarta.servlet.ServletContext;
-
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.AbstractLifeCycle;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -42,9 +30,16 @@ import org.apache.logging.log4j.core.selector.ContextSelector;
 import org.apache.logging.log4j.core.selector.NamedContextSelector;
 import org.apache.logging.log4j.core.util.Loader;
 import org.apache.logging.log4j.core.util.NetUtils;
-import org.apache.logging.log4j.core.util.SetUtils;
 import org.apache.logging.log4j.spi.LoggerContextFactory;
 import org.apache.logging.log4j.util.LoaderUtil;
+import org.apache.logging.log4j.util.Strings;
+
+import java.net.URI;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 
 /**
  * This class initializes and deinitializes Log4j no matter how the initialization occurs.
@@ -193,7 +188,7 @@ final class Log4jWebInitializerImpl extends AbstractLifeCycle implements Log4jWe
         try {
             String configLocation = location;
             if (configLocation == null) {
-                final String[] paths = SetUtils.prefixSet(servletContext.getResourcePaths(WEB_INF), WEB_INF + "log4j2");
+                final String[] paths = prefixSet(servletContext.getResourcePaths(WEB_INF), WEB_INF + "log4j2");
                 LOGGER.debug("getConfigURI found resource paths {} in servletContext at [{}]", Arrays.toString(paths), WEB_INF);
                 if (paths.length == 1) {
                     configLocation = paths[0];
@@ -235,6 +230,24 @@ final class Log4jWebInitializerImpl extends AbstractLifeCycle implements Log4jWe
         return null;
     }
 
+    /**
+     * Collects strings starting with the given {@code prefix} from the given {@code set}.
+     *
+     * @param set a (nullable) set of strings
+     * @param prefix a prefix to look for in the string set
+     * @return an array of the matching strings from the given set
+     */
+    @SuppressWarnings("SameParameterValue")
+    private static String[] prefixSet(final Set<String> set, final String prefix) {
+        if (set == null) {
+            return Strings.EMPTY_ARRAY;
+        }
+        return set
+                .stream()
+                .filter(string -> string.startsWith(prefix))
+                .toArray(String[]::new);
+    }
+
     @Override
     public synchronized boolean stop(final long timeout, final TimeUnit timeUnit) {
         if (!this.isStarted() && !this.isStopped()) {
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
index ba53d4f..323ccbb 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
@@ -16,19 +16,6 @@
  */
 package org.apache.logging.log4j.web;
 
-import java.net.URI;
-import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-
-import javax.servlet.ServletContext;
-
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.AbstractLifeCycle;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -42,9 +29,17 @@ import org.apache.logging.log4j.core.selector.ContextSelector;
 import org.apache.logging.log4j.core.selector.NamedContextSelector;
 import org.apache.logging.log4j.core.util.Loader;
 import org.apache.logging.log4j.core.util.NetUtils;
-import org.apache.logging.log4j.core.util.SetUtils;
 import org.apache.logging.log4j.spi.LoggerContextFactory;
 import org.apache.logging.log4j.util.LoaderUtil;
+import org.apache.logging.log4j.util.Strings;
+
+import javax.servlet.ServletContext;
+import java.net.URI;
+import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
 
 /**
  * This class initializes and deinitializes Log4j no matter how the initialization occurs.
@@ -193,7 +188,7 @@ final class Log4jWebInitializerImpl extends AbstractLifeCycle implements Log4jWe
         try {
             String configLocation = location;
             if (configLocation == null) {
-                final String[] paths = SetUtils.prefixSet(servletContext.getResourcePaths(WEB_INF), WEB_INF + "log4j2");
+                final String[] paths = prefixSet(servletContext.getResourcePaths(WEB_INF), WEB_INF + "log4j2");
                 LOGGER.debug("getConfigURI found resource paths {} in servletContext at [{}]", Arrays.toString(paths), WEB_INF);
                 if (paths.length == 1) {
                     configLocation = paths[0];
@@ -235,6 +230,24 @@ final class Log4jWebInitializerImpl extends AbstractLifeCycle implements Log4jWe
         return null;
     }
 
+    /**
+     * Collects strings starting with the given {@code prefix} from the given {@code set}.
+     *
+     * @param set a (nullable) set of strings
+     * @param prefix a prefix to look for in the string set
+     * @return an array of the matching strings from the given set
+     */
+    @SuppressWarnings("SameParameterValue")
+    private static String[] prefixSet(final Set<String> set, final String prefix) {
+        if (set == null) {
+            return Strings.EMPTY_ARRAY;
+        }
+        return set
+                .stream()
+                .filter(string -> string.startsWith(prefix))
+                .toArray(String[]::new);
+    }
+
     @Override
     public synchronized boolean stop(final long timeout, final TimeUnit timeUnit) {
         if (!this.isStarted() && !this.isStopped()) {