Skip to content

Commit

Permalink
Merge pull request #353 from jamezp/LOGMGR-298
Browse files Browse the repository at this point in the history
[LOGMGR-298] Require a minimum of Java 11 for both compile and runtim…
  • Loading branch information
jamezp authored Mar 25, 2022
2 parents 5aa9ec9 + e5764c2 commit 84d1c3f
Show file tree
Hide file tree
Showing 18 changed files with 282 additions and 1,563 deletions.
17 changes: 4 additions & 13 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,18 @@ jobs:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
java: ['11', '17']

steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: 8
distribution: 'temurin'
cache: 'maven'
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven Linux
if: runner.os == 'Linux'
run: mvn -B clean verify -Djava8.home=$JAVA_HOME_8_X64
- name: Build with Maven Windows
if: runner.os == 'Windows'
run: mvn -B clean verify '-Djava8.home="%JAVA_HOME_8_X64%"'
- name: Build and Test with Java ${{ matrix.java }}
run: mvn -B clean verify
75 changes: 17 additions & 58 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,26 @@
</configuration>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
<!-- Adding OSGI metadata to the JAR without changing the packaging type. -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
<!-- Adding OSGI metadata to the JAR without changing the packaging type. -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
Expand Down Expand Up @@ -142,51 +148,4 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>java9-tests</id>
<activation>
<jdk>[9,</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>test-compile-java9</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<release>9</release>
<buildDirectory>${project.build.directory}</buildDirectory>
<compileSourceRoots>${project.basedir}/src/test/java9</compileSourceRoots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
91 changes: 88 additions & 3 deletions core/src/main/java/org/jboss/logmanager/JBossLoggerFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,96 @@

package org.jboss.logmanager;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.EnumMap;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* For Java 8 this is just an empty type. For Java 9 or greater this implements the {@code System.LoggerFinder}. It
* will make an attempt to set the {@code java.util.logging.manager} system property before a logger is accessed.
* Implements the {@code System.LoggerFinder}. It will make an attempt to set the {@code java.util.logging.manager}
* system property before a logger is accessed.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
public class JBossLoggerFinder {
public class JBossLoggerFinder extends System.LoggerFinder {
private static final Map<System.Logger.Level, java.util.logging.Level> LEVELS = new EnumMap<>(System.Logger.Level.class);
private static final AtomicBoolean LOGGED = new AtomicBoolean(false);
private static volatile boolean PROPERTY_SET = false;

static {
LEVELS.put(System.Logger.Level.ALL, Level.ALL);
LEVELS.put(System.Logger.Level.TRACE, Level.TRACE);
LEVELS.put(System.Logger.Level.DEBUG, Level.DEBUG);
LEVELS.put(System.Logger.Level.INFO, Level.INFO);
LEVELS.put(System.Logger.Level.WARNING, Level.WARN);
LEVELS.put(System.Logger.Level.ERROR, Level.ERROR);
LEVELS.put(System.Logger.Level.OFF, Level.OFF);
}

@Override
public System.Logger getLogger(final String name, final Module module) {
if (!PROPERTY_SET) {
synchronized (this) {
if (!PROPERTY_SET) {
if (System.getSecurityManager() == null) {
if (System.getProperty("java.util.logging.manager") == null) {
System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
}
} else {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
if (System.getProperty("java.util.logging.manager") == null) {
System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
}
return null;
});
}
}
PROPERTY_SET = true;
}
}
final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(name);
if (!logger.getClass().getName().equals("org.jboss.logmanager.Logger")) {
if (LOGGED.compareAndSet(false, true)) {
logger.log(Level.ERROR, "The LogManager accessed before the \"java.util.logging.manager\" system property was set to \"org.jboss.logmanager.LogManager\". Results may be unexpected.");
}
}
return new JBossSystemLogger(logger);
}

private static class JBossSystemLogger implements System.Logger {
private static final String LOGGER_CLASS_NAME = JBossSystemLogger.class.getName();
private final java.util.logging.Logger delegate;

private JBossSystemLogger(final java.util.logging.Logger delegate) {
this.delegate = delegate;
}

@Override
public String getName() {
return delegate.getName();
}

@Override
public boolean isLoggable(final Level level) {
return delegate.isLoggable(LEVELS.getOrDefault(level, java.util.logging.Level.INFO));
}

@Override
public void log(final Level level, final ResourceBundle bundle, final String msg, final Throwable thrown) {
final ExtLogRecord record = new ExtLogRecord(LEVELS.getOrDefault(level, java.util.logging.Level.INFO), msg, LOGGER_CLASS_NAME);
record.setThrown(thrown);
record.setResourceBundle(bundle);
delegate.log(record);
}

@Override
public void log(final Level level, final ResourceBundle bundle, final String format, final Object... params) {
final ExtLogRecord record = new ExtLogRecord(LEVELS.getOrDefault(level, java.util.logging.Level.INFO), format, ExtLogRecord.FormatStyle.MESSAGE_FORMAT, LOGGER_CLASS_NAME);
record.setParameters(params);
record.setResourceBundle(bundle);
delegate.log(record);
}
}
}
Loading

0 comments on commit 84d1c3f

Please sign in to comment.