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 import com.android.sdklib.repository.SdkRepository; 22 23 import java.util.Arrays; 24 25 26 /** 27 * Specific command-line flags for the {@link SdkManager}. 28 */ 29 class SdkCommandLine extends CommandLineProcessor { 30 31 /* 32 * Steps needed to add a new action: 33 * - Each action is defined as a "verb object" followed by parameters. 34 * - Either reuse a VERB_ constant or define a new one. 35 * - Either reuse an OBJECT_ constant or define a new one. 36 * - Add a new entry to mAction with a one-line help summary. 37 * - In the constructor, add a define() call for each parameter (either mandatory 38 * or optional) for the given action. 39 */ 40 41 public final static String VERB_LIST = "list"; 42 public final static String VERB_CREATE = "create"; 43 public final static String VERB_MOVE = "move"; 44 public final static String VERB_DELETE = "delete"; 45 public final static String VERB_UPDATE = "update"; 46 47 public static final String OBJECT_SDK = "sdk"; 48 public static final String OBJECT_AVD = "avd"; 49 public static final String OBJECT_AVDS = "avds"; 50 public static final String OBJECT_TARGET = "target"; 51 public static final String OBJECT_TARGETS = "targets"; 52 public static final String OBJECT_PROJECT = "project"; 53 public static final String OBJECT_TEST_PROJECT = "test-project"; 54 public static final String OBJECT_LIB_PROJECT = "lib-project"; 55 public static final String OBJECT_EXPORT_PROJECT = "export-project"; 56 public static final String OBJECT_ADB = "adb"; 57 58 public static final String ARG_ALIAS = "alias"; 59 public static final String ARG_ACTIVITY = "activity"; 60 61 public static final String KEY_ACTIVITY = ARG_ACTIVITY; 62 public static final String KEY_PACKAGE = "package"; 63 public static final String KEY_MODE = "mode"; 64 public static final String KEY_TARGET_ID = OBJECT_TARGET; 65 public static final String KEY_NAME = "name"; 66 public static final String KEY_LIBRARY = "library"; 67 public static final String KEY_PATH = "path"; 68 public static final String KEY_FILTER = "filter"; 69 public static final String KEY_SKIN = "skin"; 70 public static final String KEY_SDCARD = "sdcard"; 71 public static final String KEY_FORCE = "force"; 72 public static final String KEY_RENAME = "rename"; 73 public static final String KEY_SUBPROJECTS = "subprojects"; 74 public static final String KEY_MAIN_PROJECT = "main"; 75 public static final String KEY_NO_UI = "no-ui"; 76 public static final String KEY_NO_HTTPS = "no-https"; 77 public static final String KEY_DRY_MODE = "dry-mode"; 78 public static final String KEY_OBSOLETE = "obsolete"; 79 80 /** 81 * Action definitions for SdkManager command line. 82 * <p/> 83 * This list serves two purposes: first it is used to know which verb/object 84 * actions are acceptable on the command-line; second it provides a summary 85 * for each action that is printed in the help. 86 * <p/> 87 * Each entry is a string array with: 88 * <ul> 89 * <li> the verb. 90 * <li> an object (use #NO_VERB_OBJECT if there's no object). 91 * <li> a description. 92 * <li> an alternate form for the object (e.g. plural). 93 * </ul> 94 */ 95 private final static String[][] ACTIONS = { 96 { VERB_LIST, NO_VERB_OBJECT, 97 "Lists existing targets or virtual devices." }, 98 { VERB_LIST, OBJECT_AVD, 99 "Lists existing Android Virtual Devices.", 100 OBJECT_AVDS }, 101 { VERB_LIST, OBJECT_TARGET, 102 "Lists existing targets.", 103 OBJECT_TARGETS }, 104 105 { VERB_CREATE, OBJECT_AVD, 106 "Creates a new Android Virtual Device." }, 107 { VERB_MOVE, OBJECT_AVD, 108 "Moves or renames an Android Virtual Device." }, 109 { VERB_DELETE, OBJECT_AVD, 110 "Deletes an Android Virtual Device." }, 111 { VERB_UPDATE, OBJECT_AVD, 112 "Updates an Android Virtual Device to match the folders of a new SDK." }, 113 114 { VERB_CREATE, OBJECT_PROJECT, 115 "Creates a new Android Project." }, 116 { VERB_UPDATE, OBJECT_PROJECT, 117 "Updates an Android Project (must have an AndroidManifest.xml)." }, 118 119 { VERB_CREATE, OBJECT_TEST_PROJECT, 120 "Creates a new Android Test Project." }, 121 { VERB_UPDATE, OBJECT_TEST_PROJECT, 122 "Updates an Android Test Project (must have an AndroidManifest.xml)." }, 123 124 { VERB_CREATE, OBJECT_LIB_PROJECT, 125 "Creates a new Android Library Project." }, 126 { VERB_UPDATE, OBJECT_LIB_PROJECT, 127 "Updates an Android Library Project (must have an AndroidManifest.xml)." }, 128 /* 129 * disabled until the feature is officially supported. 130 { VERB_CREATE, OBJECT_EXPORT_PROJECT, 131 "Creates a new Android Export Project." }, 132 { VERB_UPDATE, OBJECT_EXPORT_PROJECT, 133 "Updates an Android Export Project (must have an export.properties)." }, 134 */ 135 { VERB_UPDATE, OBJECT_ADB, 136 "Updates adb to support the USB devices declared in the SDK add-ons." }, 137 138 { VERB_UPDATE, OBJECT_SDK, 139 "Updates the SDK by suggesting new platforms to install if available." } 140 }; 141 SdkCommandLine(ISdkLog logger)142 public SdkCommandLine(ISdkLog logger) { 143 super(logger, ACTIONS); 144 145 // The following defines the parameters of the actions defined in mAction. 146 147 // --- create avd --- 148 149 define(Mode.STRING, false, 150 VERB_CREATE, OBJECT_AVD, "p", KEY_PATH, 151 "Location path of the directory where the new AVD will be created", null); 152 define(Mode.STRING, true, 153 VERB_CREATE, OBJECT_AVD, "n", KEY_NAME, 154 "Name of the new AVD", null); 155 define(Mode.STRING, true, 156 VERB_CREATE, OBJECT_AVD, "t", KEY_TARGET_ID, 157 "Target id of the new AVD", null); 158 define(Mode.STRING, false, 159 VERB_CREATE, OBJECT_AVD, "s", KEY_SKIN, 160 "Skin of the new AVD", null); 161 define(Mode.STRING, false, 162 VERB_CREATE, OBJECT_AVD, "c", KEY_SDCARD, 163 "Path to a shared SD card image, or size of a new sdcard for the new AVD", null); 164 define(Mode.BOOLEAN, false, 165 VERB_CREATE, OBJECT_AVD, "f", KEY_FORCE, 166 "Force creation (override an existing AVD)", false); 167 168 // --- delete avd --- 169 170 define(Mode.STRING, true, 171 VERB_DELETE, OBJECT_AVD, "n", KEY_NAME, 172 "Name of the AVD to delete", null); 173 174 // --- move avd --- 175 176 define(Mode.STRING, true, 177 VERB_MOVE, OBJECT_AVD, "n", KEY_NAME, 178 "Name of the AVD to move or rename", null); 179 define(Mode.STRING, false, 180 VERB_MOVE, OBJECT_AVD, "r", KEY_RENAME, 181 "New name of the AVD to rename", null); 182 define(Mode.STRING, false, 183 VERB_MOVE, OBJECT_AVD, "p", KEY_PATH, 184 "New location path of the directory where to move the AVD", null); 185 186 // --- update avd --- 187 188 define(Mode.STRING, true, 189 VERB_UPDATE, OBJECT_AVD, "n", KEY_NAME, 190 "Name of the AVD to update", null); 191 192 // --- update sdk --- 193 194 define(Mode.BOOLEAN, false, 195 VERB_UPDATE, OBJECT_SDK, "u", KEY_NO_UI, 196 "Update from command-line, without any UI", false); 197 198 define(Mode.BOOLEAN, false, 199 VERB_UPDATE, OBJECT_SDK, "s", KEY_NO_HTTPS, 200 "Use HTTP instead of the default HTTPS for downloads", false); 201 202 define(Mode.BOOLEAN, false, 203 VERB_UPDATE, OBJECT_SDK, "f", KEY_FORCE, 204 "Force replacing things that have been modified (samples, adb)", false); 205 206 define(Mode.STRING, false, 207 VERB_UPDATE, OBJECT_SDK, "t", KEY_FILTER, 208 "A coma-separated list of " + Arrays.toString(SdkRepository.NODES) + 209 " to limit update to specified types of packages", 210 null); 211 212 define(Mode.BOOLEAN, false, 213 VERB_UPDATE, OBJECT_SDK, "o", KEY_OBSOLETE, 214 "Install obsolete packages", 215 false); 216 217 define(Mode.BOOLEAN, false, 218 VERB_UPDATE, OBJECT_SDK, "n", KEY_DRY_MODE, 219 "Only simulates what would be updated but does not download/install anything", 220 false); 221 222 // --- create project --- 223 224 /* Disabled for ADT 0.9 / Cupcake SDK 1.5_r1 release. [bug #1795718]. 225 This currently does not work, the alias build rules need to be fixed. 226 227 define(Mode.ENUM, true, 228 VERB_CREATE, OBJECT_PROJECT, "m", KEY_MODE, 229 "Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS }); 230 */ 231 define(Mode.STRING, true, 232 VERB_CREATE, OBJECT_PROJECT, 233 "p", KEY_PATH, 234 "Location path of new project", null); 235 define(Mode.STRING, true, 236 VERB_CREATE, OBJECT_PROJECT, "t", KEY_TARGET_ID, 237 "Target id of the new project", null); 238 define(Mode.STRING, true, 239 VERB_CREATE, OBJECT_PROJECT, "k", KEY_PACKAGE, 240 "Package name", null); 241 define(Mode.STRING, true, 242 VERB_CREATE, OBJECT_PROJECT, "a", KEY_ACTIVITY, 243 "Activity name", null); 244 define(Mode.STRING, false, 245 VERB_CREATE, OBJECT_PROJECT, "n", KEY_NAME, 246 "Project name", null); 247 248 // --- create test-project --- 249 250 define(Mode.STRING, true, 251 VERB_CREATE, OBJECT_TEST_PROJECT, 252 "p", KEY_PATH, 253 "Location path of new project", null); 254 define(Mode.STRING, false, 255 VERB_CREATE, OBJECT_TEST_PROJECT, "n", KEY_NAME, 256 "Project name", null); 257 define(Mode.STRING, true, 258 VERB_CREATE, OBJECT_TEST_PROJECT, "m", KEY_MAIN_PROJECT, 259 "Location path of the project to test, relative to the new project", null); 260 261 // --- create lib-project --- 262 263 define(Mode.STRING, true, 264 VERB_CREATE, OBJECT_LIB_PROJECT, 265 "p", KEY_PATH, 266 "Location path of new project", null); 267 define(Mode.STRING, true, 268 VERB_CREATE, OBJECT_LIB_PROJECT, "t", KEY_TARGET_ID, 269 "Target id of the new project", null); 270 define(Mode.STRING, false, 271 VERB_CREATE, OBJECT_LIB_PROJECT, "n", KEY_NAME, 272 "Project name", null); 273 define(Mode.STRING, true, 274 VERB_CREATE, OBJECT_LIB_PROJECT, "k", KEY_PACKAGE, 275 "Package name", null); 276 277 // --- create export-project --- 278 /* 279 * disabled until the feature is officially supported. 280 281 define(Mode.STRING, true, 282 VERB_CREATE, OBJECT_EXPORT_PROJECT, 283 "p", KEY_PATH, 284 "Location path of new project", null); 285 define(Mode.STRING, false, 286 VERB_CREATE, OBJECT_EXPORT_PROJECT, "n", KEY_NAME, 287 "Project name", null); 288 define(Mode.STRING, true, 289 VERB_CREATE, OBJECT_EXPORT_PROJECT, "k", KEY_PACKAGE, 290 "Package name", null); 291 */ 292 // --- update project --- 293 294 define(Mode.STRING, true, 295 VERB_UPDATE, OBJECT_PROJECT, 296 "p", KEY_PATH, 297 "Location path of the project", null); 298 define(Mode.STRING, false, 299 VERB_UPDATE, OBJECT_PROJECT, 300 "t", KEY_TARGET_ID, 301 "Target id to set for the project", null); 302 define(Mode.STRING, false, 303 VERB_UPDATE, OBJECT_PROJECT, 304 "n", KEY_NAME, 305 "Project name", null); 306 define(Mode.BOOLEAN, false, 307 VERB_UPDATE, OBJECT_PROJECT, 308 "s", KEY_SUBPROJECTS, 309 "Also update any projects in sub-folders, such as test projects.", false); 310 define(Mode.STRING, false, 311 VERB_UPDATE, OBJECT_PROJECT, 312 "l", KEY_LIBRARY, 313 "Location path of an Android Library to add, relative to the main project", null); 314 315 // --- update test project --- 316 317 define(Mode.STRING, true, 318 VERB_UPDATE, OBJECT_TEST_PROJECT, 319 "p", KEY_PATH, 320 "Location path of the project", null); 321 define(Mode.STRING, true, 322 VERB_UPDATE, OBJECT_TEST_PROJECT, 323 "m", KEY_MAIN_PROJECT, 324 "Location path of the project to test, relative to the new project", null); 325 326 // --- update lib project --- 327 328 define(Mode.STRING, true, 329 VERB_UPDATE, OBJECT_LIB_PROJECT, 330 "p", KEY_PATH, 331 "Location path of the project", null); 332 define(Mode.STRING, false, 333 VERB_UPDATE, OBJECT_LIB_PROJECT, 334 "t", KEY_TARGET_ID, 335 "Target id to set for the project", null); 336 337 // --- update export project --- 338 /* 339 * disabled until the feature is officially supported. 340 define(Mode.STRING, true, 341 VERB_UPDATE, OBJECT_EXPORT_PROJECT, 342 "p", KEY_PATH, 343 "Location path of the project", null); 344 define(Mode.STRING, false, 345 VERB_UPDATE, OBJECT_EXPORT_PROJECT, 346 "n", KEY_NAME, 347 "Project name", null); 348 define(Mode.BOOLEAN, false, 349 VERB_UPDATE, OBJECT_EXPORT_PROJECT, "f", KEY_FORCE, 350 "Force replacing the build.xml file", false); 351 */ 352 } 353 354 @Override acceptLackOfVerb()355 public boolean acceptLackOfVerb() { 356 return true; 357 } 358 359 // -- some helpers for generic action flags 360 361 /** Helper to retrieve the --path value. */ getParamLocationPath()362 public String getParamLocationPath() { 363 return (String) getValue(null, null, KEY_PATH); 364 } 365 366 /** 367 * Helper to retrieve the --target id value. 368 * The id is a string. It can be one of: 369 * - an integer, in which case it's the index of the target (cf "android list targets") 370 * - a symbolic name such as android-N for platforn API N 371 * - a symbolic add-on name such as written in the avd/*.ini files, 372 * e.g. "Google Inc.:Google APIs:3" 373 */ getParamTargetId()374 public String getParamTargetId() { 375 return (String) getValue(null, null, KEY_TARGET_ID); 376 } 377 378 /** Helper to retrieve the --name value. */ getParamName()379 public String getParamName() { 380 return (String) getValue(null, null, KEY_NAME); 381 } 382 383 /** Helper to retrieve the --skin value. */ getParamSkin()384 public String getParamSkin() { 385 return (String) getValue(null, null, KEY_SKIN); 386 } 387 388 /** Helper to retrieve the --sdcard value. */ getParamSdCard()389 public String getParamSdCard() { 390 return (String) getValue(null, null, KEY_SDCARD); 391 } 392 393 /** Helper to retrieve the --force flag. */ getFlagForce()394 public boolean getFlagForce() { 395 return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue(); 396 } 397 398 // -- some helpers for avd action flags 399 400 /** Helper to retrieve the --rename value for a move verb. */ getParamMoveNewName()401 public String getParamMoveNewName() { 402 return (String) getValue(VERB_MOVE, null, KEY_RENAME); 403 } 404 405 406 // -- some helpers for project action flags 407 408 /** Helper to retrieve the --package value. 409 * @param directObject the directObject of the action, either {@link #OBJECT_PROJECT} 410 * or {@link #OBJECT_LIB_PROJECT}. 411 */ getParamProjectPackage(String directObject)412 public String getParamProjectPackage(String directObject) { 413 return ((String) getValue(null, directObject, KEY_PACKAGE)); 414 } 415 416 /** Helper to retrieve the --activity for any project action. */ getParamProjectActivity()417 public String getParamProjectActivity() { 418 return ((String) getValue(null, OBJECT_PROJECT, KEY_ACTIVITY)); 419 } 420 421 /** Helper to retrieve the --library value. 422 * @param directObject the directObject of the action, either {@link #OBJECT_PROJECT} 423 * or {@link #OBJECT_LIB_PROJECT}. 424 */ getParamProjectLibrary(String directObject)425 public String getParamProjectLibrary(String directObject) { 426 return ((String) getValue(null, directObject, KEY_LIBRARY)); 427 } 428 429 430 /** Helper to retrieve the --subprojects for any project action. */ getParamSubProject()431 public boolean getParamSubProject() { 432 return ((Boolean) getValue(null, OBJECT_PROJECT, KEY_SUBPROJECTS)).booleanValue(); 433 } 434 435 // -- some helpers for test-project action flags 436 437 /** Helper to retrieve the --main value. */ getParamTestProjectMain()438 public String getParamTestProjectMain() { 439 return ((String) getValue(null, null, KEY_MAIN_PROJECT)); 440 } 441 442 443 // -- some helpers for update sdk flags 444 445 /** Helper to retrieve the --force flag. */ getFlagNoUI()446 public boolean getFlagNoUI() { 447 return ((Boolean) getValue(null, null, KEY_NO_UI)).booleanValue(); 448 } 449 450 /** Helper to retrieve the --no-https flag. */ getFlagNoHttps()451 public boolean getFlagNoHttps() { 452 return ((Boolean) getValue(null, null, KEY_NO_HTTPS)).booleanValue(); 453 } 454 455 /** Helper to retrieve the --dry-mode flag. */ getFlagDryMode()456 public boolean getFlagDryMode() { 457 return ((Boolean) getValue(null, null, KEY_DRY_MODE)).booleanValue(); 458 } 459 460 /** Helper to retrieve the --obsolete flag. */ getFlagObsolete()461 public boolean getFlagObsolete() { 462 return ((Boolean) getValue(null, null, KEY_OBSOLETE)).booleanValue(); 463 } 464 465 /** Helper to retrieve the --filter value. */ getParamFilter()466 public String getParamFilter() { 467 return ((String) getValue(null, null, KEY_FILTER)); 468 } 469 } 470