1 /* 2 * Copyright (c) 2018, 2019, 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 import java.io.File; 25 import java.nio.file.Path; 26 27 /** 28 * Helper class which contains functions to get different system 29 * dependent paths used by tests 30 */ 31 public class JPackagePath { 32 33 // Return path to test src adjusted to location of caller 34 public static String getTestSrcRoot() { 35 return JPackageHelper.TEST_SRC_ROOT; 36 } 37 38 // Return path to calling test 39 public static String getTestSrc() { 40 return JPackageHelper.TEST_SRC; 41 } 42 43 // Returns path to generate test application 44 public static String getApp() { 45 return getApp("test"); 46 } 47 48 public static String getApp(String name) { 49 return getAppSL(name, name); 50 } 51 52 // Returns path to generate test application icon 53 public static String getAppIcon() { 54 return getAppIcon("test"); 55 } 56 57 public static String getAppIcon(String name) { 58 if (JPackageHelper.isWindows()) { 59 return Path.of("output", name, name + ".ico").toString(); 60 } else if (JPackageHelper.isOSX()) { 61 return Path.of("output", name + ".app", 62 "Contents", "Resources", name + ".icns").toString(); 63 } else if (JPackageHelper.isLinux()) { 64 return Path.of("output", name, "lib", name + ".png").toString(); 65 } else { 66 throw new AssertionError("Cannot detect platform"); 67 } 68 } 69 70 // Returns path to generate secondary launcher of given application 71 public static String getAppSL(String sl) { 72 return getAppSL("test", sl); 73 } 74 75 public static String getAppSL(String app, String sl) { 76 if (JPackageHelper.isWindows()) { 77 return Path.of("output", app, sl + ".exe").toString(); 78 } else if (JPackageHelper.isOSX()) { 79 return Path.of("output", app + ".app", 80 "Contents", "MacOS", sl).toString(); 81 } else if (JPackageHelper.isLinux()) { 82 return Path.of("output", app, "bin", sl).toString(); 83 } else { 84 throw new AssertionError("Cannot detect platform"); 85 } 86 } 87 88 // Returns path to test application cfg file 89 public static String getAppCfg() { 90 return getAppCfg("test"); 91 } 92 93 public static String getAppCfg(String name) { 94 if (JPackageHelper.isWindows()) { 95 return Path.of("output", name, "app", name + ".cfg").toString(); 96 } else if (JPackageHelper.isOSX()) { 97 return Path.of("output", name + ".app", 98 "Contents", "app", name + ".cfg").toString(); 99 } else if (JPackageHelper.isLinux()) { 100 return Path.of("output", name, "lib", "app", name + ".cfg").toString(); 101 } else { 102 throw new AssertionError("Cannot detect platform"); 103 } 104 } 105 106 // Returns path including executable to java in image runtime folder 107 public static String getRuntimeJava() { 108 return getRuntimeJava("test"); 109 } 110 111 public static String getRuntimeJava(String name) { 112 if (JPackageHelper.isWindows()) { 113 return Path.of(getRuntimeBin(name), "java.exe").toString(); 114 } 115 return Path.of(getRuntimeBin(name), "java").toString(); 116 } 117 118 // Returns output file name generate by test application 119 public static String getAppOutputFile() { 120 return "appOutput.txt"; 121 } 122 123 // Returns path to bin folder in image runtime 124 public static String getRuntimeBin() { 125 return getRuntimeBin("test"); 126 } 127 128 public static String getRuntimeBin(String name) { 129 if (JPackageHelper.isWindows()) { 130 return Path.of("output", name, "runtime", "bin").toString(); 131 } else if (JPackageHelper.isOSX()) { 132 return Path.of("output", name + ".app", 133 "Contents", "runtime", 134 "Contents", "Home", "bin").toString(); 135 } else if (JPackageHelper.isLinux()) { 136 return Path.of("output", name, "lib", "runtime", "bin").toString(); 137 } else { 138 throw new AssertionError("Cannot detect platform"); 139 } 140 } 141 142 public static String getOSXInstalledApp(String testName) { 143 return File.separator + "Applications" 144 + File.separator + testName + ".app" 145 + File.separator + "Contents" 146 + File.separator + "MacOS" 147 + File.separator + testName; 148 } 149 150 public static String getOSXInstalledApp(String subDir, String testName) { 151 return File.separator + "Applications" 152 + File.separator + subDir 153 + File.separator + testName + ".app" 154 + File.separator + "Contents" 155 + File.separator + "MacOS" 156 + File.separator + testName; 157 } 158 159 // Returs path to test license file 160 public static String getLicenseFilePath() { 161 String path = JPackagePath.getTestSrcRoot() 162 + File.separator + "resources" 163 + File.separator + "license.txt"; 164 165 return path; 166 } 167 }