ADT #1856119: 'android update project' can now update sub-projects.

This commit is contained in:
Raphael
2009-06-10 11:34:08 -07:00
parent 891968b78e
commit 61df13dec4
5 changed files with 165 additions and 126 deletions

View File

@@ -85,13 +85,13 @@ public class CommandLineProcessor {
mLog = logger; mLog = logger;
mActions = actions; mActions = actions;
define(MODE.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "v", KEY_VERBOSE, define(Mode.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "v", KEY_VERBOSE,
"Verbose mode: errors, warnings and informational messages are printed.", "Verbose mode: errors, warnings and informational messages are printed.",
false); false);
define(MODE.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "s", KEY_SILENT, define(Mode.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "s", KEY_SILENT,
"Silent mode: only errors are printed out.", "Silent mode: only errors are printed out.",
false); false);
define(MODE.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "h", KEY_HELP, define(Mode.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "h", KEY_HELP,
"This help.", "This help.",
false); false);
} }
@@ -507,7 +507,7 @@ public class CommandLineProcessor {
} }
} else if (arg.getDefaultValue() != null) { } else if (arg.getDefaultValue() != null) {
Object v = arg.getDefaultValue(); Object v = arg.getDefaultValue();
if (arg.getMode() != MODE.BOOLEAN || v.equals(Boolean.TRUE)) { if (arg.getMode() != Mode.BOOLEAN || v.equals(Boolean.TRUE)) {
value = v.toString(); value = v.toString();
} }
} }
@@ -537,7 +537,7 @@ public class CommandLineProcessor {
* The mode of an argument specifies the type of variable it represents, * 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. * whether an extra parameter is required after the flag and how to parse it.
*/ */
static enum MODE { static enum Mode {
/** Argument value is a Boolean. Default value is a Boolean. */ /** Argument value is a Boolean. Default value is a Boolean. */
BOOLEAN { BOOLEAN {
@Override @Override
@@ -628,7 +628,7 @@ public class CommandLineProcessor {
* An argument accepted by the command-line, also called "a flag". * An argument accepted by the command-line, also called "a flag".
* Arguments must have a short version (one letter), a long version name and a description. * 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. * 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 * 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 { static class Arg {
@@ -645,7 +645,7 @@ public class CommandLineProcessor {
/** A default value. Can be null. */ /** A default value. Can be null. */
private final Object mDefaultValue; private final Object mDefaultValue;
/** The argument mode (type + process method). Never null. */ /** The argument mode (type + process method). Never null. */
private final MODE mMode; private final Mode mMode;
/** True if this argument is mandatory for this verb/directobject. */ /** True if this argument is mandatory for this verb/directobject. */
private final boolean mMandatory; private final boolean mMandatory;
/** Current value. Initially set to the default value. */ /** Current value. Initially set to the default value. */
@@ -656,15 +656,15 @@ public class CommandLineProcessor {
/** /**
* Creates a new argument flag description. * Creates a new argument flag description.
* *
* @param mode The {@link MODE} for the argument. * @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 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 shortName The one-letter short argument name. Cannot be empty nor null.
* @param longName The long argument name. Cannot be empty nor null. * @param longName The long argument name. Cannot be empty nor null.
* @param description The description. Cannot be null. * @param description The description. Cannot be null.
* @param defaultValue The default value (or values), which depends on the selected {@link MODE}. * @param defaultValue The default value (or values), which depends on the selected {@link Mode}.
*/ */
public Arg(MODE mode, public Arg(Mode mode,
boolean mandatory, boolean mandatory,
String verb, String verb,
String directObject, String directObject,
@@ -734,7 +734,7 @@ public class CommandLineProcessor {
} }
/** Returns the argument mode (type + process method). Never null. */ /** Returns the argument mode (type + process method). Never null. */
public MODE getMode() { public Mode getMode() {
return mMode; return mMode;
} }
@@ -752,21 +752,21 @@ public class CommandLineProcessor {
/** /**
* Internal helper to define a new argument for a give action. * Internal helper to define a new argument for a give action.
* *
* @param mode The {@link MODE} for the argument. * @param mode The {@link Mode} for the argument.
* @param verb The verb name. Can be #INTERNAL_VERB. * @param verb The verb name. Can be #INTERNAL_VERB.
* @param directObject The action name. Can be #NO_VERB_OBJECT or #INTERNAL_FLAG. * @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 shortName The one-letter short argument name. Cannot be empty nor null.
* @param longName The long argument name. Cannot be empty nor null. * @param longName The long argument name. Cannot be empty nor null.
* @param description The description. Cannot be null. * @param description The description. Cannot be null.
* @param defaultValue The default value (or values), which depends on the selected {@link MODE}. * @param defaultValue The default value (or values), which depends on the selected {@link Mode}.
*/ */
protected void define(MODE mode, protected void define(Mode mode,
boolean mandatory, boolean mandatory,
String verb, String verb,
String directObject, String directObject,
String shortName, String longName, String shortName, String longName,
String description, Object defaultValue) { String description, Object defaultValue) {
assert(mandatory || mode == MODE.BOOLEAN); // a boolean mode cannot be mandatory assert(mandatory || mode == Mode.BOOLEAN); // a boolean mode cannot be mandatory
if (directObject == null) { if (directObject == null) {
directObject = NO_VERB_OBJECT; directObject = NO_VERB_OBJECT;

View File

@@ -337,6 +337,33 @@ class Main {
creator.updateProject(projectDir, creator.updateProject(projectDir,
target, target,
mSdkCommandLine.getParamName()); mSdkCommandLine.getParamName());
boolean doSubProjects = mSdkCommandLine.getParamSubProject();
boolean couldHaveDone = false;
// If there are any sub-folders with a manifest, try to update them as projects
// too. This will take care of updating any underlying test project even if the
// user changed the folder name.
File[] files = new File(projectDir).listFiles();
if (files != null) {
for (File dir : files) {
if (dir.isDirectory() &&
new File(dir, SdkConstants.FN_ANDROID_MANIFEST_XML).isFile()) {
if (doSubProjects) {
creator.updateProject(dir.getPath(),
target,
mSdkCommandLine.getParamName());
} else {
couldHaveDone = true;
}
}
}
}
if (couldHaveDone) {
mSdkLog.printf("It seems that there are sub-projects. If you want to update them\nplease use the --%1$s parameter.",
SdkCommandLine.KEY_SUBPROJECTS);
}
} }
/** /**

View File

@@ -38,20 +38,21 @@ public class SdkCommandLine extends CommandLineProcessor {
public static final String OBJECT_PROJECT = "project"; public static final String OBJECT_PROJECT = "project";
public static final String OBJECT_ADB = "adb"; public static final String OBJECT_ADB = "adb";
public static final String ARG_ALIAS = "alias"; public static final String ARG_ALIAS = "alias";
public static final String ARG_ACTIVITY = "activity"; public static final String ARG_ACTIVITY = "activity";
public static final String KEY_ACTIVITY = ARG_ACTIVITY; public static final String KEY_ACTIVITY = ARG_ACTIVITY;
public static final String KEY_PACKAGE = "package"; public static final String KEY_PACKAGE = "package";
public static final String KEY_MODE = "mode"; public static final String KEY_MODE = "mode";
public static final String KEY_TARGET_ID = OBJECT_TARGET; public static final String KEY_TARGET_ID = OBJECT_TARGET;
public static final String KEY_NAME = "name"; public static final String KEY_NAME = "name";
public static final String KEY_PATH = "path"; public static final String KEY_PATH = "path";
public static final String KEY_FILTER = "filter"; public static final String KEY_FILTER = "filter";
public static final String KEY_SKIN = "skin"; public static final String KEY_SKIN = "skin";
public static final String KEY_SDCARD = "sdcard"; public static final String KEY_SDCARD = "sdcard";
public static final String KEY_FORCE = "force"; public static final String KEY_FORCE = "force";
public static final String KEY_RENAME = "rename"; public static final String KEY_RENAME = "rename";
public static final String KEY_SUBPROJECTS = "subprojects";
/** /**
* Action definitions for SdkManager command line. * Action definitions for SdkManager command line.
@@ -97,46 +98,46 @@ public class SdkCommandLine extends CommandLineProcessor {
// --- create avd --- // --- create avd ---
define(MODE.STRING, false, define(Mode.STRING, false,
VERB_CREATE, OBJECT_AVD, "p", KEY_PATH, VERB_CREATE, OBJECT_AVD, "p", KEY_PATH,
"Location path of the directory where the new AVD will be created", null); "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, VERB_CREATE, OBJECT_AVD, "n", KEY_NAME,
"Name of the new AVD", null); "Name of the new AVD", null);
define(MODE.INTEGER, true, define(Mode.INTEGER, true,
VERB_CREATE, OBJECT_AVD, "t", KEY_TARGET_ID, VERB_CREATE, OBJECT_AVD, "t", KEY_TARGET_ID,
"Target id of the new AVD", null); "Target id of the new AVD", null);
define(MODE.STRING, false, define(Mode.STRING, false,
VERB_CREATE, OBJECT_AVD, "s", KEY_SKIN, VERB_CREATE, OBJECT_AVD, "s", KEY_SKIN,
"Skin of the new AVD", null); "Skin of the new AVD", null);
define(MODE.STRING, false, define(Mode.STRING, false,
VERB_CREATE, OBJECT_AVD, "c", KEY_SDCARD, 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); "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, VERB_CREATE, OBJECT_AVD, "f", KEY_FORCE,
"Force creation (override an existing AVD)", false); "Force creation (override an existing AVD)", false);
// --- delete avd --- // --- delete avd ---
define(MODE.STRING, true, define(Mode.STRING, true,
VERB_DELETE, OBJECT_AVD, "n", KEY_NAME, VERB_DELETE, OBJECT_AVD, "n", KEY_NAME,
"Name of the AVD to delete", null); "Name of the AVD to delete", null);
// --- move avd --- // --- move avd ---
define(MODE.STRING, true, define(Mode.STRING, true,
VERB_MOVE, OBJECT_AVD, "n", KEY_NAME, VERB_MOVE, OBJECT_AVD, "n", KEY_NAME,
"Name of the AVD to move or rename", null); "Name of the AVD to move or rename", null);
define(MODE.STRING, false, define(Mode.STRING, false,
VERB_MOVE, OBJECT_AVD, "r", KEY_RENAME, VERB_MOVE, OBJECT_AVD, "r", KEY_RENAME,
"New name of the AVD to rename", null); "New name of the AVD to rename", null);
define(MODE.STRING, false, define(Mode.STRING, false,
VERB_MOVE, OBJECT_AVD, "p", KEY_PATH, VERB_MOVE, OBJECT_AVD, "p", KEY_PATH,
"New location path of the directory where to move the AVD", null); "New location path of the directory where to move the AVD", null);
// --- update avd --- // --- update avd ---
define(MODE.STRING, true, define(Mode.STRING, true,
VERB_UPDATE, OBJECT_AVD, "n", KEY_NAME, VERB_UPDATE, OBJECT_AVD, "n", KEY_NAME,
"Name of the AVD to update", null); "Name of the AVD to update", null);
@@ -145,41 +146,45 @@ public class SdkCommandLine extends CommandLineProcessor {
/* Disabled for ADT 0.9 / Cupcake SDK 1.5_r1 release. [bug #1795718]. /* 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. 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, VERB_CREATE, OBJECT_PROJECT, "m", KEY_MODE,
"Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS }); "Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS });
*/ */
define(MODE.STRING, true, define(Mode.STRING, true,
VERB_CREATE, OBJECT_PROJECT, VERB_CREATE, OBJECT_PROJECT,
"p", KEY_PATH, "p", KEY_PATH,
"Location path of new project", null); "Location path of new project", null);
define(MODE.INTEGER, true, define(Mode.INTEGER, true,
VERB_CREATE, OBJECT_PROJECT, "t", KEY_TARGET_ID, VERB_CREATE, OBJECT_PROJECT, "t", KEY_TARGET_ID,
"Target id of the new project", null); "Target id of the new project", null);
define(MODE.STRING, true, define(Mode.STRING, true,
VERB_CREATE, OBJECT_PROJECT, "k", KEY_PACKAGE, VERB_CREATE, OBJECT_PROJECT, "k", KEY_PACKAGE,
"Package name", null); "Package name", null);
define(MODE.STRING, true, define(Mode.STRING, true,
VERB_CREATE, OBJECT_PROJECT, "a", KEY_ACTIVITY, VERB_CREATE, OBJECT_PROJECT, "a", KEY_ACTIVITY,
"Activity name", null); "Activity name", null);
define(MODE.STRING, false, define(Mode.STRING, false,
VERB_CREATE, OBJECT_PROJECT, "n", KEY_NAME, VERB_CREATE, OBJECT_PROJECT, "n", KEY_NAME,
"Project name", null); "Project name", null);
// --- update project --- // --- update project ---
define(MODE.STRING, true, define(Mode.STRING, true,
VERB_UPDATE, OBJECT_PROJECT, VERB_UPDATE, OBJECT_PROJECT,
"p", KEY_PATH, "p", KEY_PATH,
"Location path of the project", null); "Location path of the project", null);
define(MODE.INTEGER, true, define(Mode.INTEGER, true,
VERB_UPDATE, OBJECT_PROJECT, VERB_UPDATE, OBJECT_PROJECT,
"t", KEY_TARGET_ID, "t", KEY_TARGET_ID,
"Target id to set for the project", -1); "Target id to set for the project", -1);
define(MODE.STRING, false, define(Mode.STRING, false,
VERB_UPDATE, OBJECT_PROJECT, VERB_UPDATE, OBJECT_PROJECT,
"n", KEY_NAME, "n", KEY_NAME,
"Project name", null); "Project name", null);
define(Mode.BOOLEAN, false,
VERB_UPDATE, OBJECT_PROJECT,
"s", KEY_SUBPROJECTS,
"Also update any projects in sub-folders, such as test projects.", false);
} }
@Override @Override
@@ -234,8 +239,13 @@ public class SdkCommandLine extends CommandLineProcessor {
return ((String) getValue(null, OBJECT_PROJECT, KEY_PACKAGE)); return ((String) getValue(null, OBJECT_PROJECT, KEY_PACKAGE));
} }
/** Helper to retrieve the --activity for the new project action. */ /** Helper to retrieve the --activity for any project action. */
public String getParamProjectActivity() { public String getParamProjectActivity() {
return ((String) getValue(null, OBJECT_PROJECT, KEY_ACTIVITY)); return ((String) getValue(null, OBJECT_PROJECT, KEY_ACTIVITY));
} }
/** Helper to retrieve the --subprojects for any project action. */
public boolean getParamSubProject() {
return ((Boolean) getValue(null, OBJECT_PROJECT, KEY_SUBPROJECTS)).booleanValue();
}
} }

View File

@@ -41,9 +41,9 @@ public class CommandLineProcessorTest extends TestCase {
{ "verb1", "action1", "Some action" }, { "verb1", "action1", "Some action" },
{ "verb1", "action2", "Another action" }, { "verb1", "action2", "Another action" },
}); });
define(MODE.STRING, false /*mandatory*/, define(Mode.STRING, false /*mandatory*/,
"verb1", "action1", "1", "first", "non-mandatory flag", null); "verb1", "action1", "1", "first", "non-mandatory flag", null);
define(MODE.STRING, true /*mandatory*/, define(Mode.STRING, true /*mandatory*/,
"verb1", "action1", "2", "second", "mandatory flag", null); "verb1", "action1", "2", "second", "mandatory flag", null);
} }

View File

@@ -139,7 +139,9 @@ public class ProjectCreator {
* null if no activity should be created. The name must match the * null if no activity should be created. The name must match the
* {@link #RE_ACTIVITY_NAME} regex. * {@link #RE_ACTIVITY_NAME} regex.
* @param target the project target. * @param target the project target.
* @param isTestProject whether the project to create is a test project. * @param isTestProject whether the project to create is a test project. Caller should
* initially call this will false. The method will call itself back to create
* a test project as needed.
*/ */
public void createProject(String folderPath, String projectName, public void createProject(String folderPath, String projectName,
String packageName, String activityName, IAndroidTarget target, String packageName, String activityName, IAndroidTarget target,
@@ -313,7 +315,7 @@ public class ProjectCreator {
* @param target the project target. Can be null. * @param target the project target. Can be null.
* @param projectName The project name from --name. Can be null. * @param projectName The project name from --name. Can be null.
*/ */
public void updateProject(String folderPath, IAndroidTarget target, String projectName ) { public void updateProject(String folderPath, IAndroidTarget target, String projectName) {
// project folder must exist and be a directory, since this is an update // project folder must exist and be a directory, since this is an update
File projectFolder = new File(folderPath); File projectFolder = new File(folderPath);
if (!projectFolder.isDirectory()) { if (!projectFolder.isDirectory()) {