< prev index next >
test/testlibrary/jdk/test/lib/Utils.java
Print this page
*** 21,35 ****
--- 21,39 ----
* questions.
*/
package jdk.test.lib;
+ import java.io.File;
import static jdk.test.lib.Asserts.assertTrue;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.InetAddress;
+ import java.net.MalformedURLException;
import java.net.ServerSocket;
+ import java.net.URL;
+ import java.net.URLClassLoader;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
*** 48,57 ****
--- 52,66 ----
* Common library for various test helper functions.
*/
public final class Utils {
/**
+ * Returns the value of 'test.class.path' system property.
+ */
+ public static final String TEST_CLASS_PATH = System.getProperty("test.class.path", ".");
+
+ /**
* Returns the sequence used by operating system to separate lines.
*/
public static final String NEW_LINE = System.getProperty("line.separator");
/**
*** 426,431 ****
--- 435,461 ----
* system property
*/
public static long adjustTimeout(long tOut) {
return Math.round(tOut * Utils.TIMEOUT_FACTOR);
}
+
+ /**
+ * @param parent parent class loader
+ * @return an UrlClassLoader with urls made of the 'test.class.path' jtreg
+ * property and with the given parent
+ */
+ public static URLClassLoader getTestClassPathURLClassLoader(ClassLoader parent) {
+ URL[] urls = Arrays.stream(TEST_CLASS_PATH.split(File.pathSeparator))
+ .map(Paths::get)
+ .map(Path::toUri)
+ .map(x -> {
+ try {
+ return x.toURL();
+ } catch (MalformedURLException ex) {
+ throw new Error("Test issue. JTREG property"
+ + " 'test.class.path'"
+ + " is not defined correctly", ex);
+ }
+ }).toArray(URL[]::new);
+ return new URLClassLoader(urls, parent);
+ }
}
< prev index next >