< prev index next >
test/lib/testlibrary/jdk/testlibrary/ProcessTools.java
Print this page
@@ -21,18 +21,21 @@
* questions.
*/
package jdk.testlibrary;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -337,10 +340,42 @@
}
System.out.println();
}
}
+ public static OutputAnalyzer executeModularTest(String module, String mainClass,
+ List<String> otherOptions,
+ List<Path> classPath, List<Path> modulePath, List<String> addMods,
+ String... arguments) throws Exception {
+ List<String> args = new ArrayList<>();
+ if (otherOptions != null && otherOptions.size() > 0) {
+ args.addAll(otherOptions);
+ }
+ args.add("-mp");
+ args.add(modulePath.stream()
+ .map(Path::toString)
+ .collect(Collectors.joining(File.pathSeparator)));
+ if (classPath != null && classPath.size() > 0) {
+ args.add("-cp");
+ args.add(classPath.stream()
+ .map(Path::toString)
+ .collect(Collectors.joining(File.pathSeparator)));
+ }
+ if (addMods != null && addMods.size() > 0) {
+ args.add("-addmods");
+ args.add(String.join(",", addMods));
+ }
+ if (module != null) {
+ args.add("-m"); args.add(module + ((mainClass != null) ? "/"+ mainClass : ""));
+ } else {
+ args.add(mainClass);
+ }
+ args.addAll(Arrays.asList(arguments));
+ ProcessBuilder pb = createJavaProcessBuilder(args.toArray(new String[0]));
+ return executeProcess(pb);
+ }
+
/**
* Executes a test java process, waits for it to finish and returns the process output.
* The default options from jtreg, test.vm.opts and test.java.opts, are added.
* The java from the test.jdk is used to execute the command.
*
< prev index next >