auto import from //branches/cupcake/...@127101

This commit is contained in:
The Android Open Source Project
2009-01-20 14:03:55 -08:00
parent b8d704a517
commit 7b53e39377
57 changed files with 1009 additions and 1269 deletions

View File

@@ -45,6 +45,8 @@ public class CommandLineProcessor {
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";
/** The internal action flag. */
public static final String KEY_ACTION = "action";
@@ -65,10 +67,18 @@ public class CommandLineProcessor {
mLog = logger;
mActions = actions;
define(MODE.STRING, false, INTERNAL_FLAG, null, KEY_ACTION, "Selected Action", null);
define(MODE.STRING, false, INTERNAL_FLAG, null, KEY_ACTION,
"Selected Action", null);
define(MODE.BOOLEAN, false, GLOBAL_FLAG, "v", KEY_VERBOSE, "Verbose mode", false);
define(MODE.BOOLEAN, false, GLOBAL_FLAG, "h", KEY_HELP, "This help", false);
define(MODE.BOOLEAN, false, GLOBAL_FLAG, "v", KEY_VERBOSE,
"Verbose mode: errors, warnings and informational messages are printed.",
false);
define(MODE.BOOLEAN, false, GLOBAL_FLAG, "s", KEY_SILENT,
"Silent mode: only errors are printed out.",
false);
define(MODE.BOOLEAN, false, GLOBAL_FLAG, "h", KEY_HELP,
"This help.",
false);
}
//------------------
@@ -79,6 +89,11 @@ public class CommandLineProcessor {
return ((Boolean) getValue(GLOBAL_FLAG, KEY_VERBOSE)).booleanValue();
}
/** Helper that returns true if --silent was requested. */
public boolean isSilent() {
return ((Boolean) getValue(GLOBAL_FLAG, KEY_SILENT)).booleanValue();
}
/** Helper that returns true if --help was requested. */
public boolean isHelpRequested() {
return ((Boolean) getValue(GLOBAL_FLAG, KEY_HELP)).booleanValue();
@@ -204,18 +219,29 @@ public class CommandLineProcessor {
needsHelp = "Missing action name.";
} else {
// Validate that all mandatory arguments are non-null for this action
String missing = null;
boolean plural = false;
for (Entry<String, Arg> entry : mArguments.entrySet()) {
Arg arg = entry.getValue();
if (arg.getAction().equals(action)) {
if (arg.isMandatory() && arg.getCurrentValue() == null) {
needsHelp = String.format("The parameter --%1$s must be defined for action '%2$s'",
arg.getLongArg(),
action);
break;
if (missing == null) {
missing = "--" + arg.getLongArg();
} else {
missing += ", --" + arg.getLongArg();
plural = true;
}
}
}
}
if (missing != null) {
needsHelp = String.format("The %1$s %2$s must be defined for action '%3$s'",
plural ? "parameters" : "parameter",
missing,
action);
}
setValue(INTERNAL_FLAG, KEY_ACTION, action);
}
}
@@ -324,24 +350,29 @@ public class CommandLineProcessor {
Arg arg = entry.getValue();
if (arg.getAction().equals(action)) {
String value = null;
String value = "";
if (arg.getDefaultValue() instanceof String[]) {
value = "";
for (String v : (String[]) arg.getDefaultValue()) {
if (value.length() > 0) {
value += "|";
value += ", ";
}
value += v;
}
} else if (arg.getDefaultValue() != null) {
value = arg.getDefaultValue().toString();
}
if (value.length() > 0) {
value = " (" + value + ")";
}
String required = arg.isMandatory() ? " [required]" : "";
stdout(" -%1$s %2$-10s %3$s%4$s",
stdout(" -%1$s %2$-10s %3$s%4$s%5$s",
arg.getShortArg(),
"--" + arg.getLongArg(),
arg.getDescription(),
value == null ? "" : " (" + value + ")");
value,
required);
numOptions++;
}
}

View File

@@ -144,7 +144,7 @@ class Main {
if (mSdkFolder == null) {
errorAndExit("The tools directory property is not set, please make sure you are executing %1$s",
SdkConstants.AndroidCmdName());
SdkConstants.androidCmdName());
}
// We might get passed a property for the working directory
@@ -203,19 +203,48 @@ class Main {
IAndroidTarget[] targets = mSdkManager.getTargets();
if (targetId < 1 || targetId > targets.length) {
errorAndExit("Target id is not valid. Use '%s list -f target' to get the target Ids.",
SdkConstants.AndroidCmdName());
SdkConstants.androidCmdName());
}
IAndroidTarget target = targets[targetId - 1];
ProjectCreator creator = new ProjectCreator(mSdkFolder,
mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE : OutputLevel.NORMAL,
mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
OutputLevel.NORMAL,
mSdkLog);
String projectDir = getProjectLocation(mSdkCommandLine.getNewProjectLocation());
creator.createProject(projectDir,
mSdkCommandLine.getNewProjectName(), mSdkCommandLine.getNewProjectPackage(),
mSdkCommandLine.getNewProjectActivity(), target, false /* isTestProject*/);
mSdkCommandLine.getNewProjectName(),
mSdkCommandLine.getNewProjectPackage(),
mSdkCommandLine.getNewProjectActivity(),
target,
false /* isTestProject*/);
} else if (SdkCommandLine.ACTION_UPDATE_PROJECT.equals(action)) {
// get the target and try to resolve it.
IAndroidTarget target = null;
int targetId = mSdkCommandLine.getUpdateProjectTargetId();
if (targetId >= 0) {
IAndroidTarget[] targets = mSdkManager.getTargets();
if (targetId < 1 || targetId > targets.length) {
errorAndExit("Target id is not valid. Use '%s list -f target' to get the target Ids.",
SdkConstants.androidCmdName());
}
target = targets[targetId - 1];
}
ProjectCreator creator = new ProjectCreator(mSdkFolder,
mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
OutputLevel.NORMAL,
mSdkLog);
String projectDir = getProjectLocation(mSdkCommandLine.getUpdateProjectLocation());
creator.updateProject(projectDir,
target,
mSdkCommandLine.getUpdateProjectName());
} else {
mSdkCommandLine.printHelpAndExit(null);
}
@@ -355,7 +384,7 @@ class Main {
target = mSdkManager.getTargets()[targetId-1]; // target it is 1-based
} else {
errorAndExit("Target id is not valid. Use '%s list -f target' to get the target Ids.",
SdkConstants.AndroidCmdName());
SdkConstants.androidCmdName());
}
try {
@@ -384,8 +413,7 @@ class Main {
mSdkCommandLine.getNewVmName(),
target,
mSdkCommandLine.getNewVmSkin(),
null /*sdcardPath*/,
0 /*sdcardSize*/,
mSdkCommandLine.getNewVmSdCard(),
hardwareConfig,
mSdkLog);
}

View File

@@ -31,7 +31,6 @@ public class SdkCommandLine extends CommandLineProcessor {
public static final String ARG_TARGET = "target";
public static final String ARG_ALL = "all";
public static final String KEY_IN = "in";
public static final String KEY_ACTIVITY = ARG_ACTIVITY;
public static final String KEY_PACKAGE = "package";
public static final String KEY_MODE = "mode";
@@ -40,7 +39,7 @@ public class SdkCommandLine extends CommandLineProcessor {
public static final String KEY_OUT = "out";
public static final String KEY_FILTER = "filter";
public static final String KEY_SKIN = "skin";
public static final String KEY_SDCARD_PATH = "sdcard";
public static final String KEY_SDCARD = "sdcard";
public final static String ACTION_LIST = "list";
public final static String ACTION_NEW_VM = ARG_VM;
@@ -72,26 +71,28 @@ public class SdkCommandLine extends CommandLineProcessor {
"Target id of the new VM", null);
define(MODE.STRING, true, ACTION_NEW_VM, "s", KEY_SKIN,
"Skin of the new VM", null);
define(MODE.STRING, true, ACTION_NEW_VM, "p", KEY_SDCARD_PATH,
"Path to a shared SD card image for the new VM", null);
define(MODE.STRING, false, ACTION_NEW_VM, "c", KEY_SDCARD,
"Path to a shared SD card image, or size of a new sdcard for the new VM", null);
define(MODE.ENUM, true, ACTION_NEW_PROJECT, "m", KEY_MODE,
"Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS });
define(MODE.STRING, false, ACTION_NEW_PROJECT, "o", KEY_OUT,
define(MODE.STRING, true, ACTION_NEW_PROJECT, "o", KEY_OUT,
"Location path of new project", null);
define(MODE.STRING, true, ACTION_NEW_PROJECT, "n", KEY_NAME,
"Name of the new project", null);
define(MODE.INTEGER, true, ACTION_NEW_PROJECT, "t", KEY_TARGET_ID,
"Target id of the new project", null);
define(MODE.STRING, true, ACTION_NEW_PROJECT, "p", KEY_PACKAGE,
"Package name", null);
define(MODE.STRING, true, ACTION_NEW_PROJECT, "a", KEY_ACTIVITY,
"Activity name", null);
define(MODE.STRING, false, ACTION_NEW_PROJECT, "n", KEY_NAME,
"Project name", null);
define(MODE.STRING, false, ACTION_UPDATE_PROJECT, "i", KEY_IN,
"Directory location of the project", null);
define(MODE.STRING, true, ACTION_UPDATE_PROJECT, "t", KEY_TARGET_ID,
"Target id to set for the project", null);
define(MODE.STRING, true, ACTION_UPDATE_PROJECT, "o", KEY_OUT,
"Location path of the project", null);
define(MODE.INTEGER, true, ACTION_UPDATE_PROJECT, "t", KEY_TARGET_ID,
"Target id to set for the project", -1);
define(MODE.STRING, false, ACTION_UPDATE_PROJECT, "n", KEY_NAME,
"Project name", null);
}
// -- some helpers for list action flags
@@ -123,9 +124,9 @@ public class SdkCommandLine extends CommandLineProcessor {
return ((String) getValue(ACTION_NEW_VM, KEY_SKIN));
}
/** Helper to retrieve the --sdcard name for the new vm action. */
/** Helper to retrieve the --sdcard data for the new vm action. */
public String getNewVmSdCard() {
return ((String) getValue(ACTION_NEW_VM, KEY_SDCARD_PATH));
return ((String) getValue(ACTION_NEW_VM, KEY_SDCARD));
}
@@ -167,4 +168,9 @@ public class SdkCommandLine extends CommandLineProcessor {
public int getUpdateProjectTargetId() {
return ((Integer) getValue(ACTION_UPDATE_PROJECT, KEY_TARGET_ID)).intValue();
}
/** Helper to retrieve the --name for the update project action. */
public String getUpdateProjectName() {
return ((String) getValue(ACTION_UPDATE_PROJECT, KEY_NAME));
}
}