openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1848273 - in /openwebbeans/meecrowave/trunk: integration-tests/no-cxf/ integration-tests/no-cxf/src/test/java/org/apache/meecrowave/nocxf/itest/ meecrowave-core/src/main/java/org/apache/meecrowave/ meecrowave-core/src/main/java/org/apache/...
Date Thu, 06 Dec 2018 08:55:24 GMT
Author: rmannibucau
Date: Thu Dec  6 08:55:23 2018
New Revision: 1848273

URL: http://svn.apache.org/viewvc?rev=1848273&view=rev
Log:
MEECROWAVE-163 ensure log4j2 is optional

Added:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2s.java
Modified:
    openwebbeans/meecrowave/trunk/integration-tests/no-cxf/pom.xml
    openwebbeans/meecrowave/trunk/integration-tests/no-cxf/src/test/java/org/apache/meecrowave/nocxf/itest/RunWithoutCxfTest.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java

Modified: openwebbeans/meecrowave/trunk/integration-tests/no-cxf/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/no-cxf/pom.xml?rev=1848273&r1=1848272&r2=1848273&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/no-cxf/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/integration-tests/no-cxf/pom.xml Thu Dec  6 08:55:23 2018
@@ -58,6 +58,10 @@
           <groupId>org.apache.geronimo.specs</groupId>
           <artifactId>geronimo-jaxrs_2.1_spec</artifactId>
         </exclusion>
+        <exclusion>
+          <groupId>org.apache.logging.log4j</groupId>
+          <artifactId>*</artifactId>
+        </exclusion>
       </exclusions>
     </dependency>
 

Modified: openwebbeans/meecrowave/trunk/integration-tests/no-cxf/src/test/java/org/apache/meecrowave/nocxf/itest/RunWithoutCxfTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/integration-tests/no-cxf/src/test/java/org/apache/meecrowave/nocxf/itest/RunWithoutCxfTest.java?rev=1848273&r1=1848272&r2=1848273&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/integration-tests/no-cxf/src/test/java/org/apache/meecrowave/nocxf/itest/RunWithoutCxfTest.java
(original)
+++ openwebbeans/meecrowave/trunk/integration-tests/no-cxf/src/test/java/org/apache/meecrowave/nocxf/itest/RunWithoutCxfTest.java
Thu Dec  6 08:55:23 2018
@@ -20,8 +20,8 @@ package org.apache.meecrowave.nocxf.ites
 
 import static org.junit.Assert.assertEquals;
 
+import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.StringWriter;
 import java.net.URL;
@@ -30,7 +30,6 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.logging.log4j.core.util.IOUtils;
 import org.apache.meecrowave.Meecrowave;
 import org.junit.Test;
 
@@ -49,8 +48,8 @@ public class RunWithoutCxfTest {
         }}.randomHttpPort()).bake()) {
             final String url = "http://localhost:" + container.getConfiguration().getHttpPort()
+ "/test";
             final StringWriter output = new StringWriter();
-            try (final InputStream stream = new URL(url).openStream()) {
-                IOUtils.copy(new InputStreamReader(stream), output);
+            try (final BufferedReader stream = new BufferedReader(new InputStreamReader(new
URL(url).openStream()))) {
+                output.write(stream.readLine());
             }
             assertEquals("servlet :)", output.toString().trim());
         }

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java?rev=1848273&r1=1848272&r2=1848273&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
Thu Dec  6 08:55:23 2018
@@ -109,6 +109,7 @@ import org.apache.meecrowave.io.IO;
 import org.apache.meecrowave.lang.Substitutor;
 import org.apache.meecrowave.logging.jul.Log4j2Logger;
 import org.apache.meecrowave.logging.log4j2.Log4j2Shutdown;
+import org.apache.meecrowave.logging.log4j2.Log4j2s;
 import org.apache.meecrowave.logging.openwebbeans.Log4j2LoggerFactory;
 import org.apache.meecrowave.logging.tomcat.Log4j2Log;
 import org.apache.meecrowave.logging.tomcat.LogFacade;
@@ -432,11 +433,11 @@ public class Meecrowave implements AutoC
             configuration.loadFrom(configuration.getMeecrowaveProperties());
         }
 
-        if (configuration.isUseLog4j2JulLogManager()) { // /!\ don't move this line or add
anything before without checking log setup
+        if (configuration.isUseLog4j2JulLogManager() && Log4j2s.IS_PRESENT) { //
/!\ don't move this line or add anything before without checking log setup
             System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
         }
 
-        if (configuration.loggingGlobalSetup) {
+        if (configuration.loggingGlobalSetup && Log4j2s.IS_PRESENT) {
 
             setSystemProperty(systemPropsToRestore, "log4j.shutdownHookEnabled", "false");
             setSystemProperty(systemPropsToRestore, "openwebbeans.logging.factory", Log4j2LoggerFactory.class.getName());
@@ -444,7 +445,9 @@ public class Meecrowave implements AutoC
             setSystemProperty(systemPropsToRestore, "org.apache.tomcat.Logger", Log4j2Log.class.getName());
 
             postTask = () -> {
-                new Log4j2Shutdown().shutodwn();
+                if (Log4j2s.IS_PRESENT) {
+                    new Log4j2Shutdown().shutdown();
+                }
                 systemPropsToRestore.forEach((key, value) -> {
                     if (value == null) {
                         System.clearProperty(key);

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java?rev=1848273&r1=1848272&r2=1848273&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java
Thu Dec  6 08:55:23 2018
@@ -25,7 +25,7 @@ import org.apache.logging.log4j.LogManag
  */
 public class Log4j2Shutdown {
 
-    public void shutodwn() {
+    public void shutdown() {
         try {
             // We disabled the log4j shutdown hook to gain more control and keep logs during
shutdown.
             // See #disableLog4jShutdownHook()

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2s.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2s.java?rev=1848273&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2s.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2s.java
Thu Dec  6 08:55:23 2018
@@ -0,0 +1,39 @@
+/*
+ * 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.meecrowave.logging.log4j2;
+
+import org.apache.meecrowave.logging.tomcat.LogFacade;
+
+public class Log4j2s {
+    public static final boolean IS_PRESENT;
+    static {
+        boolean hasLog4j2;
+        try {
+            LogFacade.class.getClassLoader().loadClass("org.apache.logging.log4j.Logger");
+            hasLog4j2 = true;
+        } catch (final Exception | NoClassDefFoundError e) {
+            hasLog4j2 = false;
+        }
+        IS_PRESENT = hasLog4j2;
+    }
+
+    private Log4j2s() {
+        // no-op
+    }
+}

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java?rev=1848273&r1=1848272&r2=1848273&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java
Thu Dec  6 08:55:23 2018
@@ -19,6 +19,7 @@
 package org.apache.meecrowave.logging.tomcat;
 
 import org.apache.juli.logging.Log;
+import org.apache.meecrowave.logging.log4j2.Log4j2s;
 
 public class LogFacade implements Log {
     private final Log delegate;
@@ -29,7 +30,7 @@ public class LogFacade implements Log {
 
     public LogFacade(final String name) {
         // should be read per launch and not once per JVM
-        this.delegate = "org.apache.meecrowave.logging.tomcat.Log4j2Log".equals(System.getProperty("org.apache.tomcat.Logger",
"jul")) ?
+        this.delegate = Log4j2s.IS_PRESENT && "org.apache.meecrowave.logging.tomcat.Log4j2Log".equals(System.getProperty("org.apache.tomcat.Logger",
"jul")) ?
                 new Log4j2Log(name) : new JULLog(name);
     }
 



Mime
View raw message