Fix non-system specific path separator

This commit is contained in:
Erik C. Thauvin 2025-03-25 21:46:59 -07:00
parent 9625db4b62
commit 0f7a7cf090
Signed by: erik
GPG key ID: 776702A6A2DA330E

View file

@ -75,6 +75,19 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
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<TestNgOperation, List<String>
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");
@ -372,6 +387,14 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
return this;
}
private String joinClasspathJar(List<File> 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}