You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/08/30 09:33:38 UTC
[11/26] logging-log4j2 git commit: Fix string-joining of packages
configuration attribute
Fix string-joining of packages configuration attribute
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/871a0971
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/871a0971
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/871a0971
Branch: refs/heads/master
Commit: 871a097181aa7f6136638d9f0a9e7095e32ef29f
Parents: 0353fa4
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Sun Aug 21 16:47:20 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Sun Aug 21 16:47:20 2016 +0200
----------------------------------------------------------------------
.../org/apache/logging/log4j/util/Strings.java | 63 ++++++++++++++++++++
.../core/config/AbstractConfiguration.java | 3 +-
2 files changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/871a0971/log4j-api/src/main/java/org/apache/logging/log4j/util/Strings.java
----------------------------------------------------------------------
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 294b771..747bed4 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
@@ -16,7 +16,9 @@
*/
package org.apache.logging.log4j.util;
+import java.util.Iterator;
import java.util.Locale;
+import java.util.Objects;
/**
* <em>Consider this class private.</em>
@@ -166,4 +168,65 @@ public final class Strings {
final String ts = str == null ? null : str.trim();
return isEmpty(ts) ? null : ts;
}
+
+ /**
+ * <p>Joins the elements of the provided {@code Iterable} into
+ * a single String containing the provided elements.</p>
+ *
+ * <p>No delimiter is added before or after the list. Null objects or empty
+ * strings within the iteration are represented by empty strings.</p>
+ *
+ * @param iterable the {@code Iterable} providing the values to join together, may be null
+ * @param separator the separator character to use
+ * @return the joined String, {@code null} if null iterator input
+ */
+ public static String join(final Iterable<?> iterable, final char separator) {
+ if (iterable == null) {
+ return null;
+ }
+ return join(iterable.iterator(), separator);
+ }
+
+ /**
+ * <p>Joins the elements of the provided {@code Iterator} into
+ * a single String containing the provided elements.</p>
+ *
+ * <p>No delimiter is added before or after the list. Null objects or empty
+ * strings within the iteration are represented by empty strings.</p>
+ *
+ * @param iterator the {@code Iterator} of values to join together, may be null
+ * @param separator the separator character to use
+ * @return the joined String, {@code null} if null iterator input
+ */
+ public static String join(final Iterator<?> iterator, final char separator) {
+
+ // handle null, zero and one elements before building a buffer
+ if (iterator == null) {
+ return null;
+ }
+ if (!iterator.hasNext()) {
+ return EMPTY;
+ }
+ final Object first = iterator.next();
+ if (!iterator.hasNext()) {
+ return Objects.toString(first);
+ }
+
+ // two or more elements
+ final StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
+ if (first != null) {
+ buf.append(first);
+ }
+
+ while (iterator.hasNext()) {
+ buf.append(separator);
+ final Object obj = iterator.next();
+ if (obj != null) {
+ buf.append(obj);
+ }
+ }
+
+ return buf.toString();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/871a0971/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index f123991..d89b8f5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -46,6 +46,7 @@ import org.apache.logging.log4j.core.util.NameUtil;
import org.apache.logging.log4j.core.util.NanoClock;
import org.apache.logging.log4j.core.util.WatchManager;
import org.apache.logging.log4j.util.PropertiesUtil;
+import org.apache.logging.log4j.util.Strings;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
@@ -236,7 +237,7 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
}
*/
if (!getPluginPackages().isEmpty()) {
- xmlWriter.writeAttribute("packages", getPluginPackages().toString()); // TODO comma-separated string
+ xmlWriter.writeAttribute("packages", Strings.join(getPluginPackages(), ','));
}
if (!isShutdownHookEnabled()) {
xmlWriter.writeAttribute("shutdownHook", "disable");