1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.sdkmanager; 18 19 import com.android.sdklib.ISdkLog; 20 import com.android.sdklib.SdkManager; 21 22 23 /** 24 * Specific command-line flags for the {@link SdkManager}. 25 */ 26 class SdkCommandLine extends CommandLineProcessor { 27 28 /* 29 * Steps needed to add a new action: 30 * - Each action is defined as a "verb object" followed by parameters. 31 * - Either reuse a VERB_ constant or define a new one. 32 * - Either reuse an OBJECT_ constant or define a new one. 33 * - Add a new entry to mAction with a one-line help summary. 34 * - In the constructor, add a define() call for each parameter (either mandatory 35 * or optional) for the given action. 36 */ 37 38 public final static String VERB_LIST = "list"; 39 public final static String VERB_CREATE = "create"; 40 public final static String VERB_MOVE = "move"; 41 public final static String VERB_DELETE = "delete"; 42 public final static String VERB_UPDATE = "update"; 43 44 public static final String OBJECT_SDK = "sdk"; 45 public static final String OBJECT_AVD = "avd"; 46 public static final String OBJECT_AVDS = "avds"; 47 public static final String OBJECT_TARGET = "target"; 48 public static final String OBJECT_TARGETS = "targets"; 49 public static final String OBJECT_PROJECT = "project"; 50 public static final String OBJECT_TEST_PROJECT = "test-project"; 51 public static final String OBJECT_LIB_PROJECT = "lib-project"; 52 public static final String OBJECT_ADB = "adb"; 53 54 public static final String ARG_ALIAS = "alias"; 55 public static final String ARG_ACTIVITY = "activity"; 56 57 public static final String KEY_ACTIVITY = ARG_ACTIVITY; 58 public static final String KEY_PACKAGE = "package"; 59 public static final String KEY_MODE = "mode"; 60 public static final String KEY_TARGET_ID = OBJECT_TARGET; 61 public static final String KEY_NAME = "name"; 62 public static final String KEY_LIBRARY = "library"; 63 public static final String KEY_PATH = "path"; 64 public static final String KEY_FILTER = "filter"; 65 public static final String KEY_SKIN = "skin"; 66 public static final String KEY_SDCARD = "sdcard"; 67 public static final String KEY_FORCE = "force"; 68 public static final String KEY_RENAME = "rename"; 69 public static final String KEY_SUBPROJECTS = "subprojects"; 70 public static final String KEY_MAIN_PROJECT = "main"; 71 72 /** 73 * Action definitions for SdkManager command line. 74 * <p/> 75 * This list serves two purposes: first it is used to know which verb/object 76 * actions are acceptable on the command-line; second it provides a summary 77 * for each action that is printed in the help. 78 * <p/> 79 * Each entry is a string array with: 80 * <ul> 81 * <li> the verb. 82 * <li> an object (use #NO_VERB_OBJECT if there's no object). 83 * <li> a description. 84 * <li> an alternate form for the object (e.g. plural). 85 * </ul> 86 */ 87 private final static String[][] ACTIONS = { 88 { VERB_LIST, NO_VERB_OBJECT, 89 "Lists existing targets or virtual devices." }, 90 { VERB_LIST, OBJECT_AVD, 91 "Lists existing Android Virtual Devices.", 92 OBJECT_AVDS }, 93 { VERB_LIST, OBJECT_TARGET, 94 "Lists existing targets.", 95 OBJECT_TARGETS }, 96 97 { VERB_CREATE, OBJECT_AVD, 98 "Creates a new Android Virtual Device." }, 99 { VERB_MOVE, OBJECT_AVD, 100 "Moves or renames an Android Virtual Device." }, 101 { VERB_DELETE, OBJECT_AVD, 102 "Deletes an Android Virtual Device." }, 103 { VERB_UPDATE, OBJECT_AVD, 104 "Updates an Android Virtual Device to match the folders of a new SDK." }, 105 106 { VERB_CREATE, OBJECT_PROJECT, 107 "Creates a new Android Project." }, 108 { VERB_UPDATE, OBJECT_PROJECT, 109 "Updates an Android Project (must have an AndroidManifest.xml)." }, 110 111 { VERB_CREATE, OBJECT_TEST_PROJECT, 112 "Creates a new Android Test Project." }, 113 { VERB_UPDATE, OBJECT_TEST_PROJECT, 114 "Updates an Android Test Project (must have an AndroidManifest.xml)." }, 115 116 { VERB_CREATE, OBJECT_LIB_PROJECT, 117 "Creates a new Android Library Project." }, 118 { VERB_UPDATE, OBJECT_LIB_PROJECT, 119 "Updates an Android Library Project (must have an AndroidManifest.xml)." }, 120 121 { VERB_UPDATE, OBJECT_ADB, 122 "Updates adb to support the USB devices declared in the SDK add-ons." }, 123 124 { VERB_UPDATE, OBJECT_SDK, 125 "Updates the SDK by suggesting new platforms to install if available." } 126 }; 127 128 public SdkCommandLine(ISdkLog logger) { 129 super(logger, ACTIONS); 130 131 // The following defines the parameters of the actions defined in mAction. 132 133 // --- create avd --- 134 135 define(Mode.STRING, false, 136 VERB_CREATE, OBJECT_AVD, "p", KEY_PATH, 137 "Location path of the directory where the new AVD will be created", null); 138 define(Mode.STRING, true, 139 VERB_CREATE, OBJECT_AVD, "n", KEY_NAME, 140 "Name of the new AVD", null); 141 define(Mode.STRING, true, 142 VERB_CREATE, OBJECT_AVD, "t", KEY_TARGET_ID, 143 "Target id of the new AVD", null); 144 define(Mode.STRING, false, 145 VERB_CREATE, OBJECT_AVD, "s", KEY_SKIN, 146 "Skin of the new AVD", null); 147 define(Mode.STRING, false, 148 VERB_CREATE, OBJECT_AVD, "c", KEY_SDCARD, 149 "Path to a shared SD card image, or size of a new sdcard for the new AVD", null); 150 define(Mode.BOOLEAN, false, 151 VERB_CREATE, OBJECT_AVD, "f", KEY_FORCE, 152 "Force creation (override an existing AVD)", false); 153 154 // --- delete avd --- 155 156 define(Mode.STRING, true, 157 VERB_DELETE, OBJECT_AVD, "n", KEY_NAME, 158 "Name of the AVD to delete", null); 159 160 // --- move avd --- 161 162 define(Mode.STRING, true, 163 VERB_MOVE, OBJECT_AVD, "n", KEY_NAME, 164 "Name of the AVD to move or rename", null); 165 define(Mode.STRING, false, 166 VERB_MOVE, OBJECT_AVD, "r", KEY_RENAME, 167 "New name of the AVD to rename", null); 168 define(Mode.STRING, false, 169 VERB_MOVE, OBJECT_AVD, "p", KEY_PATH, 170 "New location path of the directory where to move the AVD", null); 171 172 // --- update avd --- 173 174 define(Mode.STRING, true, 175 VERB_UPDATE, OBJECT_AVD, "n", KEY_NAME, 176 "Name of the AVD to update", null); 177 178 // --- create project --- 179 180 /* Disabled for ADT 0.9 / Cupcake SDK 1.5_r1 release. [bug #1795718]. 181 This currently does not work, the alias build rules need to be fixed. 182 183 define(Mode.ENUM, true, 184 VERB_CREATE, OBJECT_PROJECT, "m", KEY_MODE, 185 "Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS }); 186 */ 187 define(Mode.STRING, true, 188 VERB_CREATE, OBJECT_PROJECT, 189 "p", KEY_PATH, 190 "Location path of new project", null); 191 define(Mode.STRING, true, 192 VERB_CREATE, OBJECT_PROJECT, "t", KEY_TARGET_ID, 193 "Target id of the new project", null); 194 define(Mode.STRING, true, 195 VERB_CREATE, OBJECT_PROJECT, "k", KEY_PACKAGE, 196 "Package name", null); 197 define(Mode.STRING, true, 198 VERB_CREATE, OBJECT_PROJECT, "a", KEY_ACTIVITY, 199 "Activity name", null); 200 define(Mode.STRING, false, 201 VERB_CREATE, OBJECT_PROJECT, "n", KEY_NAME, 202 "Project name", null); 203 204 // --- create test-project --- 205 206 define(Mode.STRING, true, 207 VERB_CREATE, OBJECT_TEST_PROJECT, 208 "p", KEY_PATH, 209 "Location path of new project", null); 210 define(Mode.STRING, false, 211 VERB_CREATE, OBJECT_TEST_PROJECT, "n", KEY_NAME, 212 "Project name", null); 213 define(Mode.STRING, true, 214 VERB_CREATE, OBJECT_TEST_PROJECT, "m", KEY_MAIN_PROJECT, 215 "Location path of the project to test, relative to the new project", null); 216 217 // --- create lib-project --- 218 219 define(Mode.STRING, true, 220 VERB_CREATE, OBJECT_LIB_PROJECT, 221 "p", KEY_PATH, 222 "Location path of new project", null); 223 define(Mode.STRING, true, 224 VERB_CREATE, OBJECT_LIB_PROJECT, "t", KEY_TARGET_ID, 225 "Target id of the new project", null); 226 define(Mode.STRING, false, 227 VERB_CREATE, OBJECT_LIB_PROJECT, "n", KEY_NAME, 228 "Project name", null); 229 define(Mode.STRING, true, 230 VERB_CREATE, OBJECT_LIB_PROJECT, "k", KEY_PACKAGE, 231 "Package name", null); 232 233 // --- update project --- 234 235 define(Mode.STRING, true, 236 VERB_UPDATE, OBJECT_PROJECT, 237 "p", KEY_PATH, 238 "Location path of the project", null); 239 define(Mode.STRING, false, 240 VERB_UPDATE, OBJECT_PROJECT, 241 "t", KEY_TARGET_ID, 242 "Target id to set for the project", null); 243 define(Mode.STRING, false, 244 VERB_UPDATE, OBJECT_PROJECT, 245 "n", KEY_NAME, 246 "Project name", null); 247 define(Mode.BOOLEAN, false, 248 VERB_UPDATE, OBJECT_PROJECT, 249 "s", KEY_SUBPROJECTS, 250 "Also update any projects in sub-folders, such as test projects.", false); 251 define(Mode.STRING, false, 252 VERB_UPDATE, OBJECT_PROJECT, 253 "l", KEY_LIBRARY, 254 "Location path of an Android Library to add, relative to the main project", null); 255 256 // --- update test project --- 257 258 define(Mode.STRING, true, 259 VERB_UPDATE, OBJECT_TEST_PROJECT, 260 "p", KEY_PATH, 261 "Location path of the project", null); 262 define(Mode.STRING, true, 263 VERB_UPDATE, OBJECT_TEST_PROJECT, 264 "m", KEY_MAIN_PROJECT, 265 "Location path of the project to test, relative to the new project", null); 266 267 // --- update lib project --- 268 269 define(Mode.STRING, true, 270 VERB_UPDATE, OBJECT_LIB_PROJECT, 271 "p", KEY_PATH, 272 "Location path of the project", null); 273 define(Mode.STRING, false, 274 VERB_UPDATE, OBJECT_LIB_PROJECT, 275 "t", KEY_TARGET_ID, 276 "Target id to set for the project", null); 277 define(Mode.STRING, false, 278 VERB_UPDATE, OBJECT_LIB_PROJECT, 279 "l", KEY_LIBRARY, 280 "Location path of an Android Library to add, relative to the main project", null); 281 } 282 283 @Override 284 public boolean acceptLackOfVerb() { 285 return true; 286 } 287 288 // -- some helpers for generic action flags 289 290 /** Helper to retrieve the --path value. */ 291 public String getParamLocationPath() { 292 return (String) getValue(null, null, KEY_PATH); 293 } 294 295 /** 296 * Helper to retrieve the --target id value. 297 * The id is a string. It can be one of: 298 * - an integer, in which case it's the index of the target (cf "android list targets") 299 * - a symbolic name such as android-N for platforn API N 300 * - a symbolic add-on name such as written in the avd/*.ini files, 301 * e.g. "Google Inc.:Google APIs:3" 302 */ 303 public String getParamTargetId() { 304 return (String) getValue(null, null, KEY_TARGET_ID); 305 } 306 307 /** Helper to retrieve the --name value. */ 308 public String getParamName() { 309 return (String) getValue(null, null, KEY_NAME); 310 } 311 312 /** Helper to retrieve the --skin value. */ 313 public String getParamSkin() { 314 return (String) getValue(null, null, KEY_SKIN); 315 } 316 317 /** Helper to retrieve the --sdcard value. */ 318 public String getParamSdCard() { 319 return (String) getValue(null, null, KEY_SDCARD); 320 } 321 322 /** Helper to retrieve the --force flag. */ 323 public boolean getFlagForce() { 324 return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue(); 325 } 326 327 // -- some helpers for avd action flags 328 329 /** Helper to retrieve the --rename value for a move verb. */ 330 public String getParamMoveNewName() { 331 return (String) getValue(VERB_MOVE, null, KEY_RENAME); 332 } 333 334 335 // -- some helpers for project action flags 336 337 /** Helper to retrieve the --package value. 338 * @param directObject the directObject of the action, either {@link #OBJECT_PROJECT} 339 * or {@link #OBJECT_LIB_PROJECT}. 340 */ 341 public String getParamProjectPackage(String directObject) { 342 return ((String) getValue(null, directObject, KEY_PACKAGE)); 343 } 344 345 /** Helper to retrieve the --activity for any project action. */ 346 public String getParamProjectActivity() { 347 return ((String) getValue(null, OBJECT_PROJECT, KEY_ACTIVITY)); 348 } 349 350 /** Helper to retrieve the --library value. 351 * @param directObject the directObject of the action, either {@link #OBJECT_PROJECT} 352 * or {@link #OBJECT_LIB_PROJECT}. 353 */ 354 public String getParamProjectLibrary(String directObject) { 355 return ((String) getValue(null, directObject, KEY_LIBRARY)); 356 } 357 358 359 /** Helper to retrieve the --subprojects for any project action. */ 360 public boolean getParamSubProject() { 361 return ((Boolean) getValue(null, OBJECT_PROJECT, KEY_SUBPROJECTS)).booleanValue(); 362 } 363 364 // -- some helpers for test-project action flags 365 366 /** Helper to retrieve the --main value. */ 367 public String getParamTestProjectMain() { 368 return ((String) getValue(null, null, KEY_MAIN_PROJECT)); 369 } 370 } 371