1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package jdk.testlibrary; 25 26 import java.io.FileNotFoundException; 27 import java.nio.file.Path; 28 import java.nio.file.Paths; 29 30 /** 31 * @deprecated This class is deprecated. Use the one from 32 * {@code <root>/test/lib/share/classes/jdk/test/lib} 33 */ 34 @Deprecated 35 public final class JDKToolFinder { 36 37 private JDKToolFinder() { 38 } 39 40 /** 41 * Returns the full path to an executable in jdk/bin based on System 42 * property {@code test.jdk} or {@code compile.jdk} (both are set by the jtreg test suite) 43 * 44 * @return Full path to an executable in jdk/bin 45 */ 46 public static String getJDKTool(String tool) { 47 48 // First try to find the executable in test.jdk 49 try { 50 return getTool(tool, "test.jdk"); 51 } catch (FileNotFoundException e) { 52 53 } 54 55 // Now see if it's available in compile.jdk 56 try { 57 return getTool(tool, "compile.jdk"); 58 } catch (FileNotFoundException e) { 59 throw new RuntimeException("Failed to find " + tool + 60 ", looked in test.jdk (" + System.getProperty("test.jdk") + 61 ") and compile.jdk (" + System.getProperty("compile.jdk") + ")"); 62 } 63 } 64 65 /** 66 * Returns the full path to an executable in jdk/bin based on System 67 * property {@code compile.jdk} 68 * 69 * @return Full path to an executable in jdk/bin 70 */ 71 public static String getCompileJDKTool(String tool) { 72 try { 73 return getTool(tool, "compile.jdk"); 74 } catch (FileNotFoundException e) { 75 throw new RuntimeException(e); 76 } 77 } 78 79 /** 80 * Returns the full path to an executable in jdk/bin based on System 81 * property {@code test.jdk} 82 * 83 * @return Full path to an executable in jdk/bin 84 */ 85 public static String getTestJDKTool(String tool) { 86 try { 87 return getTool(tool, "test.jdk"); 88 } catch (FileNotFoundException e) { 89 throw new RuntimeException(e); 90 } 91 } 92 93 private static String getTool(String tool, String property) throws FileNotFoundException { 94 String jdkPath = System.getProperty(property); 95 96 if (jdkPath == null) { 97 throw new RuntimeException( 98 "System property '" + property + "' not set. This property is normally set by jtreg. " 99 + "When running test separately, set this property using '-D" + property + "=/path/to/jdk'."); 100 } 101 102 Path toolName = Paths.get("bin", tool + (Platform.isWindows() ? ".exe" : "")); 103 104 Path jdkTool = Paths.get(jdkPath, toolName.toString()); 105 if (!jdkTool.toFile().exists()) { 106 throw new FileNotFoundException("Could not find file " + jdkTool.toAbsolutePath()); 107 } 108 109 return jdkTool.toAbsolutePath().toString(); 110 } 111 }