1 11 package org.eclipse.help.internal.standalone; 12 13 import java.io.*; 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 20 public class Options { 21 public static final String PARAM_FEATUREID = "featureId"; 24 public static final String PARAM_VERSION = "version"; 26 public static final String PARAM_FROM = "from"; 28 public static final String PARAM_TO = "to"; 30 public static final String PARAM_VERIFYONLY = "verifyOnly"; 32 private static boolean debug = false; 34 35 private static boolean useExe = true; 37 38 private static File eclipseHome; 40 41 private static File workspace; 43 44 private static File lockFile; 46 47 private static File hostPortFile; 50 51 private static String vm; 53 54 private static List vmArgs; 56 57 private static List eclipseArgs; 59 60 private static List helpCommand; 62 63 private static String host; 65 66 private static String port; 68 69 private static String adminId = null; 71 72 private static String adminPassword = null; 74 75 private static String trustStoreLocation = null; 78 79 private static String trustStorePassword = null; 82 83 private static String [] updateParameters; 85 86 98 public static void init(String appId, String [] args) { 99 List list = new ArrayList (); 101 for (int i = 0; i < args.length; i++) { 102 list.add(args[i]); 103 } 104 105 init(appId, list); 106 } 107 108 120 public static void init(String appId, List options) { 121 eclipseArgs = new ArrayList (); 123 eclipseArgs.addAll(options); 124 125 helpCommand = extractOption(eclipseArgs, "-command"); if (helpCommand == null) { 128 helpCommand = new ArrayList (0); 129 } 130 List parameters = new ArrayList (); 132 List param = extractOption(eclipseArgs, "-" + PARAM_FEATUREID); if (param != null) { 134 parameters.add(PARAM_FEATUREID + "=" + (String ) param.get(0)); } 136 param = extractOption(eclipseArgs, "-" + PARAM_VERSION); if (param != null) { 138 parameters.add(PARAM_VERSION + "=" + (String ) param.get(0)); } 140 param = extractOption(eclipseArgs, "-" + PARAM_FROM); if (param != null) { 142 parameters.add(PARAM_FROM + "=" + (String ) param.get(0)); } 144 param = extractOption(eclipseArgs, "-" + PARAM_TO); if (param != null) { 146 parameters.add(PARAM_TO + "=" + (String ) param.get(0)); } 148 param = extractOption(eclipseArgs, "-" + PARAM_VERIFYONLY); if (param != null) { 150 parameters.add(PARAM_VERIFYONLY + "=" + (String ) param.get(0)); } 152 updateParameters = (String []) parameters.toArray(new String [parameters 153 .size()]); 154 155 if (getOption(eclipseArgs, "-debug") != null) { debug = true; 158 System.out.println("Debugging is on."); } 160 if (extractOption(eclipseArgs, "-noexec") != null) { useExe = false; 163 } 164 List homes = extractOption(eclipseArgs, "-eclipseHome"); if (homes == null || homes.isEmpty()) { 167 homes = extractOption(eclipseArgs, "-eclipse_Home"); } 169 if (homes != null && !homes.isEmpty()) { 170 eclipseHome = new File((String ) homes.get(0)); 171 } else { 172 eclipseHome = new File(System.getProperty("user.dir")); } 174 175 List workspaces = extractOption(eclipseArgs, "-data"); if (workspaces != null && !workspaces.isEmpty()) { 178 String workspacePath = (String ) workspaces.get(0); 179 workspace = new File(workspacePath); 180 if (!workspace.isAbsolute()) { 181 workspace = new File(eclipseHome, workspacePath); 182 } 183 } else { 184 workspace = new File(eclipseHome, "workspace"); } 186 lockFile = new File(workspace, "/.metadata/.helplock"); hostPortFile = new File(workspace, "/.metadata/.connection"); 189 List hosts = extractOption(eclipseArgs, "-host"); if (hosts != null && hosts.size() > 0) { 192 host = (String ) hosts.get(0); 193 } 194 195 List ports = extractOption(eclipseArgs, "-port"); if (ports != null && ports.size() > 0) { 198 port = (String ) ports.get(0); 199 } 200 201 List adminIds = extractOption(eclipseArgs, "-adminId"); if (adminIds != null && adminIds.size() > 0) { 204 adminId = (String ) adminIds.get(0); 205 } 206 207 List adminPasswords = extractOption(eclipseArgs, "-adminPassword"); if (adminPasswords != null && adminPasswords.size() > 0) { 210 adminPassword = (String ) adminPasswords.get(0); 211 } 212 213 List trustStoreLocations = extractOption(eclipseArgs, "-trustStoreLocation"); if (trustStoreLocations != null && trustStoreLocations.size() > 0) { 216 trustStoreLocation = (String ) trustStoreLocations.get(0); 217 } 218 219 List trustStorePasswords = extractOption(eclipseArgs, "-trustStorePassword"); if (trustStorePasswords != null && trustStorePasswords.size() > 0) { 222 trustStorePassword = (String ) trustStorePasswords.get(0); 223 } 224 225 List vms = extractOption(eclipseArgs, "-vm"); if (vms != null && !vms.isEmpty()) { 228 vm = (String ) vms.get(0); 229 } else { 230 String vmName = System.getProperty("java.vm.name"); String executable = "J9".equals(vmName) ? "j9" : "java"; if (System.getProperty("os.name").startsWith("Win")) { if (!debug) { 234 executable += "w.exe"; } else { 236 executable += ".exe"; } 238 } 239 vm = System.getProperty("java.home") + File.separator + "bin" + File.separator + executable; 242 } 243 244 vmArgs = new ArrayList (0); 246 List passedVmArgs = extractOption(eclipseArgs, "-vmargs"); if (passedVmArgs != null && passedVmArgs.size() > 0) { 248 vmArgs = passedVmArgs; 249 } 250 251 eclipseArgs.add(0, "-data"); eclipseArgs.add(1, getWorkspace().getAbsolutePath()); 255 256 extractOption(eclipseArgs, "-application"); eclipseArgs.add(0, "-application"); eclipseArgs.add(1, appId); 259 260 extractOption(eclipseArgs, "-showsplash"); extractOption(eclipseArgs, "-endsplash"); extractOption(eclipseArgs, "-nosplash"); eclipseArgs.add(0, "-nosplash"); 266 if (host != null || port != null) { 268 if (host != null) { 269 vmArgs.add("-Dserver_host=" + host); } 271 if (port != null) { 272 vmArgs.add("-Dserver_port=" + port); } 274 } 275 } 276 277 280 public static boolean isDebug() { 281 return debug; 282 } 283 284 public static String getAdminId() { 285 return adminId; 286 } 287 288 public static String getAdminPassword() { 289 return adminPassword; 290 } 291 292 public static String getTrustStoreLocation() { 293 return trustStoreLocation; 294 } 295 296 public static String getTrustStorePassword() { 297 return trustStorePassword; 298 } 299 300 public static File getConnectionFile() { 301 return hostPortFile; 302 } 303 304 public static File getLockFile() { 305 return lockFile; 306 } 307 308 public static File getEclipseHome() { 309 return eclipseHome; 310 } 311 312 public static File getWorkspace() { 313 return workspace; 314 } 315 316 public static List getHelpCommand() { 317 return helpCommand; 318 } 319 320 public static String [] getUpdateParameters() { 321 return updateParameters; 322 } 323 324 public static List getEclipseArgs() { 325 return eclipseArgs; 326 } 327 328 336 private static List extractOption(List options, String optionName) { 337 List values = null; 338 for (int i = 0; i < options.size();) { 339 if (optionName.equalsIgnoreCase((String ) options.get(i))) { 340 if (values == null) { 341 values = new ArrayList (1); 342 } 343 options.remove(i); 345 while (i < options.size()) { 347 if (((String ) options.get(i)).startsWith("-") && !optionName.equals("-vmargs")) { break; 351 } 352 values.add(options.get(i)); 354 options.remove(i); 355 } 356 } else { 357 i++; 358 } 359 } 360 return values; 361 } 362 363 373 private static List getOption(List options, String optionName) { 374 List values = null; 375 for (int i = 0; i < options.size(); i++) { 376 if (optionName.equalsIgnoreCase((String ) options.get(i))) { 377 if (values == null) { 378 values = new ArrayList (1); 379 } 380 for (int j = i + 1; j < options.size(); j++) { 382 if (((String ) options.get(j)).startsWith("-") && !optionName.equals("-vmargs")) { i = j; 386 break; 387 } 388 values.add(options.get(j)); 389 } 390 } 391 } 392 return values; 393 } 394 395 public static String getVm() { 396 return vm; 397 } 398 399 public static List getVmArgs() { 400 return vmArgs; 401 } 402 403 408 public static boolean useExe() { 409 return useExe; 410 } 411 412 } 413 | Popular Tags |