Checkstyle
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/640f4f2f Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/640f4f2f Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/640f4f2f Branch: refs/heads/LOG4J2-1136 Commit: 640f4f2fdf45dcb93823c2ec44138d7e31fa24bc Parents: 79e447c Author: rpopma <[email protected]> Authored: Thu Sep 24 19:41:14 2015 +0200 Committer: Ralph Goers <[email protected]> Committed: Sun Sep 27 10:49:28 2015 -0700 ---------------------------------------------------------------------- .../appender/mom/jeromq/JeroMqAppender.java | 152 ++++++++--------- .../core/appender/mom/jeromq/package-info.java | 23 +++ .../core/appender/mom/kafka/package-info.java | 23 +++ .../plugins/processor/PluginProcessor.java | 35 ++-- .../config/plugins/processor/package-info.java | 2 +- .../core/config/plugins/util/ResolverUtil.java | 6 +- .../core/config/plugins/util/package-info.java | 2 +- .../validators/RequiredValidator.java | 4 +- .../plugins/visitors/AbstractPluginVisitor.java | 39 +++-- .../plugins/visitors/PluginNodeVisitor.java | 2 +- .../config/plugins/visitors/package-info.java | 2 +- .../PropertiesConfigurationFactory.java | 32 ++-- .../log4j/core/config/xml/XmlConfiguration.java | 161 ++++++++++--------- .../logging/log4j/core/layout/XmlLayout.java | 3 + .../log4j/core/lookup/AbstractLookup.java | 2 +- .../log4j/core/lookup/MainMapLookup.java | 22 +-- .../logging/log4j/core/lookup/MapLookup.java | 44 ++--- .../log4j/core/net/MulticastDnsAdvertiser.java | 99 ++++++------ 18 files changed, 372 insertions(+), 281 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/JeroMqAppender.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/JeroMqAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/JeroMqAppender.java index cca824d..948f466 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/JeroMqAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/JeroMqAppender.java @@ -53,6 +53,16 @@ import org.zeromq.ZMQ.Socket; @Plugin(name = "JeroMQ", category = "Core", elementType = "appender", printObject = true) public final class JeroMqAppender extends AbstractAppender { + /** + * System property to enable shutdown hook. + */ + static final String SYS_PROPERTY_ENABLE_SHUTDOWN_HOOK = "log4j.jeromq.enableShutdownHook"; + + /** + * System property to control JeroMQ I/O thread count. + */ + static final String SYS_PROPERTY_IO_THREADS = "log4j.jeromq.ioThreads"; + // Per ZMQ docs, there should usually only be one ZMQ context per process. private static volatile ZMQ.Context context; @@ -73,10 +83,6 @@ public final class JeroMqAppender extends AbstractAppender { private static final String SIMPLE_NAME = JeroMqAppender.class.getSimpleName(); - static final String SYS_PROPERTY_ENABLE_SHUTDOWN_HOOK = "log4j.jeromq.enableShutdownHook"; - - static final String SYS_PROPERTY_IO_THREADS = "log4j.jeromq.ioThreads"; - static { logger = StatusLogger.getLogger(); final PropertiesUtil managerProps = PropertiesUtil.getProperties(); @@ -99,6 +105,62 @@ public final class JeroMqAppender extends AbstractAppender { } } + private final long affinity; + private final long backlog; + private final boolean delayAttachOnConnect; + private final List<String> endpoints; + private final byte[] identity; + private final int ioThreads = 1; + private final boolean ipv4Only; + private final long linger; + private final long maxMsgSize; + private final long rcvHwm; + private final long receiveBufferSize; + private final int receiveTimeOut; + private final long reconnectIVL; + private final long reconnectIVLMax; + private final long sendBufferSize; + private int sendRcFalse; + private int sendRcTrue; + private final int sendTimeOut; + private final long sndHwm; + private final int tcpKeepAlive; + private final long tcpKeepAliveCount; + private final long tcpKeepAliveIdle; + private final long tcpKeepAliveInterval; + private final boolean xpubVerbose; + + private JeroMqAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout, + final boolean ignoreExceptions, final List<String> endpoints, final long affinity, final long backlog, + final boolean delayAttachOnConnect, final byte[] identity, final boolean ipv4Only, final long linger, + final long maxMsgSize, final long rcvHwm, final long receiveBufferSize, final int receiveTimeOut, + final long reconnectIVL, final long reconnectIVLMax, final long sendBufferSize, final int sendTimeOut, + final long sndHWM, final int tcpKeepAlive, final long tcpKeepAliveCount, final long tcpKeepAliveIdle, + final long tcpKeepAliveInterval, final boolean xpubVerbose) { + super(name, filter, layout, ignoreExceptions); + this.endpoints = endpoints; + this.affinity = affinity; + this.backlog = backlog; + this.delayAttachOnConnect = delayAttachOnConnect; + this.identity = identity; + this.ipv4Only = ipv4Only; + this.linger = linger; + this.maxMsgSize = maxMsgSize; + this.rcvHwm = rcvHwm; + this.receiveBufferSize = receiveBufferSize; + this.receiveTimeOut = receiveTimeOut; + this.reconnectIVL = reconnectIVL; + this.reconnectIVLMax = reconnectIVLMax; + this.sendBufferSize = sendBufferSize; + this.sendTimeOut = sendTimeOut; + this.sndHwm = sndHWM; + this.tcpKeepAlive = tcpKeepAlive; + this.tcpKeepAliveCount = tcpKeepAliveCount; + this.tcpKeepAliveIdle = tcpKeepAliveIdle; + this.tcpKeepAliveInterval = tcpKeepAliveInterval; + this.xpubVerbose = xpubVerbose; + } + // The ZMQ.Socket class has other set methods that we do not cover because // they throw unsupported operation exceptions. @PluginFactory @@ -153,9 +215,9 @@ public final class JeroMqAppender extends AbstractAppender { logger.debug("Creating JeroMqAppender with name={}, filter={}, layout={}, ignoreExceptions={}, endpoints={}", name, filter, layout, ignoreExceptions, endpoints); return new JeroMqAppender(name, filter, layout, ignoreExceptions, endpoints, affinity, backlog, - delayAttachOnConnect, identity, ipv4Only, linger, maxMsgSize, rcvHwm, receiveBufferSize, receiveTimeOut, - reconnectIVL, reconnectIVLMax, sendBufferSize, sendTimeOut, sndHwm, tcpKeepAlive, tcpKeepAliveCount, - tcpKeepAliveIdle, tcpKeepAliveInterval, xpubVerbose); + delayAttachOnConnect, identity, ipv4Only, linger, maxMsgSize, rcvHwm, receiveBufferSize, + receiveTimeOut, reconnectIVL, reconnectIVLMax, sendBufferSize, sendTimeOut, sndHwm, tcpKeepAlive, + tcpKeepAliveCount, tcpKeepAliveIdle, tcpKeepAliveInterval, xpubVerbose); } static ZMQ.Context getContext() { @@ -181,62 +243,6 @@ public final class JeroMqAppender extends AbstractAppender { } } - private final long affinity; - private final long backlog; - private final boolean delayAttachOnConnect; - private final List<String> endpoints; - private final byte[] identity; - private final int ioThreads = 1; - private final boolean ipv4Only; - private final long linger; - private final long maxMsgSize; - private final long rcvHwm; - private final long receiveBufferSize; - private final int receiveTimeOut; - private final long reconnectIVL; - private final long reconnectIVLMax; - private final long sendBufferSize; - private int sendRcFalse; - private int sendRcTrue; - private final int sendTimeOut; - private final long sndHwm; - private final int tcpKeepAlive; - private final long tcpKeepAliveCount; - private final long tcpKeepAliveIdle; - private final long tcpKeepAliveInterval; - private final boolean xpubVerbose; - - private JeroMqAppender(final String name, final Filter filter, final Layout<? extends Serializable> layout, - final boolean ignoreExceptions, final List<String> endpoints, final long affinity, final long backlog, - final boolean delayAttachOnConnect, final byte[] identity, final boolean ipv4Only, final long linger, - final long maxMsgSize, final long rcvHwm, final long receiveBufferSize, final int receiveTimeOut, - final long reconnectIVL, final long reconnectIVLMax, final long sendBufferSize, final int sendTimeOut, - final long sndHWM, final int tcpKeepAlive, final long tcpKeepAliveCount, final long tcpKeepAliveIdle, - final long tcpKeepAliveInterval, final boolean xpubVerbose) { - super(name, filter, layout, ignoreExceptions); - this.endpoints = endpoints; - this.affinity = affinity; - this.backlog = backlog; - this.delayAttachOnConnect = delayAttachOnConnect; - this.identity = identity; - this.ipv4Only = ipv4Only; - this.linger = linger; - this.maxMsgSize = maxMsgSize; - this.rcvHwm = rcvHwm; - this.receiveBufferSize = receiveBufferSize; - this.receiveTimeOut = receiveTimeOut; - this.reconnectIVL = reconnectIVL; - this.reconnectIVLMax = reconnectIVLMax; - this.sendBufferSize = sendBufferSize; - this.sendTimeOut = sendTimeOut; - this.sndHwm = sndHWM; - this.tcpKeepAlive = tcpKeepAlive; - this.tcpKeepAliveCount = tcpKeepAliveCount; - this.tcpKeepAliveIdle = tcpKeepAliveIdle; - this.tcpKeepAliveInterval = tcpKeepAliveInterval; - this.xpubVerbose = xpubVerbose; - } - @Override public synchronized void append(final LogEvent event) { final String formattedMessage = event.getMessage().getFormattedMessage(); @@ -244,8 +250,7 @@ public final class JeroMqAppender extends AbstractAppender { sendRcTrue++; } else { sendRcFalse++; - logger.error("Appender {} could not send message {} to JeroMQ {}", getName(), sendRcFalse, - formattedMessage); + logger.error("Appender {} could not send message {} to JeroMQ {}", getName(), sendRcFalse, formattedMessage); } } @@ -274,8 +279,8 @@ public final class JeroMqAppender extends AbstractAppender { logger.debug("{} {} context {} with ioThreads={}", prefix, name, context, ioThreads); // final ZMQ.Socket socketPub = getPublisher(); - logger.trace("{} {} setting {} publisher properties for instance {}", prefix, name, - socketPub.getClass().getName(), socketPub); + logger.trace("{} {} setting {} publisher properties for instance {}", prefix, name, socketPub.getClass() + .getName(), socketPub); logger.trace("{} {} publisher setAffinity({})", prefix, name, affinity); socketPub.setAffinity(affinity); logger.trace("{} {} publisher setBacklog({})", prefix, name, backlog); @@ -326,12 +331,13 @@ public final class JeroMqAppender extends AbstractAppender { + "sendTimeOut={}, sndHWM={}, TCPKeepAlive={}, TCPKeepAliveCount={}, TCPKeepAliveIdle={}, TCPKeepAliveInterval={}, TCPKeepAliveSetting={}", name, socketPub, socketPub.getType(), socketPub.getAffinity(), socketPub.getBacklog(), socketPub.getDelayAttachOnConnect(), socketPub.getEvents(), socketPub.getIPv4Only(), - socketPub.getLinger(), socketPub.getMaxMsgSize(), socketPub.getMulticastHops(), socketPub.getRate(), - socketPub.getRcvHWM(), socketPub.getReceiveBufferSize(), socketPub.getReceiveTimeOut(), - socketPub.getReconnectIVL(), socketPub.getReconnectIVLMax(), socketPub.getRecoveryInterval(), - socketPub.getSendBufferSize(), socketPub.getSendTimeOut(), socketPub.getSndHWM(), - socketPub.getTCPKeepAlive(), socketPub.getTCPKeepAliveCount(), socketPub.getTCPKeepAliveIdle(), - socketPub.getTCPKeepAliveInterval(), socketPub.getTCPKeepAliveSetting()); + socketPub.getLinger(), socketPub.getMaxMsgSize(), socketPub.getMulticastHops(), + socketPub.getRate(), socketPub.getRcvHWM(), socketPub.getReceiveBufferSize(), + socketPub.getReceiveTimeOut(), socketPub.getReconnectIVL(), socketPub.getReconnectIVLMax(), + socketPub.getRecoveryInterval(), socketPub.getSendBufferSize(), socketPub.getSendTimeOut(), + socketPub.getSndHWM(), socketPub.getTCPKeepAlive(), socketPub.getTCPKeepAliveCount(), + socketPub.getTCPKeepAliveIdle(), socketPub.getTCPKeepAliveInterval(), + socketPub.getTCPKeepAliveSetting()); } for (final String endpoint : endpoints) { logger.debug("Binding {} appender {} to endpoint {}", SIMPLE_NAME, name, endpoint); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/package-info.java new file mode 100644 index 0000000..b1df1e7 --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/jeromq/package-info.java @@ -0,0 +1,23 @@ +/* + * 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. + */ + +/** + * Classes and interfaces for ZeroMQ/JeroMQ support. + * + * @since 2.4 + */ +package org.apache.logging.log4j.core.appender.mom.jeromq; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/package-info.java new file mode 100644 index 0000000..60f4dcf --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/kafka/package-info.java @@ -0,0 +1,23 @@ +/* + * 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. + */ + +/** + * Classes and interfaces for Kafka appender support. + * + * @since 2.4 + */ +package org.apache.logging.log4j.core.appender.mom.kafka; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java index ff4e25b..d759dd9 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java @@ -17,9 +17,14 @@ package org.apache.logging.log4j.core.config.plugins.processor; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAliases; -import org.apache.logging.log4j.util.Strings; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.RoundEnvironment; @@ -33,14 +38,10 @@ import javax.lang.model.util.SimpleElementVisitor6; import javax.tools.Diagnostic.Kind; import javax.tools.FileObject; import javax.tools.StandardLocation; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; -import java.util.Set; + +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAliases; +import org.apache.logging.log4j.util.Strings; /** * Annotation processor for pre-scanning Log4j 2 plugins. @@ -54,7 +55,8 @@ public class PluginProcessor extends AbstractProcessor { * The location of the plugin cache data file. This file is written to by this processor, and read from by * {@link org.apache.logging.log4j.core.config.plugins.util.PluginManager}. */ - public static final String PLUGIN_CACHE_FILE = "META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat"; + public static final String PLUGIN_CACHE_FILE = + "META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat"; private final PluginCache pluginCache = new PluginCache(); @@ -85,10 +87,9 @@ public class PluginProcessor extends AbstractProcessor { private void collectPlugins(final Iterable<? extends Element> elements) { final Elements elementUtils = processingEnv.getElementUtils(); - final ElementVisitor<PluginEntry, Plugin> pluginVisitor = - new PluginElementVisitor(elementUtils); - final ElementVisitor<Collection<PluginEntry>, Plugin> pluginAliasesVisitor = - new PluginAliasesElementVisitor(elementUtils); + final ElementVisitor<PluginEntry, Plugin> pluginVisitor = new PluginElementVisitor(elementUtils); + final ElementVisitor<Collection<PluginEntry>, Plugin> pluginAliasesVisitor = new PluginAliasesElementVisitor( + elementUtils); for (final Element element : elements) { final Plugin plugin = element.getAnnotation(Plugin.class); final PluginEntry entry = element.accept(pluginVisitor, plugin); @@ -142,7 +143,7 @@ public class PluginProcessor extends AbstractProcessor { private final Elements elements; private PluginAliasesElementVisitor(final Elements elements) { - super(Collections.<PluginEntry>emptyList()); + super(Collections.<PluginEntry> emptyList()); this.elements = elements; } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/package-info.java index c775237..dcd2b1a 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/package-info.java @@ -19,4 +19,4 @@ * Java annotation processor for pre-scanning Log4j 2 plugins. This is provided as an alternative to using the * executable {@link org.apache.logging.log4j.core.config.plugins.util.PluginManager} class in your build process. */ -package org.apache.logging.log4j.core.config.plugins.processor; \ No newline at end of file +package org.apache.logging.log4j.core.config.plugins.processor; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java index 4197321..227e451 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java @@ -131,11 +131,11 @@ public class ResolverUtil { * Sets an explicit ClassLoader that should be used when scanning for classes. If none is set then the context * classloader will be used. * - * @param classloader + * @param aClassloader * a ClassLoader to use when scanning for classes */ - public void setClassLoader(final ClassLoader classloader) { - this.classloader = classloader; + public void setClassLoader(final ClassLoader aClassloader) { + this.classloader = aClassloader; } /** http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/package-info.java index 18dde61..a3d5932 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/package-info.java @@ -18,4 +18,4 @@ /** * Utility and manager classes for Log4j 2 plugins. */ -package org.apache.logging.log4j.core.config.plugins.util; \ No newline at end of file +package org.apache.logging.log4j.core.config.plugins.util; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidator.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidator.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidator.java index 5a93691..d02136c 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidator.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiredValidator.java @@ -43,8 +43,8 @@ public class RequiredValidator implements ConstraintValidator<Required> { private Required annotation; @Override - public void initialize(final Required annotation) { - this.annotation = annotation; + public void initialize(final Required anAnnotation) { + this.annotation = anAnnotation; } @Override http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/AbstractPluginVisitor.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/AbstractPluginVisitor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/AbstractPluginVisitor.java index f278c2c..ac341bb 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/AbstractPluginVisitor.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/AbstractPluginVisitor.java @@ -36,13 +36,32 @@ import org.apache.logging.log4j.util.Strings; */ public abstract class AbstractPluginVisitor<A extends Annotation> implements PluginVisitor<A> { + /** Status logger. */ protected static final Logger LOGGER = StatusLogger.getLogger(); + /** + * + */ protected final Class<A> clazz; + /** + * + */ protected A annotation; + /** + * + */ protected String[] aliases; + /** + * + */ protected Class<?> conversionType; + /** + * + */ protected StrSubstitutor substitutor; + /** + * + */ protected Member member; /** @@ -56,8 +75,8 @@ public abstract class AbstractPluginVisitor<A extends Annotation> implements Plu @SuppressWarnings("unchecked") @Override - public PluginVisitor<A> setAnnotation(final Annotation annotation) { - final Annotation a = Objects.requireNonNull(annotation, "No annotation was provided"); + public PluginVisitor<A> setAnnotation(final Annotation anAnnotation) { + final Annotation a = Objects.requireNonNull(anAnnotation, "No annotation was provided"); if (this.clazz.isInstance(a)) { this.annotation = (A) a; } @@ -65,26 +84,26 @@ public abstract class AbstractPluginVisitor<A extends Annotation> implements Plu } @Override - public PluginVisitor<A> setAliases(final String... aliases) { - this.aliases = aliases; + public PluginVisitor<A> setAliases(final String... someAliases) { + this.aliases = someAliases; return this; } @Override - public PluginVisitor<A> setConversionType(final Class<?> conversionType) { - this.conversionType = Objects.requireNonNull(conversionType, "No conversion type class was provided"); + public PluginVisitor<A> setConversionType(final Class<?> aConversionType) { + this.conversionType = Objects.requireNonNull(aConversionType, "No conversion type class was provided"); return this; } @Override - public PluginVisitor<A> setStrSubstitutor(final StrSubstitutor substitutor) { - this.substitutor = Objects.requireNonNull(substitutor, "No StrSubstitutor was provided"); + public PluginVisitor<A> setStrSubstitutor(final StrSubstitutor aSubstitutor) { + this.substitutor = Objects.requireNonNull(aSubstitutor, "No StrSubstitutor was provided"); return this; } @Override - public PluginVisitor<A> setMember(final Member member) { - this.member = member; + public PluginVisitor<A> setMember(final Member aMember) { + this.member = aMember; return this; } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/PluginNodeVisitor.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/PluginNodeVisitor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/PluginNodeVisitor.java index 413acad..566aece 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/PluginNodeVisitor.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/PluginNodeVisitor.java @@ -23,7 +23,7 @@ import org.apache.logging.log4j.core.config.Node; import org.apache.logging.log4j.core.config.plugins.PluginNode; /** - * PluginVisitor implementation for {@link PluginNode} + * PluginVisitor implementation for {@link PluginNode}. */ public class PluginNodeVisitor extends AbstractPluginVisitor<PluginNode> { public PluginNodeVisitor() { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/package-info.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/package-info.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/package-info.java index b789e17..af2a036 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/package-info.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/package-info.java @@ -21,4 +21,4 @@ * and the corresponding annotation must be annotated with * {@link org.apache.logging.log4j.core.config.plugins.PluginVisitorStrategy}. */ -package org.apache.logging.log4j.core.config.plugins.visitors; \ No newline at end of file +package org.apache.logging.log4j.core.config.plugins.visitors; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java index 5cb6a0c..50f9285 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java @@ -40,6 +40,7 @@ import java.util.Properties; /** * Creates a PropertiesConfiguration from a properties file. + * * @since 2.4 */ @Plugin(name = "PropertiesConfigurationFactory", category = ConfigurationFactory.CATEGORY) @@ -124,8 +125,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { String[] appenderNames = appenderProp.split(","); for (String appenderName : appenderNames) { String name = appenderName.trim(); - builder.add( - createAppender(builder, name, PropertiesUtil.extractSubset(properties, "appender." + name))); + builder.add(createAppender(builder, name, PropertiesUtil.extractSubset(properties, "appender." + + name))); } } String loggerProp = properties.getProperty("loggers"); @@ -134,8 +135,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { for (String loggerName : loggerNames) { String name = loggerName.trim(); if (!name.equals(LoggerConfig.ROOT)) { - builder.add( - createLogger(builder, name, PropertiesUtil.extractSubset(properties, "logger." + name))); + builder.add(createLogger(builder, name, PropertiesUtil.extractSubset(properties, "logger." + + name))); } } } @@ -148,7 +149,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { return builder.build(); } - private AppenderComponentBuilder createAppender(ConfigurationBuilder<PropertiesConfiguration> builder, String key, Properties properties) { + private AppenderComponentBuilder createAppender(ConfigurationBuilder<PropertiesConfiguration> builder, String key, + Properties properties) { String name = properties.getProperty(CONFIG_NAME); if (Strings.isEmpty(name)) { throw new ConfigurationException("No name attribute provided for Appender " + key); @@ -179,7 +181,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { return appenderBuilder; } - private FilterComponentBuilder createFilter(ConfigurationBuilder<PropertiesConfiguration> builder, String key, Properties properties) { + private FilterComponentBuilder createFilter(ConfigurationBuilder<PropertiesConfiguration> builder, String key, + Properties properties) { String type = properties.getProperty(CONFIG_TYPE); if (Strings.isEmpty(type)) { throw new ConfigurationException("No type attribute provided for Appender " + key); @@ -198,7 +201,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { return filterBuilder; } - private AppenderRefComponentBuilder createAppenderRef(ConfigurationBuilder<PropertiesConfiguration> builder, String key, Properties properties) { + private AppenderRefComponentBuilder createAppenderRef(ConfigurationBuilder<PropertiesConfiguration> builder, + String key, Properties properties) { String ref = properties.getProperty("ref"); if (Strings.isEmpty(ref)) { throw new ConfigurationException("No ref attribute provided for AppenderRef " + key); @@ -222,7 +226,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { return appenderRefBuilder; } - private LoggerComponentBuilder createLogger(ConfigurationBuilder<PropertiesConfiguration> builder, String key, Properties properties) { + private LoggerComponentBuilder createLogger(ConfigurationBuilder<PropertiesConfiguration> builder, String key, + Properties properties) { String name = properties.getProperty(CONFIG_NAME); if (Strings.isEmpty(name)) { throw new ConfigurationException("No name attribute provided for Logger " + key); @@ -270,7 +275,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { return loggerBuilder; } - private RootLoggerComponentBuilder createRootLogger(ConfigurationBuilder<PropertiesConfiguration> builder, Properties properties) { + private RootLoggerComponentBuilder createRootLogger(ConfigurationBuilder<PropertiesConfiguration> builder, + Properties properties) { String level = properties.getProperty("level"); if (level != null) { properties.remove("level"); @@ -309,7 +315,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { return loggerBuilder; } - private LayoutComponentBuilder createLayout(ConfigurationBuilder<PropertiesConfiguration> builder, String appenderName, Properties properties) { + private LayoutComponentBuilder createLayout(ConfigurationBuilder<PropertiesConfiguration> builder, + String appenderName, Properties properties) { String type = properties.getProperty(CONFIG_TYPE); if (Strings.isEmpty(type)) { throw new ConfigurationException("No type attribute provided for Layout on Appender " + appenderName); @@ -320,7 +327,8 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { return layoutBuilder; } - private <B extends ComponentBuilder<B>> ComponentBuilder<B> createComponent(ComponentBuilder<?> parent, String key, Properties properties) { + private <B extends ComponentBuilder<B>> ComponentBuilder<B> createComponent(ComponentBuilder<?> parent, String key, + Properties properties) { String name = properties.getProperty(CONFIG_NAME); if (name != null) { properties.remove(CONFIG_NAME); @@ -345,7 +353,7 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory { String prefix = propertyName.substring(0, index); Properties componentProperties = PropertiesUtil.extractSubset(properties, prefix); builder.addComponent(createComponent(builder, prefix, componentProperties)); - } else { + } else { builder.addAttribute(propertyName, properties.getProperty(propertyName)); properties.remove(propertyName); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java index aac5ca8..af13000 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java @@ -16,6 +16,25 @@ */ package org.apache.logging.log4j.core.config.xml; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; + import org.apache.logging.log4j.core.config.AbstractConfiguration; import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.ConfigurationSource; @@ -38,24 +57,6 @@ import org.w3c.dom.Text; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Source; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; -import javax.xml.validation.Validator; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - /** * Creates a Node hierarchy from an XML file. */ @@ -63,9 +64,11 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu private static final long serialVersionUID = 1L; - private static final String XINCLUDE_FIXUP_LANGUAGE = "http://apache.org/xml/features/xinclude/fixup-language"; - private static final String XINCLUDE_FIXUP_BASE_URIS = "http://apache.org/xml/features/xinclude/fixup-base-uris"; - private static final String[] VERBOSE_CLASSES = new String[] { ResolverUtil.class.getName() }; + private static final String XINCLUDE_FIXUP_LANGUAGE = + "http://apache.org/xml/features/xinclude/fixup-language"; + private static final String XINCLUDE_FIXUP_BASE_URIS = + "http://apache.org/xml/features/xinclude/fixup-base-uris"; + private static final String[] VERBOSE_CLASSES = new String[] {ResolverUtil.class.getName()}; private static final String LOG4J_XSD = "Log4j-config.xsd"; private final List<Status> status = new ArrayList<>(); @@ -73,59 +76,6 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu private boolean strict; private String schemaResource; - /** - * Creates a new DocumentBuilder suitable for parsing a configuration file. - * @param xIncludeAware enabled XInclude - * @return a new DocumentBuilder - * @throws ParserConfigurationException - */ - static DocumentBuilder newDocumentBuilder(boolean xIncludeAware) throws ParserConfigurationException { - final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - if (xIncludeAware) { - enableXInclude(factory); - } - return factory.newDocumentBuilder(); - } - - /** - * Enables XInclude for the given DocumentBuilderFactory - * - * @param factory a DocumentBuilderFactory - */ - private static void enableXInclude(final DocumentBuilderFactory factory) { - try { - // Alternative: We set if a system property on the command line is set, for example: - // -DLog4j.XInclude=true - factory.setXIncludeAware(true); - } catch (final UnsupportedOperationException e) { - LOGGER.warn("The DocumentBuilderFactory [{}] does not support XInclude: {}", factory, e); - } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError err) { - LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support XInclude: {}", factory, err); - } catch (final NoSuchMethodError err) { - // LOG4J2-919 - LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support XInclude: {}", factory, err); - } - try { - // Alternative: We could specify all features and values with system properties like: - // -DLog4j.DocumentBuilderFactory.Feature="http://apache.org/xml/features/xinclude/fixup-base-uris true" - factory.setFeature(XINCLUDE_FIXUP_BASE_URIS, true); - } catch (final ParserConfigurationException e) { - LOGGER.warn("The DocumentBuilderFactory [{}] does not support the feature [{}]: {}", factory, - XINCLUDE_FIXUP_BASE_URIS, e); - } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError err) { - LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support setFeature: {}", factory, err); - } - try { - factory.setFeature(XINCLUDE_FIXUP_LANGUAGE, true); - } catch (final ParserConfigurationException e) { - LOGGER.warn("The DocumentBuilderFactory [{}] does not support the feature [{}]: {}", factory, - XINCLUDE_FIXUP_LANGUAGE, e); - } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError err) { - LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support setFeature: {}", factory, err); - } - } - public XmlConfiguration(final ConfigurationSource configSource) { super(configSource); final File configFile = configSource.getFile(); @@ -149,7 +99,8 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu Throwable throwable = Throwables.getRootCause(e); if (throwable instanceof UnsupportedOperationException) { LOGGER.warn( - "The DocumentBuilder {} does not support an operation: {}. Trying again without XInclude...", + "The DocumentBuilder {} does not support an operation: {}." + + "Trying again without XInclude...", documentBuilder, e); document = newDocumentBuilder(false).parse(source); } else { @@ -230,6 +181,64 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu } } + /** + * Creates a new DocumentBuilder suitable for parsing a configuration file. + * + * @param xIncludeAware enabled XInclude + * @return a new DocumentBuilder + * @throws ParserConfigurationException + */ + static DocumentBuilder newDocumentBuilder(boolean xIncludeAware) throws ParserConfigurationException { + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + if (xIncludeAware) { + enableXInclude(factory); + } + return factory.newDocumentBuilder(); + } + + /** + * Enables XInclude for the given DocumentBuilderFactory + * + * @param factory a DocumentBuilderFactory + */ + private static void enableXInclude(final DocumentBuilderFactory factory) { + try { + // Alternative: We set if a system property on the command line is set, for example: + // -DLog4j.XInclude=true + factory.setXIncludeAware(true); + } catch (final UnsupportedOperationException e) { + LOGGER.warn("The DocumentBuilderFactory [{}] does not support XInclude: {}", factory, e); + } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError err) { + LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support XInclude: {}", factory, + err); + } catch (final NoSuchMethodError err) { + // LOG4J2-919 + LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support XInclude: {}", factory, + err); + } + try { + // Alternative: We could specify all features and values with system properties like: + // -DLog4j.DocumentBuilderFactory.Feature="http://apache.org/xml/features/xinclude/fixup-base-uris true" + factory.setFeature(XINCLUDE_FIXUP_BASE_URIS, true); + } catch (final ParserConfigurationException e) { + LOGGER.warn("The DocumentBuilderFactory [{}] does not support the feature [{}]: {}", factory, + XINCLUDE_FIXUP_BASE_URIS, e); + } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError err) { + LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support setFeature: {}", factory, + err); + } + try { + factory.setFeature(XINCLUDE_FIXUP_LANGUAGE, true); + } catch (final ParserConfigurationException e) { + LOGGER.warn("The DocumentBuilderFactory [{}] does not support the feature [{}]: {}", factory, + XINCLUDE_FIXUP_LANGUAGE, e); + } catch (@SuppressWarnings("ErrorNotRethrown") final AbstractMethodError err) { + LOGGER.warn("The DocumentBuilderFactory [{}] is out of date and does not support setFeature: {}", factory, + err); + } + } + @Override public void setup() { if (rootElement == null) { @@ -356,7 +365,7 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu this.element = element; this.errorType = errorType; } - + @Override public String toString() { return "Status [name=" + name + ", element=" + element + ", errorType=" + errorType + "]"; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java index 84e5eb4..5badaca 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/XmlLayout.java @@ -28,6 +28,8 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.apache.logging.log4j.core.jackson.XmlConstants; +// Lines too long... +//CHECKSTYLE:OFF /** * Appends a series of {@code event} elements as defined in the <a href="log4j.dtd">log4j.dtd</a>. * @@ -186,6 +188,7 @@ import org.apache.logging.log4j.core.jackson.XmlConstants; * Message content may contain, of course, end-of-lines. * </p> */ +//CHECKSTYLE:ON @Plugin(name = "XmlLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true) public final class XmlLayout extends AbstractJacksonLayout { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java index a1317c8..1dba499 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/AbstractLookup.java @@ -24,7 +24,7 @@ package org.apache.logging.log4j.core.lookup; public abstract class AbstractLookup implements StrLookup { /** - * Calls {@code lookup(null, key);} + * Calls {@code lookup(null, key)} in the super class. * * @see StrLookup#lookup(LogEvent, String) */ http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MainMapLookup.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MainMapLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MainMapLookup.java index cd6d18f..a50de0d 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MainMapLookup.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MainMapLookup.java @@ -37,6 +37,17 @@ public class MainMapLookup extends MapLookup { static final MapLookup MAIN_SINGLETON = new MapLookup(MapLookup.newMap(0)); /** + * Constructor when used directly as a plugin. + */ + public MainMapLookup() { + // no-init + } + + public MainMapLookup(final Map<String, String> map) { + super(map); + } + + /** * An application's {@code public static main(String[])} method calls this method to make its main arguments * available for lookup with the prefix {@code main}. * <p> @@ -67,17 +78,6 @@ public class MainMapLookup extends MapLookup { initMap(args, MainMapLookup.MAIN_SINGLETON.getMap()); } - /** - * Constructor when used directly as a plugin. - */ - public MainMapLookup() { - // no-init - } - - public MainMapLookup(final Map<String, String> map) { - super(map); - } - @Override public String lookup(final LogEvent event, final String key) { return MAIN_SINGLETON.getMap().get(key); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java index 5889dcc..c369a0b 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java @@ -30,6 +30,28 @@ import org.apache.logging.log4j.message.MapMessage; @Plugin(name = "map", category = StrLookup.CATEGORY) public class MapLookup implements StrLookup { + /** + * Map keys are variable names and value. + */ + private final Map<String, String> map; + + /** + * Constructor when used directly as a plugin. + */ + public MapLookup() { + this.map = null; + } + + /** + * Creates a new instance backed by a Map. Used by the default lookup. + * + * @param map + * the map of keys to values, may be null + */ + public MapLookup(final Map<String, String> map) { + this.map = map; + } + static Map<String, String> initMap(final String[] srcArgs, final Map<String, String> destMap) { for (int i = 0; i < srcArgs.length; i++) { final int next = i + 1; @@ -90,28 +112,6 @@ public class MapLookup implements StrLookup { return initMap(args, newMap(args.length)); } - /** - * Map keys are variable names and value. - */ - private final Map<String, String> map; - - /** - * Constructor when used directly as a plugin. - */ - public MapLookup() { - this.map = null; - } - - /** - * Creates a new instance backed by a Map. Used by the default lookup. - * - * @param map - * the map of keys to values, may be null - */ - public MapLookup(final Map<String, String> map) { - this.map = map; - } - protected Map<String, String> getMap() { return map; } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/640f4f2f/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java index e86720a..ae90b27 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/MulticastDnsAdvertiser.java @@ -31,64 +31,68 @@ import org.apache.logging.log4j.status.StatusLogger; /** * Advertise an entity via ZeroConf/MulticastDNS and the JmDNS library. * - * The length of property names and values must be 255 bytes or less. - * Entries with names or values larger than 255 bytes will be removed prior to advertisement. + * The length of property names and values must be 255 bytes or less. Entries with names or values larger than 255 bytes + * will be removed prior to advertisement. * */ @Plugin(name = "multicastdns", category = "Core", elementType = "advertiser", printObject = false) public class MulticastDnsAdvertiser implements Advertiser { + /** + * + */ + private static final int MAX_LENGTH = 255; + /** + * Status logger. + */ protected static final Logger LOGGER = StatusLogger.getLogger(); - private static Object jmDNS = initializeJmDns(); + private static final int DEFAULT_PORT = 4555; + private static Object jmDNS = initializeJmDns(); private static Class<?> jmDNSClass; private static Class<?> serviceInfoClass; - public MulticastDnsAdvertiser() - { - //no arg constructor for reflection + public MulticastDnsAdvertiser() { + // no arg constructor for reflection } /** * Advertise the provided entity. * - * Properties map provided in advertise method must include a "name" entry - * but may also provide "protocol" (tcp/udp) as well as a "port" entry + * Properties map provided in advertise method must include a "name" entry but may also provide "protocol" (tcp/udp) + * as well as a "port" entry * - * The length of property names and values must be 255 bytes or less. - * Entries with names or values larger than 255 bytes will be removed prior to advertisement. + * The length of property names and values must be 255 bytes or less. Entries with names or values larger than 255 + * bytes will be removed prior to advertisement. * * @param properties the properties representing the entity to advertise * @return the object which can be used to unadvertise, or null if advertisement was unsuccessful */ @Override public Object advertise(final Map<String, String> properties) { - //default to tcp if "protocol" was not set + // default to tcp if "protocol" was not set final Map<String, String> truncatedProperties = new HashMap<>(); - for (final Map.Entry<String, String> entry:properties.entrySet()) - { - if (entry.getKey().length() <= 255 && entry.getValue().length() <= 255) - { + for (final Map.Entry<String, String> entry : properties.entrySet()) { + if (entry.getKey().length() <= MAX_LENGTH && entry.getValue().length() <= MAX_LENGTH) { truncatedProperties.put(entry.getKey(), entry.getValue()); } } final String protocol = truncatedProperties.get("protocol"); - final String zone = "._log4j._"+(protocol != null ? protocol : "tcp") + ".local."; - //default to 4555 if "port" was not set + final String zone = "._log4j._" + (protocol != null ? protocol : "tcp") + ".local."; + // default to 4555 if "port" was not set final String portString = truncatedProperties.get("port"); - final int port = Integers.parseInt(portString, 4555); + final int port = Integers.parseInt(portString, DEFAULT_PORT); final String name = truncatedProperties.get("name"); - //if version 3 is available, use it to construct a serviceInfo instance, otherwise support the version1 API - if (jmDNS != null) - { + // if version 3 is available, use it to construct a serviceInfo instance, otherwise support the version1 API + if (jmDNS != null) { boolean isVersion3 = false; try { - //create method is in version 3, not version 1 + // create method is in version 3, not version 1 jmDNSClass.getMethod("create"); isVersion3 = true; } catch (final NoSuchMethodException e) { - //no-op + // no-op } Object serviceInfo; if (isVersion3) { @@ -100,11 +104,11 @@ public class MulticastDnsAdvertiser implements Advertiser { try { final Method method = jmDNSClass.getMethod("registerService", serviceInfoClass); method.invoke(jmDNS, serviceInfo); - } catch(final IllegalAccessException e) { + } catch (final IllegalAccessException e) { LOGGER.warn("Unable to invoke registerService method", e); - } catch(final NoSuchMethodException e) { + } catch (final NoSuchMethodException e) { LOGGER.warn("No registerService method", e); - } catch(final InvocationTargetException e) { + } catch (final InvocationTargetException e) { LOGGER.warn("Unable to invoke registerService method", e); } return serviceInfo; @@ -115,6 +119,7 @@ public class MulticastDnsAdvertiser implements Advertiser { /** * Unadvertise the previously advertised entity + * * @param serviceInfo */ @Override @@ -123,18 +128,17 @@ public class MulticastDnsAdvertiser implements Advertiser { try { final Method method = jmDNSClass.getMethod("unregisterService", serviceInfoClass); method.invoke(jmDNS, serviceInfo); - } catch(final IllegalAccessException e) { + } catch (final IllegalAccessException e) { LOGGER.warn("Unable to invoke unregisterService method", e); - } catch(final NoSuchMethodException e) { + } catch (final NoSuchMethodException e) { LOGGER.warn("No unregisterService method", e); - } catch(final InvocationTargetException e) { + } catch (final InvocationTargetException e) { LOGGER.warn("Unable to invoke unregisterService method", e); } } } - private static Object createJmDnsVersion1() - { + private static Object createJmDnsVersion1() { try { return jmDNSClass.getConstructor().newInstance(); } catch (final InstantiationException e) { @@ -149,11 +153,10 @@ public class MulticastDnsAdvertiser implements Advertiser { return null; } - private static Object createJmDnsVersion3() - { + private static Object createJmDnsVersion3() { try { final Method jmDNSCreateMethod = jmDNSClass.getMethod("create"); - return jmDNSCreateMethod.invoke(null, (Object[])null); + return jmDNSCreateMethod.invoke(null, (Object[]) null); } catch (final IllegalAccessException e) { LOGGER.warn("Unable to invoke create method", e); } catch (final NoSuchMethodException e) { @@ -164,17 +167,14 @@ public class MulticastDnsAdvertiser implements Advertiser { return null; } - private static Object buildServiceInfoVersion1(final String zone, - final int port, - final String name, - final Map<String, String> properties) { - //version 1 uses a hashtable + private static Object buildServiceInfoVersion1(final String zone, final int port, final String name, + final Map<String, String> properties) { + // version 1 uses a hashtable @SuppressWarnings("UseOfObsoleteCollectionType") final Hashtable<String, String> hashtableProperties = new Hashtable<>(properties); try { - return serviceInfoClass - .getConstructor(String.class, String.class, int.class, int.class, int.class, Hashtable.class) - .newInstance(zone, name, port, 0, 0, hashtableProperties); + return serviceInfoClass.getConstructor(String.class, String.class, int.class, int.class, int.class, + Hashtable.class).newInstance(zone, name, port, 0, 0, hashtableProperties); } catch (final IllegalAccessException e) { LOGGER.warn("Unable to construct ServiceInfo instance", e); } catch (final NoSuchMethodException e) { @@ -187,12 +187,11 @@ public class MulticastDnsAdvertiser implements Advertiser { return null; } - private static Object buildServiceInfoVersion3(final String zone, - final int port, - final String name, - final Map<String, String> properties) { + private static Object buildServiceInfoVersion3(final String zone, final int port, final String name, + final Map<String, String> properties) { try { - return serviceInfoClass // zone/type display name port weight priority properties + return serviceInfoClass + // zone/type display name port weight priority properties .getMethod("create", String.class, String.class, int.class, int.class, int.class, Map.class) .invoke(null, zone, name, port, 0, 0, properties); } catch (final IllegalAccessException e) { @@ -209,14 +208,14 @@ public class MulticastDnsAdvertiser implements Advertiser { try { jmDNSClass = Loader.loadClass("javax.jmdns.JmDNS"); serviceInfoClass = Loader.loadClass("javax.jmdns.ServiceInfo"); - //if version 3 is available, use it to constuct a serviceInfo instance, otherwise support the version1 API + // if version 3 is available, use it to constuct a serviceInfo instance, otherwise support the version1 API boolean isVersion3 = false; try { - //create method is in version 3, not version 1 + // create method is in version 3, not version 1 jmDNSClass.getMethod("create"); isVersion3 = true; } catch (final NoSuchMethodException e) { - //no-op + // no-op } if (isVersion3) {
