aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/app/src
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2009-05-15 17:36:26 -0700
committerRaphael <raphael@google.com>2009-05-15 17:36:26 -0700
commitdf94d1fe1bfb13f009e0ee1d92b2d72654d1f1f5 (patch)
tree889ac32d5d3b178117ebf55ed57207efde5cf0f7 /sdkmanager/app/src
parentc28e97a0db9c383cd656cb51f3b720dfb53b8d21 (diff)
downloadsdk-df94d1fe1bfb13f009e0ee1d92b2d72654d1f1f5.zip
sdk-df94d1fe1bfb13f009e0ee1d92b2d72654d1f1f5.tar.gz
sdk-df94d1fe1bfb13f009e0ee1d92b2d72654d1f1f5.tar.bz2
Skeleton App Windows for Sdk Updater built using SWT Designer.
The window is shown when the "android" tool is invoked with no parameter.
Diffstat (limited to 'sdkmanager/app/src')
-rw-r--r--sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java159
-rw-r--r--sdkmanager/app/src/com/android/sdkmanager/Main.java140
-rw-r--r--sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java73
3 files changed, 202 insertions, 170 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java
index c20bfa4..4a3c16c 100644
--- a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java
+++ b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java
@@ -29,7 +29,7 @@ import java.util.Map.Entry;
* <li>override it.
* <li>pass an action array to the constructor.
* <li>define flags for your actions.
- * </ul>
+ * </ul>
* <p/>
* To use, call {@link #parseArgs(String[])} and then
* call {@link #getValue(String, String, String)}.
@@ -38,17 +38,17 @@ public class CommandLineProcessor {
/** Internal verb name for internally hidden flags. */
public final static String GLOBAL_FLAG_VERB = "@@internal@@";
-
+
/** String to use when the verb doesn't need any object. */
public final static String NO_VERB_OBJECT = "";
-
- /** The global help flag. */
+
+ /** The global help flag. */
public static final String KEY_HELP = "help";
/** The global verbose flag. */
public static final String KEY_VERBOSE = "verbose";
/** The global silent flag. */
public static final String KEY_SILENT = "silent";
-
+
/** Verb requested by the user. Null if none specified, which will be an error. */
private String mVerbRequested;
/** Direct object requested by the user. Can be null. */
@@ -66,7 +66,7 @@ public class CommandLineProcessor {
* </ul>
*/
private final String[][] mActions;
-
+
private static final int ACTION_VERB_INDEX = 0;
private static final int ACTION_OBJECT_INDEX = 1;
private static final int ACTION_DESC_INDEX = 2;
@@ -80,7 +80,7 @@ public class CommandLineProcessor {
private final HashMap<String, Arg> mArguments = new HashMap<String, Arg>();
/** Logger */
private final ISdkLog mLog;
-
+
public CommandLineProcessor(ISdkLog logger, String[][] actions) {
mLog = logger;
mActions = actions;
@@ -95,7 +95,18 @@ public class CommandLineProcessor {
"This help.",
false);
}
-
+
+ /**
+ * Indicates if this command-line can work when no verb is specified.
+ * The default is false, which generates an error when no verb/object is specified.
+ * Derived implementations can set this to true if they can deal with a lack
+ * of verb/action.
+ */
+ public boolean acceptLackOfVerb() {
+ return false;
+ }
+
+
//------------------
// Helpers to get flags values
@@ -113,7 +124,7 @@ public class CommandLineProcessor {
public boolean isHelpRequested() {
return ((Boolean) getValue(GLOBAL_FLAG_VERB, NO_VERB_OBJECT, KEY_HELP)).booleanValue();
}
-
+
/** Returns the verb name from the command-line. Can be null. */
public String getVerb() {
return mVerbRequested;
@@ -123,9 +134,9 @@ public class CommandLineProcessor {
public String getDirectObject() {
return mDirectObjectRequested;
}
-
+
//------------------
-
+
/**
* Raw access to parsed parameter values.
* <p/>
@@ -133,10 +144,10 @@ public class CommandLineProcessor {
* command line are returned first. Otherwise one with a non-null value is returned.
* <p/>
* Both a verb and a direct object filter can be specified. When they are non-null they limit
- * the scope of the search.
+ * the scope of the search.
* <p/>
* If nothing has been found, return the last default value seen matching the filter.
- *
+ *
* @param verb The verb name, including {@link #GLOBAL_FLAG_VERB}. If null, all possible
* verbs that match the direct object condition will be examined and the first
* value set will be used.
@@ -153,7 +164,7 @@ public class CommandLineProcessor {
Arg arg = mArguments.get(key);
return arg.getCurrentValue();
}
-
+
Object lastDefault = null;
for (Arg arg : mArguments.values()) {
if (arg.getLongArg().equals(longFlagName)) {
@@ -169,7 +180,7 @@ public class CommandLineProcessor {
}
}
}
-
+
return lastDefault;
}
@@ -191,7 +202,7 @@ public class CommandLineProcessor {
* Parses the command-line arguments.
* <p/>
* This method will exit and not return if a parsing error arise.
- *
+ *
* @param args The arguments typically received by a main method.
*/
public void parseArgs(String[] args) {
@@ -209,7 +220,7 @@ public class CommandLineProcessor {
} else if (a.startsWith("-")) {
arg = findShortArg(verb, directObject, a.substring(1));
}
-
+
// No matching argument name found
if (arg == null) {
// Does it looks like a dashed parameter?
@@ -217,7 +228,7 @@ public class CommandLineProcessor {
if (verb == null || directObject == null) {
// It looks like a dashed parameter and we don't have a a verb/object
// set yet, the parameter was just given too early.
-
+
needsHelp = String.format(
"Flag '%1$s' is not a valid global flag. Did you mean to specify it after the verb/object name?",
a);
@@ -225,14 +236,14 @@ public class CommandLineProcessor {
} else {
// It looks like a dashed parameter and but it is unknown by this
// verb-object combination
-
+
needsHelp = String.format(
"Flag '%1$s' is not valid for '%2$s %3$s'.",
a, verb, directObject);
return;
}
}
-
+
if (verb == null) {
// Fill verb first. Find it.
for (String[] actionDesc : mActions) {
@@ -241,7 +252,7 @@ public class CommandLineProcessor {
break;
}
}
-
+
// Error if it was not a valid verb
if (verb == null) {
needsHelp = String.format(
@@ -249,7 +260,7 @@ public class CommandLineProcessor {
a);
return;
}
-
+
} else if (directObject == null) {
// Then fill the direct object. Find it.
for (String[] actionDesc : mActions) {
@@ -266,20 +277,20 @@ public class CommandLineProcessor {
}
}
}
-
+
// Error if it was not a valid object for that verb
if (directObject == null) {
needsHelp = String.format(
"Expected verb after global parameters but found '%1$s' instead.",
a);
return;
-
+
}
}
} else if (arg != null) {
// This argument was present on the command line
arg.setInCommandLine(true);
-
+
// Process keyword
String error = null;
if (arg.getMode().needsExtra()) {
@@ -287,11 +298,11 @@ public class CommandLineProcessor {
needsHelp = String.format("Missing argument for flag %1$s.", a);
return;
}
-
+
error = arg.getMode().process(arg, args[i]);
} else {
error = arg.getMode().process(arg, null);
-
+
// If we just toggled help, we want to exit now without printing any error.
// We do this test here only when a Boolean flag is toggled since booleans
// are the only flags that don't take parameters and help is a boolean.
@@ -302,18 +313,18 @@ public class CommandLineProcessor {
return;
}
}
-
+
if (error != null) {
needsHelp = String.format("Invalid usage for flag %1$s: %2$s.", a, error);
return;
}
}
}
-
+
if (needsHelp == null) {
- if (verb == null) {
+ if (verb == null && !acceptLackOfVerb()) {
needsHelp = "Missing verb name.";
- } else {
+ } else if (verb != null) {
if (directObject == null) {
// Make sure this verb has an optional direct object
for (String[] actionDesc : mActions) {
@@ -323,13 +334,13 @@ public class CommandLineProcessor {
break;
}
}
-
+
if (directObject == null) {
needsHelp = String.format("Missing object name for verb '%1$s'.", verb);
return;
}
}
-
+
// Validate that all mandatory arguments are non-null for this action
String missing = null;
boolean plural = false;
@@ -347,7 +358,7 @@ public class CommandLineProcessor {
}
}
}
-
+
if (missing != null) {
needsHelp = String.format(
"The %1$s %2$s must be defined for action '%3$s %4$s'",
@@ -367,7 +378,7 @@ public class CommandLineProcessor {
}
}
}
-
+
/**
* Finds an {@link Arg} given an action name and a long flag name.
* @return The {@link Arg} found or null.
@@ -409,23 +420,23 @@ public class CommandLineProcessor {
/**
* Prints the help/usage and exits.
- *
- * @param errorFormat Optional error message to print prior to usage using String.format
+ *
+ * @param errorFormat Optional error message to print prior to usage using String.format
* @param args Arguments for String.format
*/
public void printHelpAndExit(String errorFormat, Object... args) {
printHelpAndExitForAction(null /*verb*/, null /*directObject*/, errorFormat, args);
}
-
+
/**
* Prints the help/usage and exits.
- *
+ *
* @param verb If null, displays help for all verbs. If not null, display help only
* for that specific verb. In all cases also displays general usage and action list.
* @param directObject If null, displays help for all verb objects.
* If not null, displays help only for that specific action
* In all cases also display general usage and action list.
- * @param errorFormat Optional error message to print prior to usage using String.format
+ * @param errorFormat Optional error message to print prior to usage using String.format
* @param args Arguments for String.format
*/
public void printHelpAndExitForAction(String verb, String directObject,
@@ -433,7 +444,7 @@ public class CommandLineProcessor {
if (errorFormat != null) {
stderr(errorFormat, args);
}
-
+
/*
* usage should fit in 80 columns
* 12345678901234567890123456789012345678901234567890123456789012345678901234567890
@@ -448,14 +459,14 @@ public class CommandLineProcessor {
if (verb == null || directObject == null) {
stdout("\nValid actions are composed of a verb and an optional direct object:");
for (String[] action : mActions) {
-
+
stdout("- %1$6s %2$-7s: %3$s",
action[ACTION_VERB_INDEX],
action[ACTION_OBJECT_INDEX],
action[ACTION_DESC_INDEX]);
}
}
-
+
for (String[] action : mActions) {
if (verb == null || verb.equals(action[ACTION_VERB_INDEX])) {
if (directObject == null || directObject.equals(action[ACTION_OBJECT_INDEX])) {
@@ -468,7 +479,7 @@ public class CommandLineProcessor {
}
}
}
-
+
exit();
}
@@ -480,12 +491,12 @@ public class CommandLineProcessor {
for (Entry<String, Arg> entry : mArguments.entrySet()) {
Arg arg = entry.getValue();
if (arg.getVerb().equals(verb) && arg.getDirectObject().equals(directObject)) {
-
+
String value = "";
String required = "";
if (arg.isMandatory()) {
required = " [required]";
-
+
} else {
if (arg.getDefaultValue() instanceof String[]) {
for (String v : (String[]) arg.getDefaultValue()) {
@@ -504,7 +515,7 @@ public class CommandLineProcessor {
value = " [Default: " + value + "]";
}
}
-
+
stdout(" -%1$s %2$-10s %3$s%4$s%5$s",
arg.getShortArg(),
"--" + arg.getLongArg(),
@@ -514,14 +525,14 @@ public class CommandLineProcessor {
numOptions++;
}
}
-
+
if (numOptions == 0) {
stdout(" No options");
}
}
//----
-
+
/**
* The mode of an argument specifies the type of variable it represents,
* whether an extra parameter is required after the flag and how to parse it.
@@ -558,7 +569,7 @@ public class CommandLineProcessor {
}
}
},
-
+
/** Argument value is a String. Default value is a String[]. */
ENUM {
@Override
@@ -574,7 +585,7 @@ public class CommandLineProcessor {
arg.setCurrentValue(extra);
return null;
}
-
+
if (desc.length() != 0) {
desc.append(", ");
}
@@ -584,7 +595,7 @@ public class CommandLineProcessor {
return String.format("'%1$s' is not one of %2$s", extra, desc.toString());
}
},
-
+
/** Argument value is a String. Default value is a null. */
STRING {
@Override
@@ -597,7 +608,7 @@ public class CommandLineProcessor {
return null;
}
};
-
+
/**
* Returns true if this mode requires an extra parameter.
*/
@@ -605,9 +616,9 @@ public class CommandLineProcessor {
/**
* Processes the flag for this argument.
- *
+ *
* @param arg The argument being processed.
- * @param extra The extra parameter. Null if {@link #needsExtra()} returned false.
+ * @param extra The extra parameter. Null if {@link #needsExtra()} returned false.
* @return An error string or null if there's no error.
*/
public abstract String process(Arg arg, String extra);
@@ -618,7 +629,7 @@ public class CommandLineProcessor {
* Arguments must have a short version (one letter), a long version name and a description.
* They can have a default value, or it can be null.
* Depending on the {@link MODE}, the default value can be a Boolean, an Integer, a String
- * or a String array (in which case the first item is the current by default.)
+ * or a String array (in which case the first item is the current by default.)
*/
static class Arg {
/** Verb for that argument. Never null. */
@@ -644,9 +655,9 @@ public class CommandLineProcessor {
/**
* Creates a new argument flag description.
- *
+ *
* @param mode The {@link MODE} for the argument.
- * @param mandatory True if this argument is mandatory for this action.
+ * @param mandatory True if this argument is mandatory for this action.
* @param directObject The action name. Can be #NO_VERB_OBJECT or #INTERNAL_FLAG.
* @param shortName The one-letter short argument name. Cannot be empty nor null.
* @param longName The long argument name. Cannot be empty nor null.
@@ -676,27 +687,27 @@ public class CommandLineProcessor {
mCurrentValue = mDefaultValue;
}
}
-
+
/** Return true if this argument is mandatory for this verb/directobject. */
public boolean isMandatory() {
return mMandatory;
}
-
+
/** Returns the 1-letter short name of the argument, e.g. -v. */
public String getShortArg() {
return mShortName;
}
-
+
/** Returns the long name of the argument, e.g. --verbose. */
public String getLongArg() {
return mLongName;
}
-
+
/** Returns the description. Never null. */
public String getDescription() {
return mDescription;
}
-
+
/** Returns the verb for that argument. Never null. */
public String getVerb() {
return mVerb;
@@ -706,12 +717,12 @@ public class CommandLineProcessor {
public String getDirectObject() {
return mDirectObject;
}
-
+
/** Returns the default value. Can be null. */
public Object getDefaultValue() {
return mDefaultValue;
}
-
+
/** Returns the current value. Initially set to the default value. Can be null. */
public Object getCurrentValue() {
return mCurrentValue;
@@ -721,26 +732,26 @@ public class CommandLineProcessor {
public void setCurrentValue(Object currentValue) {
mCurrentValue = currentValue;
}
-
+
/** Returns the argument mode (type + process method). Never null. */
public MODE getMode() {
return mMode;
}
-
+
/** Returns true if the argument has been used on the command line. */
public boolean isInCommandLine() {
return mInCommandLine;
}
-
+
/** Sets if the argument has been used on the command line. */
public void setInCommandLine(boolean inCommandLine) {
mInCommandLine = inCommandLine;
}
}
-
+
/**
* Internal helper to define a new argument for a give action.
- *
+ *
* @param mode The {@link MODE} for the argument.
* @param verb The verb name. Can be #INTERNAL_VERB.
* @param directObject The action name. Can be #NO_VERB_OBJECT or #INTERNAL_FLAG.
@@ -756,11 +767,11 @@ public class CommandLineProcessor {
String shortName, String longName,
String description, Object defaultValue) {
assert(mandatory || mode == MODE.BOOLEAN); // a boolean mode cannot be mandatory
-
+
if (directObject == null) {
directObject = NO_VERB_OBJECT;
}
-
+
String key = verb + "/" + directObject + "/" + longName;
mArguments.put(key, new Arg(mode, mandatory,
verb, directObject, shortName, longName, description, defaultValue));
@@ -777,7 +788,7 @@ public class CommandLineProcessor {
/**
* Prints a line to stdout.
* This is protected so that it can be overridden in unit tests.
- *
+ *
* @param format The string to be formatted. Cannot be null.
* @param args Format arguments.
*/
@@ -788,7 +799,7 @@ public class CommandLineProcessor {
/**
* Prints a line to stderr.
* This is protected so that it can be overridden in unit tests.
- *
+ *
* @param format The string to be formatted. Cannot be null.
* @param args Format arguments.
*/
diff --git a/sdkmanager/app/src/com/android/sdkmanager/Main.java b/sdkmanager/app/src/com/android/sdkmanager/Main.java
index 5386c89..a5550b5 100644
--- a/sdkmanager/app/src/com/android/sdkmanager/Main.java
+++ b/sdkmanager/app/src/com/android/sdkmanager/Main.java
@@ -29,6 +29,7 @@ import com.android.sdklib.internal.avd.AvdManager.AvdInfo;
import com.android.sdklib.internal.avd.HardwareProperties.HardwareProperty;
import com.android.sdklib.internal.project.ProjectCreator;
import com.android.sdklib.internal.project.ProjectCreator.OutputLevel;
+import com.android.sdkuilib.repository.UpdaterWindow;
import java.io.File;
import java.io.IOException;
@@ -46,11 +47,11 @@ class Main {
/** Java property that defines the working directory. On Windows the current working directory
* is actually the tools dir, in which case this is used to get the original CWD. */
private final static String WORKDIR = "com.android.sdkmanager.workdir";
-
+
private final static String[] BOOLEAN_YES_REPLIES = new String[] { "yes", "y" };
private final static String[] BOOLEAN_NO_REPLIES = new String[] { "no", "n" };
-
-
+
+
/** Path to the SDK folder. This is the parent of {@link #TOOLSDIR}. */
private String mSdkFolder;
/** Logger object. Use this to print normal output, warnings or errors. */
@@ -65,7 +66,7 @@ class Main {
public static void main(String[] args) {
new Main().run(args);
}
-
+
/**
* Runs the sdk manager app
*/
@@ -124,7 +125,7 @@ class Main {
// for debugging, it's easier to override using the process environment
toolsDirProp = System.getenv(TOOLSDIR);
}
-
+
if (toolsDirProp != null) {
// got back a level for the SDK folder
File tools;
@@ -145,7 +146,7 @@ class Main {
errorAndExit("The tools directory property is not set, please make sure you are executing %1$s",
SdkConstants.androidCmdName());
}
-
+
// We might get passed a property for the working directory
// Either it is a valid directory and mWorkDir is set to it's absolute canonical value
// or mWorkDir remains null.
@@ -172,19 +173,19 @@ class Main {
*/
private void parseSdk() {
mSdkManager = SdkManager.createManager(mSdkFolder, mSdkLog);
-
+
if (mSdkManager == null) {
errorAndExit("Unable to parse SDK content.");
}
}
-
+
/**
* Actually do an action...
*/
private void doAction() {
String verb = mSdkCommandLine.getVerb();
String directObject = mSdkCommandLine.getDirectObject();
-
+
if (SdkCommandLine.VERB_LIST.equals(verb)) {
// list action.
if (SdkCommandLine.OBJECT_TARGET.equals(directObject)) {
@@ -220,13 +221,28 @@ class Main {
SdkCommandLine.OBJECT_PROJECT.equals(directObject)) {
updateProject();
+ } else if (verb == null && directObject == null) {
+ showMainWindow();
+
} else {
mSdkCommandLine.printHelpAndExit(null);
}
}
/**
- * Creates a new Android project based on command-line parameters
+ * Display the main SdkManager app window
+ */
+ private void showMainWindow() {
+ try {
+ UpdaterWindow window = new UpdaterWindow();
+ window.open();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Creates a new Android project based on command-line parameters
*/
private void createProject() {
// get the target and try to resolve it.
@@ -237,7 +253,7 @@ class Main {
SdkConstants.androidCmdName());
}
IAndroidTarget target = targets[targetId - 1];
-
+
ProjectCreator creator = new ProjectCreator(mSdkFolder,
mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
@@ -249,7 +265,7 @@ class Main {
String projectName = mSdkCommandLine.getParamName();
String packageName = mSdkCommandLine.getParamProjectPackage();
String activityName = mSdkCommandLine.getParamProjectActivity();
-
+
if (projectName != null &&
!ProjectCreator.RE_PROJECT_NAME.matcher(projectName).matches()) {
errorAndExit(
@@ -285,7 +301,7 @@ class Main {
}
/**
- * Updates an existing Android project based on command-line parameters
+ * Updates an existing Android project based on command-line parameters
*/
private void updateProject() {
// get the target and try to resolve it.
@@ -299,7 +315,7 @@ class Main {
}
target = targets[targetId - 1];
}
-
+
ProjectCreator creator = new ProjectCreator(mSdkFolder,
mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
@@ -307,7 +323,7 @@ class Main {
mSdkLog);
String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
-
+
creator.updateProject(projectDir,
target,
mSdkCommandLine.getParamName());
@@ -316,12 +332,12 @@ class Main {
/**
* Adjusts the project location to make it absolute & canonical relative to the
* working directory, if any.
- *
+ *
* @return The project absolute path relative to {@link #mWorkDir} or the original
* newProjectLocation otherwise.
*/
private String getProjectLocation(String newProjectLocation) {
-
+
// If the new project location is absolute, use it as-is
File projectDir = new File(newProjectLocation);
if (projectDir.isAbsolute()) {
@@ -336,7 +352,7 @@ class Main {
// Combine then and get an absolute canonical directory
try {
projectDir = new File(mWorkDir, newProjectLocation).getCanonicalFile();
-
+
return projectDir.getPath();
} catch (IOException e) {
errorAndExit("Failed to combine working directory '%1$s' with project location '%2$s': %3$s",
@@ -368,7 +384,7 @@ class Main {
}
mSdkLog.printf(" Based on Android %s (API level %d)\n",
target.getApiVersionName(), target.getApiVersionNumber());
-
+
// display the optional libraries.
IOptionalLibrary[] libraries = target.getOptionalLibraries();
if (libraries != null) {
@@ -384,7 +400,7 @@ class Main {
// get the target skins
displaySkinList(target, " Skins: ");
-
+
index++;
}
}
@@ -405,7 +421,7 @@ class Main {
first = false;
}
mSdkLog.printf(skin);
-
+
if (skin.equals(defaultSkin)) {
mSdkLog.printf(" (default)");
}
@@ -415,7 +431,7 @@ class Main {
mSdkLog.printf("no skins.\n");
}
}
-
+
/**
* Displays the list of available AVDs.
*/
@@ -445,7 +461,7 @@ class Main {
mSdkLog.printf(" Based on Android %s (API level %d)\n", target
.getApiVersionName(), target.getApiVersionNumber());
}
-
+
// display some extra values.
Map<String, String> properties = info.getProperties();
if (properties != null) {
@@ -495,7 +511,7 @@ class Main {
// find a matching target
int targetId = mSdkCommandLine.getParamTargetId();
IAndroidTarget target = null;
-
+
if (targetId >= 1 && targetId <= mSdkManager.getTargets().length) {
target = mSdkManager.getTargets()[targetId-1]; // target it is 1-based
} else {
@@ -508,14 +524,14 @@ class Main {
AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
String avdName = mSdkCommandLine.getParamName();
-
+
if (!AvdManager.RE_AVD_NAME.matcher(avdName).matches()) {
errorAndExit(
"AVD name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
avdName, AvdManager.CHARS_AVD_NAME);
return;
}
-
+
AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/);
if (info != null) {
if (removePrevious) {
@@ -550,7 +566,7 @@ class Main {
if (removePrevious) {
oldAvdInfo = avdManager.getAvd(avdName, false /*validAvdOnly*/);
}
-
+
// Validate skin is either default (empty) or NNNxMMM or a valid skin name.
String skin = mSdkCommandLine.getParamSkin();
if (skin != null && skin.length() == 0) {
@@ -566,7 +582,7 @@ class Main {
break;
}
}
-
+
// Is it NNNxMMM?
if (!valid) {
valid = AvdManager.NUMERIC_SKIN_SIZE.matcher(skin).matches();
@@ -578,7 +594,7 @@ class Main {
return;
}
}
-
+
AvdInfo newAvdInfo = avdManager.createAvd(avdFolder,
avdName,
target,
@@ -586,7 +602,7 @@ class Main {
mSdkCommandLine.getParamSdCard(),
hardwareConfig,
removePrevious);
-
+
} catch (AndroidLocationException e) {
errorAndExit(e.getMessage());
}
@@ -601,18 +617,18 @@ class Main {
String avdName = mSdkCommandLine.getParamName();
AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/);
-
+
if (info == null) {
errorAndExit("There is no Android Virtual Device named '%s'.", avdName);
return;
}
-
+
avdManager.deleteAvd(info, mSdkLog);
} catch (AndroidLocationException e) {
errorAndExit(e.getMessage());
}
}
-
+
/**
* Moves an AVD.
*/
@@ -621,12 +637,12 @@ class Main {
String avdName = mSdkCommandLine.getParamName();
AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
AvdInfo info = avdManager.getAvd(avdName, true /*validAvdOnly*/);
-
+
if (info == null) {
errorAndExit("There is no valid Android Virtual Device named '%s'.", avdName);
return;
}
-
+
// This is a rename if there's a new name for the AVD
String newName = mSdkCommandLine.getParamMoveNewName();
if (newName != null && newName.equals(info.getName())) {
@@ -647,17 +663,17 @@ class Main {
}
} catch (IOException e) {
// Fail to resolve canonical path. Fail now since a move operation might fail
- // later and be harder to recover from.
+ // later and be harder to recover from.
errorAndExit(e.getMessage());
return;
}
}
-
+
if (newName == null && paramFolderPath == null) {
mSdkLog.warning("Move operation aborted: same AVD name, same canonical data path");
return;
}
-
+
// If a rename was requested and no data move was requested, check if the original
// data path is our default constructed from the AVD name. In this case we still want
// to rename that folder too.
@@ -674,12 +690,12 @@ class Main {
newName + AvdManager.AVD_FOLDER_EXTENSION);
paramFolderPath = f.getCanonicalPath();
} catch (IOException e) {
- // Fail to resolve canonical path. Fail now rather than later.
+ // Fail to resolve canonical path. Fail now rather than later.
errorAndExit(e.getMessage());
}
}
}
-
+
// Check for conflicts
if (newName != null) {
if (avdManager.getAvd(newName, false /*validAvdOnly*/) != null) {
@@ -699,7 +715,7 @@ class Main {
"There is already a file or directory at '%s'.\nUse --path to specify a different data folder.",
paramFolderPath);
}
-
+
avdManager.moveAvd(info, newName, paramFolderPath, mSdkLog);
} catch (AndroidLocationException e) {
errorAndExit(e.getMessage());
@@ -707,7 +723,7 @@ class Main {
errorAndExit(e.getMessage());
}
}
-
+
/**
* Updates a broken AVD.
*/
@@ -722,20 +738,20 @@ class Main {
errorAndExit(e.getMessage());
}
}
-
+
/**
* Prompts the user to setup a hardware config for a Platform-based AVD.
- * @throws IOException
+ * @throws IOException
*/
private Map<String, String> promptForHardware(IAndroidTarget createTarget) throws IOException {
byte[] readLineBuffer = new byte[256];
String result;
String defaultAnswer = "no";
-
+
mSdkLog.printf("%s is a basic Android platform.\n", createTarget.getName());
mSdkLog.printf("Do you wish to create a custom hardware profile [%s]",
defaultAnswer);
-
+
result = readLine(readLineBuffer).trim();
// handle default:
if (result.length() == 0) {
@@ -746,17 +762,17 @@ class Main {
// no custom config.
return null;
}
-
+
mSdkLog.printf("\n"); // empty line
-
+
// get the list of possible hardware properties
File hardwareDefs = new File (mSdkFolder + File.separator +
SdkConstants.OS_SDK_TOOLS_LIB_FOLDER, SdkConstants.FN_HARDWARE_INI);
List<HardwareProperty> list = HardwareProperties.parseHardwareDefinitions(hardwareDefs,
null /*sdkLog*/);
-
+
HashMap<String, String> map = new HashMap<String, String>();
-
+
for (int i = 0 ; i < list.size() ;) {
HardwareProperty property = list.get(i);
@@ -768,13 +784,13 @@ class Main {
}
String defaultValue = property.getDefault();
-
+
if (defaultValue != null) {
mSdkLog.printf("%s [%s]:", property.getName(), defaultValue);
} else {
mSdkLog.printf("%s (%s):", property.getName(), property.getType());
}
-
+
result = readLine(readLineBuffer);
if (result.length() == 0) {
if (defaultValue != null) {
@@ -784,7 +800,7 @@ class Main {
}
continue;
}
-
+
switch (property.getType()) {
case BOOLEAN:
try {
@@ -816,13 +832,13 @@ class Main {
i++; // valid reply, move to next property
break;
}
-
+
mSdkLog.printf("\n"); // empty line
}
return map;
}
-
+
/**
* Reads the line from the input stream.
* @param buffer
@@ -830,7 +846,7 @@ class Main {
*/
private String readLine(byte[] buffer) throws IOException {
int count = System.in.read(buffer);
-
+
// is the input longer than the buffer?
if (count == buffer.length && buffer[count-1] != 10) {
// create a new temp buffer
@@ -838,7 +854,7 @@ class Main {
// and read the rest
String secondHalf = readLine(tempBuffer);
-
+
// return a concat of both
return new String(buffer, 0, count) + secondHalf;
}
@@ -847,16 +863,16 @@ class Main {
while (count > 0 && (buffer[count-1] == '\r' || buffer[count-1] == '\n')) {
count--;
}
-
+
return new String(buffer, 0, count);
}
-
+
/**
* Returns the boolean value represented by the string.
* @throws IOException If the value is not a boolean string.
*/
private boolean getBooleanReply(String reply) throws IOException {
-
+
for (String valid : BOOLEAN_YES_REPLIES) {
if (valid.equalsIgnoreCase(reply)) {
return true;
@@ -871,9 +887,9 @@ class Main {
throw new IOException(String.format("%s is not a valid reply", reply));
}
-
+
private void errorAndExit(String format, Object...args) {
mSdkLog.error(null, format, args);
System.exit(1);
}
-} \ No newline at end of file
+}
diff --git a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
index 36172e9..81f712c 100644
--- a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
+++ b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
@@ -72,7 +72,7 @@ public class SdkCommandLine extends CommandLineProcessor {
{ VERB_LIST, OBJECT_TARGET,
"Lists existing targets.",
OBJECT_TARGETS },
-
+
{ VERB_CREATE, OBJECT_AVD,
"Creates a new Android Virtual Device." },
{ VERB_MOVE, OBJECT_AVD,
@@ -81,58 +81,58 @@ public class SdkCommandLine extends CommandLineProcessor {
"Deletes an Android Virtual Device." },
{ VERB_UPDATE, OBJECT_AVD,
"Updates an Android Virtual Device to match the folders of a new SDK." },
-
+
{ VERB_CREATE, OBJECT_PROJECT,
"Creates a new Android Project." },
{ VERB_UPDATE, OBJECT_PROJECT,
"Updates an Android Project (must have an AndroidManifest.xml)." },
};
-
+
public SdkCommandLine(ISdkLog logger) {
super(logger, ACTIONS);
// --- create avd ---
-
- define(MODE.STRING, false,
+
+ define(MODE.STRING, false,
VERB_CREATE, OBJECT_AVD, "p", KEY_PATH,
"Location path of the directory where the new AVD will be created", null);
- define(MODE.STRING, true,
+ define(MODE.STRING, true,
VERB_CREATE, OBJECT_AVD, "n", KEY_NAME,
"Name of the new AVD", null);
- define(MODE.INTEGER, true,
+ define(MODE.INTEGER, true,
VERB_CREATE, OBJECT_AVD, "t", KEY_TARGET_ID,
"Target id of the new AVD", null);
- define(MODE.STRING, false,
+ define(MODE.STRING, false,
VERB_CREATE, OBJECT_AVD, "s", KEY_SKIN,
"Skin of the new AVD", null);
- define(MODE.STRING, false,
+ define(MODE.STRING, false,
VERB_CREATE, OBJECT_AVD, "c", KEY_SDCARD,
"Path to a shared SD card image, or size of a new sdcard for the new AVD", null);
- define(MODE.BOOLEAN, false,
+ define(MODE.BOOLEAN, false,
VERB_CREATE, OBJECT_AVD, "f", KEY_FORCE,
"Force creation (override an existing AVD)", false);
// --- delete avd ---
-
- define(MODE.STRING, true,
+
+ define(MODE.STRING, true,
VERB_DELETE, OBJECT_AVD, "n", KEY_NAME,
"Name of the AVD to delete", null);
// --- move avd ---
-
- define(MODE.STRING, true,
+
+ define(MODE.STRING, true,
VERB_MOVE, OBJECT_AVD, "n", KEY_NAME,
"Name of the AVD to move or rename", null);
- define(MODE.STRING, false,
+ define(MODE.STRING, false,
VERB_MOVE, OBJECT_AVD, "r", KEY_RENAME,
"New name of the AVD to rename", null);
- define(MODE.STRING, false,
+ define(MODE.STRING, false,
VERB_MOVE, OBJECT_AVD, "p", KEY_PATH,
"New location path of the directory where to move the AVD", null);
// --- update avd ---
-
- define(MODE.STRING, true,
+
+ define(MODE.STRING, true,
VERB_UPDATE, OBJECT_AVD, "n", KEY_NAME,
"Name of the AVD to update", null);
@@ -140,51 +140,56 @@ public class SdkCommandLine extends CommandLineProcessor {
/* Disabled for ADT 0.9 / Cupcake SDK 1.5_r1 release. [bug #1795718].
This currently does not work, the alias build rules need to be fixed.
-
- define(MODE.ENUM, true,
+
+ define(MODE.ENUM, true,
VERB_CREATE, OBJECT_PROJECT, "m", KEY_MODE,
"Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS });
*/
- define(MODE.STRING, true,
+ define(MODE.STRING, true,
VERB_CREATE, OBJECT_PROJECT,
"p", KEY_PATH,
"Location path of new project", null);
- define(MODE.INTEGER, true,
+ define(MODE.INTEGER, true,
VERB_CREATE, OBJECT_PROJECT, "t", KEY_TARGET_ID,
"Target id of the new project", null);
- define(MODE.STRING, true,
+ define(MODE.STRING, true,
VERB_CREATE, OBJECT_PROJECT, "k", KEY_PACKAGE,
"Package name", null);
- define(MODE.STRING, true,
+ define(MODE.STRING, true,
VERB_CREATE, OBJECT_PROJECT, "a", KEY_ACTIVITY,
"Activity name", null);
- define(MODE.STRING, false,
+ define(MODE.STRING, false,
VERB_CREATE, OBJECT_PROJECT, "n", KEY_NAME,
"Project name", null);
// --- update project ---
- define(MODE.STRING, true,
+ define(MODE.STRING, true,
VERB_UPDATE, OBJECT_PROJECT,
"p", KEY_PATH,
"Location path of the project", null);
- define(MODE.INTEGER, true,
+ define(MODE.INTEGER, true,
VERB_UPDATE, OBJECT_PROJECT,
"t", KEY_TARGET_ID,
"Target id to set for the project", -1);
- define(MODE.STRING, false,
+ define(MODE.STRING, false,
VERB_UPDATE, OBJECT_PROJECT,
"n", KEY_NAME,
"Project name", null);
}
-
+
+ @Override
+ public boolean acceptLackOfVerb() {
+ return true;
+ }
+
// -- some helpers for generic action flags
-
+
/** Helper to retrieve the --path value. */
public String getParamLocationPath() {
return ((String) getValue(null, null, KEY_PATH));
}
-
+
/** Helper to retrieve the --target id value. */
public int getParamTargetId() {
return ((Integer) getValue(null, null, KEY_TARGET_ID)).intValue();
@@ -194,7 +199,7 @@ public class SdkCommandLine extends CommandLineProcessor {
public String getParamName() {
return ((String) getValue(null, null, KEY_NAME));
}
-
+
/** Helper to retrieve the --skin value. */
public String getParamSkin() {
return ((String) getValue(null, null, KEY_SKIN));
@@ -204,7 +209,7 @@ public class SdkCommandLine extends CommandLineProcessor {
public String getParamSdCard() {
return ((String) getValue(null, null, KEY_SDCARD));
}
-
+
/** Helper to retrieve the --force flag. */
public boolean getFlagForce() {
return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue();
@@ -219,7 +224,7 @@ public class SdkCommandLine extends CommandLineProcessor {
// -- some helpers for project action flags
-
+
/** Helper to retrieve the --package value. */
public String getParamProjectPackage() {
return ((String) getValue(null, OBJECT_PROJECT, KEY_PACKAGE));