diff --git a/src/main/java/rife/bld/extension/TestNgOperation.java b/src/main/java/rife/bld/extension/TestNgOperation.java index 0617152..298857f 100644 --- a/src/main/java/rife/bld/extension/TestNgOperation.java +++ b/src/main/java/rife/bld/extension/TestNgOperation.java @@ -75,6 +75,19 @@ public class TestNgOperation extends TestOperation return this; } + private String buildClassPath(String... path) { + var classpath = new StringBuilder(); + for (var p : path) { + if (!p.isBlank()) { + if (!classpath.isEmpty()) { + classpath.append(File.pathSeparator); + } + classpath.append(p); + } + } + return classpath.toString(); + } + /** * This sets the default maximum number of threads to use for data providers when running tests in parallel. * It will only take effect if the parallel mode has been selected (for example,with the @@ -202,11 +215,13 @@ public class TestNgOperation extends TestOperation args.add("-cp"); if (testClasspath_.isEmpty()) { - args.add(String.format("%s:%s:%s:%s", new File(project_.libTestDirectory(), "*"), - new File(project_.libCompileDirectory(), "*"), project_.buildMainDirectory(), - project_.buildTestDirectory())); + args.add(buildClassPath(joinClasspathJar(project_.testClasspathJars()), + joinClasspathJar(project_.compileClasspathJars()), + joinClasspathJar(project_.providedClasspathJars()), + project_.buildMainDirectory().getAbsolutePath(), + project_.buildTestDirectory().getAbsolutePath())); } else { - args.add(String.join(":", testClasspath_)); + args.add(String.join(File.pathSeparator, testClasspath_)); } args.add("org.testng.TestNG"); @@ -224,7 +239,7 @@ public class TestNgOperation extends TestOperation } catch (IOException ioe) { if (LOGGER.isLoggable(Level.SEVERE) && !silent()) { LOGGER.severe("An IO error occurred while accessing the default testng.xml file: " - + ioe.getMessage()); + + ioe.getMessage()); } throw new RuntimeException(ioe); } @@ -372,6 +387,14 @@ public class TestNgOperation extends TestOperation return this; } + private String joinClasspathJar(List jars) { + if (!jars.isEmpty()) { + return String.join(File.pathSeparator, jars.stream().map(File::getAbsolutePath).toList()); + } else { + return ""; + } + } + /** * The list of {@code .class} files or list of class names implementing {@code ITestListener} or * {@code ISuiteListener} @@ -1056,10 +1079,10 @@ public class TestNgOperation extends TestOperation var temp = tempFile(); try (var bufWriter = Files.newBufferedWriter(Paths.get(temp.getPath()))) { bufWriter.write("" + - "" + - "" + - "" + - ""); + "" + + "" + + "" + + ""); for (var p : packages_) { bufWriter.write(String.format("", p)); }