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 2019/05/13 05:31:25 UTC
[logging-log4j2] branch master updated (05fb297 -> 502f9fc)
This is an automated email from the ASF dual-hosted git repository.
rgoers pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.
from 05fb297 LOG4J2-1103 - FailoverAppender was failing with ERROR appender Failover has no parameter that matches element Failovers
new 0bf3ae5 JEP223 detection
new a56448a Test for JEP223 detection
new 8796ae5 Test for JEP223 detection
new 16fa74e Delegate method call to make it testable (without having to use reflection).
new 93e66ae Use existing JDK version detection that is JEP223 aware. Version testing moved to org.apache.logging.log4j.util.ConstantsTest.testJdkVersionDetection
new 502f9fc Cleaned up unused imports
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/org/apache/logging/log4j/util/Constants.java | 5 ++++-
.../org/apache/logging/log4j/util/ConstantsTest.java | 16 ++++++++++++++++
.../logging/log4j/core/layout/AbstractStringLayout.java | 9 +--------
.../log4j/core/layout/AbstractStringLayoutTest.java | 1 +
4 files changed, 22 insertions(+), 9 deletions(-)
create mode 100644 log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java
[logging-log4j2] 02/06: Test for JEP223 detection
Posted by rg...@apache.org.
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
commit a56448a13021a6fc108f7842f1aba76c020ade49
Author: ulrichenslin <ul...@gmail.com>
AuthorDate: Sat Mar 2 08:43:55 2019 +0200
Test for JEP223 detection
---
.../log4j/core/layout/AbstractStringLayoutTest.java | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
index 04505d4..f0b3d69 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
@@ -15,7 +15,10 @@ package org.apache.logging.log4j.core.layout;/*
* limitations under the license.
*/
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.nio.charset.Charset;
+import java.util.Properties;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.Test;
@@ -74,4 +77,22 @@ public class AbstractStringLayoutTest {
assertEquals("capacity, trimmed to MAX_STRING_BUILDER_SIZE", ConcreteStringLayout.MAX_STRING_BUILDER_SIZE, sb3.capacity());
assertEquals("empty, ready for use", 0, sb3.length());
}
+
+ @Test
+ public void testJdkVersionDetection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+
+ Properties properties120 = new Properties();
+ properties120.put("java.version","1.2.0");
+ System.setProperties(properties120);
+
+ Method method = AbstractStringLayout.class.getDeclaredMethod("isPreJava8",null);
+ method.setAccessible(true);
+ assertTrue ((Boolean) method.invoke("isPreJava8"));
+
+ Properties properties900 = new Properties();
+ properties120.put("java.version","9.1.0");
+ System.setProperties(properties120);
+
+ assertFalse ((Boolean) method.invoke("isPreJava8"));
+ }
}
\ No newline at end of file
[logging-log4j2] 03/06: Test for JEP223 detection
Posted by rg...@apache.org.
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
commit 8796ae582de28d056fba1aa0fb5531d07b8dd361
Author: ulrichenslin <ue...@apple.com>
AuthorDate: Sat Mar 2 08:47:43 2019 +0200
Test for JEP223 detection
---
.../log4j/core/layout/AbstractStringLayoutTest.java | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
index f0b3d69..9dce991 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
@@ -81,18 +81,26 @@ public class AbstractStringLayoutTest {
@Test
public void testJdkVersionDetection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- Properties properties120 = new Properties();
- properties120.put("java.version","1.2.0");
- System.setProperties(properties120);
+ final String currentVersion = System.getProperty("java.version");
+
+ Properties properties = new Properties();
+ properties.put("java.version","1.2.0");
+ System.setProperties(properties);
Method method = AbstractStringLayout.class.getDeclaredMethod("isPreJava8",null);
method.setAccessible(true);
assertTrue ((Boolean) method.invoke("isPreJava8"));
- Properties properties900 = new Properties();
- properties120.put("java.version","9.1.0");
- System.setProperties(properties120);
+ properties = new Properties();
+ properties.put("java.version","9.1.0");
+ System.setProperties(properties);
assertFalse ((Boolean) method.invoke("isPreJava8"));
+
+ //reset the value to the current version
+ properties = new Properties();
+ properties.put("java.version", currentVersion);
+ System.setProperties(properties);
+
}
}
\ No newline at end of file
[logging-log4j2] 05/06: Use existing JDK version detection that is
JEP223 aware. Version testing moved to
org.apache.logging.log4j.util.ConstantsTest.testJdkVersionDetection
Posted by rg...@apache.org.
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
commit 93e66ae7d88e829d0019fde332cf4aca67fb6693
Author: ulrichenslin <ue...@apple.com>
AuthorDate: Mon Mar 4 08:25:41 2019 +0200
Use existing JDK version detection that is JEP223 aware.
Version testing moved to org.apache.logging.log4j.util.ConstantsTest.testJdkVersionDetection
---
.../log4j/core/layout/AbstractStringLayout.java | 15 +------------
.../core/layout/AbstractStringLayoutTest.java | 25 ----------------------
2 files changed, 1 insertion(+), 39 deletions(-)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
index deea87f..3b9eb61 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
@@ -131,20 +131,7 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
// LOG4J2-1151: If the built-in JDK 8 encoders are available we should use them.
private static boolean isPreJava8() {
- final String version = System.getProperty("java.version");
- final String[] parts = version.split("\\.");
- try {
- int major = Integer.parseInt(parts[1]);
-
- final int token = Integer.parseInt(parts[0]);
- boolean isJEP223 = token != 1;
- if (isJEP223) {
- major = token;
- }
- return major < 8;
- } catch (final Exception ex) {
- return true;
- }
+ return org.apache.logging.log4j.util.Constants.JAVA_MAJOR_VERSION < 8;
}
private static int size(final String property, final int defaultValue) {
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
index 9dce991..2b35bac 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
@@ -78,29 +78,4 @@ public class AbstractStringLayoutTest {
assertEquals("empty, ready for use", 0, sb3.length());
}
- @Test
- public void testJdkVersionDetection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
-
- final String currentVersion = System.getProperty("java.version");
-
- Properties properties = new Properties();
- properties.put("java.version","1.2.0");
- System.setProperties(properties);
-
- Method method = AbstractStringLayout.class.getDeclaredMethod("isPreJava8",null);
- method.setAccessible(true);
- assertTrue ((Boolean) method.invoke("isPreJava8"));
-
- properties = new Properties();
- properties.put("java.version","9.1.0");
- System.setProperties(properties);
-
- assertFalse ((Boolean) method.invoke("isPreJava8"));
-
- //reset the value to the current version
- properties = new Properties();
- properties.put("java.version", currentVersion);
- System.setProperties(properties);
-
- }
}
\ No newline at end of file
[logging-log4j2] 04/06: Delegate method call to make it testable
(without having to use reflection).
Posted by rg...@apache.org.
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
commit 16fa74e9c6ffba32246b70649140b4cfcabe7ee5
Author: ulrichenslin <ue...@apple.com>
AuthorDate: Mon Mar 4 08:22:19 2019 +0200
Delegate method call to make it testable (without having to use reflection).
---
.../org/apache/logging/log4j/util/Constants.java | 5 ++++-
.../org/apache/logging/log4j/util/ConstantsTest.java | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
index c0d18d7..2fc67f4 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/Constants.java
@@ -89,7 +89,10 @@ public final class Constants {
}
private static int getMajorVersion() {
- final String version = System.getProperty("java.version");
+ return getMajorVersion(System.getProperty("java.version"));
+ }
+
+ static int getMajorVersion(final String version) {
final String[] parts = version.split("-|\\.");
boolean isJEP223;
try {
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java
new file mode 100644
index 0000000..f568c9f
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java
@@ -0,0 +1,20 @@
+package org.apache.logging.log4j.util;
+
+import org.junit.Test;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class ConstantsTest {
+
+ @Test
+ public void testJdkVersionDetection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ assertEquals(1, Constants.getMajorVersion("1.1.2"));
+ assertEquals(8, Constants.getMajorVersion("1.8.2"));
+ assertEquals(9, Constants.getMajorVersion("9.1.1"));
+ assertEquals(11, Constants.getMajorVersion("11.1.1"));
+ }
+}
\ No newline at end of file
[logging-log4j2] 06/06: Cleaned up unused imports
Posted by rg...@apache.org.
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
commit 502f9fc700820d0b97d5aaacea89535810f96eb2
Author: ulrichenslin <ue...@apple.com>
AuthorDate: Mon Mar 4 15:19:25 2019 +0200
Cleaned up unused imports
---
.../src/test/java/org/apache/logging/log4j/util/ConstantsTest.java | 6 +-----
.../apache/logging/log4j/core/layout/AbstractStringLayoutTest.java | 3 ---
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java
index f568c9f..8d323be 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/ConstantsTest.java
@@ -2,16 +2,12 @@ package org.apache.logging.log4j.util;
import org.junit.Test;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Properties;
-
import static org.junit.Assert.*;
public class ConstantsTest {
@Test
- public void testJdkVersionDetection() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ public void testJdkVersionDetection() {
assertEquals(1, Constants.getMajorVersion("1.1.2"));
assertEquals(8, Constants.getMajorVersion("1.8.2"));
assertEquals(9, Constants.getMajorVersion("9.1.1"));
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
index 2b35bac..add4387 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/AbstractStringLayoutTest.java
@@ -15,10 +15,7 @@ package org.apache.logging.log4j.core.layout;/*
* limitations under the license.
*/
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.nio.charset.Charset;
-import java.util.Properties;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.Test;
[logging-log4j2] 01/06: JEP223 detection
Posted by rg...@apache.org.
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
commit 0bf3ae517fdea41ef5f9a10d628b78464ae2639b
Author: ulrichenslin <ue...@apple.com>
AuthorDate: Fri Mar 1 18:24:22 2019 +0200
JEP223 detection
---
.../apache/logging/log4j/core/layout/AbstractStringLayout.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
index d8403b6..deea87f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
@@ -134,7 +134,13 @@ public abstract class AbstractStringLayout extends AbstractLayout<String> implem
final String version = System.getProperty("java.version");
final String[] parts = version.split("\\.");
try {
- final int major = Integer.parseInt(parts[1]);
+ int major = Integer.parseInt(parts[1]);
+
+ final int token = Integer.parseInt(parts[0]);
+ boolean isJEP223 = token != 1;
+ if (isJEP223) {
+ major = token;
+ }
return major < 8;
} catch (final Exception ex) {
return true;