Skip to content

Commit 5c50f91

Browse files
committed
standardize version checking
Signed-off-by: ceki <[email protected]>
1 parent f0c4a06 commit 5c50f91

19 files changed

Lines changed: 96 additions & 667 deletions

File tree

logback-classic-blackbox/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<useModulePath>true</useModulePath>
113113

114114
<excludes>
115-
<exclude>ch.qos.logback.classic.blackbox.VersionCheckTest</exclude>
115+
<exclude>ch.qos.logback.classic.blackbox.WithOlderCoreVersionCheckTest</exclude>
116116
</excludes>
117117
</configuration>
118118
</execution>
@@ -125,7 +125,7 @@
125125
<profiles>
126126
<!--
127127
cd logback-classic-blackbox
128-
mvn test -P older-core -Dtest=ch.qos.logback.classic.blackbox.VersionCheckTest
128+
mvn test -P older-core -Dtest=ch.qos.logback.classic.blackbox.WithOlderCoreVersionCheckTest
129129
-->
130130
<profile>
131131
<id>older-core</id>
@@ -158,7 +158,7 @@
158158
<reportFormat>plain</reportFormat>
159159
<disableXmlReport>true</disableXmlReport>
160160
<includes>
161-
<include>ch.qos.logback.classic.blackbox.VersionCheckTest</include>
161+
<include>ch.qos.logback.classic.blackbox.WithOlderCoreVersionCheckTest</include>
162162
</includes>
163163
<excludes>
164164
<exclude>**/*Xest.java</exclude>

logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/VersionCheckTest.java renamed to logback-classic-blackbox/src/test/java/ch/qos/logback/classic/blackbox/WithOlderCoreVersionCheckTest.java

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import org.junit.jupiter.api.Test;
2323

2424
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertTrue;
2526
import static org.junit.jupiter.api.Assertions.fail;
2627

2728
/**
28-
* The VersionCheckTest class is designed to perform a validation test
29+
* The WithOlderCoreVersionCheckTest class is designed to perform a validation test
2930
* on the compatibility of version dependencies, specifically focusing
3031
* on the interaction between "logback-classic" and "logback-core" libraries.
3132
*
@@ -36,47 +37,25 @@
3637
* <p>Use the following command to run this test
3738
* </p>
3839
*
39-
* <pre> cd logback-classic-blackbox;
40-
* mvn test -P older-core -Dtest=ch.qos.logback.classic.blackbox.VersionCheckTest
40+
* <pre> mvn install; # ensure up to date compilation
41+
* cd logback-classic-blackbox;
42+
* mvn test -P older-core -Dtest=ch.qos.logback.classic.blackbox.WithOlderCoreVersionCheckTest
4143
* </pre>
4244
*
4345
* @since 1.5.25
4446
*/
4547

46-
public class VersionCheckTest {
48+
public class WithOlderCoreVersionCheckTest {
4749

4850

49-
// WARNING: do not add other tests to this file
51+
// WARNING: do not add other tests to this file without careful consideration
5052

5153
LoggerContext loggerContext = new LoggerContext();
5254

53-
/**
54-
*
55-
* Assertions:
56-
* 1. Verifies that the "olderCore" property matches the expected value "1.5.20".
57-
* 2. Ensures that a {@link NoClassDefFoundError} is thrown in presence of logback-core version
58-
* 1.5.25 or older.
59-
*/
6055
@Test
61-
@Disabled
62-
public void versionTest() {
56+
public void olderCoreVersionTest() {
6357
String olderCoreVersion = System.getProperty("olderCore", "none");
64-
//assertEquals("1.5.20", olderCoreVersion);
65-
assertEquals("1.5.25", olderCoreVersion);
66-
try {
67-
VersionUtil.checkForVersionEquality(loggerContext, this.getClass(), CoreConstants.class, "logback-classic", "logback-core");
68-
fail("Expected NoClassDefFoundError");
69-
} catch (NoClassDefFoundError e) {
70-
// logback-core version is older than 1.5.25
71-
System.out.println("Got expected NoClassDefFoundError.");
72-
}
73-
}
74-
75-
@Test
76-
public void otherVersionTest() {
77-
String olderCoreVersion = System.getProperty("olderCore", "none");
78-
//assertEquals("1.5.20", olderCoreVersion);
79-
assertEquals("1.5.25", olderCoreVersion);
58+
assertTrue(olderCoreVersion.startsWith("1.5"));
8059
try {
8160
CoreVersionUtil.getCoreVersionBySelfDeclaredProperties();
8261
fail("Expected Error");
@@ -92,6 +71,6 @@ public void otherVersionTest() {
9271

9372

9473

95-
// WARNING: do not add other tests to this file
74+
// WARNING: do not add other tests to this file without careful consideration
9675

9776
}

logback-classic/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@
141141

142142
<build>
143143
<resources>
144-
<resource>
145-
<directory>src/main/resources</directory>
146-
</resource>
147-
148144
<resource>
149145
<directory>src/main/java/</directory>
150146
<filtering>true</filtering>

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
*/
3131
public class ClassicVersionUtil {
3232

33+
static String CLASSIC_MODULE_NAME = "logback-classic";
34+
static String CLASSIC_MODULE_VERSION_PROPERTIES_FILE = CLASSIC_MODULE_NAME + "-version.properties";
35+
static String CLASSIC_MODULE_VERSION_PROPERTY_KEY = CLASSIC_MODULE_NAME + "-version";
36+
37+
3338
// Code copied from VersionUtil. It must be located in the encompassing module and cannot be
3439
// shared.
3540
//
@@ -61,13 +66,28 @@ static String getVersionBySelfDeclaredProperties(Class<?> aClass, String moduleN
6166
* The method looks for a properties file named "logback-classic-version.properties" within the classpath,
6267
* reads its contents, and fetches the value associated with the "logback-classic-version" key.
6368
*
69+
* <p>Note that the Class.getResourceAsStream() method checks that the resource is open to the
70+
* caller. This entails that the caller must be in the same module as the properties file.
71+
* </p>
72+
*
6473
* @return the version string of the "logback-classic" module if found, or null if the properties file or version
6574
* key is not present or an error occurs while reading the properties file.
6675
*
6776
* @since 1.5.26
6877
*/
6978
static public String getVersionBySelfDeclaredProperties() {
70-
return getVersionBySelfDeclaredProperties(ClassicConstants.class, "logback-classic");
79+
Properties props = new Properties();
80+
81+
try (InputStream is = ClassicConstants.class.getResourceAsStream(CLASSIC_MODULE_VERSION_PROPERTIES_FILE)) {
82+
if (is != null) {
83+
props.load(is);
84+
return props.getProperty(CLASSIC_MODULE_VERSION_PROPERTY_KEY);
85+
} else {
86+
return null;
87+
}
88+
} catch (IOException e) {
89+
return null;
90+
}
7191
}
7292

7393
}

logback-classic/src/main/resources/ch/qos/logback/classic/db/script/db2.sql

Lines changed: 0 additions & 56 deletions
This file was deleted.

logback-classic/src/main/resources/ch/qos/logback/classic/db/script/h2.sql

Lines changed: 0 additions & 46 deletions
This file was deleted.

logback-classic/src/main/resources/ch/qos/logback/classic/db/script/hsqldb.sql

Lines changed: 0 additions & 46 deletions
This file was deleted.

logback-classic/src/main/resources/ch/qos/logback/classic/db/script/mssql.sql

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)