You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2013/04/28 03:27:29 UTC

svn commit: r1476703 [4/4] - in /logging/log4j/log4j2/trunk: ./ api/ core/ core/src/main/java/org/apache/logging/log4j/core/appender/ core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/ core/src/main/java/org/apache/logging/log4j/core/ap...

Modified: logging/log4j/log4j2/trunk/taglib/src/test/java/org/apache/logging/log4j/taglib/ExitTagTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/taglib/src/test/java/org/apache/logging/log4j/taglib/ExitTagTest.java?rev=1476703&r1=1476702&r2=1476703&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/taglib/src/test/java/org/apache/logging/log4j/taglib/ExitTagTest.java (original)
+++ logging/log4j/log4j2/trunk/taglib/src/test/java/org/apache/logging/log4j/taglib/ExitTagTest.java Sun Apr 28 01:27:27 2013
@@ -90,13 +90,14 @@ public class ExitTagTest {
         verify("exit with(5792) TRACE M-EXIT[ FLOW ] E");
     }
 
+    @SuppressWarnings("unchecked")
     private void verify(final String expected) {
         final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         final Map<String, Appender<?>> list = ctx.getConfiguration().getAppenders();
         final Appender<?> listApp = list.get("List");
         assertNotNull("Missing Appender", listApp);
         assertTrue("Not a ListAppender", listApp instanceof ListAppender);
-        final List<String> events = ((ListAppender) listApp).getMessages();
+        final List<String> events = ((ListAppender<String>) listApp).getMessages();
         try
         {
             assertEquals("Incorrect number of messages.", 1, events.size());

Modified: logging/log4j/log4j2/trunk/taglib/src/test/java/org/apache/logging/log4j/taglib/LoggingMessageTagSupportTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/taglib/src/test/java/org/apache/logging/log4j/taglib/LoggingMessageTagSupportTest.java?rev=1476703&r1=1476702&r2=1476703&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/taglib/src/test/java/org/apache/logging/log4j/taglib/LoggingMessageTagSupportTest.java (original)
+++ logging/log4j/log4j2/trunk/taglib/src/test/java/org/apache/logging/log4j/taglib/LoggingMessageTagSupportTest.java Sun Apr 28 01:27:27 2013
@@ -293,13 +293,14 @@ public class LoggingMessageTagSupportTes
                 "This is another test");
     }
 
+    @SuppressWarnings("unchecked")
     private void verify(final String expected) {
         final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         final Map<String, Appender<?>> list = ctx.getConfiguration().getAppenders();
         final Appender<?> listApp = list.get("List");
         assertNotNull("Missing Appender", listApp);
         assertTrue("Not a ListAppender", listApp instanceof ListAppender);
-        final List<String> events = ((ListAppender) listApp).getMessages();
+        final List<String> events = ((ListAppender<String>) listApp).getMessages();
         try
         {
             assertEquals("Incorrect number of messages.", 1, events.size());

Modified: logging/log4j/log4j2/trunk/web/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/web/pom.xml?rev=1476703&r1=1476702&r2=1476703&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/web/pom.xml (original)
+++ logging/log4j/log4j2/trunk/web/pom.xml Sun Apr 28 01:27:27 2013
@@ -171,7 +171,7 @@
             <artifactId>maven-pmd-plugin</artifactId>
             <version>${pmd.plugin.version}</version>
             <configuration>
-              <targetJdk>1.5</targetJdk>
+              <targetJdk>${maven.compile.target}</targetJdk>
             </configuration>
           </plugin>
           <plugin>

Modified: logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java?rev=1476703&r1=1476702&r2=1476703&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java (original)
+++ logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java Sun Apr 28 01:27:27 2013
@@ -16,13 +16,12 @@
  */
 package org.apache.logging.log4j.core.web;
 
-import org.apache.logging.log4j.core.config.Configurator;
 import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configurator;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
-import java.lang.reflect.Method;
 
 /**
  * Saves the LoggerContext into the ServletContext as an attribute.
@@ -72,23 +71,12 @@ public class Log4jContextListener implem
     }
 
     private ClassLoader getClassLoader(final ServletContext context) {
-        final Method[] methods = context.getClass().getMethods();
-        Method getClassLoader = null;
-        for (final Method method : methods) {
-            if (method.getName().equals("getClassLoader")) {
-                getClassLoader = method;
-                break;
-            }
+        try {
+            // if container is Servlet 3.0, use its getClassLoader method
+            return (ClassLoader)context.getClass().getMethod("getClassLoader").invoke(context);
+        } catch (Exception ignore) {
+            // otherwise, use this class's class loader
+            return Log4jContextListener.class.getClassLoader();
         }
-
-        if (getClassLoader != null) {
-            try {
-                return (ClassLoader) getClassLoader.invoke(context, null);
-            } catch (final Exception ex) {
-                // Ignore the exception
-            }
-        }
-
-        return Log4jContextListener.class.getClassLoader();
     }
 }

Modified: logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java?rev=1476703&r1=1476702&r2=1476703&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java (original)
+++ logging/log4j/log4j2/trunk/web/src/test/java/org/apache/logging/log4j/core/web/Log4jContextListenerTest.java Sun Apr 28 01:27:27 2013
@@ -17,7 +17,6 @@
 package org.apache.logging.log4j.core.web;
 
 import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
@@ -37,8 +36,8 @@ import java.util.Hashtable;
 import java.util.Map;
 import java.util.Set;
 
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 /**
  *
@@ -55,14 +54,14 @@ public class Log4jContextListenerTest {
         final Log4jContextListener listener = new Log4jContextListener();
         final ServletContextEvent event = new ServletContextEvent(context);
         listener.contextInitialized(event);
-        final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
+        LogManager.getLogger("org.apache.test.TestConfigurator");
         final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         Configuration config = ctx.getConfiguration();
         assertNotNull("No configuration", config);
         assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
             CONFIG_NAME.equals(config.getName()));
         final Map<String, Appender<?>> map = config.getAppenders();
-        assertNotNull("No Appenders", map != null && map.size() > 0);
+        assertTrue("No Appenders", map != null && map.size() > 0);
         assertTrue("Wrong configuration", map.containsKey("List"));
         listener.contextDestroyed(event);
         config = ctx.getConfiguration();
@@ -78,14 +77,14 @@ public class Log4jContextListenerTest {
         final Log4jContextListener listener = new Log4jContextListener();
         final ServletContextEvent event = new ServletContextEvent(context);
         listener.contextInitialized(event);
-        final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
+        LogManager.getLogger("org.apache.test.TestConfigurator");
         final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         Configuration config = ctx.getConfiguration();
         assertNotNull("No configuration", config);
         assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
             CONFIG_NAME.equals(config.getName()));
         final Map<String, Appender<?>> map = config.getAppenders();
-        assertNotNull("No Appenders", map != null && map.size() > 0);
+        assertTrue("No Appenders", map != null && map.size() > 0);
         assertTrue("Wrong configuration", map.containsKey("List"));
         listener.contextDestroyed(event);
         config = ctx.getConfiguration();
@@ -100,14 +99,14 @@ public class Log4jContextListenerTest {
         final Log4jContextListener listener = new Log4jContextListener();
         final ServletContextEvent event = new ServletContextEvent(context);
         listener.contextInitialized(event);
-        final Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
+        LogManager.getLogger("org.apache.test.TestConfigurator");
         final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         Configuration config = ctx.getConfiguration();
         assertNotNull("No configuration", config);
         assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
             CONFIG_NAME.equals(config.getName()));
         final Map<String, Appender<?>> map = config.getAppenders();
-        assertNotNull("No Appenders", map != null && map.size() > 0);
+        assertTrue("No Appenders", map != null && map.size() > 0);
         assertTrue("Wrong configuration", map.containsKey("List"));
         listener.contextDestroyed(event);
         config = ctx.getConfiguration();
@@ -117,79 +116,101 @@ public class Log4jContextListenerTest {
 
 
     private class MockServletContext implements ServletContext {
-        private String name;
-
         private final Hashtable<String, String> params = new Hashtable<String, String>();
 
         private final Hashtable<String, Object> attrs = new Hashtable<String, Object>();
 
-
+        @Override
         public ServletContext getContext(final String s) {
             return null;
         }
 
+        @Override
         public int getMajorVersion() {
             return 0;
         }
 
+        @Override
         public int getMinorVersion() {
             return 0;
         }
 
+        @Override
         public String getMimeType(final String s) {
             return null;
         }
 
+        @Override
         public Set getResourcePaths(final String s) {
             return null;
         }
 
+        @Override
         public URL getResource(final String s) throws MalformedURLException {
             return null;
         }
 
+        @Override
         public InputStream getResourceAsStream(final String s) {
             return null;
         }
 
+        @Override
         public RequestDispatcher getRequestDispatcher(final String s) {
             return null;
         }
 
+        @Override
         public RequestDispatcher getNamedDispatcher(final String s) {
             return null;
         }
 
+        @Override
+        @Deprecated
+        @SuppressWarnings("deprecation")
         public Servlet getServlet(final String s) throws ServletException {
             return null;
         }
 
+        @Override
+        @Deprecated
+        @SuppressWarnings("deprecation")
         public Enumeration getServlets() {
             return null;
         }
 
+        @Override
+        @Deprecated
+        @SuppressWarnings("deprecation")
         public Enumeration getServletNames() {
             return null;
         }
 
+        @Override
         public void log(final String s) {
             System.out.println(s);
         }
 
+        @Override
+        @Deprecated
+        @SuppressWarnings("deprecation")
         public void log(final Exception e, final String s) {
             System.out.println(s);
             e.printStackTrace();
         }
 
+        @Override
         public void log(final String s, final Throwable throwable) {
             System.out.println(s);
             throwable.printStackTrace();
         }
 
+        @Override
         public String getRealPath(final String s) {
             return null;
         }
 
+        @Override
         public String getServerInfo() {
             return "Mock";
         }
@@ -198,34 +219,42 @@ public class Log4jContextListenerTest {
             params.put(key, value);
         }
 
+        @Override
         public String getInitParameter(final String s) {
             return params.get(s);
         }
 
+        @Override
         public Enumeration getInitParameterNames() {
             return params.keys();
         }
 
+        @Override
         public Object getAttribute(final String s) {
             return attrs.get(s);
         }
 
+        @Override
         public Enumeration getAttributeNames() {
             return attrs.keys();
         }
 
+        @Override
         public void setAttribute(final String s, final Object o) {
             attrs.put(s, o);
         }
 
+        @Override
         public void removeAttribute(final String s) {
             attrs.remove(s);
         }
 
+        @Override
         public String getServletContextName() {
             return null;
         }
 
+        @Override
         public String getContextPath() {
             return null;
         }