Merge change 1834 into donut

* changes:
  Skeleton App Windows for Sdk Updater built using SWT Designer. The window is shown when the "android" tool is invoked with no parameter.
This commit is contained in:
Android (Google) Code Review
2009-05-15 18:51:02 -07:00
8 changed files with 504 additions and 248 deletions

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/> <classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/> <classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/>
<classpathentry combineaccessrules="false" kind="src" path="/AndroidPrefs"/> <classpathentry combineaccessrules="false" kind="src" path="/AndroidPrefs"/>
<classpathentry combineaccessrules="false" kind="src" path="/SdkUiLib"/> <classpathentry combineaccessrules="false" kind="src" path="/SdkUiLib"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>SdkManager</name> <name>SdkManager</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> <project>SdkLib</project>
<buildSpec> <project>SdkUiLib</project>
<buildCommand> </projects>
<name>org.eclipse.jdt.core.javabuilder</name> <buildSpec>
<arguments> <buildCommand>
</arguments> <name>org.eclipse.jdt.core.javabuilder</name>
</buildCommand> <arguments>
</buildSpec> </arguments>
<natures> </buildCommand>
<nature>org.eclipse.jdt.core.javanature</nature> </buildSpec>
</natures> <natures>
</projectDescription> <nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -29,7 +29,7 @@ import java.util.Map.Entry;
* <li>override it. * <li>override it.
* <li>pass an action array to the constructor. * <li>pass an action array to the constructor.
* <li>define flags for your actions. * <li>define flags for your actions.
* </ul> * </ul>
* <p/> * <p/>
* To use, call {@link #parseArgs(String[])} and then * To use, call {@link #parseArgs(String[])} and then
* call {@link #getValue(String, String, String)}. * call {@link #getValue(String, String, String)}.
@@ -38,17 +38,17 @@ public class CommandLineProcessor {
/** Internal verb name for internally hidden flags. */ /** Internal verb name for internally hidden flags. */
public final static String GLOBAL_FLAG_VERB = "@@internal@@"; public final static String GLOBAL_FLAG_VERB = "@@internal@@";
/** String to use when the verb doesn't need any object. */ /** String to use when the verb doesn't need any object. */
public final static String NO_VERB_OBJECT = ""; public final static String NO_VERB_OBJECT = "";
/** The global help flag. */ /** The global help flag. */
public static final String KEY_HELP = "help"; public static final String KEY_HELP = "help";
/** The global verbose flag. */ /** The global verbose flag. */
public static final String KEY_VERBOSE = "verbose"; public static final String KEY_VERBOSE = "verbose";
/** The global silent flag. */ /** The global silent flag. */
public static final String KEY_SILENT = "silent"; public static final String KEY_SILENT = "silent";
/** Verb requested by the user. Null if none specified, which will be an error. */ /** Verb requested by the user. Null if none specified, which will be an error. */
private String mVerbRequested; private String mVerbRequested;
/** Direct object requested by the user. Can be null. */ /** Direct object requested by the user. Can be null. */
@@ -66,7 +66,7 @@ public class CommandLineProcessor {
* </ul> * </ul>
*/ */
private final String[][] mActions; private final String[][] mActions;
private static final int ACTION_VERB_INDEX = 0; private static final int ACTION_VERB_INDEX = 0;
private static final int ACTION_OBJECT_INDEX = 1; private static final int ACTION_OBJECT_INDEX = 1;
private static final int ACTION_DESC_INDEX = 2; 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>(); private final HashMap<String, Arg> mArguments = new HashMap<String, Arg>();
/** Logger */ /** Logger */
private final ISdkLog mLog; private final ISdkLog mLog;
public CommandLineProcessor(ISdkLog logger, String[][] actions) { public CommandLineProcessor(ISdkLog logger, String[][] actions) {
mLog = logger; mLog = logger;
mActions = actions; mActions = actions;
@@ -95,7 +95,18 @@ public class CommandLineProcessor {
"This help.", "This help.",
false); 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 // Helpers to get flags values
@@ -113,7 +124,7 @@ public class CommandLineProcessor {
public boolean isHelpRequested() { public boolean isHelpRequested() {
return ((Boolean) getValue(GLOBAL_FLAG_VERB, NO_VERB_OBJECT, KEY_HELP)).booleanValue(); return ((Boolean) getValue(GLOBAL_FLAG_VERB, NO_VERB_OBJECT, KEY_HELP)).booleanValue();
} }
/** Returns the verb name from the command-line. Can be null. */ /** Returns the verb name from the command-line. Can be null. */
public String getVerb() { public String getVerb() {
return mVerbRequested; return mVerbRequested;
@@ -123,9 +134,9 @@ public class CommandLineProcessor {
public String getDirectObject() { public String getDirectObject() {
return mDirectObjectRequested; return mDirectObjectRequested;
} }
//------------------ //------------------
/** /**
* Raw access to parsed parameter values. * Raw access to parsed parameter values.
* <p/> * <p/>
@@ -133,10 +144,10 @@ public class CommandLineProcessor {
* command line are returned first. Otherwise one with a non-null value is returned. * command line are returned first. Otherwise one with a non-null value is returned.
* <p/> * <p/>
* Both a verb and a direct object filter can be specified. When they are non-null they limit * 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/> * <p/>
* If nothing has been found, return the last default value seen matching the filter. * 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 * @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 * verbs that match the direct object condition will be examined and the first
* value set will be used. * value set will be used.
@@ -153,7 +164,7 @@ public class CommandLineProcessor {
Arg arg = mArguments.get(key); Arg arg = mArguments.get(key);
return arg.getCurrentValue(); return arg.getCurrentValue();
} }
Object lastDefault = null; Object lastDefault = null;
for (Arg arg : mArguments.values()) { for (Arg arg : mArguments.values()) {
if (arg.getLongArg().equals(longFlagName)) { if (arg.getLongArg().equals(longFlagName)) {
@@ -169,7 +180,7 @@ public class CommandLineProcessor {
} }
} }
} }
return lastDefault; return lastDefault;
} }
@@ -191,7 +202,7 @@ public class CommandLineProcessor {
* Parses the command-line arguments. * Parses the command-line arguments.
* <p/> * <p/>
* This method will exit and not return if a parsing error arise. * This method will exit and not return if a parsing error arise.
* *
* @param args The arguments typically received by a main method. * @param args The arguments typically received by a main method.
*/ */
public void parseArgs(String[] args) { public void parseArgs(String[] args) {
@@ -209,7 +220,7 @@ public class CommandLineProcessor {
} else if (a.startsWith("-")) { } else if (a.startsWith("-")) {
arg = findShortArg(verb, directObject, a.substring(1)); arg = findShortArg(verb, directObject, a.substring(1));
} }
// No matching argument name found // No matching argument name found
if (arg == null) { if (arg == null) {
// Does it looks like a dashed parameter? // Does it looks like a dashed parameter?
@@ -217,7 +228,7 @@ public class CommandLineProcessor {
if (verb == null || directObject == null) { if (verb == null || directObject == null) {
// It looks like a dashed parameter and we don't have a a verb/object // It looks like a dashed parameter and we don't have a a verb/object
// set yet, the parameter was just given too early. // set yet, the parameter was just given too early.
needsHelp = String.format( needsHelp = String.format(
"Flag '%1$s' is not a valid global flag. Did you mean to specify it after the verb/object name?", "Flag '%1$s' is not a valid global flag. Did you mean to specify it after the verb/object name?",
a); a);
@@ -225,14 +236,14 @@ public class CommandLineProcessor {
} else { } else {
// It looks like a dashed parameter and but it is unknown by this // It looks like a dashed parameter and but it is unknown by this
// verb-object combination // verb-object combination
needsHelp = String.format( needsHelp = String.format(
"Flag '%1$s' is not valid for '%2$s %3$s'.", "Flag '%1$s' is not valid for '%2$s %3$s'.",
a, verb, directObject); a, verb, directObject);
return; return;
} }
} }
if (verb == null) { if (verb == null) {
// Fill verb first. Find it. // Fill verb first. Find it.
for (String[] actionDesc : mActions) { for (String[] actionDesc : mActions) {
@@ -241,7 +252,7 @@ public class CommandLineProcessor {
break; break;
} }
} }
// Error if it was not a valid verb // Error if it was not a valid verb
if (verb == null) { if (verb == null) {
needsHelp = String.format( needsHelp = String.format(
@@ -249,7 +260,7 @@ public class CommandLineProcessor {
a); a);
return; return;
} }
} else if (directObject == null) { } else if (directObject == null) {
// Then fill the direct object. Find it. // Then fill the direct object. Find it.
for (String[] actionDesc : mActions) { for (String[] actionDesc : mActions) {
@@ -266,20 +277,20 @@ public class CommandLineProcessor {
} }
} }
} }
// Error if it was not a valid object for that verb // Error if it was not a valid object for that verb
if (directObject == null) { if (directObject == null) {
needsHelp = String.format( needsHelp = String.format(
"Expected verb after global parameters but found '%1$s' instead.", "Expected verb after global parameters but found '%1$s' instead.",
a); a);
return; return;
} }
} }
} else if (arg != null) { } else if (arg != null) {
// This argument was present on the command line // This argument was present on the command line
arg.setInCommandLine(true); arg.setInCommandLine(true);
// Process keyword // Process keyword
String error = null; String error = null;
if (arg.getMode().needsExtra()) { if (arg.getMode().needsExtra()) {
@@ -287,11 +298,11 @@ public class CommandLineProcessor {
needsHelp = String.format("Missing argument for flag %1$s.", a); needsHelp = String.format("Missing argument for flag %1$s.", a);
return; return;
} }
error = arg.getMode().process(arg, args[i]); error = arg.getMode().process(arg, args[i]);
} else { } else {
error = arg.getMode().process(arg, null); error = arg.getMode().process(arg, null);
// If we just toggled help, we want to exit now without printing any error. // 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 // 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. // are the only flags that don't take parameters and help is a boolean.
@@ -302,18 +313,18 @@ public class CommandLineProcessor {
return; return;
} }
} }
if (error != null) { if (error != null) {
needsHelp = String.format("Invalid usage for flag %1$s: %2$s.", a, error); needsHelp = String.format("Invalid usage for flag %1$s: %2$s.", a, error);
return; return;
} }
} }
} }
if (needsHelp == null) { if (needsHelp == null) {
if (verb == null) { if (verb == null && !acceptLackOfVerb()) {
needsHelp = "Missing verb name."; needsHelp = "Missing verb name.";
} else { } else if (verb != null) {
if (directObject == null) { if (directObject == null) {
// Make sure this verb has an optional direct object // Make sure this verb has an optional direct object
for (String[] actionDesc : mActions) { for (String[] actionDesc : mActions) {
@@ -323,13 +334,13 @@ public class CommandLineProcessor {
break; break;
} }
} }
if (directObject == null) { if (directObject == null) {
needsHelp = String.format("Missing object name for verb '%1$s'.", verb); needsHelp = String.format("Missing object name for verb '%1$s'.", verb);
return; return;
} }
} }
// Validate that all mandatory arguments are non-null for this action // Validate that all mandatory arguments are non-null for this action
String missing = null; String missing = null;
boolean plural = false; boolean plural = false;
@@ -347,7 +358,7 @@ public class CommandLineProcessor {
} }
} }
} }
if (missing != null) { if (missing != null) {
needsHelp = String.format( needsHelp = String.format(
"The %1$s %2$s must be defined for action '%3$s %4$s'", "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. * Finds an {@link Arg} given an action name and a long flag name.
* @return The {@link Arg} found or null. * @return The {@link Arg} found or null.
@@ -409,23 +420,23 @@ public class CommandLineProcessor {
/** /**
* Prints the help/usage and exits. * 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 * @param args Arguments for String.format
*/ */
public void printHelpAndExit(String errorFormat, Object... args) { public void printHelpAndExit(String errorFormat, Object... args) {
printHelpAndExitForAction(null /*verb*/, null /*directObject*/, errorFormat, args); printHelpAndExitForAction(null /*verb*/, null /*directObject*/, errorFormat, args);
} }
/** /**
* Prints the help/usage and exits. * Prints the help/usage and exits.
* *
* @param verb If null, displays help for all verbs. If not null, display help only * @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. * for that specific verb. In all cases also displays general usage and action list.
* @param directObject If null, displays help for all verb objects. * @param directObject If null, displays help for all verb objects.
* If not null, displays help only for that specific action * If not null, displays help only for that specific action
* In all cases also display general usage and action list. * 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 * @param args Arguments for String.format
*/ */
public void printHelpAndExitForAction(String verb, String directObject, public void printHelpAndExitForAction(String verb, String directObject,
@@ -433,7 +444,7 @@ public class CommandLineProcessor {
if (errorFormat != null) { if (errorFormat != null) {
stderr(errorFormat, args); stderr(errorFormat, args);
} }
/* /*
* usage should fit in 80 columns * usage should fit in 80 columns
* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 * 12345678901234567890123456789012345678901234567890123456789012345678901234567890
@@ -448,14 +459,14 @@ public class CommandLineProcessor {
if (verb == null || directObject == null) { if (verb == null || directObject == null) {
stdout("\nValid actions are composed of a verb and an optional direct object:"); stdout("\nValid actions are composed of a verb and an optional direct object:");
for (String[] action : mActions) { for (String[] action : mActions) {
stdout("- %1$6s %2$-7s: %3$s", stdout("- %1$6s %2$-7s: %3$s",
action[ACTION_VERB_INDEX], action[ACTION_VERB_INDEX],
action[ACTION_OBJECT_INDEX], action[ACTION_OBJECT_INDEX],
action[ACTION_DESC_INDEX]); action[ACTION_DESC_INDEX]);
} }
} }
for (String[] action : mActions) { for (String[] action : mActions) {
if (verb == null || verb.equals(action[ACTION_VERB_INDEX])) { if (verb == null || verb.equals(action[ACTION_VERB_INDEX])) {
if (directObject == null || directObject.equals(action[ACTION_OBJECT_INDEX])) { if (directObject == null || directObject.equals(action[ACTION_OBJECT_INDEX])) {
@@ -468,7 +479,7 @@ public class CommandLineProcessor {
} }
} }
} }
exit(); exit();
} }
@@ -480,12 +491,12 @@ public class CommandLineProcessor {
for (Entry<String, Arg> entry : mArguments.entrySet()) { for (Entry<String, Arg> entry : mArguments.entrySet()) {
Arg arg = entry.getValue(); Arg arg = entry.getValue();
if (arg.getVerb().equals(verb) && arg.getDirectObject().equals(directObject)) { if (arg.getVerb().equals(verb) && arg.getDirectObject().equals(directObject)) {
String value = ""; String value = "";
String required = ""; String required = "";
if (arg.isMandatory()) { if (arg.isMandatory()) {
required = " [required]"; required = " [required]";
} else { } else {
if (arg.getDefaultValue() instanceof String[]) { if (arg.getDefaultValue() instanceof String[]) {
for (String v : (String[]) arg.getDefaultValue()) { for (String v : (String[]) arg.getDefaultValue()) {
@@ -504,7 +515,7 @@ public class CommandLineProcessor {
value = " [Default: " + value + "]"; value = " [Default: " + value + "]";
} }
} }
stdout(" -%1$s %2$-10s %3$s%4$s%5$s", stdout(" -%1$s %2$-10s %3$s%4$s%5$s",
arg.getShortArg(), arg.getShortArg(),
"--" + arg.getLongArg(), "--" + arg.getLongArg(),
@@ -514,14 +525,14 @@ public class CommandLineProcessor {
numOptions++; numOptions++;
} }
} }
if (numOptions == 0) { if (numOptions == 0) {
stdout(" No options"); stdout(" No options");
} }
} }
//---- //----
/** /**
* 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.
@@ -558,7 +569,7 @@ public class CommandLineProcessor {
} }
} }
}, },
/** Argument value is a String. Default value is a String[]. */ /** Argument value is a String. Default value is a String[]. */
ENUM { ENUM {
@Override @Override
@@ -574,7 +585,7 @@ public class CommandLineProcessor {
arg.setCurrentValue(extra); arg.setCurrentValue(extra);
return null; return null;
} }
if (desc.length() != 0) { if (desc.length() != 0) {
desc.append(", "); desc.append(", ");
} }
@@ -584,7 +595,7 @@ public class CommandLineProcessor {
return String.format("'%1$s' is not one of %2$s", extra, desc.toString()); return String.format("'%1$s' is not one of %2$s", extra, desc.toString());
} }
}, },
/** Argument value is a String. Default value is a null. */ /** Argument value is a String. Default value is a null. */
STRING { STRING {
@Override @Override
@@ -597,7 +608,7 @@ public class CommandLineProcessor {
return null; return null;
} }
}; };
/** /**
* Returns true if this mode requires an extra parameter. * Returns true if this mode requires an extra parameter.
*/ */
@@ -605,9 +616,9 @@ public class CommandLineProcessor {
/** /**
* Processes the flag for this argument. * Processes the flag for this argument.
* *
* @param arg The argument being processed. * @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. * @return An error string or null if there's no error.
*/ */
public abstract String process(Arg arg, String extra); 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. * 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 {
/** Verb for that argument. Never null. */ /** Verb for that argument. Never null. */
@@ -644,9 +655,9 @@ 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.
@@ -676,27 +687,27 @@ public class CommandLineProcessor {
mCurrentValue = mDefaultValue; mCurrentValue = mDefaultValue;
} }
} }
/** Return true if this argument is mandatory for this verb/directobject. */ /** Return true if this argument is mandatory for this verb/directobject. */
public boolean isMandatory() { public boolean isMandatory() {
return mMandatory; return mMandatory;
} }
/** Returns the 1-letter short name of the argument, e.g. -v. */ /** Returns the 1-letter short name of the argument, e.g. -v. */
public String getShortArg() { public String getShortArg() {
return mShortName; return mShortName;
} }
/** Returns the long name of the argument, e.g. --verbose. */ /** Returns the long name of the argument, e.g. --verbose. */
public String getLongArg() { public String getLongArg() {
return mLongName; return mLongName;
} }
/** Returns the description. Never null. */ /** Returns the description. Never null. */
public String getDescription() { public String getDescription() {
return mDescription; return mDescription;
} }
/** Returns the verb for that argument. Never null. */ /** Returns the verb for that argument. Never null. */
public String getVerb() { public String getVerb() {
return mVerb; return mVerb;
@@ -706,12 +717,12 @@ public class CommandLineProcessor {
public String getDirectObject() { public String getDirectObject() {
return mDirectObject; return mDirectObject;
} }
/** Returns the default value. Can be null. */ /** Returns the default value. Can be null. */
public Object getDefaultValue() { public Object getDefaultValue() {
return mDefaultValue; return mDefaultValue;
} }
/** Returns the current value. Initially set to the default value. Can be null. */ /** Returns the current value. Initially set to the default value. Can be null. */
public Object getCurrentValue() { public Object getCurrentValue() {
return mCurrentValue; return mCurrentValue;
@@ -721,26 +732,26 @@ public class CommandLineProcessor {
public void setCurrentValue(Object currentValue) { public void setCurrentValue(Object currentValue) {
mCurrentValue = currentValue; mCurrentValue = currentValue;
} }
/** 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;
} }
/** Returns true if the argument has been used on the command line. */ /** Returns true if the argument has been used on the command line. */
public boolean isInCommandLine() { public boolean isInCommandLine() {
return mInCommandLine; return mInCommandLine;
} }
/** Sets if the argument has been used on the command line. */ /** Sets if the argument has been used on the command line. */
public void setInCommandLine(boolean inCommandLine) { public void setInCommandLine(boolean inCommandLine) {
mInCommandLine = inCommandLine; mInCommandLine = inCommandLine;
} }
} }
/** /**
* 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.
@@ -756,11 +767,11 @@ public class CommandLineProcessor {
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;
} }
String key = verb + "/" + directObject + "/" + longName; String key = verb + "/" + directObject + "/" + longName;
mArguments.put(key, new Arg(mode, mandatory, mArguments.put(key, new Arg(mode, mandatory,
verb, directObject, shortName, longName, description, defaultValue)); verb, directObject, shortName, longName, description, defaultValue));
@@ -777,7 +788,7 @@ public class CommandLineProcessor {
/** /**
* Prints a line to stdout. * Prints a line to stdout.
* This is protected so that it can be overridden in unit tests. * This is protected so that it can be overridden in unit tests.
* *
* @param format The string to be formatted. Cannot be null. * @param format The string to be formatted. Cannot be null.
* @param args Format arguments. * @param args Format arguments.
*/ */
@@ -788,7 +799,7 @@ public class CommandLineProcessor {
/** /**
* Prints a line to stderr. * Prints a line to stderr.
* This is protected so that it can be overridden in unit tests. * This is protected so that it can be overridden in unit tests.
* *
* @param format The string to be formatted. Cannot be null. * @param format The string to be formatted. Cannot be null.
* @param args Format arguments. * @param args Format arguments.
*/ */

View File

@@ -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.avd.HardwareProperties.HardwareProperty;
import com.android.sdklib.internal.project.ProjectCreator; import com.android.sdklib.internal.project.ProjectCreator;
import com.android.sdklib.internal.project.ProjectCreator.OutputLevel; import com.android.sdklib.internal.project.ProjectCreator.OutputLevel;
import com.android.sdkuilib.repository.UpdaterWindow;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -46,11 +47,11 @@ class Main {
/** Java property that defines the working directory. On Windows the current working directory /** 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. */ * 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 WORKDIR = "com.android.sdkmanager.workdir";
private final static String[] BOOLEAN_YES_REPLIES = new String[] { "yes", "y" }; private final static String[] BOOLEAN_YES_REPLIES = new String[] { "yes", "y" };
private final static String[] BOOLEAN_NO_REPLIES = new String[] { "no", "n" }; private final static String[] BOOLEAN_NO_REPLIES = new String[] { "no", "n" };
/** Path to the SDK folder. This is the parent of {@link #TOOLSDIR}. */ /** Path to the SDK folder. This is the parent of {@link #TOOLSDIR}. */
private String mSdkFolder; private String mSdkFolder;
/** Logger object. Use this to print normal output, warnings or errors. */ /** Logger object. Use this to print normal output, warnings or errors. */
@@ -65,7 +66,7 @@ class Main {
public static void main(String[] args) { public static void main(String[] args) {
new Main().run(args); new Main().run(args);
} }
/** /**
* Runs the sdk manager app * Runs the sdk manager app
*/ */
@@ -124,7 +125,7 @@ class Main {
// for debugging, it's easier to override using the process environment // for debugging, it's easier to override using the process environment
toolsDirProp = System.getenv(TOOLSDIR); toolsDirProp = System.getenv(TOOLSDIR);
} }
if (toolsDirProp != null) { if (toolsDirProp != null) {
// got back a level for the SDK folder // got back a level for the SDK folder
File tools; File tools;
@@ -145,7 +146,7 @@ class Main {
errorAndExit("The tools directory property is not set, please make sure you are executing %1$s", 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 // 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 // Either it is a valid directory and mWorkDir is set to it's absolute canonical value
// or mWorkDir remains null. // or mWorkDir remains null.
@@ -172,19 +173,19 @@ class Main {
*/ */
private void parseSdk() { private void parseSdk() {
mSdkManager = SdkManager.createManager(mSdkFolder, mSdkLog); mSdkManager = SdkManager.createManager(mSdkFolder, mSdkLog);
if (mSdkManager == null) { if (mSdkManager == null) {
errorAndExit("Unable to parse SDK content."); errorAndExit("Unable to parse SDK content.");
} }
} }
/** /**
* Actually do an action... * Actually do an action...
*/ */
private void doAction() { private void doAction() {
String verb = mSdkCommandLine.getVerb(); String verb = mSdkCommandLine.getVerb();
String directObject = mSdkCommandLine.getDirectObject(); String directObject = mSdkCommandLine.getDirectObject();
if (SdkCommandLine.VERB_LIST.equals(verb)) { if (SdkCommandLine.VERB_LIST.equals(verb)) {
// list action. // list action.
if (SdkCommandLine.OBJECT_TARGET.equals(directObject)) { if (SdkCommandLine.OBJECT_TARGET.equals(directObject)) {
@@ -220,13 +221,28 @@ class Main {
SdkCommandLine.OBJECT_PROJECT.equals(directObject)) { SdkCommandLine.OBJECT_PROJECT.equals(directObject)) {
updateProject(); updateProject();
} else if (verb == null && directObject == null) {
showMainWindow();
} else { } else {
mSdkCommandLine.printHelpAndExit(null); 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() { private void createProject() {
// get the target and try to resolve it. // get the target and try to resolve it.
@@ -237,7 +253,7 @@ class Main {
SdkConstants.androidCmdName()); SdkConstants.androidCmdName());
} }
IAndroidTarget target = targets[targetId - 1]; IAndroidTarget target = targets[targetId - 1];
ProjectCreator creator = new ProjectCreator(mSdkFolder, ProjectCreator creator = new ProjectCreator(mSdkFolder,
mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE : mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
mSdkCommandLine.isSilent() ? OutputLevel.SILENT : mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
@@ -249,7 +265,7 @@ class Main {
String projectName = mSdkCommandLine.getParamName(); String projectName = mSdkCommandLine.getParamName();
String packageName = mSdkCommandLine.getParamProjectPackage(); String packageName = mSdkCommandLine.getParamProjectPackage();
String activityName = mSdkCommandLine.getParamProjectActivity(); String activityName = mSdkCommandLine.getParamProjectActivity();
if (projectName != null && if (projectName != null &&
!ProjectCreator.RE_PROJECT_NAME.matcher(projectName).matches()) { !ProjectCreator.RE_PROJECT_NAME.matcher(projectName).matches()) {
errorAndExit( 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() { private void updateProject() {
// get the target and try to resolve it. // get the target and try to resolve it.
@@ -299,7 +315,7 @@ class Main {
} }
target = targets[targetId - 1]; target = targets[targetId - 1];
} }
ProjectCreator creator = new ProjectCreator(mSdkFolder, ProjectCreator creator = new ProjectCreator(mSdkFolder,
mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE : mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
mSdkCommandLine.isSilent() ? OutputLevel.SILENT : mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
@@ -307,7 +323,7 @@ class Main {
mSdkLog); mSdkLog);
String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath()); String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
creator.updateProject(projectDir, creator.updateProject(projectDir,
target, target,
mSdkCommandLine.getParamName()); mSdkCommandLine.getParamName());
@@ -316,12 +332,12 @@ class Main {
/** /**
* Adjusts the project location to make it absolute & canonical relative to the * Adjusts the project location to make it absolute & canonical relative to the
* working directory, if any. * working directory, if any.
* *
* @return The project absolute path relative to {@link #mWorkDir} or the original * @return The project absolute path relative to {@link #mWorkDir} or the original
* newProjectLocation otherwise. * newProjectLocation otherwise.
*/ */
private String getProjectLocation(String newProjectLocation) { private String getProjectLocation(String newProjectLocation) {
// If the new project location is absolute, use it as-is // If the new project location is absolute, use it as-is
File projectDir = new File(newProjectLocation); File projectDir = new File(newProjectLocation);
if (projectDir.isAbsolute()) { if (projectDir.isAbsolute()) {
@@ -336,7 +352,7 @@ class Main {
// Combine then and get an absolute canonical directory // Combine then and get an absolute canonical directory
try { try {
projectDir = new File(mWorkDir, newProjectLocation).getCanonicalFile(); projectDir = new File(mWorkDir, newProjectLocation).getCanonicalFile();
return projectDir.getPath(); return projectDir.getPath();
} catch (IOException e) { } catch (IOException e) {
errorAndExit("Failed to combine working directory '%1$s' with project location '%2$s': %3$s", 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", mSdkLog.printf(" Based on Android %s (API level %d)\n",
target.getApiVersionName(), target.getApiVersionNumber()); target.getApiVersionName(), target.getApiVersionNumber());
// display the optional libraries. // display the optional libraries.
IOptionalLibrary[] libraries = target.getOptionalLibraries(); IOptionalLibrary[] libraries = target.getOptionalLibraries();
if (libraries != null) { if (libraries != null) {
@@ -384,7 +400,7 @@ class Main {
// get the target skins // get the target skins
displaySkinList(target, " Skins: "); displaySkinList(target, " Skins: ");
index++; index++;
} }
} }
@@ -405,7 +421,7 @@ class Main {
first = false; first = false;
} }
mSdkLog.printf(skin); mSdkLog.printf(skin);
if (skin.equals(defaultSkin)) { if (skin.equals(defaultSkin)) {
mSdkLog.printf(" (default)"); mSdkLog.printf(" (default)");
} }
@@ -415,7 +431,7 @@ class Main {
mSdkLog.printf("no skins.\n"); mSdkLog.printf("no skins.\n");
} }
} }
/** /**
* Displays the list of available AVDs. * Displays the list of available AVDs.
*/ */
@@ -445,7 +461,7 @@ class Main {
mSdkLog.printf(" Based on Android %s (API level %d)\n", target mSdkLog.printf(" Based on Android %s (API level %d)\n", target
.getApiVersionName(), target.getApiVersionNumber()); .getApiVersionName(), target.getApiVersionNumber());
} }
// display some extra values. // display some extra values.
Map<String, String> properties = info.getProperties(); Map<String, String> properties = info.getProperties();
if (properties != null) { if (properties != null) {
@@ -495,7 +511,7 @@ class Main {
// find a matching target // find a matching target
int targetId = mSdkCommandLine.getParamTargetId(); int targetId = mSdkCommandLine.getParamTargetId();
IAndroidTarget target = null; IAndroidTarget target = null;
if (targetId >= 1 && targetId <= mSdkManager.getTargets().length) { if (targetId >= 1 && targetId <= mSdkManager.getTargets().length) {
target = mSdkManager.getTargets()[targetId-1]; // target it is 1-based target = mSdkManager.getTargets()[targetId-1]; // target it is 1-based
} else { } else {
@@ -508,14 +524,14 @@ class Main {
AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog); AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
String avdName = mSdkCommandLine.getParamName(); String avdName = mSdkCommandLine.getParamName();
if (!AvdManager.RE_AVD_NAME.matcher(avdName).matches()) { if (!AvdManager.RE_AVD_NAME.matcher(avdName).matches()) {
errorAndExit( errorAndExit(
"AVD name '%1$s' contains invalid characters.\nAllowed characters are: %2$s", "AVD name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
avdName, AvdManager.CHARS_AVD_NAME); avdName, AvdManager.CHARS_AVD_NAME);
return; return;
} }
AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/); AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/);
if (info != null) { if (info != null) {
if (removePrevious) { if (removePrevious) {
@@ -550,7 +566,7 @@ class Main {
if (removePrevious) { if (removePrevious) {
oldAvdInfo = avdManager.getAvd(avdName, false /*validAvdOnly*/); oldAvdInfo = avdManager.getAvd(avdName, false /*validAvdOnly*/);
} }
// Validate skin is either default (empty) or NNNxMMM or a valid skin name. // Validate skin is either default (empty) or NNNxMMM or a valid skin name.
String skin = mSdkCommandLine.getParamSkin(); String skin = mSdkCommandLine.getParamSkin();
if (skin != null && skin.length() == 0) { if (skin != null && skin.length() == 0) {
@@ -566,7 +582,7 @@ class Main {
break; break;
} }
} }
// Is it NNNxMMM? // Is it NNNxMMM?
if (!valid) { if (!valid) {
valid = AvdManager.NUMERIC_SKIN_SIZE.matcher(skin).matches(); valid = AvdManager.NUMERIC_SKIN_SIZE.matcher(skin).matches();
@@ -578,7 +594,7 @@ class Main {
return; return;
} }
} }
AvdInfo newAvdInfo = avdManager.createAvd(avdFolder, AvdInfo newAvdInfo = avdManager.createAvd(avdFolder,
avdName, avdName,
target, target,
@@ -586,7 +602,7 @@ class Main {
mSdkCommandLine.getParamSdCard(), mSdkCommandLine.getParamSdCard(),
hardwareConfig, hardwareConfig,
removePrevious); removePrevious);
} catch (AndroidLocationException e) { } catch (AndroidLocationException e) {
errorAndExit(e.getMessage()); errorAndExit(e.getMessage());
} }
@@ -601,18 +617,18 @@ class Main {
String avdName = mSdkCommandLine.getParamName(); String avdName = mSdkCommandLine.getParamName();
AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog); AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/); AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/);
if (info == null) { if (info == null) {
errorAndExit("There is no Android Virtual Device named '%s'.", avdName); errorAndExit("There is no Android Virtual Device named '%s'.", avdName);
return; return;
} }
avdManager.deleteAvd(info, mSdkLog); avdManager.deleteAvd(info, mSdkLog);
} catch (AndroidLocationException e) { } catch (AndroidLocationException e) {
errorAndExit(e.getMessage()); errorAndExit(e.getMessage());
} }
} }
/** /**
* Moves an AVD. * Moves an AVD.
*/ */
@@ -621,12 +637,12 @@ class Main {
String avdName = mSdkCommandLine.getParamName(); String avdName = mSdkCommandLine.getParamName();
AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog); AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
AvdInfo info = avdManager.getAvd(avdName, true /*validAvdOnly*/); AvdInfo info = avdManager.getAvd(avdName, true /*validAvdOnly*/);
if (info == null) { if (info == null) {
errorAndExit("There is no valid Android Virtual Device named '%s'.", avdName); errorAndExit("There is no valid Android Virtual Device named '%s'.", avdName);
return; return;
} }
// This is a rename if there's a new name for the AVD // This is a rename if there's a new name for the AVD
String newName = mSdkCommandLine.getParamMoveNewName(); String newName = mSdkCommandLine.getParamMoveNewName();
if (newName != null && newName.equals(info.getName())) { if (newName != null && newName.equals(info.getName())) {
@@ -647,17 +663,17 @@ class Main {
} }
} catch (IOException e) { } catch (IOException e) {
// Fail to resolve canonical path. Fail now since a move operation might fail // 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()); errorAndExit(e.getMessage());
return; return;
} }
} }
if (newName == null && paramFolderPath == null) { if (newName == null && paramFolderPath == null) {
mSdkLog.warning("Move operation aborted: same AVD name, same canonical data path"); mSdkLog.warning("Move operation aborted: same AVD name, same canonical data path");
return; return;
} }
// If a rename was requested and no data move was requested, check if the original // 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 // data path is our default constructed from the AVD name. In this case we still want
// to rename that folder too. // to rename that folder too.
@@ -674,12 +690,12 @@ class Main {
newName + AvdManager.AVD_FOLDER_EXTENSION); newName + AvdManager.AVD_FOLDER_EXTENSION);
paramFolderPath = f.getCanonicalPath(); paramFolderPath = f.getCanonicalPath();
} catch (IOException e) { } 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()); errorAndExit(e.getMessage());
} }
} }
} }
// Check for conflicts // Check for conflicts
if (newName != null) { if (newName != null) {
if (avdManager.getAvd(newName, false /*validAvdOnly*/) != 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.", "There is already a file or directory at '%s'.\nUse --path to specify a different data folder.",
paramFolderPath); paramFolderPath);
} }
avdManager.moveAvd(info, newName, paramFolderPath, mSdkLog); avdManager.moveAvd(info, newName, paramFolderPath, mSdkLog);
} catch (AndroidLocationException e) { } catch (AndroidLocationException e) {
errorAndExit(e.getMessage()); errorAndExit(e.getMessage());
@@ -707,7 +723,7 @@ class Main {
errorAndExit(e.getMessage()); errorAndExit(e.getMessage());
} }
} }
/** /**
* Updates a broken AVD. * Updates a broken AVD.
*/ */
@@ -722,20 +738,20 @@ class Main {
errorAndExit(e.getMessage()); errorAndExit(e.getMessage());
} }
} }
/** /**
* Prompts the user to setup a hardware config for a Platform-based AVD. * 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 { private Map<String, String> promptForHardware(IAndroidTarget createTarget) throws IOException {
byte[] readLineBuffer = new byte[256]; byte[] readLineBuffer = new byte[256];
String result; String result;
String defaultAnswer = "no"; String defaultAnswer = "no";
mSdkLog.printf("%s is a basic Android platform.\n", createTarget.getName()); mSdkLog.printf("%s is a basic Android platform.\n", createTarget.getName());
mSdkLog.printf("Do you wish to create a custom hardware profile [%s]", mSdkLog.printf("Do you wish to create a custom hardware profile [%s]",
defaultAnswer); defaultAnswer);
result = readLine(readLineBuffer).trim(); result = readLine(readLineBuffer).trim();
// handle default: // handle default:
if (result.length() == 0) { if (result.length() == 0) {
@@ -746,17 +762,17 @@ class Main {
// no custom config. // no custom config.
return null; return null;
} }
mSdkLog.printf("\n"); // empty line mSdkLog.printf("\n"); // empty line
// get the list of possible hardware properties // get the list of possible hardware properties
File hardwareDefs = new File (mSdkFolder + File.separator + File hardwareDefs = new File (mSdkFolder + File.separator +
SdkConstants.OS_SDK_TOOLS_LIB_FOLDER, SdkConstants.FN_HARDWARE_INI); SdkConstants.OS_SDK_TOOLS_LIB_FOLDER, SdkConstants.FN_HARDWARE_INI);
List<HardwareProperty> list = HardwareProperties.parseHardwareDefinitions(hardwareDefs, List<HardwareProperty> list = HardwareProperties.parseHardwareDefinitions(hardwareDefs,
null /*sdkLog*/); null /*sdkLog*/);
HashMap<String, String> map = new HashMap<String, String>(); HashMap<String, String> map = new HashMap<String, String>();
for (int i = 0 ; i < list.size() ;) { for (int i = 0 ; i < list.size() ;) {
HardwareProperty property = list.get(i); HardwareProperty property = list.get(i);
@@ -768,13 +784,13 @@ class Main {
} }
String defaultValue = property.getDefault(); String defaultValue = property.getDefault();
if (defaultValue != null) { if (defaultValue != null) {
mSdkLog.printf("%s [%s]:", property.getName(), defaultValue); mSdkLog.printf("%s [%s]:", property.getName(), defaultValue);
} else { } else {
mSdkLog.printf("%s (%s):", property.getName(), property.getType()); mSdkLog.printf("%s (%s):", property.getName(), property.getType());
} }
result = readLine(readLineBuffer); result = readLine(readLineBuffer);
if (result.length() == 0) { if (result.length() == 0) {
if (defaultValue != null) { if (defaultValue != null) {
@@ -784,7 +800,7 @@ class Main {
} }
continue; continue;
} }
switch (property.getType()) { switch (property.getType()) {
case BOOLEAN: case BOOLEAN:
try { try {
@@ -816,13 +832,13 @@ class Main {
i++; // valid reply, move to next property i++; // valid reply, move to next property
break; break;
} }
mSdkLog.printf("\n"); // empty line mSdkLog.printf("\n"); // empty line
} }
return map; return map;
} }
/** /**
* Reads the line from the input stream. * Reads the line from the input stream.
* @param buffer * @param buffer
@@ -830,7 +846,7 @@ class Main {
*/ */
private String readLine(byte[] buffer) throws IOException { private String readLine(byte[] buffer) throws IOException {
int count = System.in.read(buffer); int count = System.in.read(buffer);
// is the input longer than the buffer? // is the input longer than the buffer?
if (count == buffer.length && buffer[count-1] != 10) { if (count == buffer.length && buffer[count-1] != 10) {
// create a new temp buffer // create a new temp buffer
@@ -838,7 +854,7 @@ class Main {
// and read the rest // and read the rest
String secondHalf = readLine(tempBuffer); String secondHalf = readLine(tempBuffer);
// return a concat of both // return a concat of both
return new String(buffer, 0, count) + secondHalf; return new String(buffer, 0, count) + secondHalf;
} }
@@ -847,16 +863,16 @@ class Main {
while (count > 0 && (buffer[count-1] == '\r' || buffer[count-1] == '\n')) { while (count > 0 && (buffer[count-1] == '\r' || buffer[count-1] == '\n')) {
count--; count--;
} }
return new String(buffer, 0, count); return new String(buffer, 0, count);
} }
/** /**
* Returns the boolean value represented by the string. * Returns the boolean value represented by the string.
* @throws IOException If the value is not a boolean string. * @throws IOException If the value is not a boolean string.
*/ */
private boolean getBooleanReply(String reply) throws IOException { private boolean getBooleanReply(String reply) throws IOException {
for (String valid : BOOLEAN_YES_REPLIES) { for (String valid : BOOLEAN_YES_REPLIES) {
if (valid.equalsIgnoreCase(reply)) { if (valid.equalsIgnoreCase(reply)) {
return true; return true;
@@ -871,9 +887,9 @@ class Main {
throw new IOException(String.format("%s is not a valid reply", reply)); throw new IOException(String.format("%s is not a valid reply", reply));
} }
private void errorAndExit(String format, Object...args) { private void errorAndExit(String format, Object...args) {
mSdkLog.error(null, format, args); mSdkLog.error(null, format, args);
System.exit(1); System.exit(1);
} }
} }

View File

@@ -72,7 +72,7 @@ public class SdkCommandLine extends CommandLineProcessor {
{ VERB_LIST, OBJECT_TARGET, { VERB_LIST, OBJECT_TARGET,
"Lists existing targets.", "Lists existing targets.",
OBJECT_TARGETS }, OBJECT_TARGETS },
{ VERB_CREATE, OBJECT_AVD, { VERB_CREATE, OBJECT_AVD,
"Creates a new Android Virtual Device." }, "Creates a new Android Virtual Device." },
{ VERB_MOVE, OBJECT_AVD, { VERB_MOVE, OBJECT_AVD,
@@ -81,58 +81,58 @@ public class SdkCommandLine extends CommandLineProcessor {
"Deletes an Android Virtual Device." }, "Deletes an Android Virtual Device." },
{ VERB_UPDATE, OBJECT_AVD, { VERB_UPDATE, OBJECT_AVD,
"Updates an Android Virtual Device to match the folders of a new SDK." }, "Updates an Android Virtual Device to match the folders of a new SDK." },
{ VERB_CREATE, OBJECT_PROJECT, { VERB_CREATE, OBJECT_PROJECT,
"Creates a new Android Project." }, "Creates a new Android Project." },
{ VERB_UPDATE, OBJECT_PROJECT, { VERB_UPDATE, OBJECT_PROJECT,
"Updates an Android Project (must have an AndroidManifest.xml)." }, "Updates an Android Project (must have an AndroidManifest.xml)." },
}; };
public SdkCommandLine(ISdkLog logger) { public SdkCommandLine(ISdkLog logger) {
super(logger, ACTIONS); super(logger, ACTIONS);
// --- 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);
@@ -140,51 +140,56 @@ 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);
} }
@Override
public boolean acceptLackOfVerb() {
return true;
}
// -- some helpers for generic action flags // -- some helpers for generic action flags
/** Helper to retrieve the --path value. */ /** Helper to retrieve the --path value. */
public String getParamLocationPath() { public String getParamLocationPath() {
return ((String) getValue(null, null, KEY_PATH)); return ((String) getValue(null, null, KEY_PATH));
} }
/** Helper to retrieve the --target id value. */ /** Helper to retrieve the --target id value. */
public int getParamTargetId() { public int getParamTargetId() {
return ((Integer) getValue(null, null, KEY_TARGET_ID)).intValue(); return ((Integer) getValue(null, null, KEY_TARGET_ID)).intValue();
@@ -194,7 +199,7 @@ public class SdkCommandLine extends CommandLineProcessor {
public String getParamName() { public String getParamName() {
return ((String) getValue(null, null, KEY_NAME)); return ((String) getValue(null, null, KEY_NAME));
} }
/** Helper to retrieve the --skin value. */ /** Helper to retrieve the --skin value. */
public String getParamSkin() { public String getParamSkin() {
return ((String) getValue(null, null, KEY_SKIN)); return ((String) getValue(null, null, KEY_SKIN));
@@ -204,7 +209,7 @@ public class SdkCommandLine extends CommandLineProcessor {
public String getParamSdCard() { public String getParamSdCard() {
return ((String) getValue(null, null, KEY_SDCARD)); return ((String) getValue(null, null, KEY_SDCARD));
} }
/** Helper to retrieve the --force flag. */ /** Helper to retrieve the --force flag. */
public boolean getFlagForce() { public boolean getFlagForce() {
return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue(); return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue();
@@ -219,7 +224,7 @@ public class SdkCommandLine extends CommandLineProcessor {
// -- some helpers for project action flags // -- some helpers for project action flags
/** Helper to retrieve the --package value. */ /** Helper to retrieve the --package value. */
public String getParamProjectPackage() { public String getParamProjectPackage() {
return ((String) getValue(null, OBJECT_PROJECT, KEY_PACKAGE)); return ((String) getValue(null, OBJECT_PROJECT, KEY_PACKAGE));

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/ANDROID_SWT"/> <classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/ANDROID_SWT"/>
<classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/> <classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008 The Android Open Source Project * Copyright (C) 2009 The Android Open Source Project
* *
* Licensed under the Eclipse Public License, Version 1.0 (the "License"); * Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ import org.eclipse.swt.widgets.TableItem;
* and finally use {@link #getSelected()} to retrieve the selection. * and finally use {@link #getSelected()} to retrieve the selection.
*/ */
public final class AvdSelector { public final class AvdSelector {
private AvdInfo[] mAvds; private AvdInfo[] mAvds;
private SelectionListener mSelectionListener; private SelectionListener mSelectionListener;
private Table mTable; private Table mTable;
@@ -84,28 +84,28 @@ public final class AvdSelector {
* This is invoked once when the button is created and cannot be changed later. * This is invoked once when the button is created and cannot be changed later.
*/ */
public String label(); public String label();
/** /**
* This is invoked just after the selection has changed to update the "enabled" * This is invoked just after the selection has changed to update the "enabled"
* state of the action. Implementation should use {@link AvdSelector#getSelected()}. * state of the action. Implementation should use {@link AvdSelector#getSelected()}.
*/ */
public boolean isEnabled(); public boolean isEnabled();
/** /**
* Run the action, invoked when the button is clicked. * Run the action, invoked when the button is clicked.
* *
* The caller's action is responsible for reloading the AVD list * The caller's action is responsible for reloading the AVD list
* using {@link AvdSelector#setAvds(AvdInfo[], IAndroidTarget)}. * using {@link AvdSelector#setAvds(AvdInfo[], IAndroidTarget)}.
*/ */
public void run(); public void run();
} }
/** /**
* Creates a new SDK Target Selector, and fills it with a list of {@link AvdInfo}, filtered * Creates a new SDK Target Selector, and fills it with a list of {@link AvdInfo}, filtered
* by a {@link IAndroidTarget}. * by a {@link IAndroidTarget}.
* <p/>Only the {@link AvdInfo} able to run application developed for the given * <p/>Only the {@link AvdInfo} able to run application developed for the given
* {@link IAndroidTarget} will be displayed. * {@link IAndroidTarget} will be displayed.
* *
* @param parent The parent composite where the selector will be added. * @param parent The parent composite where the selector will be added.
* @param avds The list of AVDs. This is <em>not</em> copied, the caller must not modify. * @param avds The list of AVDs. This is <em>not</em> copied, the caller must not modify.
* It can be null. * It can be null.
@@ -149,10 +149,10 @@ public final class AvdSelector {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
super.widgetSelected(e); super.widgetSelected(e);
mExtraAction.run(); mExtraAction.run();
} }
}); });
} }
// create the table columns // create the table columns
final TableColumn column0 = new TableColumn(mTable, SWT.NONE); final TableColumn column0 = new TableColumn(mTable, SWT.NONE);
column0.setText("AVD Name"); column0.setText("AVD Name");
@@ -171,7 +171,7 @@ public final class AvdSelector {
/** /**
* Creates a new SDK Target Selector, and fills it with a list of {@link AvdInfo}. * Creates a new SDK Target Selector, and fills it with a list of {@link AvdInfo}.
* *
* @param parent The parent composite where the selector will be added. * @param parent The parent composite where the selector will be added.
* @param avds The list of AVDs. This is <em>not</em> copied, the caller must not modify. * @param avds The list of AVDs. This is <em>not</em> copied, the caller must not modify.
* It can be null. * It can be null.
@@ -187,7 +187,7 @@ public final class AvdSelector {
/** /**
* Creates a new SDK Target Selector, and fills it with a list of {@link AvdInfo}. * Creates a new SDK Target Selector, and fills it with a list of {@link AvdInfo}.
* *
* @param parent The parent composite where the selector will be added. * @param parent The parent composite where the selector will be added.
* @param extraAction When non-null, displays an extra action button. * @param extraAction When non-null, displays an extra action button.
* @param selectionMode One of {@link SelectionMode#SELECT} or {@link SelectionMode#CHECK} * @param selectionMode One of {@link SelectionMode#SELECT} or {@link SelectionMode#CHECK}
@@ -200,7 +200,7 @@ public final class AvdSelector {
/** /**
* Sets the table grid layout data. * Sets the table grid layout data.
* *
* @param heightHint If > 0, the height hint is set to the requested value. * @param heightHint If > 0, the height hint is set to the requested value.
*/ */
public void setTableHeightHint(int heightHint) { public void setTableHeightHint(int heightHint) {
@@ -215,26 +215,26 @@ public final class AvdSelector {
data.verticalAlignment = GridData.FILL; data.verticalAlignment = GridData.FILL;
mTable.setLayoutData(data); mTable.setLayoutData(data);
} }
/** /**
* Sets a new set of AVD, with an optional filter. * Sets a new set of AVD, with an optional filter.
* Tries to keep the selection. * Tries to keep the selection.
* <p/> * <p/>
* This must be called from the UI thread. * This must be called from the UI thread.
* *
* *
* @param avds The list of AVDs. This is <em>not</em> copied, the caller must not modify. * @param avds The list of AVDs. This is <em>not</em> copied, the caller must not modify.
* It can be null. * It can be null.
* @param filter An IAndroidTarget. If non-null, only AVD whose target are compatible with the * @param filter An IAndroidTarget. If non-null, only AVD whose target are compatible with the
* filter target will displayed an available for selection. * filter target will displayed an available for selection.
*/ */
public void setAvds(AvdInfo[] avds, IAndroidTarget filter) { public void setAvds(AvdInfo[] avds, IAndroidTarget filter) {
AvdInfo selected = getSelected(); AvdInfo selected = getSelected();
mAvds = avds; mAvds = avds;
fillTable(mTable, filter); fillTable(mTable, filter);
setSelection(selected); setSelection(selected);
} }
@@ -256,19 +256,19 @@ public final class AvdSelector {
* The {@link TableItem#getData()} contains an {@link IAndroidTarget}. * The {@link TableItem#getData()} contains an {@link IAndroidTarget}.
* <p/> * <p/>
* It is recommended that the caller uses the {@link #getSelected()} method instead. * It is recommended that the caller uses the {@link #getSelected()} method instead.
* *
* @param selectionListener The new listener or null to remove it. * @param selectionListener The new listener or null to remove it.
*/ */
public void setSelectionListener(SelectionListener selectionListener) { public void setSelectionListener(SelectionListener selectionListener) {
mSelectionListener = selectionListener; mSelectionListener = selectionListener;
} }
/** /**
* Sets the current target selection. * Sets the current target selection.
* <p/> * <p/>
* If the selection is actually changed, this will invoke the selection listener * If the selection is actually changed, this will invoke the selection listener
* (if any) with a null event. * (if any) with a null event.
* *
* @param target the target to be selected. Use null to deselect everything. * @param target the target to be selected. Use null to deselect everything.
* @return true if the target could be selected, false otherwise. * @return true if the target could be selected, false otherwise.
*/ */
@@ -288,7 +288,7 @@ public final class AvdSelector {
} }
break; break;
} }
index++; index++;
} else if (mSelectionMode == SelectionMode.CHECK){ } else if (mSelectionMode == SelectionMode.CHECK){
@@ -304,21 +304,21 @@ public final class AvdSelector {
} }
} }
} }
if (modified && mSelectionListener != null) { if (modified && mSelectionListener != null) {
mSelectionListener.widgetSelected(null); mSelectionListener.widgetSelected(null);
} }
if (mExtraAction != null && mExtraActionButton != null) { if (mExtraAction != null && mExtraActionButton != null) {
mExtraActionButton.setEnabled(mExtraAction.isEnabled()); mExtraActionButton.setEnabled(mExtraAction.isEnabled());
} }
return found; return found;
} }
/** /**
* Returns the currently selected item. * Returns the currently selected item.
* *
* @return The currently selected item or null. * @return The currently selected item or null.
*/ */
public AvdInfo getSelected() { public AvdInfo getSelected() {
@@ -342,7 +342,7 @@ public final class AvdSelector {
* Enables the receiver if the argument is true, and disables it otherwise. * Enables the receiver if the argument is true, and disables it otherwise.
* A disabled control is typically not selectable from the user interface * A disabled control is typically not selectable from the user interface
* and draws with an inactive or "grayed" look. * and draws with an inactive or "grayed" look.
* *
* @param enabled the new enabled state. * @param enabled the new enabled state.
*/ */
public void setEnabled(boolean enabled) { public void setEnabled(boolean enabled) {
@@ -366,7 +366,7 @@ public final class AvdSelector {
@Override @Override
public void controlResized(ControlEvent e) { public void controlResized(ControlEvent e) {
Rectangle r = table.getClientArea(); Rectangle r = table.getClientArea();
column0.setWidth(r.width * 30 / 100); // 30% column0.setWidth(r.width * 30 / 100); // 30%
column1.setWidth(r.width * 45 / 100); // 45% column1.setWidth(r.width * 45 / 100); // 45%
column2.setWidth(r.width * 10 / 100); // 10% column2.setWidth(r.width * 10 / 100); // 10%
column3.setWidth(r.width * 15 / 100); // 15% column3.setWidth(r.width * 15 / 100); // 15%
@@ -382,7 +382,7 @@ public final class AvdSelector {
private void setupSelectionListener(final Table table) { private void setupSelectionListener(final Table table) {
// Add a selection listener that will check/uncheck items when they are double-clicked // Add a selection listener that will check/uncheck items when they are double-clicked
table.addSelectionListener(new SelectionListener() { table.addSelectionListener(new SelectionListener() {
/** /**
* Handles single-click selection on the table. * Handles single-click selection on the table.
* {@inheritDoc} * {@inheritDoc}
@@ -397,7 +397,7 @@ public final class AvdSelector {
if (mSelectionListener != null) { if (mSelectionListener != null) {
mSelectionListener.widgetSelected(e); mSelectionListener.widgetSelected(e);
} }
if (mExtraAction != null && mExtraActionButton != null) { if (mExtraAction != null && mExtraActionButton != null) {
mExtraActionButton.setEnabled(mExtraAction.isEnabled()); mExtraActionButton.setEnabled(mExtraAction.isEnabled());
} }
@@ -406,9 +406,9 @@ public final class AvdSelector {
/** /**
* Handles double-click selection on the table. * Handles double-click selection on the table.
* Note that the single-click handler will probably already have been called. * Note that the single-click handler will probably already have been called.
* *
* On double-click, <em>always</em> check the table item. * On double-click, <em>always</em> check the table item.
* *
* {@inheritDoc} * {@inheritDoc}
*/ */
public void widgetDefaultSelected(SelectionEvent e) { public void widgetDefaultSelected(SelectionEvent e) {
@@ -424,7 +424,7 @@ public final class AvdSelector {
if (mSelectionListener != null) { if (mSelectionListener != null) {
mSelectionListener.widgetDefaultSelected(e); mSelectionListener.widgetDefaultSelected(e);
} }
if (mExtraAction != null && mExtraActionButton != null) { if (mExtraAction != null && mExtraActionButton != null) {
mExtraActionButton.setEnabled(mExtraAction.isEnabled()); mExtraActionButton.setEnabled(mExtraAction.isEnabled());
} }
@@ -437,7 +437,7 @@ public final class AvdSelector {
private void enforceSingleSelection(TableItem item) { private void enforceSingleSelection(TableItem item) {
if (mSelectionMode == SelectionMode.SELECT) { if (mSelectionMode == SelectionMode.SELECT) {
// pass // pass
} else if (mSelectionMode == SelectionMode.CHECK) { } else if (mSelectionMode == SelectionMode.CHECK) {
if (item.getChecked()) { if (item.getChecked()) {
Table parentTable = item.getParent(); Table parentTable = item.getParent();
@@ -478,7 +478,7 @@ public final class AvdSelector {
} }
} }
} }
if (table.getItemCount() == 0) { if (table.getItemCount() == 0) {
table.setEnabled(false); table.setEnabled(false);
TableItem item = new TableItem(table, SWT.NONE); TableItem item = new TableItem(table, SWT.NONE);
@@ -498,36 +498,36 @@ public final class AvdSelector {
*/ */
private void setupTooltip(final Table table) { private void setupTooltip(final Table table) {
/* /*
* Reference: * Reference:
* http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java?view=markup * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java?view=markup
*/ */
final Listener listener = new Listener() { final Listener listener = new Listener() {
public void handleEvent(Event event) { public void handleEvent(Event event) {
switch(event.type) { switch(event.type) {
case SWT.KeyDown: case SWT.KeyDown:
case SWT.MouseExit: case SWT.MouseExit:
case SWT.MouseDown: case SWT.MouseDown:
return; return;
case SWT.MouseHover: case SWT.MouseHover:
updateDescription(table.getItem(new Point(event.x, event.y))); updateDescription(table.getItem(new Point(event.x, event.y)));
break; break;
case SWT.Selection: case SWT.Selection:
if (event.item instanceof TableItem) { if (event.item instanceof TableItem) {
updateDescription((TableItem) event.item); updateDescription((TableItem) event.item);
} }
break; break;
default: default:
return; return;
} }
} }
}; };
table.addListener(SWT.Dispose, listener); table.addListener(SWT.Dispose, listener);
table.addListener(SWT.KeyDown, listener); table.addListener(SWT.KeyDown, listener);
table.addListener(SWT.MouseMove, listener); table.addListener(SWT.MouseMove, listener);

View File

@@ -0,0 +1,222 @@
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.sdkuilib.repository;
import org.eclipse.jface.viewers.CheckboxTreeViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableTree;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
public class UpdaterWindow {
protected Shell mshlAndroidSdkUpdater;
private TabFolder tabFolder;
private TabItem mtbtmInstalledPackages;
private Composite compositeInst;
private TabItem mtbtmAvailablePackages;
private Composite compositeAvail;
private Text text;
private Button mbtnBrowse;
private Label mlblSdkLocation;
private Group mgrpDescription;
private Composite composite_3;
private Button mbtnUpdate;
private Button mbtnDelete;
private Button mbtnHomePage;
private Label placeholder1;
private Label placeholder2;
private Label mlblInstalledPackages;
private TableTree tableTree;
private Tree tree;
private Button mbtnRemoveSite;
private Button mbtnAddSite;
private Label placeholder3;
private Button mbtnRefresh;
private Button mbtnInstallSelected;
private Group mgrpDescription_1;
private Table table;
private TableColumn mtblclmnSummary;
private TableColumn mtblclmnApiLevel;
private TableColumn mtblclmnRevision;
private TreeColumn mtrclmnSummary;
private TreeColumn mtrclmnApiLevel;
private TreeColumn mtrclmnRevision;
private TreeColumn mtrclmnOs;
private TreeColumn mtrclmnInstalled;
/**
* Open the window.
* @wbp.parser.entryPoint
*/
public void open() {
Display display = Display.getDefault();
createContents();
mshlAndroidSdkUpdater.open();
mshlAndroidSdkUpdater.layout();
while (!mshlAndroidSdkUpdater.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
/**
* Create contents of the window.
*/
protected void createContents() {
mshlAndroidSdkUpdater = new Shell();
mshlAndroidSdkUpdater.setMinimumSize(new Point(200, 50));
mshlAndroidSdkUpdater.setLayout(new GridLayout(1, false));
mshlAndroidSdkUpdater.setSize(633, 433);
mshlAndroidSdkUpdater.setText("Android SDK Updater");
tabFolder = new TabFolder(mshlAndroidSdkUpdater, SWT.NONE);
tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
mtbtmInstalledPackages = new TabItem(tabFolder, SWT.NONE);
mtbtmInstalledPackages.setText("Installed Packages");
compositeInst = new Composite(tabFolder, SWT.NONE);
compositeInst.setLayout(new GridLayout(3, false));
mtbtmInstalledPackages.setControl(compositeInst);
mlblSdkLocation = new Label(compositeInst, SWT.NONE);
mlblSdkLocation.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
mlblSdkLocation.setText("SDK Location:");
text = new Text(compositeInst, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
mbtnBrowse = new Button(compositeInst, SWT.NONE);
mbtnBrowse.setText("Browse...");
mlblInstalledPackages = new Label(compositeInst, SWT.NONE);
mlblInstalledPackages.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
mlblInstalledPackages.setText("Installed Packages:");
TableViewer tableInstalledPackage = new TableViewer(compositeInst, SWT.BORDER | SWT.FULL_SELECTION);
table = tableInstalledPackage.getTable();
table.setHeaderVisible(true);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
mtblclmnSummary = new TableColumn(table, SWT.NONE);
mtblclmnSummary.setWidth(377);
mtblclmnSummary.setText("Summary");
mtblclmnApiLevel = new TableColumn(table, SWT.NONE);
mtblclmnApiLevel.setWidth(100);
mtblclmnApiLevel.setText("API Level");
mtblclmnRevision = new TableColumn(table, SWT.NONE);
mtblclmnRevision.setWidth(100);
mtblclmnRevision.setText("Revision");
mgrpDescription = new Group(compositeInst, SWT.NONE);
mgrpDescription.setText("Description");
mgrpDescription.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
composite_3 = new Composite(compositeInst, SWT.NONE);
composite_3.setLayout(new GridLayout(5, false));
composite_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
mbtnUpdate = new Button(composite_3, SWT.NONE);
mbtnUpdate.setText("Update...");
placeholder1 = new Label(composite_3, SWT.NONE);
placeholder1.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
mbtnDelete = new Button(composite_3, SWT.NONE);
mbtnDelete.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
mbtnDelete.setText("Delete...");
placeholder2 = new Label(composite_3, SWT.NONE);
placeholder2.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
mbtnHomePage = new Button(composite_3, SWT.NONE);
mbtnHomePage.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
mbtnHomePage.setText("Home Page...");
mtbtmAvailablePackages = new TabItem(tabFolder, SWT.NONE);
mtbtmAvailablePackages.setText("Available Packages");
compositeAvail = new Composite(tabFolder, SWT.NONE);
compositeAvail.setLayout(new GridLayout(5, false));
mtbtmAvailablePackages.setControl(compositeAvail);
CheckboxTreeViewer checkboxTreeAvailablePackages = new CheckboxTreeViewer(compositeAvail, SWT.BORDER);
tree = checkboxTreeAvailablePackages.getTree();
tree.setHeaderVisible(true);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 5, 1));
mtrclmnSummary = new TreeColumn(tree, SWT.NONE);
mtrclmnSummary.setWidth(289);
mtrclmnSummary.setText("Summary");
mtrclmnApiLevel = new TreeColumn(tree, SWT.NONE);
mtrclmnApiLevel.setWidth(66);
mtrclmnApiLevel.setText("API Level");
mtrclmnRevision = new TreeColumn(tree, SWT.NONE);
mtrclmnRevision.setWidth(63);
mtrclmnRevision.setText("Revision");
mtrclmnOs = new TreeColumn(tree, SWT.NONE);
mtrclmnOs.setWidth(100);
mtrclmnOs.setText("OS/Arch");
mtrclmnInstalled = new TreeColumn(tree, SWT.NONE);
mtrclmnInstalled.setWidth(59);
mtrclmnInstalled.setText("Installed");
mgrpDescription_1 = new Group(compositeAvail, SWT.NONE);
mgrpDescription_1.setText("Description");
mgrpDescription_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 5, 1));
mbtnAddSite = new Button(compositeAvail, SWT.NONE);
mbtnAddSite.setText("Add Site...");
mbtnRemoveSite = new Button(compositeAvail, SWT.NONE);
mbtnRemoveSite.setText("Delete Site...");
placeholder3 = new Label(compositeAvail, SWT.NONE);
placeholder3.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1));
mbtnRefresh = new Button(compositeAvail, SWT.NONE);
mbtnRefresh.setText("Refresh");
mbtnInstallSelected = new Button(compositeAvail, SWT.NONE);
mbtnInstallSelected.setText("Install Selected");
}
}