1 11 package org.eclipse.update.standalone; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 import java.util.HashMap ; 16 17 import org.eclipse.update.core.Utilities; 18 import org.eclipse.update.internal.core.Messages; 19 import org.eclipse.update.internal.core.UpdateCore; 20 import org.eclipse.update.internal.mirror.MirrorCommand; 21 22 32 public class CmdLineArgs { 33 private HashMap options = new HashMap (); 34 public CmdLineArgs(String [] args) { 35 38 for (int i = 0; i < args.length - 1; i++) { 39 if ("-command".equals(args[i])) { if (isValidCommand(args[i + 1])) { 41 options.put("-command", args[i + 1]); i++; 43 } else { 44 StandaloneUpdateApplication.exceptionLogged(); 45 UpdateCore.log( 46 Utilities.newCoreException( 47 Messages.Standalone_invalidCmd + args[i + 1], 48 null)); 49 return; 50 } 51 } 52 53 if (isValidParam(args[i])) { 54 options.put(args[i], args[i + 1]); 55 i++; 56 57 } 58 String to = (String ) options.get("-to"); if (to != null && to.startsWith("file:")) { try { 63 URL url = new URL (to); 64 options.put("-to", url.getFile()); } catch (MalformedURLException mue) { 66 } 67 } 68 } 69 } 70 71 private boolean isValidParam(String param) { 72 return param.equals("-command") || param.equals("-version") || param.equals("-to") || param.equals("-from") || param.equals("-featureId") || param.equals("-verifyOnly") || param.equals("-mirrorURL") || param.equals("-ignoreMissingPlugins"); } 81 82 private boolean isValidCommand(String cmd) { 83 if (cmd == null) 84 return false; 85 else 86 return cmd.equals("install") || cmd.equals("enable") || cmd.equals("disable") || cmd.equals("search") || cmd.equals("update") || cmd.equals("mirror") || cmd.equals("uninstall") || cmd.equals("listFeatures") || cmd.equals("addSite") || cmd.equals("removeSite"); } 97 98 public ScriptedCommand getCommand() { 99 try { 100 String cmd = (String ) options.get("-command"); if (cmd == null) 102 return null; 103 if (cmd.equals("install")) return new InstallCommand( 105 (String ) options.get("-featureId"), (String ) options.get("-version"), (String ) options.get("-from"), (String ) options.get("-to"), (String ) options.get("-verifyOnly")); else if (cmd.equals("enable")) return new EnableCommand( 112 (String ) options.get("-featureId"), (String ) options.get("-version"), (String ) options.get("-to"), (String ) options.get("-verifyOnly")); else if (cmd.equals("disable")) return new DisableCommand( 118 (String ) options.get("-featureId"), (String ) options.get("-version"), (String ) options.get("-to"), (String ) options.get("-verifyOnly")); else if (cmd.equals("search")) return new SearchCommand((String ) options.get("-from")); else if (cmd.equals("update")) return new UpdateCommand( 126 (String ) options.get("-featureId"), (String ) options.get("-version"), (String ) options.get("-verifyOnly")); else if (cmd.equals("mirror")) return new MirrorCommand( 131 (String ) options.get("-featureId"), (String ) options.get("-version"), (String ) options.get("-from"), (String ) options.get("-to"), (String ) options.get("-mirrorURL"), (String ) options.get("-ignoreMissingPlugins")); else if (cmd.equals("uninstall")) return new UninstallCommand( 139 (String ) options.get("-featureId"), (String ) options.get("-version"), (String ) options.get("-to"), (String ) options.get("-verifyOnly")); else if (cmd.equals("listFeatures")) return new ListFeaturesCommand((String ) options.get("-from")); else if (cmd.equals("addSite")) return new AddSiteCommand((String ) options.get("-from")); else if (cmd.equals("removeSite")) return new RemoveSiteCommand((String ) options.get("-to")); else 150 return null; 151 } catch (Exception e) { 152 StandaloneUpdateApplication.exceptionLogged(); 153 UpdateCore.log(e); 154 return null; 155 } 156 } 157 158 } 159 | Popular Tags |