Skip to content

Commit 4368333

Browse files
committed
move VersionUtil.getCoreVersionBySelfDeclaredProperties to CoreVersionUtil
Signed-off-by: ceki <[email protected]>
1 parent 8bd5660 commit 4368333

3 files changed

Lines changed: 27 additions & 19 deletions

File tree

logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import ch.qos.logback.core.joran.spi.JoranException;
1919
import ch.qos.logback.core.spi.ContextAware;
2020
import ch.qos.logback.core.spi.ContextAwareImpl;
21+
import ch.qos.logback.core.util.CoreVersionUtil;
2122
import ch.qos.logback.core.util.Loader;
2223
import ch.qos.logback.core.util.StatusListenerConfigHelper;
2324
import ch.qos.logback.core.util.VersionUtil;
@@ -101,7 +102,7 @@ public void autoConfig(ClassLoader classLoader) throws JoranException {
101102

102103
private void checkVersions() {
103104
try {
104-
String coreVersion = VersionUtil.getCoreVersionBySelfDeclaredProperties();
105+
String coreVersion = CoreVersionUtil.getCoreVersionBySelfDeclaredProperties();
105106
String classicVersion = ClassicVersionUtil.getVersionBySelfDeclaredProperties();
106107
VersionUtil.checkForVersionEquality(loggerContext, coreVersion, classicVersion, "logback-core", "logback-classic");
107108
} catch(NoClassDefFoundError e) {

logback-core/src/main/java/ch/qos/logback/core/util/CoreVersionUtil.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,27 @@
1414

1515
package ch.qos.logback.core.util;
1616

17+
import ch.qos.logback.core.CoreConstants;
18+
19+
/**
20+
* Utility class for retrieving version information of the "logback-core" module.
21+
*
22+
* @since 1.5.26
23+
*/
1724
public class CoreVersionUtil {
25+
/**
26+
* Retrieves the version of the "logback-core" module using a properties file
27+
* associated with the module.
28+
*
29+
* <p>The method locates and reads a properties file named "logback-core-version.properties"
30+
* in the package of the {@code CoreConstants.class}. It then extracts the version
31+
* information using the key "logback-core-version".
32+
* </p>
33+
*
34+
* @return the version of the "logback-core" module as a string, or null if the version cannot be determined
35+
* @since 1.5.26
36+
*/
37+
static public String getCoreVersionBySelfDeclaredProperties() {
38+
return VersionUtil.getArtifactVersionBySelfDeclaredProperties(CoreConstants.class, "logback-core");
39+
}
1840
}

logback-core/src/main/java/ch/qos/logback/core/util/VersionUtil.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package ch.qos.logback.core.util;
1616

1717
import ch.qos.logback.core.Context;
18-
import ch.qos.logback.core.CoreConstants;
1918
import ch.qos.logback.core.status.InfoStatus;
2019
import ch.qos.logback.core.status.WarnStatus;
2120

@@ -97,7 +96,7 @@ static private String getVersionOfClassByModule(Class<?> aClass) {
9796
/**
9897
* Retrieves the version of a module using a properties file associated with the module.
9998
*
100-
* <p>Unfortunately, this code cannot be called by depender modules. It needs to be copy-pasted.</p>
99+
* <p>Unfortunately, this code cannot be called by other modules. It needs to be duplicated.</p>
101100
*
102101
* <p>The method looks for a properties file with a name derived from the <code>moduleName</code> parameter,
103102
* in the same location, e.g. package, as the <code>aClass</code> parameter. It attempts to load the properties file
@@ -111,6 +110,8 @@ static private String getVersionOfClassByModule(Class<?> aClass) {
111110
* @param aClass the class used to locate the resource file, the properties file is expected to be in the same package
112111
* @param moduleName the name of the module, which is used to construct the properties file name and the key
113112
* @return the version of the module as a string, or null if the version cannot be determined
113+
*
114+
* @since 1.5.26
114115
*/
115116
static public String getArtifactVersionBySelfDeclaredProperties(Class<?> aClass, String moduleName) {
116117
Properties props = new Properties();
@@ -130,22 +131,6 @@ static public String getArtifactVersionBySelfDeclaredProperties(Class<?> aClass,
130131
}
131132
}
132133

133-
/**
134-
* Retrieves the version of the "logback-core" module using a properties file
135-
* associated with the module.
136-
*
137-
* <p>The method locates and reads a properties file named "logback-core-version.properties"
138-
* in the package of the {@code CoreConstants.class}. It then extracts the version
139-
* information using the key "logback-core-version".
140-
* </p>
141-
*
142-
* @return the version of the "logback-core" module as a string, or null if the version cannot be determined
143-
* @since 1.5.26
144-
*/
145-
static public String getCoreVersionBySelfDeclaredProperties() {
146-
return getArtifactVersionBySelfDeclaredProperties(CoreConstants.class, "logback-core");
147-
}
148-
149134

150135
// dependency synonym dependee
151136
// depender synonym dependent

0 commit comments

Comments
 (0)