--- old/test/testlibrary/jdk/test/lib/Utils.java 2015-09-08 18:49:43.538282471 +0300 +++ new/test/testlibrary/jdk/test/lib/Utils.java 2015-09-08 18:49:43.426282469 +0300 @@ -23,11 +23,15 @@ 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; @@ -50,6 +54,11 @@ 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"); @@ -428,4 +437,25 @@ 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); + } }