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 26 /** 27 * Helper class which contains functions to get different system dependent paths used by tests 28 */ 29 public class JPackagePath { 30 31 // Path to Windows "Program Files" folder 32 // Probably better to figure this out programattically 33 private static final String WIN_PROGRAM_FILES = "C:\\Program Files"; 34 35 // Path to Windows Start menu items 36 private static final String WIN_START_MENU = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs"; 37 38 // Path to Windows public desktop location 39 private static final String WIN_PUBLIC_DESKTOP = "C:\\Users\\Public\\Desktop"; 40 41 // Return path to test src adjusted to location of caller 42 public static String getTestSrcRoot() { 43 return JPackageHelper.TEST_SRC_ROOT; 44 } 45 46 // Return path to calling test 47 public static String getTestSrc() { 48 return JPackageHelper.TEST_SRC; 49 } 50 51 // Returns path to generate test application 52 public static String getApp() { 53 if (JPackageHelper.isWindows()) { 54 return "output" + File.separator + "test" + File.separator + "test.exe"; 55 } else if (JPackageHelper.isOSX()) { 56 return "output" + File.separator + "test.app" + File.separator + "Contents" 57 + File.separator + "MacOS" + File.separator + "test"; 58 } else if (JPackageHelper.isLinux()) { 59 return "output" + File.separator + "test" + File.separator + "test"; 60 } else { 61 throw new AssertionError("Cannot detect platform"); 62 } 63 } 64 65 // Returns path to generate test application icon 66 public static String getAppIcon() { 67 if (JPackageHelper.isWindows()) { 68 return "output" + File.separator + "test" + File.separator + "test.ico"; 69 } else if (JPackageHelper.isOSX()) { 70 return "output" + File.separator + "test.app" + File.separator + "Contents" 71 + File.separator + "Resources" + File.separator + "test.icns"; 72 } else if (JPackageHelper.isLinux()) { 73 return "output" + File.separator + "test" + File.separator 74 + File.separator + "resources"+ File.separator + "test.png"; 75 } else { 76 throw new AssertionError("Cannot detect platform"); 77 } 78 } 79 80 // Returns path to generate test application without --name argument 81 public static String getAppNoName() { 82 if (JPackageHelper.isWindows()) { 83 return "output" + File.separator + "Hello" + File.separator + "Hello.exe"; 84 } else if (JPackageHelper.isOSX()) { 85 return "output" + File.separator + "Hello.app" + File.separator + "Contents" 86 + File.separator + "MacOS" + File.separator + "Hello"; 87 } else if (JPackageHelper.isLinux()) { 88 return "output" + File.separator + "Hello" + File.separator + "Hello"; 89 } else { 90 throw new AssertionError("Cannot detect platform"); 91 } 92 } 93 94 // Returns path to generate secondary launcher of test application 95 public static String getAppSL() { 96 if (JPackageHelper.isWindows()) { 97 return "output" + File.separator + "test" + File.separator + "test2.exe"; 98 } else if (JPackageHelper.isOSX()) { 99 return "output" + File.separator + "test.app" + File.separator + "Contents" 100 + File.separator + "MacOS" + File.separator + "test2"; 101 } else if (JPackageHelper.isLinux()) { 102 return "output" + File.separator + "test" + File.separator + "test2"; 103 } else { 104 throw new AssertionError("Cannot detect platform"); 105 } 106 } 107 108 // Returns path to app working directory (where test application generates its output) 109 public static String getAppWorkingDir() { 110 if (JPackageHelper.isWindows()) { 111 return "output" + File.separator + "test" + File.separator + "app"; 112 } else if (JPackageHelper.isOSX()) { 113 return "output" + File.separator + "test.app" + File.separator + "Contents" 114 + File.separator + "Java"; 115 } else if (JPackageHelper.isLinux()) { 116 return "output" + File.separator + "test" + File.separator + "app"; 117 } else { 118 throw new AssertionError("Cannot detect platform"); 119 } 120 } 121 122 // Returns path to test application cfg file 123 public static String getAppCfg() { 124 if (JPackageHelper.isWindows()) { 125 return "output" + File.separator + "test" + File.separator + "app" + File.separator 126 + "test.cfg"; 127 } else if (JPackageHelper.isOSX()) { 128 return "output" + File.separator + "test.app" + File.separator + "Contents" 129 + File.separator + "Java" + File.separator + "test.cfg"; 130 } else if (JPackageHelper.isLinux()) { 131 return "output" + File.separator + "test" + File.separator + "app" + File.separator 132 + "test.cfg"; 133 } else { 134 throw new AssertionError("Cannot detect platform"); 135 } 136 } 137 138 // Returns path to app working directory without --name (where test application generates its output) 139 public static String getAppWorkingDirNoName() { 140 if (JPackageHelper.isWindows()) { 141 return "output" + File.separator + "Hello" + File.separator + "app"; 142 } else if (JPackageHelper.isOSX()) { 143 return "output" + File.separator + "Hello.app" + File.separator + "Contents" 144 + File.separator + "Java"; 145 } else if (JPackageHelper.isLinux()) { 146 return "output" + File.separator + "Hello" + File.separator + "app"; 147 } else { 148 throw new AssertionError("Cannot detect platform"); 149 } 150 } 151 152 // Returns path including executable to java in image runtime folder 153 public static String getRuntimeJava() { 154 if (JPackageHelper.isWindows()) { 155 return "output" + File.separator + "test" + File.separator + "runtime" + File.separator 156 + "bin" + File.separator + "java.exe"; 157 } else if (JPackageHelper.isOSX()) { 158 return "output" + File.separator + "test.app" + File.separator 159 + "Contents" + File.separator + "PlugIns" + File.separator 160 + "Java.runtime" + File.separator + "Contents" + File.separator 161 + "Home" + File.separator + "bin" + File.separator + "java"; 162 } else if (JPackageHelper.isLinux()) { 163 return "output" + File.separator + "test" + File.separator + "runtime" + File.separator 164 + "bin" + File.separator + "java"; 165 } else { 166 throw new AssertionError("Cannot detect platform"); 167 } 168 } 169 170 // Returns output file name generate by test application 171 public static String getAppOutputFile() { 172 return "appOutput.txt"; 173 } 174 175 // Returns path to bin folder in image runtime 176 public static String getRuntimeBin() { 177 if (JPackageHelper.isWindows()) { 178 return "output" + File.separator + "test" + File.separator + "runtime" 179 + File.separator + "bin"; 180 } else if (JPackageHelper.isOSX()) { 181 return "output" + File.separator + "test.app" + File.separator + "Contents" 182 + File.separator + "PlugIns" + File.separator + "Java.runtime" 183 + File.separator + "Contents" + File.separator + "Home" + File.separator 184 + "bin"; 185 } else if (JPackageHelper.isLinux()) { 186 return "output" + File.separator + "test" + File.separator + "runtime" 187 + File.separator + "bin"; 188 } else { 189 throw new AssertionError("Cannot detect platform"); 190 } 191 } 192 193 public static String getWinProgramFiles() { 194 return WIN_PROGRAM_FILES; 195 } 196 197 public static String getWinUserLocal() { 198 return System.getProperty("user.home") + File.separator + "AppData" 199 + File.separator + "Local"; 200 } 201 202 public static String getWinStartMenu() { 203 return WIN_START_MENU; 204 } 205 206 public static String getWinPublicDesktop() { 207 return WIN_PUBLIC_DESKTOP; 208 } 209 210 public static String getWinUserLocalStartMenu() { 211 return System.getProperty("user.home") + File.separator + "AppData" 212 + File.separator + "Roaming" + File.separator + "Microsoft" 213 + File.separator + "Windows" + File.separator + "Start Menu" 214 + File.separator + "Programs"; 215 216 } 217 218 public static String getWinInstalledApp(String testName) { 219 return getWinProgramFiles() + File.separator + testName + File.separator 220 + testName + ".exe"; 221 } 222 223 public static String getOSXInstalledApp(String testName) { 224 return File.separator + "Applications" + File.separator + testName 225 + ".app" + File.separator + "Contents" + File.separator 226 + "MacOS" + File.separator + testName; 227 } 228 229 public static String getLinuxInstalledApp(String testName) { 230 return File.separator + "opt" + File.separator + testName + 231 File.separator + testName; 232 } 233 234 public static String getOSXInstalledApp(String subDir, String testName) { 235 return File.separator + "Applications" + File.separator + subDir 236 + File.separator + testName + ".app" + File.separator 237 + "Contents" + File.separator + "MacOS" + File.separator 238 + testName; 239 } 240 241 public static String getLinuxInstalledApp(String subDir, String testName) { 242 return File.separator + "opt" + File.separator + subDir + File.separator 243 + testName + File.separator + testName; 244 } 245 246 public static String getWinInstallFolder(String testName) { 247 return getWinProgramFiles() + File.separator + testName; 248 } 249 250 public static String getLinuxInstallFolder(String testName) { 251 return File.separator + "opt" + File.separator + testName; 252 } 253 254 public static String getLinuxInstallFolder(String subDir, String testName) { 255 if (testName == null) { 256 return File.separator + "opt" + File.separator + subDir; 257 } else { 258 return File.separator + "opt" + File.separator + subDir 259 + File.separator + testName; 260 } 261 } 262 263 public static String getWinUserLocalInstalledApp(String testName) { 264 return getWinUserLocal() + File.separator + testName + File.separator + testName + ".exe"; 265 } 266 267 public static String getWinUserLocalInstallFolder(String testName) { 268 return getWinUserLocal() + File.separator + testName; 269 } 270 271 // Returs path to test license file 272 public static String getLicenseFilePath() { 273 String path = JPackagePath.getTestSrcRoot() + File.separator + "resources" 274 + File.separator + "license.txt"; 275 276 return path; 277 } 278 279 // Returns path to app folder of installed application 280 public static String getWinInstalledAppFolder(String testName) { 281 return getWinProgramFiles() + File.separator + testName + File.separator 282 + "app"; 283 } 284 }