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_ADB = "adb"; 52 53 public static final String ARG_ALIAS = "alias"; 54 public static final String ARG_ACTIVITY = "activity"; 55 56 public static final String KEY_ACTIVITY = ARG_ACTIVITY; 57 public static final String KEY_PACKAGE = "package"; 58 public static final String KEY_MODE = "mode"; 59 public static final String KEY_TARGET_ID = OBJECT_TARGET; 60 public static final String KEY_NAME = "name"; 61 public static final String KEY_PATH = "path"; 62 public static final String KEY_FILTER = "filter"; 63 public static final String KEY_SKIN = "skin"; 64 public static final String KEY_SDCARD = "sdcard"; 65 public static final String KEY_FORCE = "force"; 66 public static final String KEY_RENAME = "rename"; 67 public static final String KEY_SUBPROJECTS = "subprojects"; 68 public static final String KEY_MAIN_PROJECT = "main"; 69 70 /** 71 * Action definitions for SdkManager command line. 72 * <p/> 73 * This list serves two purposes: first it is used to know which verb/object 74 * actions are acceptable on the command-line; second it provides a summary 75 * for each action that is printed in the help. 76 * <p/> 77 * Each entry is a string array with: 78 * <ul> 79 * <li> the verb. 80 * <li> an object (use #NO_VERB_OBJECT if there's no object). 81 * <li> a description. 82 * <li> an alternate form for the object (e.g. plural). 83 * </ul> 84 */ 85 private final static String[][] ACTIONS = { 86 { VERB_LIST, NO_VERB_OBJECT, 87 "Lists existing targets or virtual devices." }, 88 { VERB_LIST, OBJECT_AVD, 89 "Lists existing Android Virtual Devices.", 90 OBJECT_AVDS }, 91 { VERB_LIST, OBJECT_TARGET, 92 "Lists existing targets.", 93 OBJECT_TARGETS }, 94 95 { VERB_CREATE, OBJECT_AVD, 96 "Creates a new Android Virtual Device." }, 97 { VERB_MOVE, OBJECT_AVD, 98 "Moves or renames an Android Virtual Device." }, 99 { VERB_DELETE, OBJECT_AVD, 100 "Deletes an Android Virtual Device." }, 101 { VERB_UPDATE, OBJECT_AVD, 102 "Updates an Android Virtual Device to match the folders of a new SDK." }, 103 104 { VERB_CREATE, OBJECT_PROJECT, 105 "Creates a new Android Project." }, 106 { VERB_UPDATE, OBJECT_PROJECT, 107 "Updates an Android Project (must have an AndroidManifest.xml)." }, 108 109 { VERB_CREATE, OBJECT_TEST_PROJECT, 110 "Creates a new Android Test Project." }, 111 { VERB_UPDATE, OBJECT_TEST_PROJECT, 112 "Updates an Android Test Project (must have an AndroidManifest.xml)." }, 113 114 { VERB_UPDATE, OBJECT_ADB, 115 "Updates adb to support the USB devices declared in the SDK add-ons." }, 116 117 { VERB_UPDATE, OBJECT_SDK, 118 "Updates the SDK by suggesting new platforms to install if available." } 119 }; 120 SdkCommandLine(ISdkLog logger)121 public SdkCommandLine(ISdkLog logger) { 122 super(logger, ACTIONS); 123 124 // The following defines the parameters of the actions defined in mAction. 125 126 // --- create avd --- 127 128 define(Mode.STRING, false, 129 VERB_CREATE, OBJECT_AVD, "p", KEY_PATH, 130 "Location path of the directory where the new AVD will be created", null); 131 define(Mode.STRING, true, 132 VERB_CREATE, OBJECT_AVD, "n", KEY_NAME, 133 "Name of the new AVD", null); 134 define(Mode.STRING, true, 135 VERB_CREATE, OBJECT_AVD, "t", KEY_TARGET_ID, 136 "Target id of the new AVD", null); 137 define(Mode.STRING, false, 138 VERB_CREATE, OBJECT_AVD, "s", KEY_SKIN, 139 "Skin of the new AVD", null); 140 define(Mode.STRING, false, 141 VERB_CREATE, OBJECT_AVD, "c", KEY_SDCARD, 142 "Path to a shared SD card image, or size of a new sdcard for the new AVD", null); 143 define(Mode.BOOLEAN, false, 144 VERB_CREATE, OBJECT_AVD, "f", KEY_FORCE, 145 "Force creation (override an existing AVD)", false); 146 147 // --- delete avd --- 148 149 define(Mode.STRING, true, 150 VERB_DELETE, OBJECT_AVD, "n", KEY_NAME, 151 "Name of the AVD to delete", null); 152 153 // --- move avd --- 154 155 define(Mode.STRING, true, 156 VERB_MOVE, OBJECT_AVD, "n", KEY_NAME, 157 "Name of the AVD to move or rename", null); 158 define(Mode.STRING, false, 159 VERB_MOVE, OBJECT_AVD, "r", KEY_RENAME, 160 "New name of the AVD to rename", null); 161 define(Mode.STRING, false, 162 VERB_MOVE, OBJECT_AVD, "p", KEY_PATH, 163 "New location path of the directory where to move the AVD", null); 164 165 // --- update avd --- 166 167 define(Mode.STRING, true, 168 VERB_UPDATE, OBJECT_AVD, "n", KEY_NAME, 169 "Name of the AVD to update", null); 170 171 // --- create project --- 172 173 /* Disabled for ADT 0.9 / Cupcake SDK 1.5_r1 release. [bug #1795718]. 174 This currently does not work, the alias build rules need to be fixed. 175 176 define(Mode.ENUM, true, 177 VERB_CREATE, OBJECT_PROJECT, "m", KEY_MODE, 178 "Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS }); 179 */ 180 define(Mode.STRING, true, 181 VERB_CREATE, OBJECT_PROJECT, 182 "p", KEY_PATH, 183 "Location path of new project", null); 184 define(Mode.STRING, true, 185 VERB_CREATE, OBJECT_PROJECT, "t", KEY_TARGET_ID, 186 "Target id of the new project", null); 187 define(Mode.STRING, true, 188 VERB_CREATE, OBJECT_PROJECT, "k", KEY_PACKAGE, 189 "Package name", null); 190 define(Mode.STRING, true, 191 VERB_CREATE, OBJECT_PROJECT, "a", KEY_ACTIVITY, 192 "Activity name", null); 193 define(Mode.STRING, false, 194 VERB_CREATE, OBJECT_PROJECT, "n", KEY_NAME, 195 "Project name", null); 196 197 // --- create test-project --- 198 199 define(Mode.STRING, true, 200 VERB_CREATE, OBJECT_TEST_PROJECT, 201 "p", KEY_PATH, 202 "Location path of new project", null); 203 define(Mode.STRING, false, 204 VERB_CREATE, OBJECT_TEST_PROJECT, "n", KEY_NAME, 205 "Project name", null); 206 define(Mode.STRING, true, 207 VERB_CREATE, OBJECT_TEST_PROJECT, "m", KEY_MAIN_PROJECT, 208 "Location path of the project to test, relative to the new project", null); 209 210 // --- update project --- 211 212 define(Mode.STRING, true, 213 VERB_UPDATE, OBJECT_PROJECT, 214 "p", KEY_PATH, 215 "Location path of the project", null); 216 define(Mode.STRING, false, 217 VERB_UPDATE, OBJECT_PROJECT, 218 "t", KEY_TARGET_ID, 219 "Target id to set for the project", null); 220 define(Mode.STRING, false, 221 VERB_UPDATE, OBJECT_PROJECT, 222 "n", KEY_NAME, 223 "Project name", null); 224 define(Mode.BOOLEAN, false, 225 VERB_UPDATE, OBJECT_PROJECT, 226 "s", KEY_SUBPROJECTS, 227 "Also update any projects in sub-folders, such as test projects.", false); 228 229 // --- update test project --- 230 231 define(Mode.STRING, true, 232 VERB_UPDATE, OBJECT_TEST_PROJECT, 233 "p", KEY_PATH, 234 "Location path of the project", null); 235 define(Mode.STRING, true, 236 VERB_UPDATE, OBJECT_TEST_PROJECT, 237 "m", KEY_MAIN_PROJECT, 238 "Location path of the project to test, relative to the new project", null); 239 } 240 241 @Override acceptLackOfVerb()242 public boolean acceptLackOfVerb() { 243 return true; 244 } 245 246 // -- some helpers for generic action flags 247 248 /** Helper to retrieve the --path value. */ getParamLocationPath()249 public String getParamLocationPath() { 250 return (String) getValue(null, null, KEY_PATH); 251 } 252 253 /** 254 * Helper to retrieve the --target id value. 255 * The id is a string. It can be one of: 256 * - an integer, in which case it's the index of the target (cf "android list targets") 257 * - a symbolic name such as android-N for platforn API N 258 * - a symbolic add-on name such as written in the avd/*.ini files, 259 * e.g. "Google Inc.:Google APIs:3" 260 */ getParamTargetId()261 public String getParamTargetId() { 262 return (String) getValue(null, null, KEY_TARGET_ID); 263 } 264 265 /** Helper to retrieve the --name value. */ getParamName()266 public String getParamName() { 267 return (String) getValue(null, null, KEY_NAME); 268 } 269 270 /** Helper to retrieve the --skin value. */ getParamSkin()271 public String getParamSkin() { 272 return (String) getValue(null, null, KEY_SKIN); 273 } 274 275 /** Helper to retrieve the --sdcard value. */ getParamSdCard()276 public String getParamSdCard() { 277 return (String) getValue(null, null, KEY_SDCARD); 278 } 279 280 /** Helper to retrieve the --force flag. */ getFlagForce()281 public boolean getFlagForce() { 282 return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue(); 283 } 284 285 // -- some helpers for avd action flags 286 287 /** Helper to retrieve the --rename value for a move verb. */ getParamMoveNewName()288 public String getParamMoveNewName() { 289 return (String) getValue(VERB_MOVE, null, KEY_RENAME); 290 } 291 292 293 // -- some helpers for project action flags 294 295 /** Helper to retrieve the --package value. */ getParamProjectPackage()296 public String getParamProjectPackage() { 297 return ((String) getValue(null, OBJECT_PROJECT, KEY_PACKAGE)); 298 } 299 300 /** Helper to retrieve the --activity for any project action. */ getParamProjectActivity()301 public String getParamProjectActivity() { 302 return ((String) getValue(null, OBJECT_PROJECT, KEY_ACTIVITY)); 303 } 304 305 /** Helper to retrieve the --subprojects for any project action. */ getParamSubProject()306 public boolean getParamSubProject() { 307 return ((Boolean) getValue(null, OBJECT_PROJECT, KEY_SUBPROJECTS)).booleanValue(); 308 } 309 310 // -- some helpers for test-project action flags 311 312 /** Helper to retrieve the --main value. */ getParamTestProjectMain()313 public String getParamTestProjectMain() { 314 return ((String) getValue(null, null, KEY_MAIN_PROJECT)); 315 } 316 } 317