Skip to content

Commit

Permalink
fix LOGBACK-LOGBACK-1670, use Class.getModule to obtain versio info u…
Browse files Browse the repository at this point in the history
…nder JMPS

Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Sep 13, 2022
1 parent 2c53e09 commit 32a3172
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public void autoConfig() throws JoranException {

public void autoConfig(ClassLoader classLoader) throws JoranException {
String versionStr = EnvUtil.logbackVersion();
if(versionStr == null) {
versionStr = CoreConstants.NA;
}
loggerContext.getStatusManager().add(new InfoStatus(CoreConstants.LOGBACK_CLASSIC_VERSION_MESSAGE + versionStr, loggerContext));
StatusListenerConfigHelper.installIfAsked(loggerContext);
List<Configurator> configuratorList = ClassicEnvUtil.loadFromServiceLoader(Configurator.class, classLoader);
Expand Down
5 changes: 3 additions & 2 deletions logback-classic/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
requires ch.qos.logback.core;
uses ch.qos.logback.classic.spi.Configurator;
provides org.slf4j.spi.SLF4JServiceProvider with ch.qos.logback.classic.spi.LogbackServiceProvider;



provides ch.qos.logback.classic.spi.Configurator with ch.qos.logback.classic.util.DefaultJoranConfigurator;

exports ch.qos.logback.classic;
exports ch.qos.logback.classic.boolex;
exports ch.qos.logback.classic.encoder;
Expand Down
5 changes: 0 additions & 5 deletions logback-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@

<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
</manifestEntries>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
Expand Down
37 changes: 32 additions & 5 deletions logback-core/src/main/java/ch/qos/logback/core/util/EnvUtil.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2015, QOS.ch. All rights reserved.
*
* <p>
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* <p>
* or (per the licensee's choosing)
* <p>
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package ch.qos.logback.core.util;

import java.lang.module.ModuleDescriptor;
import java.util.Optional;

/**
* @author Ceki G&uuml;lc&uuml;
*/
Expand All @@ -30,13 +33,37 @@ private EnvUtil() {
* @return current version or null if missing version data
*/
static public String logbackVersion() {
String moduleVersion = logbackVersionByModule();
if(moduleVersion != null)
return moduleVersion;

Package pkg = EnvUtil.class.getPackage();
if(pkg == null) {
if (pkg == null) {
return null;
}
return pkg.getImplementationVersion();
}

/**
* <p>Returns the current version of logback via class.getModule() or null if data is not
* available.
* </p>
*
* @since 1.3.0
* @return current version or null if missing version data
*/
static private String logbackVersionByModule() {
Module module = EnvUtil.class.getModule();
if (module == null)
return null;

ModuleDescriptor md = module.getDescriptor();
if (md == null)
return null;
Optional<String> opt = md.rawVersion();
return opt.orElse(null);
}

static public int getJDKVersion(String javaVersionStr) {
int version = 0;

Expand Down
6 changes: 3 additions & 3 deletions logback-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

exports ch.qos.logback.core.rolling;
exports ch.qos.logback.core.rolling.helper;

exports ch.qos.logback.core.util;

exports ch.qos.logback.core.encoder;

exports ch.qos.logback.core.helpers;
exports ch.qos.logback.core.html;

exports ch.qos.logback.core.filter;

exports ch.qos.logback.core.model;
Expand Down Expand Up @@ -51,7 +52,6 @@

exports ch.qos.logback.core.recovery;

exports ch.qos.logback.core.util;
exports ch.qos.logback.core.read;


Expand Down

0 comments on commit 32a3172

Please sign in to comment.