From 824db3c11327236bf7a0dca58315e9ebc440950b Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Wed, 8 Nov 2023 10:49:09 -0600 Subject: [PATCH 1/2] [LOGMGR-342] Properly detect console charset --- build-release-11 | 0 pom.xml | 25 +++++++++++-- .../logmanager/handlers/ConsoleHandler.java | 1 + .../logmanager/handlers/JDKSpecific.java | 31 ++++++++++++++++ .../logmanager/handlers/JDKSpecific.java | 35 +++++++++++++++++++ 5 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 build-release-11 create mode 100644 src/main/java/org/jboss/logmanager/handlers/JDKSpecific.java create mode 100644 src/main/java17/org/jboss/logmanager/handlers/JDKSpecific.java diff --git a/build-release-11 b/build-release-11 new file mode 100644 index 00000000..e69de29b diff --git a/pom.xml b/pom.xml index c9cecaf9..295c0cf0 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ org.jboss.logging logging-parent - 1.0.1.Final + 1.0.2.Final JBoss Log Manager @@ -54,7 +54,7 @@ - 2.1.0 + 2.2.0 2.1.2 4.0.21 1.1.4 @@ -75,6 +75,9 @@ ${skipTests} + + + 17 @@ -170,6 +173,15 @@ maven-compiler-plugin + + + default-compile + + + 11 + + + net.revelc.code.formatter @@ -201,12 +213,19 @@ maven-surefire-plugin + + + default-test + + + + false ${skipUTs} **/*Tests.java - -Djava.util.logging.manager=org.jboss.logmanager.LogManager --add-modules=org.eclipse.parsson -Djdk.attach.allowAttachSelf=true ${client.jvm.jpms.args} + -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djdk.attach.allowAttachSelf=true ${client.jvm.jpms.args} false org.jboss.logmanager.LogManager diff --git a/src/main/java/org/jboss/logmanager/handlers/ConsoleHandler.java b/src/main/java/org/jboss/logmanager/handlers/ConsoleHandler.java index 5bed9a84..4962460d 100644 --- a/src/main/java/org/jboss/logmanager/handlers/ConsoleHandler.java +++ b/src/main/java/org/jboss/logmanager/handlers/ConsoleHandler.java @@ -102,6 +102,7 @@ public ConsoleHandler(final Target target) { */ public ConsoleHandler(final Target target, final Formatter formatter) { super(formatter); + setCharset(JDKSpecific.consoleCharset()); switch (target) { case SYSTEM_OUT: setOutputStream(wrap(out)); diff --git a/src/main/java/org/jboss/logmanager/handlers/JDKSpecific.java b/src/main/java/org/jboss/logmanager/handlers/JDKSpecific.java new file mode 100644 index 00000000..53b0b2de --- /dev/null +++ b/src/main/java/org/jboss/logmanager/handlers/JDKSpecific.java @@ -0,0 +1,31 @@ +package org.jboss.logmanager.handlers; + +import java.io.Console; +import java.nio.charset.Charset; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * JDK-specific code relating to {@link Console}. + */ +final class JDKSpecific { + private JDKSpecific() { + } + + private static final Charset CONSOLE_CHARSET; + + static { + // Make various guesses as to what the encoding of the console is + String encodingName = AccessController + .doPrivileged((PrivilegedAction) () -> System.getProperty("stdout.encoding")); + if (encodingName == null) { + encodingName = AccessController + .doPrivileged((PrivilegedAction) () -> System.getProperty("native.encoding")); + } + CONSOLE_CHARSET = encodingName == null ? Charset.defaultCharset() : Charset.forName(encodingName); + } + + static Charset consoleCharset() { + return CONSOLE_CHARSET; + } +} diff --git a/src/main/java17/org/jboss/logmanager/handlers/JDKSpecific.java b/src/main/java17/org/jboss/logmanager/handlers/JDKSpecific.java new file mode 100644 index 00000000..53e6a22a --- /dev/null +++ b/src/main/java17/org/jboss/logmanager/handlers/JDKSpecific.java @@ -0,0 +1,35 @@ +package org.jboss.logmanager.handlers; + +import java.io.Console; +import java.nio.charset.Charset; +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * JDK-specific code relating to {@link Console}. + */ +final class JDKSpecific { + private JDKSpecific() {} + + private static final Charset CONSOLE_CHARSET; + + static { + Console console = System.console(); + Charset charset; + if (console != null) { + charset = console.charset(); + } else { + // Make various guesses as to what the encoding of the console is + String encodingName = AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("stdout.encoding")); + if (encodingName == null) { + encodingName = AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty("native.encoding")); + } + charset = encodingName == null ? Charset.defaultCharset() : Charset.forName(encodingName); + } + CONSOLE_CHARSET = charset; + } + + static Charset consoleCharset() { + return CONSOLE_CHARSET; + } +} From adc7440b3fe67c3ee26f7e736aeb359014197361 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Wed, 8 Nov 2023 13:36:35 -0600 Subject: [PATCH 2/2] Update CI to build on 21 and test on 11, 17, and 21 --- .github/workflows/maven.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 09036cea..e2015dc9 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -23,18 +23,20 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest] - java: ['11', '17'] steps: - uses: actions/checkout@v4 - - name: Set up JDK ${{ matrix.java }} + - name: Set up JDKs uses: actions/setup-java@v3 with: - java-version: ${{ matrix.java }} distribution: 'temurin' cache: 'maven' - - name: Build and Test with Java ${{ matrix.java }} - run: mvn -B clean verify + java-version: | + 11 + 17 + 21 + - name: Build and Test + run: mvn -B clean verify "-Djava11.home=${{env.JAVA_HOME_11_X64}}" "-Djava17.home=${{env.JAVA_HOME_17_X64}}" format-check: runs-on: ubuntu-latest