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

rgoers 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 0edbb67  LOG4J2-913 - Code review changes
0edbb67 is described below

commit 0edbb670f33e883f1d077b915c3b78573e1eca59
Author: Ralph Goers <[email protected]>
AuthorDate: Thu May 9 22:09:49 2019 -0700

    LOG4J2-913 - Code review changes
---
 .../org/apache/logging/log4j/util/Base64Util.java  |  32 -------
 .../org/apache/logging/log4j/util/Base64Util.java  |  64 -------------
 .../java/org/apache/logging/log4j/util/Timer.java  |   4 +-
 .../core/util/BasicAuthorizationProvider.java      |   5 +-
 .../logging/log4j/core/util/WatchEventService.java |   5 +-
 .../logging/log4j/core/util/WatchManager.java      | 106 ++++++++++-----------
 6 files changed, 59 insertions(+), 157 deletions(-)

diff --git 
a/log4j-api-java9/src/main/java/org/apache/logging/log4j/util/Base64Util.java 
b/log4j-api-java9/src/main/java/org/apache/logging/log4j/util/Base64Util.java
deleted file mode 100644
index 63ac84f..0000000
--- 
a/log4j-api-java9/src/main/java/org/apache/logging/log4j/util/Base64Util.java
+++ /dev/null
@@ -1,32 +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.util;
-
-import java.util.Base64;
-
-
-/**
- * C
- */
-public class Base64Util {
-
-    private static final Base64.Encoder encoder = Base64.getEncoder();
-
-    public static String encode(String str) {
-        return str != null ? encoder.encodeToString(str.getBytes()) : null;
-    }
-}
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/util/Base64Util.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/util/Base64Util.java
deleted file mode 100644
index 66ff989..0000000
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Base64Util.java
+++ /dev/null
@@ -1,64 +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.util;
-
-import java.lang.reflect.Method;
-
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- *
- */
-public class Base64Util {
-
-    private static Method encodeMethod = null;
-    private static Object encoder = null;
-
-    static {
-        try {
-            Class<?> clazz = LoaderUtil.loadClass("java.util.Base64");
-            Class<?> encoderClazz = 
LoaderUtil.loadClass("java.util.Base64$Encoder");
-            Method method = clazz.getMethod("getEncoder");
-            encoder = method.invoke(null);
-            encodeMethod = encoderClazz.getMethod("encodeToString", 
byte[].class);
-        } catch (Exception ex) {
-            try {
-                Class<?> clazz = 
LoaderUtil.loadClass("javax.xml.bind.DataTypeConverter");
-                encodeMethod = clazz.getMethod("printBase64Binary");
-            } catch (Exception ex2) {
-                LowLevelLogUtil.logException("Unable to create a Base64 
Encoder", ex2);
-            }
-        }
-    }
-
-    public static String encode(String str) {
-        if (str == null) {
-            return null;
-        }
-        byte [] data = str.getBytes();
-        if (encodeMethod != null) {
-            try {
-                return (String) encodeMethod.invoke(encoder, data);
-            } catch (Exception ex) {
-                StatusLogger.getLogger().warn("Unable to encode String: " + 
ex.getMessage());
-                return str;
-            }
-        }
-        StatusLogger.getLogger().warn("No Encoder, unable to encode string");
-        return str;
-    }
-}
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Timer.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/util/Timer.java
index add41cc..5a56482 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Timer.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Timer.java
@@ -20,7 +20,9 @@ import java.io.Serializable;
 import java.text.DecimalFormat;
 
 /**
- *
+ * Primarily used in unit tests, but can be used to track elapsed time for a 
request or portion of any other operation
+ * so long as all the timer methods are called on the same thread in which it 
was started. Calling start on
+ * multiple threads will cause the the times to be aggregated.
  */
 public class Timer implements Serializable, StringBuilderFormattable
 {
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/BasicAuthorizationProvider.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/BasicAuthorizationProvider.java
index 8ad23df..038cced 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/BasicAuthorizationProvider.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/BasicAuthorizationProvider.java
@@ -17,10 +17,10 @@
 package org.apache.logging.log4j.core.util;
 
 import java.net.URLConnection;
+import java.util.Base64;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.Base64Util;
 import org.apache.logging.log4j.util.LoaderUtil;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
@@ -34,6 +34,7 @@ public class BasicAuthorizationProvider implements 
AuthorizationProvider {
     public static final String PASSWORD_DECRYPTOR = "log4j2.passwordDecryptor";
 
     private static Logger LOGGER = StatusLogger.getLogger();
+    private static final Base64.Encoder encoder = Base64.getEncoder();
 
     private String authString = null;
 
@@ -52,7 +53,7 @@ public class BasicAuthorizationProvider implements 
AuthorizationProvider {
             }
         }
         if (userName != null && password != null) {
-            authString = "Basic " + Base64Util.encode(userName + ":" + 
password);
+            authString = "Basic " + encoder.encodeToString((userName + ":" + 
password).getBytes());
         }
     }
 
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchEventService.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchEventService.java
index 31021c8..65d9df2 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchEventService.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchEventService.java
@@ -21,8 +21,7 @@ package org.apache.logging.log4j.core.util;
  */
 public interface WatchEventService {
 
-       void subscribe(WatchManager manager);
-
-       void unsubscribe(WatchManager manager);
+    void subscribe(WatchManager manager);
 
+    void unsubscribe(WatchManager manager);
 }
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
index 3e37152..058c84f 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/WatchManager.java
@@ -16,6 +16,13 @@
  */
 package org.apache.logging.log4j.core.util;
 
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.AbstractLifeCycle;
+import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
+import org.apache.logging.log4j.core.config.ConfigurationScheduler;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.LoaderUtil;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Date;
@@ -29,13 +36,6 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.AbstractLifeCycle;
-import org.apache.logging.log4j.core.config.ConfigurationFileWatcher;
-import org.apache.logging.log4j.core.config.ConfigurationScheduler;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.LoaderUtil;
-
 /**
  * Manages {@link FileWatcher}s.
  *
@@ -58,12 +58,12 @@ public class WatchManager extends AbstractLifeCycle {
     }
 
     public UUID getId() {
-       return this.id;
-       }
+        return this.id;
+    }
 
-       public boolean hasEventListeners() {
-       return eventServiceList.size() > 0;
-       }
+    public boolean hasEventListeners() {
+        return eventServiceList.size() > 0;
+    }
 
     /**
      * Resets all file monitors to their current last modified time. If this 
manager does not watch any file, nothing
@@ -77,7 +77,7 @@ public class WatchManager extends AbstractLifeCycle {
      */
     public void reset() {
         logger.debug("Resetting {}", this);
-        for (final Source source: watchers.keySet()) {
+        for (final Source source : watchers.keySet()) {
             reset(source);
         }
     }
@@ -90,8 +90,7 @@ public class WatchManager extends AbstractLifeCycle {
      * given watched file has changed during the period of time when the 
manager was stopped.
      * </p>
      *
-     * @param file
-     *            the file for the monitor to reset.
+     * @param file the file for the monitor to reset.
      * @since 2.11.0
      */
     public void reset(final File file) {
@@ -111,9 +110,8 @@ public class WatchManager extends AbstractLifeCycle {
      * given watched configuration has changed during the period of time when 
the manager was stopped.
      * </p>
      *
-     * @param source
-     *            the Source for the monitor to reset.
-     * @since 2.11.2
+     * @param source the Source for the monitor to reset.
+     * @since 2.12.0
      */
     public void reset(final Source source) {
         if (source == null) {
@@ -126,8 +124,8 @@ public class WatchManager extends AbstractLifeCycle {
                 final long lastModifiedMillis = watcher.getLastModified();
                 if (logger.isDebugEnabled()) {
                     logger.debug("Resetting file monitor for '{}' from {} ({}) 
to {} ({})", source.getLocation(),
-                        millisToString(monitor.lastModifiedMillis), 
monitor.lastModifiedMillis,
-                        millisToString(lastModifiedMillis), 
lastModifiedMillis);
+                            millisToString(monitor.lastModifiedMillis), 
monitor.lastModifiedMillis,
+                            millisToString(lastModifiedMillis), 
lastModifiedMillis);
                 }
                 monitor.setLastModifiedMillis(lastModifiedMillis);
             }
@@ -163,16 +161,16 @@ public class WatchManager extends AbstractLifeCycle {
                     TimeUnit.SECONDS);
         }
         for (WatchEventService service : eventServiceList) {
-               service.subscribe(this);
-               }
+            service.subscribe(this);
+        }
     }
 
     @Override
     public boolean stop(final long timeout, final TimeUnit timeUnit) {
         setStopping();
-               for (WatchEventService service : eventServiceList) {
-                       service.unsubscribe(this);
-               }
+        for (WatchEventService service : eventServiceList) {
+            service.unsubscribe(this);
+        }
         final boolean stopped = stop(future);
         setStopped();
         return stopped;
@@ -181,8 +179,7 @@ public class WatchManager extends AbstractLifeCycle {
     /**
      * Unwatches the given file.
      *
-     * @param file
-     *            the file to stop watching.
+     * @param file the file to stop watching.
      * @since 2.11.0
      */
     public void unwatchFile(final File file) {
@@ -194,25 +191,23 @@ public class WatchManager extends AbstractLifeCycle {
      * Unwatches the given file.
      *
      * @param source the Source to stop watching.
-     *            the file to stop watching.
-     * @since 2.11.2
+     *               the file to stop watching.
+     * @since 2.12.0
      */
     public void unwatch(final Source source) {
         logger.debug("Unwatching configuration {}", source);
         watchers.remove(source);
     }
 
-       public void checkFiles() {
-               new WatchRunnable().run();
-       }
+    public void checkFiles() {
+        new WatchRunnable().run();
+    }
 
     /**
      * Watches the given file.
      *
-     * @param file
-     *            the file to watch.
-     * @param fileWatcher
-     *            the watcher to notify of file changes.
+     * @param file        the file to watch.
+     * @param fileWatcher the watcher to notify of file changes.
      */
     public void watchFile(final File file, final FileWatcher fileWatcher) {
         Watcher watcher;
@@ -228,9 +223,8 @@ public class WatchManager extends AbstractLifeCycle {
     /**
      * Watches the given file.
      *
-     * @param source the source to watch.
-     * @param watcher
-     *            the watcher to notify of file changes.
+     * @param source  the source to watch.
+     * @param watcher the watcher to notify of file changes.
      */
     public void watch(final Source source, final Watcher watcher) {
         watcher.watching(source);
@@ -243,6 +237,7 @@ public class WatchManager extends AbstractLifeCycle {
 
     /**
      * Returns a Map of the file watchers.
+     *
      * @return A Map of the file watchers.
      * @deprecated use getConfigurationWatchers.
      */
@@ -252,7 +247,7 @@ public class WatchManager extends AbstractLifeCycle {
             if (entry.getValue().getWatcher() instanceof 
ConfigurationFileWatcher) {
                 map.put(entry.getKey().getFile(), (FileWatcher) 
entry.getValue().getWatcher());
             } else {
-                map.put(entry.getKey().getFile(), new 
WrappedFileWatcher((FileWatcher)entry.getValue().getWatcher()));
+                map.put(entry.getKey().getFile(), new 
WrappedFileWatcher((FileWatcher) entry.getValue().getWatcher()));
             }
         }
         return map;
@@ -260,6 +255,7 @@ public class WatchManager extends AbstractLifeCycle {
 
     /**
      * Return the ConfigurationWaatchers.
+     *
      * @return the ConfigurationWatchers.
      * @since 2.11.2
      */
@@ -275,21 +271,21 @@ public class WatchManager extends AbstractLifeCycle {
         return new Date(millis).toString();
     }
 
-       private List<WatchEventService> getEventServices() {
-       List<WatchEventService> list = new ArrayList<>();
-               for (final ClassLoader classLoader : 
LoaderUtil.getClassLoaders()) {
-                       try {
-                               final ServiceLoader<WatchEventService > 
serviceLoader =
-                                       
ServiceLoader.load(WatchEventService.class, classLoader);
-                               for (final WatchEventService service : 
serviceLoader) {
-                                       list.add(service);
-                               }
-                       } catch (final Throwable ex) {
-                               LOGGER.debug("Unable to retrieve 
WatchEventService from ClassLoader {}", classLoader, ex);
-                       }
-               }
-               return list;
-       }
+    private List<WatchEventService> getEventServices() {
+        List<WatchEventService> list = new ArrayList<>();
+        for (final ClassLoader classLoader : LoaderUtil.getClassLoaders()) {
+            try {
+                final ServiceLoader<WatchEventService> serviceLoader =
+                        ServiceLoader.load(WatchEventService.class, 
classLoader);
+                for (final WatchEventService service : serviceLoader) {
+                    list.add(service);
+                }
+            } catch (final Throwable ex) {
+                LOGGER.debug("Unable to retrieve WatchEventService from 
ClassLoader {}", classLoader, ex);
+            }
+        }
+        return list;
+    }
 
     private final class WatchRunnable implements Runnable {
 

Reply via email to