--- old/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java 2013-09-11 15:31:10.222388600 -0400 +++ new/test/testlibrary/com/oracle/java/testlibrary/JDKToolFinder.java 2013-09-11 15:31:09.916358400 -0400 @@ -23,28 +23,45 @@ package com.oracle.java.testlibrary; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; public final class JDKToolFinder { - private JDKToolFinder() { - } - - /** - * Returns the full path to an executable in jdk/bin based on System property - * test.jdk (set by jtreg test suite) - * - * @return Full path to an executable in jdk/bin - */ - public static String getJDKTool(String tool) { - String binPath = System.getProperty("test.jdk"); - if (binPath == null) { - throw new RuntimeException("System property 'test.jdk' not set. This property is normally set by jtreg. " - + "When running test separately, set this property using '-Dtest.jdk=/path/to/jdk'."); + private JDKToolFinder() { } - binPath += File.separatorChar + "bin" + File.separatorChar + tool; + /** + * Returns the full path to an executable in jdk/bin based on System + * property test.jdk or compile.jdk (both are set by the jtreg test suite) + * + * @return Full path to an executable in jdk/bin + */ + public static String getJDKTool(String tool) { + String compileJdkPath = System.getProperty("compile.jdk"); + String testJdkPath = System.getProperty("test.jdk"); + + if (testJdkPath == null) { + throw new RuntimeException( + "System property 'test.jdk' not set. This property is normally set by jtreg. " + + "When running test separately, set this property using '-Dtest.jdk=/path/to/jdk'."); + } + + Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : "")); + + // First try with test.jdk, if the tool can't be found there, check + // compile.jdk + Path testJdkTool = Paths.get(testJdkPath, toolName.toString()); + if (!testJdkTool.toFile().exists()) { + Path compileJdkTool = Paths.get(compileJdkPath, toolName.toString()); + if (!compileJdkTool.toFile().exists()) { + throw new RuntimeException("Failed to find " + tool + + ", looked in test.jdk (" + testJdkTool.toAbsolutePath() + + ") and compile.jdk (" + compileJdkTool.toAbsolutePath() + ")"); + } + return compileJdkTool.toAbsolutePath().toString(); + } - return binPath; - } + return testJdkTool.toAbsolutePath().toString(); + } }