Skip to content

Commit 80c32fe

Browse files
committed
improve ClasspathCustomizationTest
(cherry picked from commit 135d4d0)
1 parent fc54354 commit 80c32fe

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

maven/tomee-maven-plugin/src/test/java/org/apache/openejb/maven/plugin/test/ClasspathCustomizationTest.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.junit.Test;
2323

2424
import java.io.File;
25-
import java.io.FilenameFilter;
2625
import java.util.List;
2726

2827
import static java.util.Arrays.asList;
@@ -33,8 +32,12 @@ public class ClasspathCustomizationTest {
3332
@Rule
3433
public TomEEMavenPluginRule TMPRule = new TomEEMavenPluginRule();
3534

35+
private static final String LOG4J_VERSION = resolveLog4jVersion();
36+
3637
@Config
37-
private final List<String> classpaths = asList("org.apache.logging.log4j:log4j-api:2.6.2", "org.apache.logging.log4j:log4j-jul:2.6.2");
38+
private final List<String> classpaths = asList(
39+
"org.apache.logging.log4j:log4j-api:" + LOG4J_VERSION,
40+
"org.apache.logging.log4j:log4j-jul:" + LOG4J_VERSION);
3841

3942
@Config
4043
private final File catalinaBase = new File("target/tomee-classpath");
@@ -43,11 +46,18 @@ public class ClasspathCustomizationTest {
4346
public void log4j2WasCopied() throws Exception {
4447
final File boot = new File(catalinaBase, "boot");
4548
assertTrue(boot.isDirectory());
46-
assertEquals(2, boot.listFiles(new FilenameFilter() {
47-
@Override
48-
public boolean accept(final File dir, final String name) {
49-
return name.startsWith("log4j-") && name.endsWith("-2.6.2.jar");
49+
final File[] log4jJars = boot.listFiles((dir, name) ->
50+
name.startsWith("log4j-") && name.endsWith("-" + LOG4J_VERSION + ".jar"));
51+
assertEquals(2, log4jJars.length);
52+
}
53+
54+
private static String resolveLog4jVersion() {
55+
for (final String entry : System.getProperty("java.class.path", "").split(File.pathSeparator)) {
56+
if (entry.contains("log4j-api-") && entry.endsWith(".jar")) {
57+
final String name = new File(entry).getName();
58+
return name.substring("log4j-api-".length(), name.length() - ".jar".length());
5059
}
51-
}).length);
60+
}
61+
throw new IllegalStateException("log4j-api jar not found on classpath");
5262
}
5363
}

0 commit comments

Comments
 (0)