Skip to content

Commit f47c254

Browse files
committed
automate; read slf4j version from properties instead of hardcoding
1 parent 7f38f62 commit f47c254

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

pom.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
<properties>
4242
<java.version>21</java.version>
4343
<maven.version>3.9.9</maven.version>
44-
<!-- version should match ivy Engine sfl4j version! And version in EngineClassLoaderFactory.SLF4J_VERSION -->
4544
<slf4j.version>2.0.13</slf4j.version>
4645
<junit-jupiter.version>5.12.2</junit-jupiter.version>
4746
<site.path>snapshot</site.path>
@@ -207,6 +206,16 @@
207206
</dependencies>
208207

209208
<build>
209+
<resources>
210+
<resource>
211+
<directory>src/main/resources</directory>
212+
</resource>
213+
<resource>
214+
<directory>src/main/resources-filtered</directory>
215+
<targetPath>ch/ivyteam/ivy/maven/engine</targetPath>
216+
<filtering>true</filtering>
217+
</resource>
218+
</resources>
210219
<plugins>
211220
<plugin>
212221
<artifactId>maven-compiler-plugin</artifactId>

src/main/java/ch/ivyteam/ivy/maven/engine/EngineClassLoaderFactory.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.ArrayList;
2727
import java.util.Arrays;
2828
import java.util.List;
29+
import java.util.Properties;
2930
import java.util.function.Predicate;
3031

3132
import org.apache.maven.artifact.Artifact;
@@ -53,8 +54,7 @@ public interface OsgiDir {
5354
String LIB_BOOT = "lib/boot";
5455
}
5556

56-
/** must match version in pom.xml */
57-
private static final String SLF4J_VERSION = "2.0.13";
57+
private static final String SLF4J_VERSION = readSlf4jVersion();
5858

5959
private static final List<String> ENGINE_LIB_DIRECTORIES = Arrays.asList(
6060
OsgiDir.INSTALL_AREA + "/" + OsgiDir.LIB_BOOT,
@@ -90,6 +90,17 @@ public List<File> getSlf4jJars() {
9090
maven.getJar("org.slf4j", "log4j-over-slf4j", SLF4J_VERSION));
9191
}
9292

93+
private static String readSlf4jVersion() {
94+
String versions = "versions.properties";
95+
try (var in = EngineClassLoaderFactory.class.getResourceAsStream(versions)) {
96+
Properties props = new Properties();
97+
props.load(in);
98+
return props.getProperty("slf4j", "");
99+
} catch (IOException ex) {
100+
throw new RuntimeException("Failed to read SLF4j version from file: " + versions, ex);
101+
}
102+
}
103+
93104
public static List<File> getOsgiBootstrapClasspath(Path engineDirectory) {
94105
if (engineDirectory == null || !Files.isDirectory(engineDirectory)) {
95106
throw new RuntimeException("The engineDirectory is missing: " + engineDirectory);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
slf4j=${slf4j.version}

0 commit comments

Comments
 (0)