diff options
author | Raphael <raphael@google.com> | 2011-09-15 22:07:39 -0700 |
---|---|---|
committer | Raphael <raphael@google.com> | 2011-09-16 13:02:09 -0700 |
commit | 2c4c6561c01683bda2681a1449e6a3c0915e5d6a (patch) | |
tree | fa09561a30eac249382c67cf00aac8aea2b4c5c8 /sdkmanager/app/src | |
parent | 1bf5cb8ed2172d07e2a61ae9ed58f2d252b9d6ac (diff) | |
download | sdk-2c4c6561c01683bda2681a1449e6a3c0915e5d6a.zip sdk-2c4c6561c01683bda2681a1449e6a3c0915e5d6a.tar.gz sdk-2c4c6561c01683bda2681a1449e6a3c0915e5d6a.tar.bz2 |
SDK Manager: make 'list sdk' ids deterministic.
This changes 'android list sdk' to output deterministic
install IDs. These IDs can then be give to 'android update sdk'.
Example of usage:
$ android list sdk --extended
Refresh Sources: [...]
----------
id: 2 or "android-13"
Type: Platform
Desc: Android SDK Platform 3.2, revision 1
[...]
----------
id: 41 or "extra-google-usb_driver"
Type: Extra
Desc: USB Driver for Windows, revision 4
$ android update sdk --no-ui --filter android-13,extra-google-usb_driver
=> This installs the platform API 13 and the USB Driver.
SDK Bug: 19504
Change-Id: I3109c90371d292df4e9cf845208bf8efe774233f
Diffstat (limited to 'sdkmanager/app/src')
3 files changed, 31 insertions, 83 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java index 86c6141..e60fba3 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java +++ b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java @@ -16,9 +16,8 @@ package com.android.sdkmanager; -import com.android.annotations.VisibleForTesting; -import com.android.annotations.VisibleForTesting.Visibility; import com.android.sdklib.ISdkLog; +import com.android.sdklib.util.LineUtil; import java.util.HashMap; import java.util.Map.Entry; @@ -880,7 +879,7 @@ class CommandLineProcessor { */ protected void stdout(String format, Object...args) { String output = String.format(format, args); - output = reflowLine(output); + output = LineUtil.reflowLine(output); mLog.printf("%s\n", output); //$NON-NLS-1$ } @@ -894,74 +893,4 @@ class CommandLineProcessor { protected void stderr(String format, Object...args) { mLog.error(null, format, args); } - - - /** - * Reformats the line so that it fits in 78 characters max. - * <p/> - * When wrapping the second line and following, prefix the string with a number of - * spaces. This will use the first colon (:) to determine the prefix size - * or use 4 as a minimum if there are no colons in the string. - * - * @param line The line to reflow. Must be non-null. - * @return A new line to print as-is, that contains \n as needed. - */ - @VisibleForTesting(visibility=Visibility.PRIVATE) - protected String reflowLine(String line) { - final int maxLen = 78; - - // Most of time the line will fit in the given length and this will be a no-op - int n = line.length(); - if (n <= maxLen) { - return line; - } - - int prefixSize = line.indexOf(':') + 1; - // If there' some spacing after the colon, use the same when wrapping - if (prefixSize > 0 && prefixSize < maxLen) { - while(prefixSize < n && line.charAt(prefixSize) == ' ') { - prefixSize++; - } - } else { - prefixSize = 4; - } - String prefix = String.format( - "%-" + Integer.toString(prefixSize) + "s", //$NON-NLS-1$ //$NON-NLS-2$ - " "); //$NON-NLS-1$ - - StringBuilder output = new StringBuilder(n + prefixSize); - - while (n > 0) { - if (n <= maxLen) { - output.append(line); - break; - } - - // Line is longer than the max length, find the first character before and after - // the whitespace where we want to break the line. - int posNext = maxLen; - while (posNext < n && line.charAt(posNext) == ' ') { - posNext++; - } - while (posNext > 0 && line.charAt(posNext - 1) != ' ') { - posNext--; - } - - if (posNext == 0 || posNext >= n) { - // We found no whitespace separator. This should generally not occur. - posNext = maxLen; - } - int posPrev = posNext; - while (posPrev > 0 && line.charAt(posPrev - 1) == ' ') { - posPrev--; - } - - output.append(line.substring(0, posPrev)).append('\n'); - line = prefix + line.substring(posNext); - n -= posNext; - } - - return output.toString(); - } - } diff --git a/sdkmanager/app/src/com/android/sdkmanager/Main.java b/sdkmanager/app/src/com/android/sdkmanager/Main.java index f699773..0e4b1f8 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/Main.java +++ b/sdkmanager/app/src/com/android/sdkmanager/Main.java @@ -35,6 +35,8 @@ import com.android.sdklib.internal.project.ProjectCreator; import com.android.sdklib.internal.project.ProjectProperties; import com.android.sdklib.internal.project.ProjectCreator.OutputLevel; import com.android.sdklib.internal.project.ProjectProperties.PropertyType; +import com.android.sdklib.internal.repository.PlatformToolPackage; +import com.android.sdklib.internal.repository.ToolPackage; import com.android.sdklib.repository.SdkAddonConstants; import com.android.sdklib.repository.SdkRepoConstants; import com.android.sdklib.xml.AndroidXPathFactory; @@ -232,13 +234,7 @@ public class Main { displayAvdList(); } else if (SdkCommandLine.OBJECT_SDK.equals(directObject)) { - // We don't support a specific GUI for this. - // If the user forces a gui mode to see this list, simply launch the regular GUI. - if (!mSdkCommandLine.getFlagNoUI(verb)) { - showSdkManagerWindow(false /*autoUpdate*/); - } else { - displayRemoteSdkListNoUI(); - } + displayRemoteSdkListNoUI(); } else { displayTargetList(); @@ -367,12 +363,13 @@ public class Main { boolean force = mSdkCommandLine.getFlagForce(); boolean useHttp = mSdkCommandLine.getFlagNoHttps(); boolean obsolete = mSdkCommandLine.getFlagObsolete(); + boolean extended = mSdkCommandLine.getFlagExtended(); String proxyHost = mSdkCommandLine.getParamProxyHost(); String proxyPort = mSdkCommandLine.getParamProxyPort(); SdkUpdaterNoWindow upd = new SdkUpdaterNoWindow(mOsSdkFolder, mSdkManager, mSdkLog, force, useHttp, proxyHost, proxyPort); - upd.listRemotePackages(obsolete); + upd.listRemotePackages(obsolete, extended); } /** @@ -430,6 +427,16 @@ public class Main { continue; } + if (t.indexOf('-') > 0 || + t.equals(ToolPackage.INSTALL_ID) || + t.equals(PlatformToolPackage.INSTALL_ID)) { + // Heuristic: if the filter name contains a dash, it is probably + // a variable package install id. Since we haven't loaded the remote + // repositories we can't validate it yet, so just accept it. + pkgFilter.add(t); + continue; + } + if (t.replaceAll("[0-9]+", "").length() == 0) { //$NON-NLS-1$ //$NON-NLS-2$ // If the filter argument *only* contains digits, accept it. // It's probably an index for the remote repository list, diff --git a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java index 64891b9..387cd6f 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java +++ b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java @@ -79,6 +79,7 @@ class SdkCommandLine extends CommandLineProcessor { public static final String KEY_PROXY_HOST = "proxy-host"; //$NON-NLS-1$ public static final String KEY_DRY_MODE = "dry-mode"; //$NON-NLS-1$ public static final String KEY_OBSOLETE = "obsolete"; //$NON-NLS-1$ + public static final String KEY_EXTENDED = "extended"; //$NON-NLS-1$ public static final String KEY_SNAPSHOT = "snapshot"; //$NON-NLS-1$ public static final String KEY_COMPACT = "compact"; //$NON-NLS-1$ public static final String KEY_EOL_NULL = "null"; //$NON-NLS-1$ @@ -250,7 +251,12 @@ class SdkCommandLine extends CommandLineProcessor { define(Mode.BOOLEAN, false, VERB_LIST, OBJECT_SDK, "o", KEY_OBSOLETE, //$NON-NLS-1$ - "Installs obsolete packages.", + "Lists all packages (including obsolete and installed ones)", + false); + + define(Mode.BOOLEAN, false, + VERB_LIST, OBJECT_SDK, "e", KEY_EXTENDED, //$NON-NLS-1$ + "Displays extended details on each package", false); // --- update sdk --- @@ -281,7 +287,8 @@ class SdkCommandLine extends CommandLineProcessor { define(Mode.STRING, false, VERB_UPDATE, OBJECT_SDK, "t", KEY_FILTER, //$NON-NLS-1$ "A filter that limits the update to the specified types of packages in the form of a comma-separated list of " + - Arrays.toString(SdkRepoConstants.NODES), + Arrays.toString(SdkRepoConstants.NODES) + + ". This also accepts the identifiers returned by 'list sdk --extended'.", null); define(Mode.BOOLEAN, false, @@ -530,6 +537,11 @@ class SdkCommandLine extends CommandLineProcessor { return ((Boolean) getValue(null, null, KEY_OBSOLETE)).booleanValue(); } + /** Helper to retrieve the --extended flag. */ + public boolean getFlagExtended() { + return ((Boolean) getValue(null, null, KEY_EXTENDED)).booleanValue(); + } + /** Helper to retrieve the --filter value. */ public String getParamFilter() { return ((String) getValue(null, null, KEY_FILTER)); |