2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.sdkmanager;
19 import com.android.sdklib.ISdkLog;
20 import com.android.sdklib.SdkManager;
21 import com.android.sdklib.repository.SdkRepository;
23 import java.util.Arrays;
27 * Specific command-line flags for the {@link SdkManager}.
29 class SdkCommandLine extends CommandLineProcessor {
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.
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";
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";
58 public static final String ARG_ALIAS = "alias";
59 public static final String ARG_ACTIVITY = "activity";
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";
81 * Action definitions for SdkManager command line.
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.
87 * Each entry is a string array with:
90 * <li> an object (use #NO_VERB_OBJECT if there's no object).
92 * <li> an alternate form for the object (e.g. plural).
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.",
101 { VERB_LIST, OBJECT_TARGET,
102 "Lists existing targets.",
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." },
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)." },
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)." },
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)." },
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)." },
135 { VERB_UPDATE, OBJECT_ADB,
136 "Updates adb to support the USB devices declared in the SDK add-ons." },
138 { VERB_UPDATE, OBJECT_SDK,
139 "Updates the SDK by suggesting new platforms to install if available." }
142 public SdkCommandLine(ISdkLog logger) {
143 super(logger, ACTIONS);
145 // The following defines the parameters of the actions defined in mAction.
147 // --- create avd ---
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);
168 // --- delete avd ---
170 define(Mode.STRING, true,
171 VERB_DELETE, OBJECT_AVD, "n", KEY_NAME,
172 "Name of the AVD to delete", null);
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);
186 // --- update avd ---
188 define(Mode.STRING, true,
189 VERB_UPDATE, OBJECT_AVD, "n", KEY_NAME,
190 "Name of the AVD to update", null);
192 // --- update sdk ---
194 define(Mode.BOOLEAN, false,
195 VERB_UPDATE, OBJECT_SDK, "u", KEY_NO_UI,
196 "Update from command-line, without any UI", false);
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);
202 define(Mode.BOOLEAN, false,
203 VERB_UPDATE, OBJECT_SDK, "f", KEY_FORCE,
204 "Force replacing things that have been modified (samples, adb)", false);
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",
212 define(Mode.BOOLEAN, false,
213 VERB_UPDATE, OBJECT_SDK, "o", KEY_OBSOLETE,
214 "Install obsolete packages",
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",
222 // --- create project ---
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.
227 define(Mode.ENUM, true,
228 VERB_CREATE, OBJECT_PROJECT, "m", KEY_MODE,
229 "Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS });
231 define(Mode.STRING, true,
232 VERB_CREATE, OBJECT_PROJECT,
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);
248 // --- create test-project ---
250 define(Mode.STRING, true,
251 VERB_CREATE, OBJECT_TEST_PROJECT,
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);
261 // --- create lib-project ---
263 define(Mode.STRING, true,
264 VERB_CREATE, OBJECT_LIB_PROJECT,
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);
277 // --- create export-project ---
279 * disabled until the feature is officially supported.
281 define(Mode.STRING, true,
282 VERB_CREATE, OBJECT_EXPORT_PROJECT,
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);
292 // --- update project ---
294 define(Mode.STRING, true,
295 VERB_UPDATE, OBJECT_PROJECT,
297 "Location path of the project", null);
298 define(Mode.STRING, false,
299 VERB_UPDATE, OBJECT_PROJECT,
301 "Target id to set for the project", null);
302 define(Mode.STRING, false,
303 VERB_UPDATE, OBJECT_PROJECT,
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,
313 "Location path of an Android Library to add, relative to the main project", null);
315 // --- update test project ---
317 define(Mode.STRING, true,
318 VERB_UPDATE, OBJECT_TEST_PROJECT,
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);
326 // --- update lib project ---
328 define(Mode.STRING, true,
329 VERB_UPDATE, OBJECT_LIB_PROJECT,
331 "Location path of the project", null);
332 define(Mode.STRING, false,
333 VERB_UPDATE, OBJECT_LIB_PROJECT,
335 "Target id to set for the project", null);
337 // --- update export project ---
339 * disabled until the feature is officially supported.
340 define(Mode.STRING, true,
341 VERB_UPDATE, OBJECT_EXPORT_PROJECT,
343 "Location path of the project", null);
344 define(Mode.STRING, false,
345 VERB_UPDATE, OBJECT_EXPORT_PROJECT,
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);
355 public boolean acceptLackOfVerb() {
359 // -- some helpers for generic action flags
361 /** Helper to retrieve the --path value. */
362 public String getParamLocationPath() {
363 return (String) getValue(null, null, KEY_PATH);
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"
374 public String getParamTargetId() {
375 return (String) getValue(null, null, KEY_TARGET_ID);
378 /** Helper to retrieve the --name value. */
379 public String getParamName() {
380 return (String) getValue(null, null, KEY_NAME);
383 /** Helper to retrieve the --skin value. */
384 public String getParamSkin() {
385 return (String) getValue(null, null, KEY_SKIN);
388 /** Helper to retrieve the --sdcard value. */
389 public String getParamSdCard() {
390 return (String) getValue(null, null, KEY_SDCARD);
393 /** Helper to retrieve the --force flag. */
394 public boolean getFlagForce() {
395 return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue();
398 // -- some helpers for avd action flags
400 /** Helper to retrieve the --rename value for a move verb. */
401 public String getParamMoveNewName() {
402 return (String) getValue(VERB_MOVE, null, KEY_RENAME);
406 // -- some helpers for project action flags
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}.
412 public String getParamProjectPackage(String directObject) {
413 return ((String) getValue(null, directObject, KEY_PACKAGE));
416 /** Helper to retrieve the --activity for any project action. */
417 public String getParamProjectActivity() {
418 return ((String) getValue(null, OBJECT_PROJECT, KEY_ACTIVITY));
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}.
425 public String getParamProjectLibrary(String directObject) {
426 return ((String) getValue(null, directObject, KEY_LIBRARY));
430 /** Helper to retrieve the --subprojects for any project action. */
431 public boolean getParamSubProject() {
432 return ((Boolean) getValue(null, OBJECT_PROJECT, KEY_SUBPROJECTS)).booleanValue();
435 // -- some helpers for test-project action flags
437 /** Helper to retrieve the --main value. */
438 public String getParamTestProjectMain() {
439 return ((String) getValue(null, null, KEY_MAIN_PROJECT));
443 // -- some helpers for update sdk flags
445 /** Helper to retrieve the --force flag. */
446 public boolean getFlagNoUI() {
447 return ((Boolean) getValue(null, null, KEY_NO_UI)).booleanValue();
450 /** Helper to retrieve the --no-https flag. */
451 public boolean getFlagNoHttps() {
452 return ((Boolean) getValue(null, null, KEY_NO_HTTPS)).booleanValue();
455 /** Helper to retrieve the --dry-mode flag. */
456 public boolean getFlagDryMode() {
457 return ((Boolean) getValue(null, null, KEY_DRY_MODE)).booleanValue();
460 /** Helper to retrieve the --obsolete flag. */
461 public boolean getFlagObsolete() {
462 return ((Boolean) getValue(null, null, KEY_OBSOLETE)).booleanValue();
465 /** Helper to retrieve the --filter value. */
466 public String getParamFilter() {
467 return ((String) getValue(null, null, KEY_FILTER));