summaryrefslogtreecommitdiffstats
path: root/tools/sdkmanager/app
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2009-11-17 15:11:59 -0800
committerXavier Ducrohet <xav@android.com>2009-11-17 15:17:25 -0800
commit19cb54ea7da270254852dcd1f476fe1becf1e8a9 (patch)
treeab5ea192a5354547035e8b0840d06b6496a88d7b /tools/sdkmanager/app
parentf4c63fae0c6d0654ab49e05b3292e218f82f97d8 (diff)
downloadandroid_development-19cb54ea7da270254852dcd1f476fe1becf1e8a9.tar.gz
android_development-19cb54ea7da270254852dcd1f476fe1becf1e8a9.tar.bz2
android_development-19cb54ea7da270254852dcd1f476fe1becf1e8a9.zip
Remove components that were moved to sdk.git and update build scripts.
Diffstat (limited to 'tools/sdkmanager/app')
-rw-r--r--tools/sdkmanager/app/.classpath12
-rw-r--r--tools/sdkmanager/app/.project19
-rw-r--r--tools/sdkmanager/app/Android.mk5
-rw-r--r--tools/sdkmanager/app/etc/Android.mk8
-rwxr-xr-xtools/sdkmanager/app/etc/android117
-rwxr-xr-xtools/sdkmanager/app/etc/android.bat70
-rw-r--r--tools/sdkmanager/app/etc/manifest.txt1
-rw-r--r--tools/sdkmanager/app/src/Android.mk22
-rw-r--r--tools/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java832
-rw-r--r--tools/sdkmanager/app/src/com/android/sdkmanager/Main.java1189
-rw-r--r--tools/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java316
-rwxr-xr-xtools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java110
-rwxr-xr-xtools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java212
-rw-r--r--tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/logo.pngbin2381 -> 0 bytes
-rw-r--r--tools/sdkmanager/app/tests/com/android/sdkmanager/CommandLineProcessorTest.java186
-rw-r--r--tools/sdkmanager/app/tests/com/android/sdkmanager/MockStdLogger.java48
-rw-r--r--tools/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java141
17 files changed, 0 insertions, 3288 deletions
diff --git a/tools/sdkmanager/app/.classpath b/tools/sdkmanager/app/.classpath
deleted file mode 100644
index 3380ba1a7..000000000
--- a/tools/sdkmanager/app/.classpath
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="tests"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/>
- <classpathentry combineaccessrules="false" kind="src" path="/AndroidPrefs"/>
- <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.USER_LIBRARY/ANDROID_SWT"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/tools/sdkmanager/app/.project b/tools/sdkmanager/app/.project
deleted file mode 100644
index aa82db59e..000000000
--- a/tools/sdkmanager/app/.project
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>SdkManager</name>
- <comment></comment>
- <projects>
- <project>SdkLib</project>
- <project>SdkUiLib</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/tools/sdkmanager/app/Android.mk b/tools/sdkmanager/app/Android.mk
deleted file mode 100644
index 24ba61fc0..000000000
--- a/tools/sdkmanager/app/Android.mk
+++ /dev/null
@@ -1,5 +0,0 @@
-# Copyright 2007 The Android Open Source Project
-#
-SDKMANAGERAPP_LOCAL_DIR := $(call my-dir)
-include $(SDKMANAGERAPP_LOCAL_DIR)/etc/Android.mk
-include $(SDKMANAGERAPP_LOCAL_DIR)/src/Android.mk
diff --git a/tools/sdkmanager/app/etc/Android.mk b/tools/sdkmanager/app/etc/Android.mk
deleted file mode 100644
index 8723cd89f..000000000
--- a/tools/sdkmanager/app/etc/Android.mk
+++ /dev/null
@@ -1,8 +0,0 @@
-# Copyright 2008 The Android Open Source Project
-#
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_PREBUILT_EXECUTABLES := android
-include $(BUILD_HOST_PREBUILT)
-
diff --git a/tools/sdkmanager/app/etc/android b/tools/sdkmanager/app/etc/android
deleted file mode 100755
index 8feb5f263..000000000
--- a/tools/sdkmanager/app/etc/android
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/bin/sh
-# Copyright 2005-2007, The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
-#
-# 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.
-
-# Set up prog to be the path of this script, including following symlinks,
-# and set up progdir to be the fully-qualified pathname of its directory.
-prog="$0"
-while [ -h "${prog}" ]; do
- newProg=`/bin/ls -ld "${prog}"`
- newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
- if expr "x${newProg}" : 'x/' >/dev/null; then
- prog="${newProg}"
- else
- progdir=`dirname "${prog}"`
- prog="${progdir}/${newProg}"
- fi
-done
-oldwd=`pwd`
-progdir=`dirname "${prog}"`
-cd "${progdir}"
-progdir=`pwd`
-prog="${progdir}"/`basename "${prog}"`
-cd "${oldwd}"
-
-jarfile=sdkmanager.jar
-frameworkdir="$progdir"
-libdir="$progdir"
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- frameworkdir=`dirname "$progdir"`/tools/lib
- libdir=`dirname "$progdir"`/tools/lib
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- frameworkdir=`dirname "$progdir"`/framework
- libdir=`dirname "$progdir"`/lib
-fi
-if [ ! -r "$frameworkdir/$jarfile" ]
-then
- echo `basename "$prog"`": can't find $jarfile"
- exit 1
-fi
-
-
-# Check args.
-if [ debug = "$1" ]; then
- # add this in for debugging
- java_debug=-agentlib:jdwp=transport=dt_socket,server=y,address=8050,suspend=y
- shift 1
-else
- java_debug=
-fi
-
-java_cmd="java"
-
-# Mac OS X needs an additional arg, or you get an "illegal thread" complaint.
-if [ `uname` = "Darwin" ]; then
- os_opts="-XstartOnFirstThread"
-else
- os_opts=
-fi
-
-if [ `uname` = "Linux" ]; then
- export GDK_NATIVE_WINDOWS=true
-fi
-
-if [ "$OSTYPE" = "cygwin" ] ; then
- jarpath=`cygpath -w "$frameworkdir/$jarfile"`
- progdir=`cygpath -w "$progdir"`
-else
- jarpath="$frameworkdir/$jarfile"
-fi
-
-# Figure out the path to the swt.jar for the current architecture.
-# if ANDROID_SWT is defined, then just use this.
-# else, if running in the Android source tree, then look for the correct swt folder in prebuilt
-# else, look for the correct swt folder in the SDK under tools/lib/
-swtpath=""
-if [ -n "$ANDROID_SWT" ]; then
- swtpath="$ANDROID_SWT"
-else
- vmarch=`${java_cmd} -jar "${frameworkdir}"/archquery.jar`
- if [ -n "$ANDROID_BUILD_TOP" ]; then
- osname=`uname -s | tr A-Z a-z`
- swtpath="${ANDROID_BUILD_TOP}/prebuilt/${osname}-${vmarch}/swt"
- else
- swtpath="${frameworkdir}/${vmarch}"
- fi
-fi
-
-# Combine the swtpath and the framework dir path.
-if [ -d "$swtpath" ]; then
- frameworkdir="${swtpath}:${frameworkdir}"
-else
- echo "SWT folder '${swtpath}' does not exist."
- echo "Please export ANDROID_SWT to point to the folder containing swt.jar for your platform."
- exit 1
-fi
-
-if [ -z "$1" ]; then
- echo "Starting Android SDK and AVD Manager"
-fi
-
-# need to use "java.ext.dirs" because "-jar" causes classpath to be ignored
-# might need more memory, e.g. -Xmx128M
-exec "$java_cmd" -Xmx256M $os_opts $java_debug -Djava.ext.dirs="$frameworkdir" -Dcom.android.sdkmanager.toolsdir="$progdir" -jar "$jarpath" "$@"
diff --git a/tools/sdkmanager/app/etc/android.bat b/tools/sdkmanager/app/etc/android.bat
deleted file mode 100755
index 58790ce1a..000000000
--- a/tools/sdkmanager/app/etc/android.bat
+++ /dev/null
@@ -1,70 +0,0 @@
-@echo off
-rem Copyright (C) 2007 The Android Open Source Project
-rem
-rem Licensed under the Apache License, Version 2.0 (the "License");
-rem you may not use this file except in compliance with the License.
-rem You may obtain a copy of the License at
-rem
-rem http://www.apache.org/licenses/LICENSE-2.0
-rem
-rem Unless required by applicable law or agreed to in writing, software
-rem distributed under the License is distributed on an "AS IS" BASIS,
-rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-rem See the License for the specific language governing permissions and
-rem limitations under the License.
-
-rem don't modify the caller's environment
-setlocal
-
-rem Set up prog to be the path of this script, including following symlinks,
-rem and set up progdir to be the fully-qualified pathname of its directory.
-set prog=%~f0
-
-rem Grab current directory before we change it
-set workdir=%cd%
-
-rem Change current directory and drive to where the script is, to avoid
-rem issues with directories containing whitespaces.
-cd /d %~dp0
-
-set jarpath=lib\sdkmanager.jar
-
-rem Set SWT.Jar path based on current architecture (x86 or x86_64)
-for /f %%a in ('java -jar lib\archquery.jar') do set swt_path=lib\%%a
-
-if "%1 %2"=="update sdk" goto StartUi
-if not "%1"=="" goto EndTempCopy
-:StartUi
- echo Starting Android SDK and AVD Manager
-
- rem We're now going to create a temp dir to hold all the Jar files needed
- rem to run the android tool, copy them in the temp dir and finally execute
- rem from that path. We do this only when the launcher is run without
- rem arguments, to display the SDK Updater UI. This allows the updater to
- rem update the tools directory where the updater itself is located.
-
- set tmpdir=%TEMP%\temp-android-tool
- xcopy lib\x86 %tmpdir%\lib\x86 /I /E /C /G /R /Y /Q > nul
- copy /B /D /Y lib\androidprefs.jar %tmpdir%\lib\ > nul
- copy /B /D /Y lib\org.eclipse.* %tmpdir%\lib\ > nul
- copy /B /D /Y lib\sdk* %tmpdir%\lib\ > nul
- copy /B /D /Y lib\commons-compress* %tmpdir%\lib\ > nul
-
- rem jarpath and swt_path are relative to PWD so we don't need to adjust them, just change dirs.
- set toolsdir=%cd%
- cd %tmpdir%
-
-:EndTempCopy
-
-rem The global ANDROID_SWT always override the SWT.Jar path
-if defined ANDROID_SWT set swt_path=%ANDROID_SWT%
-
-if exist %swt_path% goto SetPath
- echo SWT folder '%swt_path%' does not exist.
- echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
- exit /B
-
-:SetPath
-set javaextdirs=%swt_path%;lib\
-
-call java -Djava.ext.dirs=%javaextdirs% -Dcom.android.sdkmanager.toolsdir="%toolsdir%" -Dcom.android.sdkmanager.workdir="%workdir%" -jar %jarpath% %*
diff --git a/tools/sdkmanager/app/etc/manifest.txt b/tools/sdkmanager/app/etc/manifest.txt
deleted file mode 100644
index 56766348f..000000000
--- a/tools/sdkmanager/app/etc/manifest.txt
+++ /dev/null
@@ -1 +0,0 @@
-Main-Class: com.android.sdkmanager.Main
diff --git a/tools/sdkmanager/app/src/Android.mk b/tools/sdkmanager/app/src/Android.mk
deleted file mode 100644
index b51a113ba..000000000
--- a/tools/sdkmanager/app/src/Android.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-# Copyright 2007 The Android Open Source Project
-#
-LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-LOCAL_JAVA_RESOURCE_DIRS := .
-
-LOCAL_JAR_MANIFEST := ../etc/manifest.txt
-LOCAL_JAVA_LIBRARIES := \
- androidprefs \
- sdklib \
- sdkuilib \
- swt \
- org.eclipse.jface_3.4.2.M20090107-0800 \
- org.eclipse.equinox.common_3.4.0.v20080421-2006 \
- org.eclipse.core.commands_3.4.0.I20080509-2000
-
-LOCAL_MODULE := sdkmanager
-
-include $(BUILD_HOST_JAVA_LIBRARY)
-
diff --git a/tools/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java b/tools/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java
deleted file mode 100644
index ab105ec06..000000000
--- a/tools/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java
+++ /dev/null
@@ -1,832 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * 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.sdkmanager;
-
-import com.android.sdklib.ISdkLog;
-
-import java.util.HashMap;
-import java.util.Map.Entry;
-
-/**
- * Parses the command-line and stores flags needed or requested.
- * <p/>
- * This is a base class. To be useful you want to:
- * <ul>
- * <li>override it.
- * <li>pass an action array to the constructor.
- * <li>define flags for your actions.
- * </ul>
- * <p/>
- * To use, call {@link #parseArgs(String[])} and then
- * call {@link #getValue(String, String, String)}.
- */
-class CommandLineProcessor {
-
- /*
- * Steps needed to add a new action:
- * - Each action is defined as a "verb object" followed by parameters.
- * - Either reuse a VERB_ constant or define a new one.
- * - Either reuse an OBJECT_ constant or define a new one.
- * - Add a new entry to mAction with a one-line help summary.
- * - In the constructor, add a define() call for each parameter (either mandatory
- * or optional) for the given action.
- */
-
- /** Internal verb name for internally hidden flags. */
- public final static String GLOBAL_FLAG_VERB = "@@internal@@";
-
- /** String to use when the verb doesn't need any object. */
- public final static String NO_VERB_OBJECT = "";
-
- /** The global help flag. */
- public static final String KEY_HELP = "help";
- /** The global verbose flag. */
- public static final String KEY_VERBOSE = "verbose";
- /** The global silent flag. */
- public static final String KEY_SILENT = "silent";
-
- /** Verb requested by the user. Null if none specified, which will be an error. */
- private String mVerbRequested;
- /** Direct object requested by the user. Can be null. */
- private String mDirectObjectRequested;
-
- /**
- * Action definitions.
- * <p/>
- * This list serves two purposes: first it is used to know which verb/object
- * actions are acceptable on the command-line; second it provides a summary
- * for each action that is printed in the help.
- * <p/>
- * Each entry is a string array with:
- * <ul>
- * <li> the verb.
- * <li> a direct object (use {@link #NO_VERB_OBJECT} if there's no object).
- * <li> a description.
- * <li> an alternate form for the object (e.g. plural).
- * </ul>
- */
- private final String[][] mActions;
-
- private static final int ACTION_VERB_INDEX = 0;
- private static final int ACTION_OBJECT_INDEX = 1;
- private static final int ACTION_DESC_INDEX = 2;
- private static final int ACTION_ALT_OBJECT_INDEX = 3;
-
- /**
- * The map of all defined arguments.
- * <p/>
- * The key is a string "verb/directObject/longName".
- */
- private final HashMap<String, Arg> mArguments = new HashMap<String, Arg>();
- /** Logger */
- private final ISdkLog mLog;
-
- /**
- * Constructs a new command-line processor.
- *
- * @param logger An SDK logger object. Must not be null.
- * @param actions The list of actions recognized on the command-line.
- * See the javadoc of {@link #mActions} for more details.
- *
- * @see #mActions
- */
- public CommandLineProcessor(ISdkLog logger, String[][] actions) {
- mLog = logger;
- mActions = actions;
-
- define(Mode.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "v", KEY_VERBOSE,
- "Verbose mode: errors, warnings and informational messages are printed.",
- false);
- define(Mode.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "s", KEY_SILENT,
- "Silent mode: only errors are printed out.",
- false);
- define(Mode.BOOLEAN, false, GLOBAL_FLAG_VERB, NO_VERB_OBJECT, "h", KEY_HELP,
- "This help.",
- false);
- }
-
- /**
- * Indicates if this command-line can work when no verb is specified.
- * The default is false, which generates an error when no verb/object is specified.
- * Derived implementations can set this to true if they can deal with a lack
- * of verb/action.
- */
- public boolean acceptLackOfVerb() {
- return false;
- }
-
-
- //------------------
- // Helpers to get flags values
-
- /** Helper that returns true if --verbose was requested. */
- public boolean isVerbose() {
- return ((Boolean) getValue(GLOBAL_FLAG_VERB, NO_VERB_OBJECT, KEY_VERBOSE)).booleanValue();
- }
-
- /** Helper that returns true if --silent was requested. */
- public boolean isSilent() {
- return ((Boolean) getValue(GLOBAL_FLAG_VERB, NO_VERB_OBJECT, KEY_SILENT)).booleanValue();
- }
-
- /** Helper that returns true if --help was requested. */
- public boolean isHelpRequested() {
- return ((Boolean) getValue(GLOBAL_FLAG_VERB, NO_VERB_OBJECT, KEY_HELP)).booleanValue();
- }
-
- /** Returns the verb name from the command-line. Can be null. */
- public String getVerb() {
- return mVerbRequested;
- }
-
- /** Returns the direct object name from the command-line. Can be null. */
- public String getDirectObject() {
- return mDirectObjectRequested;
- }
-
- //------------------
-
- /**
- * Raw access to parsed parameter values.
- * <p/>
- * The default is to scan all parameters. Parameters that have been explicitly set on the
- * command line are returned first. Otherwise one with a non-null value is returned.
- * <p/>
- * Both a verb and a direct object filter can be specified. When they are non-null they limit
- * the scope of the search.
- * <p/>
- * If nothing has been found, return the last default value seen matching the filter.
- *
- * @param verb The verb name, including {@link #GLOBAL_FLAG_VERB}. If null, all possible
- * verbs that match the direct object condition will be examined and the first
- * value set will be used.
- * @param directObject The direct object name, including {@link #NO_VERB_OBJECT}. If null,
- * all possible direct objects that match the verb condition will be examined and
- * the first value set will be used.
- * @param longFlagName The long flag name for the given action. Mandatory. Cannot be null.
- * @return The current value object stored in the parameter, which depends on the argument mode.
- */
- public Object getValue(String verb, String directObject, String longFlagName) {
-
- if (verb != null && directObject != null) {
- String key = verb + "/" + directObject + "/" + longFlagName;
- Arg arg = mArguments.get(key);
- return arg.getCurrentValue();
- }
-
- Object lastDefault = null;
- for (Arg arg : mArguments.values()) {
- if (arg.getLongArg().equals(longFlagName)) {
- if (verb == null || arg.getVerb().equals(verb)) {
- if (directObject == null || arg.getDirectObject().equals(directObject)) {
- if (arg.isInCommandLine()) {
- return arg.getCurrentValue();
- }
- if (arg.getCurrentValue() != null) {
- lastDefault = arg.getCurrentValue();
- }
- }
- }
- }
- }
-
- return lastDefault;
- }
-
- /**
- * Internal setter for raw parameter value.
- * @param verb The verb name, including {@link #GLOBAL_FLAG_VERB}.
- * @param directObject The direct object name, including {@link #NO_VERB_OBJECT}.
- * @param longFlagName The long flag name for the given action.
- * @param value The new current value object stored in the parameter, which depends on the
- * argument mode.
- */
- protected void setValue(String verb, String directObject, String longFlagName, Object value) {
- String key = verb + "/" + directObject + "/" + longFlagName;
- Arg arg = mArguments.get(key);
- arg.setCurrentValue(value);
- }
-
- /**
- * Parses the command-line arguments.
- * <p/>
- * This method will exit and not return if a parsing error arise.
- *
- * @param args The arguments typically received by a main method.
- */
- public void parseArgs(String[] args) {
- String needsHelp = null;
- String verb = null;
- String directObject = null;
-
- try {
- int n = args.length;
- for (int i = 0; i < n; i++) {
- Arg arg = null;
- String a = args[i];
- if (a.startsWith("--")) {
- arg = findLongArg(verb, directObject, a.substring(2));
- } else if (a.startsWith("-")) {
- arg = findShortArg(verb, directObject, a.substring(1));
- }
-
- // No matching argument name found
- if (arg == null) {
- // Does it looks like a dashed parameter?
- if (a.startsWith("-")) {
- if (verb == null || directObject == null) {
- // It looks like a dashed parameter and we don't have a a verb/object
- // set yet, the parameter was just given too early.
-
- needsHelp = String.format(
- "Flag '%1$s' is not a valid global flag. Did you mean to specify it after the verb/object name?",
- a);
- return;
- } else {
- // It looks like a dashed parameter and but it is unknown by this
- // verb-object combination
-
- needsHelp = String.format(
- "Flag '%1$s' is not valid for '%2$s %3$s'.",
- a, verb, directObject);
- return;
- }
- }
-
- if (verb == null) {
- // Fill verb first. Find it.
- for (String[] actionDesc : mActions) {
- if (actionDesc[ACTION_VERB_INDEX].equals(a)) {
- verb = a;
- break;
- }
- }
-
- // Error if it was not a valid verb
- if (verb == null) {
- needsHelp = String.format(
- "Expected verb after global parameters but found '%1$s' instead.",
- a);
- return;
- }
-
- } else if (directObject == null) {
- // Then fill the direct object. Find it.
- for (String[] actionDesc : mActions) {
- if (actionDesc[ACTION_VERB_INDEX].equals(verb)) {
- if (actionDesc[ACTION_OBJECT_INDEX].equals(a)) {
- directObject = a;
- break;
- } else if (actionDesc.length > ACTION_ALT_OBJECT_INDEX &&
- actionDesc[ACTION_ALT_OBJECT_INDEX].equals(a)) {
- // if the alternate form exist and is used, we internally
- // only memorize the default direct object form.
- directObject = actionDesc[ACTION_OBJECT_INDEX];
- break;
- }
- }
- }
-
- // Error if it was not a valid object for that verb
- if (directObject == null) {
- needsHelp = String.format(
- "Expected verb after global parameters but found '%1$s' instead.",
- a);
- return;
-
- }
- }
- } else if (arg != null) {
- // This argument was present on the command line
- arg.setInCommandLine(true);
-
- // Process keyword
- String error = null;
- if (arg.getMode().needsExtra()) {
- if (++i >= n) {
- needsHelp = String.format("Missing argument for flag %1$s.", a);
- return;
- }
-
- error = arg.getMode().process(arg, args[i]);
- } else {
- error = arg.getMode().process(arg, null);
-
- // If we just toggled help, we want to exit now without printing any error.
- // We do this test here only when a Boolean flag is toggled since booleans
- // are the only flags that don't take parameters and help is a boolean.
- if (isHelpRequested()) {
- printHelpAndExit(null);
- // The call above should terminate however in unit tests we override
- // it so we still need to return here.
- return;
- }
- }
-
- if (error != null) {
- needsHelp = String.format("Invalid usage for flag %1$s: %2$s.", a, error);
- return;
- }
- }
- }
-
- if (needsHelp == null) {
- if (verb == null && !acceptLackOfVerb()) {
- needsHelp = "Missing verb name.";
- } else if (verb != null) {
- if (directObject == null) {
- // Make sure this verb has an optional direct object
- for (String[] actionDesc : mActions) {
- if (actionDesc[ACTION_VERB_INDEX].equals(verb) &&
- actionDesc[ACTION_OBJECT_INDEX].equals(NO_VERB_OBJECT)) {
- directObject = NO_VERB_OBJECT;
- break;
- }
- }
-
- if (directObject == null) {
- needsHelp = String.format("Missing object name for verb '%1$s'.", verb);
- return;
- }
- }
-
- // Validate that all mandatory arguments are non-null for this action
- String missing = null;
- boolean plural = false;
- for (Entry<String, Arg> entry : mArguments.entrySet()) {
- Arg arg = entry.getValue();
- if (arg.getVerb().equals(verb) &&
- arg.getDirectObject().equals(directObject)) {
- if (arg.isMandatory() && arg.getCurrentValue() == null) {
- if (missing == null) {
- missing = "--" + arg.getLongArg();
- } else {
- missing += ", --" + arg.getLongArg();
- plural = true;
- }
- }
- }
- }
-
- if (missing != null) {
- needsHelp = String.format(
- "The %1$s %2$s must be defined for action '%3$s %4$s'",
- plural ? "parameters" : "parameter",
- missing,
- verb,
- directObject);
- }
-
- mVerbRequested = verb;
- mDirectObjectRequested = directObject;
- }
- }
- } finally {
- if (needsHelp != null) {
- printHelpAndExitForAction(verb, directObject, needsHelp);
- }
- }
- }
-
- /**
- * Finds an {@link Arg} given an action name and a long flag name.
- * @return The {@link Arg} found or null.
- */
- protected Arg findLongArg(String verb, String directObject, String longName) {
- if (verb == null) {
- verb = GLOBAL_FLAG_VERB;
- }
- if (directObject == null) {
- directObject = NO_VERB_OBJECT;
- }
- String key = verb + "/" + directObject + "/" + longName;
- return mArguments.get(key);
- }
-
- /**
- * Finds an {@link Arg} given an action name and a short flag name.
- * @return The {@link Arg} found or null.
- */
- protected Arg findShortArg(String verb, String directObject, String shortName) {
- if (verb == null) {
- verb = GLOBAL_FLAG_VERB;
- }
- if (directObject == null) {
- directObject = NO_VERB_OBJECT;
- }
-
- for (Entry<String, Arg> entry : mArguments.entrySet()) {
- Arg arg = entry.getValue();
- if (arg.getVerb().equals(verb) && arg.getDirectObject().equals(directObject)) {
- if (shortName.equals(arg.getShortArg())) {
- return arg;
- }
- }
- }
-
- return null;
- }
-
- /**
- * Prints the help/usage and exits.
- *
- * @param errorFormat Optional error message to print prior to usage using String.format
- * @param args Arguments for String.format
- */
- public void printHelpAndExit(String errorFormat, Object... args) {
- printHelpAndExitForAction(null /*verb*/, null /*directObject*/, errorFormat, args);
- }
-
- /**
- * Prints the help/usage and exits.
- *
- * @param verb If null, displays help for all verbs. If not null, display help only
- * for that specific verb. In all cases also displays general usage and action list.
- * @param directObject If null, displays help for all verb objects.
- * If not null, displays help only for that specific action
- * In all cases also display general usage and action list.
- * @param errorFormat Optional error message to print prior to usage using String.format
- * @param args Arguments for String.format
- */
- public void printHelpAndExitForAction(String verb, String directObject,
- String errorFormat, Object... args) {
- if (errorFormat != null) {
- stderr(errorFormat, args);
- }
-
- /*
- * usage should fit in 80 columns
- * 12345678901234567890123456789012345678901234567890123456789012345678901234567890
- */
- stdout("\n" +
- "Usage:\n" +
- " android [global options] action [action options]\n" +
- "\n" +
- "Global options:");
- listOptions(GLOBAL_FLAG_VERB, NO_VERB_OBJECT);
-
- if (verb == null || directObject == null) {
- stdout("\nValid actions are composed of a verb and an optional direct object:");
- for (String[] action : mActions) {
-
- stdout("- %1$6s %2$-12s: %3$s",
- action[ACTION_VERB_INDEX],
- action[ACTION_OBJECT_INDEX],
- action[ACTION_DESC_INDEX]);
- }
- }
-
- for (String[] action : mActions) {
- if (verb == null || verb.equals(action[ACTION_VERB_INDEX])) {
- if (directObject == null || directObject.equals(action[ACTION_OBJECT_INDEX])) {
- stdout("\nAction \"%1$s %2$s\":",
- action[ACTION_VERB_INDEX],
- action[ACTION_OBJECT_INDEX]);
- stdout(" %1$s", action[ACTION_DESC_INDEX]);
- stdout("Options:");
- listOptions(action[ACTION_VERB_INDEX], action[ACTION_OBJECT_INDEX]);
- }
- }
- }
-
- exit();
- }
-
- /**
- * Internal helper to print all the option flags for a given action name.
- */
- protected void listOptions(String verb, String directObject) {
- int numOptions = 0;
- for (Entry<String, Arg> entry : mArguments.entrySet()) {
- Arg arg = entry.getValue();
- if (arg.getVerb().equals(verb) && arg.getDirectObject().equals(directObject)) {
-
- String value = "";
- String required = "";
- if (arg.isMandatory()) {
- required = " [required]";
-
- } else {
- if (arg.getDefaultValue() instanceof String[]) {
- for (String v : (String[]) arg.getDefaultValue()) {
- if (value.length() > 0) {
- value += ", ";
- }
- value += v;
- }
- } else if (arg.getDefaultValue() != null) {
- Object v = arg.getDefaultValue();
- if (arg.getMode() != Mode.BOOLEAN || v.equals(Boolean.TRUE)) {
- value = v.toString();
- }
- }
- if (value.length() > 0) {
- value = " [Default: " + value + "]";
- }
- }
-
- stdout(" -%1$s %2$-10s %3$s%4$s%5$s",
- arg.getShortArg(),
- "--" + arg.getLongArg(),
- arg.getDescription(),
- value,
- required);
- numOptions++;
- }
- }
-
- if (numOptions == 0) {
- stdout(" No options");
- }
- }
-
- //----
-
- /**
- * The mode of an argument specifies the type of variable it represents,
- * whether an extra parameter is required after the flag and how to parse it.
- */
- static enum Mode {
- /** Argument value is a Boolean. Default value is a Boolean. */
- BOOLEAN {
- @Override
- public boolean needsExtra() {
- return false;
- }
- @Override
- public String process(Arg arg, String extra) {
- // Toggle the current value
- arg.setCurrentValue(! ((Boolean) arg.getCurrentValue()).booleanValue());
- return null;
- }
- },
-
- /** Argument value is an Integer. Default value is an Integer. */
- INTEGER {
- @Override
- public boolean needsExtra() {
- return true;
- }
- @Override
- public String process(Arg arg, String extra) {
- try {
- arg.setCurrentValue(Integer.parseInt(extra));
- return null;
- } catch (NumberFormatException e) {
- return String.format("Failed to parse '%1$s' as an integer: %2%s",
- extra, e.getMessage());
- }
- }
- },
-
- /** Argument value is a String. Default value is a String[]. */
- ENUM {
- @Override
- public boolean needsExtra() {
- return true;
- }
- @Override
- public String process(Arg arg, String extra) {
- StringBuilder desc = new StringBuilder();
- String[] values = (String[]) arg.getDefaultValue();
- for (String value : values) {
- if (value.equals(extra)) {
- arg.setCurrentValue(extra);
- return null;
- }
-
- if (desc.length() != 0) {
- desc.append(", ");
- }
- desc.append(value);
- }
-
- return String.format("'%1$s' is not one of %2$s", extra, desc.toString());
- }
- },
-
- /** Argument value is a String. Default value is a null. */
- STRING {
- @Override
- public boolean needsExtra() {
- return true;
- }
- @Override
- public String process(Arg arg, String extra) {
- arg.setCurrentValue(extra);
- return null;
- }
- };
-
- /**
- * Returns true if this mode requires an extra parameter.
- */
- public abstract boolean needsExtra();
-
- /**
- * Processes the flag for this argument.
- *
- * @param arg The argument being processed.
- * @param extra The extra parameter. Null if {@link #needsExtra()} returned false.
- * @return An error string or null if there's no error.
- */
- public abstract String process(Arg arg, String extra);
- }
-
- /**
- * 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.
- * They can have a default value, or it can be null.
- * Depending on the {@link Mode}, the default value can be a Boolean, an Integer, a String
- * or a String array (in which case the first item is the current by default.)
- */
- static class Arg {
- /** Verb for that argument. Never null. */
- private final String mVerb;
- /** Direct Object for that argument. Never null, but can be empty string. */
- private final String mDirectObject;
- /** The 1-letter short name of the argument, e.g. -v. */
- private final String mShortName;
- /** The long name of the argument, e.g. --verbose. */
- private final String mLongName;
- /** A description. Never null. */
- private final String mDescription;
- /** A default value. Can be null. */
- private final Object mDefaultValue;
- /** The argument mode (type + process method). Never null. */
- private final Mode mMode;
- /** True if this argument is mandatory for this verb/directobject. */
- private final boolean mMandatory;
- /** Current value. Initially set to the default value. */
- private Object mCurrentValue;
- /** True if the argument has been used on the command line. */
- private boolean mInCommandLine;
-
- /**
- * Creates a new argument flag description.
- *
- * @param mode The {@link Mode} for the argument.
- * @param mandatory True if this argument is mandatory for this action.
- * @param directObject The action name. Can be #NO_VERB_OBJECT or #INTERNAL_FLAG.
- * @param shortName The one-letter short argument name. Cannot be empty nor null.
- * @param longName The long argument name. Cannot be empty nor null.
- * @param description The description. Cannot be null.
- * @param defaultValue The default value (or values), which depends on the selected {@link Mode}.
- */
- public Arg(Mode mode,
- boolean mandatory,
- String verb,
- String directObject,
- String shortName,
- String longName,
- String description,
- Object defaultValue) {
- mMode = mode;
- mMandatory = mandatory;
- mVerb = verb;
- mDirectObject = directObject;
- mShortName = shortName;
- mLongName = longName;
- mDescription = description;
- mDefaultValue = defaultValue;
- mInCommandLine = false;
- if (defaultValue instanceof String[]) {
- mCurrentValue = ((String[])defaultValue)[0];
- } else {
- mCurrentValue = mDefaultValue;
- }
- }
-
- /** Return true if this argument is mandatory for this verb/directobject. */
- public boolean isMandatory() {
- return mMandatory;
- }
-
- /** Returns the 1-letter short name of the argument, e.g. -v. */
- public String getShortArg() {
- return mShortName;
- }
-
- /** Returns the long name of the argument, e.g. --verbose. */
- public String getLongArg() {
- return mLongName;
- }
-
- /** Returns the description. Never null. */
- public String getDescription() {
- return mDescription;
- }
-
- /** Returns the verb for that argument. Never null. */
- public String getVerb() {
- return mVerb;
- }
-
- /** Returns the direct Object for that argument. Never null, but can be empty string. */
- public String getDirectObject() {
- return mDirectObject;
- }
-
- /** Returns the default value. Can be null. */
- public Object getDefaultValue() {
- return mDefaultValue;
- }
-
- /** Returns the current value. Initially set to the default value. Can be null. */
- public Object getCurrentValue() {
- return mCurrentValue;
- }
-
- /** Sets the current value. Can be null. */
- public void setCurrentValue(Object currentValue) {
- mCurrentValue = currentValue;
- }
-
- /** Returns the argument mode (type + process method). Never null. */
- public Mode getMode() {
- return mMode;
- }
-
- /** Returns true if the argument has been used on the command line. */
- public boolean isInCommandLine() {
- return mInCommandLine;
- }
-
- /** Sets if the argument has been used on the command line. */
- public void setInCommandLine(boolean inCommandLine) {
- mInCommandLine = inCommandLine;
- }
- }
-
- /**
- * Internal helper to define a new argument for a give action.
- *
- * @param mode The {@link Mode} for the argument.
- * @param verb The verb name. Can be #INTERNAL_VERB.
- * @param directObject The action name. Can be #NO_VERB_OBJECT or #INTERNAL_FLAG.
- * @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 description The description. Cannot be null.
- * @param defaultValue The default value (or values), which depends on the selected {@link Mode}.
- */
- protected void define(Mode mode,
- boolean mandatory,
- String verb,
- String directObject,
- String shortName, String longName,
- String description, Object defaultValue) {
- assert(!(mandatory && mode == Mode.BOOLEAN)); // a boolean mode cannot be mandatory
-
- if (directObject == null) {
- directObject = NO_VERB_OBJECT;
- }
-
- String key = verb + "/" + directObject + "/" + longName;
- mArguments.put(key, new Arg(mode, mandatory,
- verb, directObject, shortName, longName, description, defaultValue));
- }
-
- /**
- * Exits in case of error.
- * This is protected so that it can be overridden in unit tests.
- */
- protected void exit() {
- System.exit(1);
- }
-
- /**
- * Prints a line to stdout.
- * This is protected so that it can be overridden in unit tests.
- *
- * @param format The string to be formatted. Cannot be null.
- * @param args Format arguments.
- */
- protected void stdout(String format, Object...args) {
- mLog.printf(format + "\n", args);
- }
-
- /**
- * Prints a line to stderr.
- * This is protected so that it can be overridden in unit tests.
- *
- * @param format The string to be formatted. Cannot be null.
- * @param args Format arguments.
- */
- protected void stderr(String format, Object...args) {
- mLog.error(null, format, args);
- }
-}
diff --git a/tools/sdkmanager/app/src/com/android/sdkmanager/Main.java b/tools/sdkmanager/app/src/com/android/sdkmanager/Main.java
deleted file mode 100644
index 55d435750..000000000
--- a/tools/sdkmanager/app/src/com/android/sdkmanager/Main.java
+++ /dev/null
@@ -1,1189 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * 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.sdkmanager;
-
-import com.android.prefs.AndroidLocation;
-import com.android.prefs.AndroidLocation.AndroidLocationException;
-import com.android.sdklib.IAndroidTarget;
-import com.android.sdklib.ISdkLog;
-import com.android.sdklib.SdkConstants;
-import com.android.sdklib.SdkManager;
-import com.android.sdklib.IAndroidTarget.IOptionalLibrary;
-import com.android.sdklib.internal.avd.AvdManager;
-import com.android.sdklib.internal.avd.HardwareProperties;
-import com.android.sdklib.internal.avd.AvdManager.AvdInfo;
-import com.android.sdklib.internal.avd.HardwareProperties.HardwareProperty;
-import com.android.sdklib.internal.project.ProjectCreator;
-import com.android.sdklib.internal.project.ProjectProperties;
-import com.android.sdklib.internal.project.ProjectCreator.OutputLevel;
-import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
-import com.android.sdklib.xml.AndroidXPathFactory;
-import com.android.sdkmanager.internal.repository.AboutPage;
-import com.android.sdkmanager.internal.repository.SettingsPage;
-import com.android.sdkuilib.internal.repository.LocalPackagesPage;
-import com.android.sdkuilib.repository.UpdaterWindow;
-
-import org.xml.sax.InputSource;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathExpressionException;
-
-/**
- * Main class for the 'android' application.
- */
-public class Main {
-
- /** Java property that defines the location of the sdk/tools directory. */
- public final static String TOOLSDIR = "com.android.sdkmanager.toolsdir";
- /** Java property that defines the working directory. On Windows the current working directory
- * is actually the tools dir, in which case this is used to get the original CWD. */
- private final static String WORKDIR = "com.android.sdkmanager.workdir";
-
- /** Value returned by {@link #resolveTargetName(String)} when the target id does not match. */
- private final static int INVALID_TARGET_ID = 0;
-
- private final static String[] BOOLEAN_YES_REPLIES = new String[] { "yes", "y" };
- private final static String[] BOOLEAN_NO_REPLIES = new String[] { "no", "n" };
-
- /** Path to the SDK folder. This is the parent of {@link #TOOLSDIR}. */
- private String mOsSdkFolder;
- /** Logger object. Use this to print normal output, warnings or errors. */
- private ISdkLog mSdkLog;
- /** The SDK manager parses the SDK folder and gives access to the content. */
- private SdkManager mSdkManager;
- /** Command-line processor with options specific to SdkManager. */
- private SdkCommandLine mSdkCommandLine;
- /** The working directory, either null or set to an existing absolute canonical directory. */
- private File mWorkDir;
-
- public static void main(String[] args) {
- new Main().run(args);
- }
-
- /**
- * Runs the sdk manager app
- */
- private void run(String[] args) {
- createLogger();
- init();
- mSdkCommandLine.parseArgs(args);
- parseSdk();
- doAction();
- }
-
- /**
- * Creates the {@link #mSdkLog} object.
- * <p/>
- * This must be done before {@link #init()} as it will be used to report errors.
- */
- private void createLogger() {
- mSdkLog = new ISdkLog() {
- public void error(Throwable t, String errorFormat, Object... args) {
- if (errorFormat != null) {
- System.err.printf("Error: " + errorFormat, args);
- if (!errorFormat.endsWith("\n")) {
- System.err.printf("\n");
- }
- }
- if (t != null) {
- System.err.printf("Error: %s\n", t.getMessage());
- }
- }
-
- public void warning(String warningFormat, Object... args) {
- if (mSdkCommandLine.isVerbose()) {
- System.out.printf("Warning: " + warningFormat, args);
- if (!warningFormat.endsWith("\n")) {
- System.out.printf("\n");
- }
- }
- }
-
- public void printf(String msgFormat, Object... args) {
- System.out.printf(msgFormat, args);
- }
- };
- }
-
- /**
- * Init the application by making sure the SDK path is available and
- * doing basic parsing of the SDK.
- */
- private void init() {
- mSdkCommandLine = new SdkCommandLine(mSdkLog);
-
- // We get passed a property for the tools dir
- String toolsDirProp = System.getProperty(TOOLSDIR);
- if (toolsDirProp == null) {
- // for debugging, it's easier to override using the process environment
- toolsDirProp = System.getenv(TOOLSDIR);
- }
-
- if (toolsDirProp != null) {
- // got back a level for the SDK folder
- File tools;
- if (toolsDirProp.length() > 0) {
- tools = new File(toolsDirProp);
- mOsSdkFolder = tools.getParent();
- } else {
- try {
- tools = new File(".").getCanonicalFile();
- mOsSdkFolder = tools.getParent();
- } catch (IOException e) {
- // Will print an error below since mSdkFolder is not defined
- }
- }
- }
-
- if (mOsSdkFolder == null) {
- errorAndExit("The tools directory property is not set, please make sure you are executing %1$s",
- SdkConstants.androidCmdName());
- }
-
- // We might get passed a property for the working directory
- // Either it is a valid directory and mWorkDir is set to it's absolute canonical value
- // or mWorkDir remains null.
- String workDirProp = System.getProperty(WORKDIR);
- if (workDirProp == null) {
- workDirProp = System.getenv(WORKDIR);
- }
- if (workDirProp != null) {
- // This should be a valid directory
- mWorkDir = new File(workDirProp);
- try {
- mWorkDir = mWorkDir.getCanonicalFile().getAbsoluteFile();
- } catch (IOException e) {
- mWorkDir = null;
- }
- if (mWorkDir == null || !mWorkDir.isDirectory()) {
- errorAndExit("The working directory does not seem to be valid: '%1$s", workDirProp);
- }
- }
- }
-
- /**
- * Does the basic SDK parsing required for all actions
- */
- private void parseSdk() {
- mSdkManager = SdkManager.createManager(mOsSdkFolder, mSdkLog);
-
- if (mSdkManager == null) {
- errorAndExit("Unable to parse SDK content.");
- }
- }
-
- /**
- * Actually do an action...
- */
- private void doAction() {
- String verb = mSdkCommandLine.getVerb();
- String directObject = mSdkCommandLine.getDirectObject();
-
- if (SdkCommandLine.VERB_LIST.equals(verb)) {
- // list action.
- if (SdkCommandLine.OBJECT_TARGET.equals(directObject)) {
- displayTargetList();
- } else if (SdkCommandLine.OBJECT_AVD.equals(directObject)) {
- displayAvdList();
- } else {
- displayTargetList();
- displayAvdList();
- }
-
- } else if (SdkCommandLine.VERB_CREATE.equals(verb) &&
- SdkCommandLine.OBJECT_AVD.equals(directObject)) {
- createAvd();
-
- } else if (SdkCommandLine.VERB_DELETE.equals(verb) &&
- SdkCommandLine.OBJECT_AVD.equals(directObject)) {
- deleteAvd();
-
- } else if (SdkCommandLine.VERB_MOVE.equals(verb) &&
- SdkCommandLine.OBJECT_AVD.equals(directObject)) {
- moveAvd();
-
- } else if (SdkCommandLine.VERB_UPDATE.equals(verb) &&
- SdkCommandLine.OBJECT_AVD.equals(directObject)) {
- updateAvd();
-
- } else if (SdkCommandLine.VERB_CREATE.equals(verb) &&
- SdkCommandLine.OBJECT_PROJECT.equals(directObject)) {
- createProject();
-
- } else if (SdkCommandLine.VERB_CREATE.equals(verb) &&
- SdkCommandLine.OBJECT_TEST_PROJECT.equals(directObject)) {
- createTestProject();
-
- } else if (SdkCommandLine.VERB_UPDATE.equals(verb) &&
- SdkCommandLine.OBJECT_PROJECT.equals(directObject)) {
- updateProject();
-
- } else if (SdkCommandLine.VERB_UPDATE.equals(verb) &&
- SdkCommandLine.OBJECT_TEST_PROJECT.equals(directObject)) {
- updateTestProject();
-
- } else if (verb == null && directObject == null) {
- showMainWindow(false /*autoUpdate*/);
-
- } else if (SdkCommandLine.VERB_UPDATE.equals(verb) &&
- SdkCommandLine.OBJECT_SDK.equals(directObject)) {
- showMainWindow(true /*autoUpdate*/);
-
- } else if (SdkCommandLine.VERB_UPDATE.equals(verb) &&
- SdkCommandLine.OBJECT_ADB.equals(directObject)) {
- updateAdb();
-
- } else {
- mSdkCommandLine.printHelpAndExit(null);
- }
- }
-
- /**
- * Display the main SdkManager app window
- */
- private void showMainWindow(boolean autoUpdate) {
- try {
- // display a message talking about the command line version
- System.out.printf("No command line parameters provided, launching UI.\n" +
- "See 'android --help' for operations from the command line.\n");
- UpdaterWindow window = new UpdaterWindow(
- null /* parentShell */,
- mSdkLog,
- mOsSdkFolder,
- false /*userCanChangeSdkRoot*/);
- window.registerPage("Settings", SettingsPage.class);
- window.registerPage("About", AboutPage.class);
- if (autoUpdate) {
- window.setInitialPage(LocalPackagesPage.class);
- window.setRequestAutoUpdate(true);
- }
- window.open();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Creates a new Android project based on command-line parameters
- */
- private void createProject() {
- // get the target and try to resolve it.
- int targetId = resolveTargetName(mSdkCommandLine.getParamTargetId());
- IAndroidTarget[] targets = mSdkManager.getTargets();
- if (targetId == INVALID_TARGET_ID || targetId > targets.length) {
- errorAndExit("Target id is not valid. Use '%s list targets' to get the target ids.",
- SdkConstants.androidCmdName());
- }
- IAndroidTarget target = targets[targetId - 1]; // target id is 1-based
-
- ProjectCreator creator = new ProjectCreator(mOsSdkFolder,
- mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
- mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
- OutputLevel.NORMAL,
- mSdkLog);
-
- String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
-
- String projectName = mSdkCommandLine.getParamName();
- String packageName = mSdkCommandLine.getParamProjectPackage();
- String activityName = mSdkCommandLine.getParamProjectActivity();
-
- if (projectName != null &&
- !ProjectCreator.RE_PROJECT_NAME.matcher(projectName).matches()) {
- errorAndExit(
- "Project name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
- projectName, ProjectCreator.CHARS_PROJECT_NAME);
- return;
- }
-
- if (activityName != null &&
- !ProjectCreator.RE_ACTIVITY_NAME.matcher(activityName).matches()) {
- errorAndExit(
- "Activity name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
- activityName, ProjectCreator.CHARS_ACTIVITY_NAME);
- return;
- }
-
- if (packageName != null &&
- !ProjectCreator.RE_PACKAGE_NAME.matcher(packageName).matches()) {
- errorAndExit(
- "Package name '%1$s' contains invalid characters.\n" +
- "A package name must be constitued of two Java identifiers.\n" +
- "Each identifier allowed characters are: %2$s",
- packageName, ProjectCreator.CHARS_PACKAGE_NAME);
- return;
- }
-
- creator.createProject(projectDir,
- projectName,
- packageName,
- activityName,
- target,
- null /*pathToMain*/);
- }
-
- /**
- * Creates a new Android test project based on command-line parameters
- */
- private void createTestProject() {
-
- String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
-
- // first check the path of the parent project, and make sure it's valid.
- String pathToMainProject = mSdkCommandLine.getParamTestProjectMain();
-
- File parentProject = new File(pathToMainProject);
- if (parentProject.isAbsolute() == false) {
- // if the path is not absolute, we need to resolve it based on the
- // destination path of the project
- try {
- parentProject = new File(projectDir, pathToMainProject).getCanonicalFile();
- } catch (IOException e) {
- errorAndExit("Unable to resolve Main project's directory: %1$s",
- pathToMainProject);
- return; // help Eclipse static analyzer understand we'll never execute the rest.
- }
- }
-
- if (parentProject.isDirectory() == false) {
- errorAndExit("Main project's directory does not exist: %1$s",
- pathToMainProject);
- return;
- }
-
- // now look for a manifest in there
- File manifest = new File(parentProject, SdkConstants.FN_ANDROID_MANIFEST_XML);
- if (manifest.isFile() == false) {
- errorAndExit("No AndroidManifest.xml file found in the main project directory: %1$s",
- parentProject.getAbsolutePath());
- return;
- }
-
- // now query the manifest for the package file.
- XPath xpath = AndroidXPathFactory.newXPath();
- String packageName, activityName;
-
- try {
- packageName = xpath.evaluate("/manifest/@package",
- new InputSource(new FileInputStream(manifest)));
-
- mSdkLog.printf("Found main project package: %1$s\n", packageName);
-
- // now get the name of the first activity we find
- activityName = xpath.evaluate("/manifest/application/activity[1]/@android:name",
- new InputSource(new FileInputStream(manifest)));
- // xpath will return empty string when there's no match
- if (activityName == null || activityName.length() == 0) {
- activityName = null;
- } else {
- mSdkLog.printf("Found main project activity: %1$s\n", activityName);
- }
- } catch (FileNotFoundException e) {
- // this shouldn't happen as we test it above.
- errorAndExit("No AndroidManifest.xml file found in main project.");
- return; // this is not strictly needed because errorAndExit will stop the execution,
- // but this makes the java compiler happy, wrt to uninitialized variables.
- } catch (XPathExpressionException e) {
- // looks like the main manifest is not valid.
- errorAndExit("Unable to parse main project manifest to get information.");
- return; // this is not strictly needed because errorAndExit will stop the execution,
- // but this makes the java compiler happy, wrt to uninitialized variables.
- }
-
- // now get the target hash
- ProjectProperties p = ProjectProperties.load(parentProject.getAbsolutePath(),
- PropertyType.DEFAULT);
- String targetHash = p.getProperty(ProjectProperties.PROPERTY_TARGET);
- if (targetHash == null) {
- errorAndExit("Couldn't find the main project target");
- return;
- }
-
- // and resolve it.
- IAndroidTarget target = mSdkManager.getTargetFromHashString(targetHash);
- if (target == null) {
- errorAndExit(
- "Unable to resolve main project target '%1$s'. You may want to install the platform in your SDK.",
- targetHash);
- return;
- }
-
- mSdkLog.printf("Found main project target: %1$s\n", target.getFullName());
-
- ProjectCreator creator = new ProjectCreator(mOsSdkFolder,
- mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
- mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
- OutputLevel.NORMAL,
- mSdkLog);
-
- String projectName = mSdkCommandLine.getParamName();
-
- if (projectName != null &&
- !ProjectCreator.RE_PROJECT_NAME.matcher(projectName).matches()) {
- errorAndExit(
- "Project name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
- projectName, ProjectCreator.CHARS_PROJECT_NAME);
- return;
- }
-
- creator.createProject(projectDir,
- projectName,
- packageName,
- activityName,
- target,
- pathToMainProject);
- }
-
-
- /**
- * Updates an existing Android project based on command-line parameters
- */
- private void updateProject() {
- // get the target and try to resolve it.
- IAndroidTarget target = null;
- String targetStr = mSdkCommandLine.getParamTargetId();
- // For "update project" the target parameter is optional so having null is acceptable.
- // However if there's a value, it must be valid.
- if (targetStr != null) {
- IAndroidTarget[] targets = mSdkManager.getTargets();
- int targetId = resolveTargetName(targetStr);
- if (targetId == INVALID_TARGET_ID || targetId > targets.length) {
- errorAndExit("Target id '%1$s' is not valid. Use '%2$s list targets' to get the target ids.",
- targetStr,
- SdkConstants.androidCmdName());
- }
- target = targets[targetId - 1]; // target id is 1-based
- }
-
- ProjectCreator creator = new ProjectCreator(mOsSdkFolder,
- mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
- mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
- OutputLevel.NORMAL,
- mSdkLog);
-
- String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
-
- creator.updateProject(projectDir,
- target,
- 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);
- }
- }
-
- /**
- * Updates an existing test project with a new path to the main project.
- */
- private void updateTestProject() {
- ProjectCreator creator = new ProjectCreator(mOsSdkFolder,
- mSdkCommandLine.isVerbose() ? OutputLevel.VERBOSE :
- mSdkCommandLine.isSilent() ? OutputLevel.SILENT :
- OutputLevel.NORMAL,
- mSdkLog);
-
- String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
-
- creator.updateTestProject(projectDir, mSdkCommandLine.getParamTestProjectMain());
- }
-
- /**
- * Adjusts the project location to make it absolute & canonical relative to the
- * working directory, if any.
- *
- * @return The project absolute path relative to {@link #mWorkDir} or the original
- * newProjectLocation otherwise.
- */
- private String getProjectLocation(String newProjectLocation) {
-
- // If the new project location is absolute, use it as-is
- File projectDir = new File(newProjectLocation);
- if (projectDir.isAbsolute()) {
- return newProjectLocation;
- }
-
- // if there's no working directory, just use the project location as-is.
- if (mWorkDir == null) {
- return newProjectLocation;
- }
-
- // Combine then and get an absolute canonical directory
- try {
- projectDir = new File(mWorkDir, newProjectLocation).getCanonicalFile();
-
- return projectDir.getPath();
- } catch (IOException e) {
- errorAndExit("Failed to combine working directory '%1$s' with project location '%2$s': %3$s",
- mWorkDir.getPath(),
- newProjectLocation,
- e.getMessage());
- return null;
- }
- }
-
- /**
- * Displays the list of available Targets (Platforms and Add-ons)
- */
- private void displayTargetList() {
- mSdkLog.printf("Available Android targets:\n");
-
- int index = 1;
- for (IAndroidTarget target : mSdkManager.getTargets()) {
- mSdkLog.printf("id: %1$d or \"%2$s\"\n", index, target.hashString());
- mSdkLog.printf(" Name: %s\n", target.getName());
- if (target.isPlatform()) {
- mSdkLog.printf(" Type: Platform\n");
- mSdkLog.printf(" API level: %s\n", target.getVersion().getApiString());
- mSdkLog.printf(" Revision: %d\n", target.getRevision());
- } else {
- mSdkLog.printf(" Type: Add-On\n");
- mSdkLog.printf(" Vendor: %s\n", target.getVendor());
- mSdkLog.printf(" Revision: %d\n", target.getRevision());
- if (target.getDescription() != null) {
- mSdkLog.printf(" Description: %s\n", target.getDescription());
- }
- mSdkLog.printf(" Based on Android %s (API level %s)\n",
- target.getVersionName(), target.getVersion().getApiString());
-
- // display the optional libraries.
- IOptionalLibrary[] libraries = target.getOptionalLibraries();
- if (libraries != null) {
- mSdkLog.printf(" Libraries:\n");
- for (IOptionalLibrary library : libraries) {
- mSdkLog.printf(" * %1$s (%2$s)\n",
- library.getName(), library.getJarName());
- mSdkLog.printf(String.format(
- " %1$s\n", library.getDescription()));
- }
- }
- }
-
- // get the target skins
- displaySkinList(target, " Skins: ");
-
- if (target.getUsbVendorId() != IAndroidTarget.NO_USB_ID) {
- mSdkLog.printf(" Adds USB support for devices (Vendor: 0x%04X)\n",
- target.getUsbVendorId());
- }
-
- index++;
- }
- }
-
- /**
- * Displays the skins valid for the given target.
- */
- private void displaySkinList(IAndroidTarget target, String message) {
- String[] skins = target.getSkins();
- String defaultSkin = target.getDefaultSkin();
- mSdkLog.printf(message);
- if (skins != null) {
- boolean first = true;
- for (String skin : skins) {
- if (first == false) {
- mSdkLog.printf(", ");
- } else {
- first = false;
- }
- mSdkLog.printf(skin);
-
- if (skin.equals(defaultSkin)) {
- mSdkLog.printf(" (default)");
- }
- }
- mSdkLog.printf("\n");
- } else {
- mSdkLog.printf("no skins.\n");
- }
- }
-
- /**
- * Displays the list of available AVDs.
- */
- private void displayAvdList() {
- try {
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
-
- mSdkLog.printf("Available Android Virtual Devices:\n");
-
- AvdInfo[] avds = avdManager.getValidAvds();
- for (int index = 0 ; index < avds.length ; index++) {
- AvdInfo info = avds[index];
- if (index > 0) {
- mSdkLog.printf("---------\n");
- }
- mSdkLog.printf(" Name: %s\n", info.getName());
- mSdkLog.printf(" Path: %s\n", info.getPath());
-
- // get the target of the AVD
- IAndroidTarget target = info.getTarget();
- if (target.isPlatform()) {
- mSdkLog.printf(" Target: %s (API level %s)\n", target.getName(),
- target.getVersion().getApiString());
- } else {
- mSdkLog.printf(" Target: %s (%s)\n", target.getName(), target
- .getVendor());
- mSdkLog.printf(" Based on Android %s (API level %s)\n",
- target.getVersionName(), target.getVersion().getApiString());
- }
-
- // display some extra values.
- Map<String, String> properties = info.getProperties();
- if (properties != null) {
- String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME);
- if (skin != null) {
- mSdkLog.printf(" Skin: %s\n", skin);
- }
- String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE);
- if (sdcard == null) {
- sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH);
- }
- if (sdcard != null) {
- mSdkLog.printf(" Sdcard: %s\n", sdcard);
- }
- }
- }
-
- // Are there some unused AVDs?
- AvdInfo[] badAvds = avdManager.getBrokenAvds();
-
- if (badAvds.length == 0) {
- return;
- }
-
- mSdkLog.printf("\nThe following Android Virtual Devices could not be loaded:\n");
- boolean needSeparator = false;
- for (AvdInfo info : badAvds) {
- if (needSeparator) {
- mSdkLog.printf("---------\n");
- }
- mSdkLog.printf(" Name: %s\n", info.getName() == null ? "--" : info.getName());
- mSdkLog.printf(" Path: %s\n", info.getPath() == null ? "--" : info.getPath());
-
- String error = info.getErrorMessage();
- mSdkLog.printf(" Error: %s\n", error == null ? "Uknown error" : error);
- needSeparator = true;
- }
- } catch (AndroidLocationException e) {
- errorAndExit(e.getMessage());
- }
- }
-
- /**
- * Creates a new AVD. This is a text based creation with command line prompt.
- */
- private void createAvd() {
- // find a matching target
- int targetId = resolveTargetName(mSdkCommandLine.getParamTargetId());
- IAndroidTarget[] targets = mSdkManager.getTargets();
-
- if (targetId == INVALID_TARGET_ID || targetId > targets.length) {
- errorAndExit("Target id is not valid. Use '%s list targets' to get the target ids.",
- SdkConstants.androidCmdName());
- }
-
- IAndroidTarget target = targets[targetId-1]; // target id is 1-based
-
- try {
- boolean removePrevious = mSdkCommandLine.getFlagForce();
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
-
- String avdName = mSdkCommandLine.getParamName();
-
- if (!AvdManager.RE_AVD_NAME.matcher(avdName).matches()) {
- errorAndExit(
- "AVD name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
- avdName, AvdManager.CHARS_AVD_NAME);
- return;
- }
-
- AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/);
- if (info != null) {
- if (removePrevious) {
- mSdkLog.warning(
- "Android Virtual Device '%s' already exists and will be replaced.",
- avdName);
- } else {
- errorAndExit("Android Virtual Device '%s' already exists.\n" +
- "Use --force if you want to replace it.",
- avdName);
- return;
- }
- }
-
- String paramFolderPath = mSdkCommandLine.getParamLocationPath();
- File avdFolder = null;
- if (paramFolderPath != null) {
- avdFolder = new File(paramFolderPath);
- } else {
- avdFolder = new File(AndroidLocation.getFolder() + AndroidLocation.FOLDER_AVD,
- avdName + AvdManager.AVD_FOLDER_EXTENSION);
- }
-
- // Validate skin is either default (empty) or NNNxMMM or a valid skin name.
- Map<String, String> skinHardwareConfig = null;
- String skin = mSdkCommandLine.getParamSkin();
- if (skin != null && skin.length() == 0) {
- skin = null;
- }
-
- if (skin != null && target != null) {
- boolean valid = false;
- // Is it a know skin name for this target?
- for (String s : target.getSkins()) {
- if (skin.equalsIgnoreCase(s)) {
- skin = s; // Make skin names case-insensitive.
- valid = true;
-
- // get the hardware properties for this skin
- File skinFolder = avdManager.getSkinPath(skin, target);
- File skinHardwareFile = new File(skinFolder, AvdManager.HARDWARE_INI);
- if (skinHardwareFile.isFile()) {
- skinHardwareConfig = SdkManager.parsePropertyFile(
- skinHardwareFile, mSdkLog);
- }
- break;
- }
- }
-
- // Is it NNNxMMM?
- if (!valid) {
- valid = AvdManager.NUMERIC_SKIN_SIZE.matcher(skin).matches();
- }
-
- if (!valid) {
- displaySkinList(target, "Valid skins: ");
- errorAndExit("'%s' is not a valid skin name or size (NNNxMMM)", skin);
- return;
- }
- }
-
- Map<String, String> hardwareConfig = null;
- if (target != null && target.isPlatform()) {
- try {
- hardwareConfig = promptForHardware(target, skinHardwareConfig);
- } catch (IOException e) {
- errorAndExit(e.getMessage());
- }
- }
-
- @SuppressWarnings("unused") // oldAvdInfo is never read, yet useful for debugging
- AvdInfo oldAvdInfo = null;
- if (removePrevious) {
- oldAvdInfo = avdManager.getAvd(avdName, false /*validAvdOnly*/);
- }
-
- @SuppressWarnings("unused") // newAvdInfo is never read, yet useful for debugging
- AvdInfo newAvdInfo = avdManager.createAvd(avdFolder,
- avdName,
- target,
- skin,
- mSdkCommandLine.getParamSdCard(),
- hardwareConfig,
- removePrevious,
- mSdkLog);
-
- } catch (AndroidLocationException e) {
- errorAndExit(e.getMessage());
- }
- }
-
- /**
- * Delete an AVD. If the AVD name is not part of the available ones look for an
- * invalid AVD (one not loaded due to some error) to remove it too.
- */
- private void deleteAvd() {
- try {
- String avdName = mSdkCommandLine.getParamName();
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
- AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/);
-
- if (info == null) {
- errorAndExit("There is no Android Virtual Device named '%s'.", avdName);
- return;
- }
-
- avdManager.deleteAvd(info, mSdkLog);
- } catch (AndroidLocationException e) {
- errorAndExit(e.getMessage());
- }
- }
-
- /**
- * Moves an AVD.
- */
- private void moveAvd() {
- try {
- String avdName = mSdkCommandLine.getParamName();
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
- AvdInfo info = avdManager.getAvd(avdName, true /*validAvdOnly*/);
-
- if (info == null) {
- errorAndExit("There is no valid Android Virtual Device named '%s'.", avdName);
- return;
- }
-
- // This is a rename if there's a new name for the AVD
- String newName = mSdkCommandLine.getParamMoveNewName();
- if (newName != null && newName.equals(info.getName())) {
- // same name, not actually a rename operation
- newName = null;
- }
-
- // This is a move (of the data files) if there's a new location path
- String paramFolderPath = mSdkCommandLine.getParamLocationPath();
- if (paramFolderPath != null) {
- // check if paths are the same. Use File methods to account for OS idiosyncrasies.
- try {
- File f1 = new File(paramFolderPath).getCanonicalFile();
- File f2 = new File(info.getPath()).getCanonicalFile();
- if (f1.equals(f2)) {
- // same canonical path, so not actually a move
- paramFolderPath = null;
- }
- } catch (IOException e) {
- // Fail to resolve canonical path. Fail now since a move operation might fail
- // later and be harder to recover from.
- errorAndExit(e.getMessage());
- return;
- }
- }
-
- if (newName == null && paramFolderPath == null) {
- mSdkLog.warning("Move operation aborted: same AVD name, same canonical data path");
- return;
- }
-
- // If a rename was requested and no data move was requested, check if the original
- // data path is our default constructed from the AVD name. In this case we still want
- // to rename that folder too.
- if (newName != null && paramFolderPath == null) {
- // Compute the original data path
- File originalFolder = new File(
- AndroidLocation.getFolder() + AndroidLocation.FOLDER_AVD,
- info.getName() + AvdManager.AVD_FOLDER_EXTENSION);
- if (originalFolder.equals(info.getPath())) {
- try {
- // The AVD is using the default data folder path based on the AVD name.
- // That folder needs to be adjusted to use the new name.
- File f = new File(AndroidLocation.getFolder() + AndroidLocation.FOLDER_AVD,
- newName + AvdManager.AVD_FOLDER_EXTENSION);
- paramFolderPath = f.getCanonicalPath();
- } catch (IOException e) {
- // Fail to resolve canonical path. Fail now rather than later.
- errorAndExit(e.getMessage());
- }
- }
- }
-
- // Check for conflicts
- if (newName != null) {
- if (avdManager.getAvd(newName, false /*validAvdOnly*/) != null) {
- errorAndExit("There is already an AVD named '%s'.", newName);
- return;
- }
-
- File ini = info.getIniFile();
- if (ini.equals(AvdInfo.getIniFile(newName))) {
- errorAndExit("The AVD file '%s' is in the way.", ini.getCanonicalPath());
- return;
- }
- }
-
- if (paramFolderPath != null && new File(paramFolderPath).exists()) {
- errorAndExit(
- "There is already a file or directory at '%s'.\nUse --path to specify a different data folder.",
- paramFolderPath);
- }
-
- avdManager.moveAvd(info, newName, paramFolderPath, mSdkLog);
- } catch (AndroidLocationException e) {
- errorAndExit(e.getMessage());
- } catch (IOException e) {
- errorAndExit(e.getMessage());
- }
- }
-
- /**
- * Updates a broken AVD.
- */
- private void updateAvd() {
- try {
- String avdName = mSdkCommandLine.getParamName();
- AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);
- avdManager.updateAvd(avdName, mSdkLog);
- } catch (AndroidLocationException e) {
- errorAndExit(e.getMessage());
- } catch (IOException e) {
- errorAndExit(e.getMessage());
- }
- }
-
- /**
- * Updates adb with the USB devices declared in the SDK add-ons.
- */
- private void updateAdb() {
- try {
- mSdkManager.updateAdb();
-
- mSdkLog.printf(
- "adb has been updated. You must restart adb with the following commands\n" +
- "\tadb kill-server\n" +
- "\tadb start-server\n");
- } catch (AndroidLocationException e) {
- errorAndExit(e.getMessage());
- } catch (IOException e) {
- errorAndExit(e.getMessage());
- }
- }
-
- /**
- * Prompts the user to setup a hardware config for a Platform-based AVD.
- * @throws IOException
- */
- private Map<String, String> promptForHardware(IAndroidTarget createTarget,
- Map<String, String> skinHardwareConfig) throws IOException {
- byte[] readLineBuffer = new byte[256];
- String result;
- String defaultAnswer = "no";
-
- mSdkLog.printf("%s is a basic Android platform.\n", createTarget.getName());
- mSdkLog.printf("Do you wish to create a custom hardware profile [%s]",
- defaultAnswer);
-
- result = readLine(readLineBuffer).trim();
- // handle default:
- if (result.length() == 0) {
- result = defaultAnswer;
- }
-
- if (getBooleanReply(result) == false) {
- // no custom config, return the skin hardware config in case there is one.
- return skinHardwareConfig;
- }
-
- mSdkLog.printf("\n"); // empty line
-
- // get the list of possible hardware properties
- File hardwareDefs = new File (mOsSdkFolder + File.separator +
- SdkConstants.OS_SDK_TOOLS_LIB_FOLDER, SdkConstants.FN_HARDWARE_INI);
- Map<String, HardwareProperty> hwMap = HardwareProperties.parseHardwareDefinitions(
- hardwareDefs, null /*sdkLog*/);
-
- HashMap<String, String> map = new HashMap<String, String>();
-
- // we just want to loop on the HardwareProperties
- HardwareProperty[] hwProperties = hwMap.values().toArray(
- new HardwareProperty[hwMap.size()]);
- for (int i = 0 ; i < hwProperties.length ;) {
- HardwareProperty property = hwProperties[i];
-
- String description = property.getDescription();
- if (description != null) {
- mSdkLog.printf("%s: %s\n", property.getAbstract(), description);
- } else {
- mSdkLog.printf("%s\n", property.getAbstract());
- }
-
- String defaultValue = property.getDefault();
- String defaultFromSkin = skinHardwareConfig != null ? skinHardwareConfig.get(
- property.getName()) : null;
-
- if (defaultFromSkin != null) {
- mSdkLog.printf("%s [%s (from skin)]:", property.getName(), defaultFromSkin);
- } else if (defaultValue != null) {
- mSdkLog.printf("%s [%s]:", property.getName(), defaultValue);
- } else {
- mSdkLog.printf("%s (%s):", property.getName(), property.getType());
- }
-
- result = readLine(readLineBuffer);
- if (result.length() == 0) {
- if (defaultFromSkin != null || defaultValue != null) {
- if (defaultFromSkin != null) {
- // we need to write this one in the AVD file
- map.put(property.getName(), defaultFromSkin);
- }
-
- mSdkLog.printf("\n"); // empty line
- i++; // go to the next property if we have a valid default value.
- // if there's no default, we'll redo this property
- }
- continue;
- }
-
- switch (property.getType()) {
- case BOOLEAN:
- try {
- if (getBooleanReply(result)) {
- map.put(property.getName(), "yes");
- i++; // valid reply, move to next property
- } else {
- map.put(property.getName(), "no");
- i++; // valid reply, move to next property
- }
- } catch (IOException e) {
- // display error, and do not increment i to redo this property
- mSdkLog.printf("\n%s\n", e.getMessage());
- }
- break;
- case INTEGER:
- try {
- Integer.parseInt(result);
- map.put(property.getName(), result);
- i++; // valid reply, move to next property
- } catch (NumberFormatException e) {
- // display error, and do not increment i to redo this property
- mSdkLog.printf("\n%s\n", e.getMessage());
- }
- break;
- case DISKSIZE:
- // TODO check validity
- map.put(property.getName(), result);
- i++; // valid reply, move to next property
- break;
- }
-
- mSdkLog.printf("\n"); // empty line
- }
-
- return map;
- }
-
- /**
- * Reads the line from the input stream.
- * @param buffer
- * @throws IOException
- */
- private String readLine(byte[] buffer) throws IOException {
- int count = System.in.read(buffer);
-
- // is the input longer than the buffer?
- if (count == buffer.length && buffer[count-1] != 10) {
- // create a new temp buffer
- byte[] tempBuffer = new byte[256];
-
- // and read the rest
- String secondHalf = readLine(tempBuffer);
-
- // return a concat of both
- return new String(buffer, 0, count) + secondHalf;
- }
-
- // ignore end whitespace
- while (count > 0 && (buffer[count-1] == '\r' || buffer[count-1] == '\n')) {
- count--;
- }
-
- return new String(buffer, 0, count);
- }
-
- /**
- * Returns the boolean value represented by the string.
- * @throws IOException If the value is not a boolean string.
- */
- private boolean getBooleanReply(String reply) throws IOException {
-
- for (String valid : BOOLEAN_YES_REPLIES) {
- if (valid.equalsIgnoreCase(reply)) {
- return true;
- }
- }
-
- for (String valid : BOOLEAN_NO_REPLIES) {
- if (valid.equalsIgnoreCase(reply)) {
- return false;
- }
- }
-
- throw new IOException(String.format("%s is not a valid reply", reply));
- }
-
- private void errorAndExit(String format, Object...args) {
- mSdkLog.error(null, format, args);
- System.exit(1);
- }
-
- /**
- * Converts a symbolic target name (such as those accepted by --target on the command-line)
- * to an internal target index id. A valid target name is either a numeric target id (> 0)
- * or a target hash string.
- * <p/>
- * If the given target can't be mapped, {@link #INVALID_TARGET_ID} (0) is returned.
- * It's up to the caller to output an error.
- * <p/>
- * On success, returns a value > 0.
- */
- private int resolveTargetName(String targetName) {
-
- if (targetName == null) {
- return INVALID_TARGET_ID;
- }
-
- targetName = targetName.trim();
-
- // Case of an integer number
- if (targetName.matches("[0-9]*")) {
- try {
- int n = Integer.parseInt(targetName);
- return n < 1 ? INVALID_TARGET_ID : n;
- } catch (NumberFormatException e) {
- // Ignore. Should not happen.
- }
- }
-
- // Let's try to find a platform or addon name.
- IAndroidTarget[] targets = mSdkManager.getTargets();
- for (int i = 0; i < targets.length; i++) {
- if (targetName.equals(targets[i].hashString())) {
- return i + 1;
- }
- }
-
- return INVALID_TARGET_ID;
- }
-}
diff --git a/tools/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java b/tools/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
deleted file mode 100644
index 80ee5dd36..000000000
--- a/tools/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * 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.sdkmanager;
-
-import com.android.sdklib.ISdkLog;
-import com.android.sdklib.SdkManager;
-
-
-/**
- * Specific command-line flags for the {@link SdkManager}.
- */
-class SdkCommandLine extends CommandLineProcessor {
-
- /*
- * Steps needed to add a new action:
- * - Each action is defined as a "verb object" followed by parameters.
- * - Either reuse a VERB_ constant or define a new one.
- * - Either reuse an OBJECT_ constant or define a new one.
- * - Add a new entry to mAction with a one-line help summary.
- * - In the constructor, add a define() call for each parameter (either mandatory
- * or optional) for the given action.
- */
-
- public final static String VERB_LIST = "list";
- public final static String VERB_CREATE = "create";
- public final static String VERB_MOVE = "move";
- public final static String VERB_DELETE = "delete";
- public final static String VERB_UPDATE = "update";
-
- public static final String OBJECT_SDK = "sdk";
- public static final String OBJECT_AVD = "avd";
- public static final String OBJECT_AVDS = "avds";
- public static final String OBJECT_TARGET = "target";
- public static final String OBJECT_TARGETS = "targets";
- public static final String OBJECT_PROJECT = "project";
- public static final String OBJECT_TEST_PROJECT = "test-project";
- public static final String OBJECT_ADB = "adb";
-
- public static final String ARG_ALIAS = "alias";
- public static final String ARG_ACTIVITY = "activity";
-
- public static final String KEY_ACTIVITY = ARG_ACTIVITY;
- public static final String KEY_PACKAGE = "package";
- public static final String KEY_MODE = "mode";
- public static final String KEY_TARGET_ID = OBJECT_TARGET;
- public static final String KEY_NAME = "name";
- public static final String KEY_PATH = "path";
- public static final String KEY_FILTER = "filter";
- public static final String KEY_SKIN = "skin";
- public static final String KEY_SDCARD = "sdcard";
- public static final String KEY_FORCE = "force";
- public static final String KEY_RENAME = "rename";
- public static final String KEY_SUBPROJECTS = "subprojects";
- public static final String KEY_MAIN_PROJECT = "main";
-
- /**
- * Action definitions for SdkManager command line.
- * <p/>
- * This list serves two purposes: first it is used to know which verb/object
- * actions are acceptable on the command-line; second it provides a summary
- * for each action that is printed in the help.
- * <p/>
- * Each entry is a string array with:
- * <ul>
- * <li> the verb.
- * <li> an object (use #NO_VERB_OBJECT if there's no object).
- * <li> a description.
- * <li> an alternate form for the object (e.g. plural).
- * </ul>
- */
- private final static String[][] ACTIONS = {
- { VERB_LIST, NO_VERB_OBJECT,
- "Lists existing targets or virtual devices." },
- { VERB_LIST, OBJECT_AVD,
- "Lists existing Android Virtual Devices.",
- OBJECT_AVDS },
- { VERB_LIST, OBJECT_TARGET,
- "Lists existing targets.",
- OBJECT_TARGETS },
-
- { VERB_CREATE, OBJECT_AVD,
- "Creates a new Android Virtual Device." },
- { VERB_MOVE, OBJECT_AVD,
- "Moves or renames an Android Virtual Device." },
- { VERB_DELETE, OBJECT_AVD,
- "Deletes an Android Virtual Device." },
- { VERB_UPDATE, OBJECT_AVD,
- "Updates an Android Virtual Device to match the folders of a new SDK." },
-
- { VERB_CREATE, OBJECT_PROJECT,
- "Creates a new Android Project." },
- { VERB_UPDATE, OBJECT_PROJECT,
- "Updates an Android Project (must have an AndroidManifest.xml)." },
-
- { VERB_CREATE, OBJECT_TEST_PROJECT,
- "Creates a new Android Test Project." },
- { VERB_UPDATE, OBJECT_TEST_PROJECT,
- "Updates an Android Test Project (must have an AndroidManifest.xml)." },
-
- { VERB_UPDATE, OBJECT_ADB,
- "Updates adb to support the USB devices declared in the SDK add-ons." },
-
- { VERB_UPDATE, OBJECT_SDK,
- "Updates the SDK by suggesting new platforms to install if available." }
- };
-
- public SdkCommandLine(ISdkLog logger) {
- super(logger, ACTIONS);
-
- // The following defines the parameters of the actions defined in mAction.
-
- // --- create avd ---
-
- define(Mode.STRING, false,
- VERB_CREATE, OBJECT_AVD, "p", KEY_PATH,
- "Location path of the directory where the new AVD will be created", null);
- define(Mode.STRING, true,
- VERB_CREATE, OBJECT_AVD, "n", KEY_NAME,
- "Name of the new AVD", null);
- define(Mode.STRING, true,
- VERB_CREATE, OBJECT_AVD, "t", KEY_TARGET_ID,
- "Target id of the new AVD", null);
- define(Mode.STRING, false,
- VERB_CREATE, OBJECT_AVD, "s", KEY_SKIN,
- "Skin of the new AVD", null);
- define(Mode.STRING, false,
- VERB_CREATE, OBJECT_AVD, "c", KEY_SDCARD,
- "Path to a shared SD card image, or size of a new sdcard for the new AVD", null);
- define(Mode.BOOLEAN, false,
- VERB_CREATE, OBJECT_AVD, "f", KEY_FORCE,
- "Force creation (override an existing AVD)", false);
-
- // --- delete avd ---
-
- define(Mode.STRING, true,
- VERB_DELETE, OBJECT_AVD, "n", KEY_NAME,
- "Name of the AVD to delete", null);
-
- // --- move avd ---
-
- define(Mode.STRING, true,
- VERB_MOVE, OBJECT_AVD, "n", KEY_NAME,
- "Name of the AVD to move or rename", null);
- define(Mode.STRING, false,
- VERB_MOVE, OBJECT_AVD, "r", KEY_RENAME,
- "New name of the AVD to rename", null);
- define(Mode.STRING, false,
- VERB_MOVE, OBJECT_AVD, "p", KEY_PATH,
- "New location path of the directory where to move the AVD", null);
-
- // --- update avd ---
-
- define(Mode.STRING, true,
- VERB_UPDATE, OBJECT_AVD, "n", KEY_NAME,
- "Name of the AVD to update", null);
-
- // --- create project ---
-
- /* Disabled for ADT 0.9 / Cupcake SDK 1.5_r1 release. [bug #1795718].
- This currently does not work, the alias build rules need to be fixed.
-
- define(Mode.ENUM, true,
- VERB_CREATE, OBJECT_PROJECT, "m", KEY_MODE,
- "Project mode", new String[] { ARG_ACTIVITY, ARG_ALIAS });
- */
- define(Mode.STRING, true,
- VERB_CREATE, OBJECT_PROJECT,
- "p", KEY_PATH,
- "Location path of new project", null);
- define(Mode.STRING, true,
- VERB_CREATE, OBJECT_PROJECT, "t", KEY_TARGET_ID,
- "Target id of the new project", null);
- define(Mode.STRING, true,
- VERB_CREATE, OBJECT_PROJECT, "k", KEY_PACKAGE,
- "Package name", null);
- define(Mode.STRING, true,
- VERB_CREATE, OBJECT_PROJECT, "a", KEY_ACTIVITY,
- "Activity name", null);
- define(Mode.STRING, false,
- VERB_CREATE, OBJECT_PROJECT, "n", KEY_NAME,
- "Project name", null);
-
- // --- create test-project ---
-
- define(Mode.STRING, true,
- VERB_CREATE, OBJECT_TEST_PROJECT,
- "p", KEY_PATH,
- "Location path of new project", null);
- define(Mode.STRING, false,
- VERB_CREATE, OBJECT_TEST_PROJECT, "n", KEY_NAME,
- "Project name", null);
- define(Mode.STRING, true,
- VERB_CREATE, OBJECT_TEST_PROJECT, "m", KEY_MAIN_PROJECT,
- "Location path of the project to test, relative to the new project", null);
-
- // --- update project ---
-
- define(Mode.STRING, true,
- VERB_UPDATE, OBJECT_PROJECT,
- "p", KEY_PATH,
- "Location path of the project", null);
- define(Mode.STRING, false,
- VERB_UPDATE, OBJECT_PROJECT,
- "t", KEY_TARGET_ID,
- "Target id to set for the project", null);
- define(Mode.STRING, false,
- VERB_UPDATE, OBJECT_PROJECT,
- "n", KEY_NAME,
- "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);
-
- // --- update test project ---
-
- define(Mode.STRING, true,
- VERB_UPDATE, OBJECT_TEST_PROJECT,
- "p", KEY_PATH,
- "Location path of the project", null);
- define(Mode.STRING, true,
- VERB_UPDATE, OBJECT_TEST_PROJECT,
- "m", KEY_MAIN_PROJECT,
- "Location path of the project to test, relative to the new project", null);
- }
-
- @Override
- public boolean acceptLackOfVerb() {
- return true;
- }
-
- // -- some helpers for generic action flags
-
- /** Helper to retrieve the --path value. */
- public String getParamLocationPath() {
- return (String) getValue(null, null, KEY_PATH);
- }
-
- /**
- * Helper to retrieve the --target id value.
- * The id is a string. It can be one of:
- * - an integer, in which case it's the index of the target (cf "android list targets")
- * - a symbolic name such as android-N for platforn API N
- * - a symbolic add-on name such as written in the avd/*.ini files,
- * e.g. "Google Inc.:Google APIs:3"
- */
- public String getParamTargetId() {
- return (String) getValue(null, null, KEY_TARGET_ID);
- }
-
- /** Helper to retrieve the --name value. */
- public String getParamName() {
- return (String) getValue(null, null, KEY_NAME);
- }
-
- /** Helper to retrieve the --skin value. */
- public String getParamSkin() {
- return (String) getValue(null, null, KEY_SKIN);
- }
-
- /** Helper to retrieve the --sdcard value. */
- public String getParamSdCard() {
- return (String) getValue(null, null, KEY_SDCARD);
- }
-
- /** Helper to retrieve the --force flag. */
- public boolean getFlagForce() {
- return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue();
- }
-
- // -- some helpers for avd action flags
-
- /** Helper to retrieve the --rename value for a move verb. */
- public String getParamMoveNewName() {
- return (String) getValue(VERB_MOVE, null, KEY_RENAME);
- }
-
-
- // -- some helpers for project action flags
-
- /** Helper to retrieve the --package value. */
- public String getParamProjectPackage() {
- return ((String) getValue(null, OBJECT_PROJECT, KEY_PACKAGE));
- }
-
- /** Helper to retrieve the --activity for any project action. */
- public String getParamProjectActivity() {
- 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();
- }
-
- // -- some helpers for test-project action flags
-
- /** Helper to retrieve the --main value. */
- public String getParamTestProjectMain() {
- return ((String) getValue(null, null, KEY_MAIN_PROJECT));
- }
-}
diff --git a/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java b/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java
deleted file mode 100755
index 742a065f3..000000000
--- a/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/AboutPage.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * 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.sdkmanager.internal.repository;
-
-
-import com.android.sdkmanager.*;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-public class AboutPage extends Composite {
-
- private Label mLabel;
-
- /**
- * Create the composite.
- * @param parent The parent of the composite.
- */
- public AboutPage(Composite parent) {
- super(parent, SWT.BORDER);
-
- createContents(this);
-
- postCreate(); //$hide$
- }
-
- private void createContents(Composite parent) {
- parent.setLayout(new GridLayout(2, false));
-
- Label logo = new Label(parent, SWT.NONE);
- InputStream imageStream = this.getClass().getResourceAsStream("logo.png");
-
- if (imageStream != null) {
- Image img = new Image(parent.getShell().getDisplay(), imageStream);
- logo.setImage(img);
- }
-
- mLabel = new Label(parent, SWT.NONE);
- mLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
- mLabel.setText(String.format(
- "Android SDK Updater.\nRevision %1$s\nCopyright (C) 2009 The Android Open Source Project.",
- getRevision()));
- }
-
- @Override
- protected void checkSubclass() {
- // Disable the check that prevents subclassing of SWT components
- }
-
- // -- Start of internal part ----------
- // Hide everything down-below from SWT designer
- //$hide>>$
-
- /**
- * Called by the constructor right after {@link #createContents(Composite)}.
- */
- private void postCreate() {
- }
-
- // End of hiding from SWT Designer
- //$hide<<$
-
- private String getRevision() {
- Properties p = new Properties();
- try{
- String toolsdir = System.getProperty(Main.TOOLSDIR);
- File sourceProp;
- if (toolsdir == null || toolsdir.length() == 0) {
- sourceProp = new File("source.properties"); //$NON-NLS-1$
- } else {
- sourceProp = new File(toolsdir, "source.properties"); //$NON-NLS-1$
- }
- p.load(new FileInputStream(sourceProp));
- String revision = p.getProperty("Pkg.Revision"); //$NON-NLS-1$
- if (revision != null) {
- return revision;
- }
- } catch (FileNotFoundException e) {
- // couldn't find the file? don't ping.
- } catch (IOException e) {
- // couldn't find the file? don't ping.
- }
-
- return "?";
- }
-}
diff --git a/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java b/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java
deleted file mode 100755
index c80005447..000000000
--- a/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * 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.sdkmanager.internal.repository;
-
-import com.android.sdkuilib.internal.repository.ISettingsPage;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-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.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Text;
-
-import java.util.Properties;
-
-
-public class SettingsPage extends Composite implements ISettingsPage {
-
- // data members
- private SettingsChangedCallback mSettingsChangedCallback;
-
- // UI widgets
- private Group mProxySettingsGroup;
- private Group mMiscGroup;
- private Button mApplyButton;
- private Label mProxyServerLabel;
- private Label mProxyPortLabel;
- private Text mProxyServerText;
- private Text mProxyPortText;
- private Button mForceHttpCheck;
- private Button mAskAdbRestartCheck;
-
- private ModifyListener mSetApplyDirty = new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- mApplyButton.setEnabled(true);
- }
- };
-
-
- /**
- * Create the composite.
- * @param parent The parent of the composite.
- */
- public SettingsPage(Composite parent) {
- super(parent, SWT.BORDER);
-
- createContents(this);
-
- mProxySettingsGroup = new Group(this, SWT.NONE);
- mProxySettingsGroup.setText("Proxy Settings");
- mProxySettingsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
- mProxySettingsGroup.setLayout(new GridLayout(2, false));
-
- mProxyServerLabel = new Label(mProxySettingsGroup, SWT.NONE);
- mProxyServerLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mProxyServerLabel.setText("HTTP Proxy Server");
- String tooltip = "The DNS name or IP of the HTTP proxy server to use. " +
- "When empty, no HTTP proxy is used.";
- mProxyServerLabel.setToolTipText(tooltip);
-
- mProxyServerText = new Text(mProxySettingsGroup, SWT.BORDER);
- mProxyServerText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- mProxyServerText.addModifyListener(mSetApplyDirty);
- mProxyServerText.setToolTipText(tooltip);
-
- mProxyPortLabel = new Label(mProxySettingsGroup, SWT.NONE);
- mProxyPortLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mProxyPortLabel.setText("HTTP Proxy Port");
- tooltip = "The port of the HTTP proxy server to use. " +
- "When empty, the default for HTTP or HTTPS is used.";
- mProxyPortLabel.setToolTipText(tooltip);
-
- mProxyPortText = new Text(mProxySettingsGroup, SWT.BORDER);
- mProxyPortText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- mProxyPortText.addModifyListener(mSetApplyDirty);
- mProxyPortText.setToolTipText(tooltip);
-
- mMiscGroup = new Group(this, SWT.NONE);
- mMiscGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
- mMiscGroup.setText("Misc");
- mMiscGroup.setLayout(new GridLayout(2, false));
-
- mForceHttpCheck = new Button(mMiscGroup, SWT.CHECK);
- mForceHttpCheck.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- mForceHttpCheck.setText("Force https://... sources to be fetched using http://...");
- mForceHttpCheck.setToolTipText("If you are not able to connect to the official Android repository " +
- "using HTTPS, enable this setting to force accessing it via HTTP.");
- mForceHttpCheck.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onForceHttpSelected(); //$hide$
- }
- });
-
- mAskAdbRestartCheck = new Button(mMiscGroup, SWT.CHECK);
- mAskAdbRestartCheck.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- mAskAdbRestartCheck.setText("Ask before restarting ADB");
- mAskAdbRestartCheck.setToolTipText("When checked, the user will be asked for permission " +
- "to restart ADB after updating an addon-on package or a tool package.");
- mAskAdbRestartCheck.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onForceHttpSelected(); //$hide$
- }
- });
-
- mApplyButton = new Button(this, SWT.NONE);
- mApplyButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
- mApplyButton.setText("Save && Apply");
- mApplyButton.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- onApplySelected(); //$hide$
- }
- });
-
- postCreate(); //$hide$
- }
-
- private void createContents(Composite parent) {
- parent.setLayout(new GridLayout(1, false));
- }
-
- @Override
- protected void checkSubclass() {
- // Disable the check that prevents subclassing of SWT components
- }
-
-
-
- // -- Start of internal part ----------
- // Hide everything down-below from SWT designer
- //$hide>>$
-
- /**
- * Called by the constructor right after {@link #createContents(Composite)}.
- */
- private void postCreate() {
- }
-
- /** Loads settings from the given {@link Properties} container and update the page UI. */
- public void loadSettings(Properties in_settings) {
- mProxyServerText.setText(in_settings.getProperty(KEY_HTTP_PROXY_HOST, "")); //$NON-NLS-1$
- mProxyPortText.setText( in_settings.getProperty(KEY_HTTP_PROXY_PORT, "")); //$NON-NLS-1$
- mForceHttpCheck.setSelection(Boolean.parseBoolean(in_settings.getProperty(KEY_FORCE_HTTP)));
- mAskAdbRestartCheck.setSelection(Boolean.parseBoolean(in_settings.getProperty(KEY_ASK_ADB_RESTART)));
-
- // We loaded fresh settings so there's nothing dirty to apply
- mApplyButton.setEnabled(false);
- }
-
- /** Called by the application to retrieve settings from the UI and store them in
- * the given {@link Properties} container. */
- public void retrieveSettings(Properties out_settings) {
- out_settings.setProperty(KEY_HTTP_PROXY_HOST, mProxyServerText.getText());
- out_settings.setProperty(KEY_HTTP_PROXY_PORT, mProxyPortText.getText());
- out_settings.setProperty(KEY_FORCE_HTTP,
- Boolean.toString(mForceHttpCheck.getSelection()));
- out_settings.setProperty(KEY_ASK_ADB_RESTART,
- Boolean.toString(mAskAdbRestartCheck.getSelection()));
- }
-
- /**
- * Called by the application to give a callback that the page should invoke when
- * settings must be applied. The page does not apply the settings itself, instead
- * it notifies the application.
- */
- public void setOnSettingsChanged(SettingsChangedCallback settingsChangedCallback) {
- mSettingsChangedCallback = settingsChangedCallback;
- }
-
- /**
- * Callback invoked when user presses the "Save and Apply" button.
- * Notify the application that settings have changed.
- */
- private void onApplySelected() {
- if (mSettingsChangedCallback != null) {
- mSettingsChangedCallback.onSettingsChanged(this);
- mApplyButton.setEnabled(false);
- }
- }
-
- /**
- * Callback invoked when the users presses the Force HTTPS checkbox.
- */
- private void onForceHttpSelected() {
- mSetApplyDirty.modifyText(null);
- }
-
- // End of hiding from SWT Designer
- //$hide<<$
-}
diff --git a/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/logo.png b/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/logo.png
deleted file mode 100644
index 0f1670d7f..000000000
--- a/tools/sdkmanager/app/src/com/android/sdkmanager/internal/repository/logo.png
+++ /dev/null
Binary files differ
diff --git a/tools/sdkmanager/app/tests/com/android/sdkmanager/CommandLineProcessorTest.java b/tools/sdkmanager/app/tests/com/android/sdkmanager/CommandLineProcessorTest.java
deleted file mode 100644
index a213652d7..000000000
--- a/tools/sdkmanager/app/tests/com/android/sdkmanager/CommandLineProcessorTest.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * 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.sdkmanager;
-
-import com.android.sdklib.ISdkLog;
-
-import junit.framework.TestCase;
-
-
-public class CommandLineProcessorTest extends TestCase {
-
- private MockStdLogger mLog;
-
- /**
- * A mock version of the {@link CommandLineProcessor} class that does not
- * exits and captures its stdout/stderr output.
- */
- public static class MockCommandLineProcessor extends CommandLineProcessor {
- private boolean mExitCalled;
- private boolean mHelpCalled;
- private String mStdOut = "";
- private String mStdErr = "";
-
- public MockCommandLineProcessor(ISdkLog logger) {
- super(logger,
- new String[][] {
- { "verb1", "action1", "Some action" },
- { "verb1", "action2", "Another action" },
- });
- define(Mode.STRING, false /*mandatory*/,
- "verb1", "action1", "1", "first", "non-mandatory flag", null);
- define(Mode.STRING, true /*mandatory*/,
- "verb1", "action1", "2", "second", "mandatory flag", null);
- }
-
- @Override
- public void printHelpAndExitForAction(String verb, String directObject,
- String errorFormat, Object... args) {
- mHelpCalled = true;
- super.printHelpAndExitForAction(verb, directObject, errorFormat, args);
- }
-
- @Override
- protected void exit() {
- mExitCalled = true;
- }
-
- @Override
- protected void stdout(String format, Object... args) {
- String s = String.format(format, args);
- mStdOut += s + "\n";
- // don't call super to avoid printing stuff
- }
-
- @Override
- protected void stderr(String format, Object... args) {
- String s = String.format(format, args);
- mStdErr += s + "\n";
- // don't call super to avoid printing stuff
- }
-
- public boolean wasHelpCalled() {
- return mHelpCalled;
- }
-
- public boolean wasExitCalled() {
- return mExitCalled;
- }
-
- public String getStdOut() {
- return mStdOut;
- }
-
- public String getStdErr() {
- return mStdErr;
- }
- }
-
- @Override
- protected void setUp() throws Exception {
- mLog = new MockStdLogger();
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public final void testPrintHelpAndExit() {
- MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);
- assertFalse(c.wasExitCalled());
- assertFalse(c.wasHelpCalled());
- assertTrue(c.getStdOut().equals(""));
- assertTrue(c.getStdErr().equals(""));
- c.printHelpAndExit(null);
- assertTrue(c.getStdOut().indexOf("-v") != -1);
- assertTrue(c.getStdOut().indexOf("--verbose") != -1);
- assertTrue(c.getStdErr().equals(""));
- assertTrue(c.wasExitCalled());
-
- c = new MockCommandLineProcessor(mLog);
- assertFalse(c.wasExitCalled());
- assertTrue(c.getStdOut().equals(""));
- assertTrue(c.getStdErr().indexOf("Missing parameter") == -1);
-
- c.printHelpAndExit("Missing %s", "parameter");
- assertTrue(c.wasExitCalled());
- assertFalse(c.getStdOut().equals(""));
- assertTrue(c.getStdErr().indexOf("Missing parameter") != -1);
- }
-
- public final void testVerbose() {
- MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);
-
- assertFalse(c.isVerbose());
- c.parseArgs(new String[] { "-v" });
- assertTrue(c.isVerbose());
- assertTrue(c.wasExitCalled());
- assertTrue(c.wasHelpCalled());
- assertTrue(c.getStdErr().indexOf("Missing verb name.") != -1);
-
- c = new MockCommandLineProcessor(mLog);
- c.parseArgs(new String[] { "--verbose" });
- assertTrue(c.isVerbose());
- assertTrue(c.wasExitCalled());
- assertTrue(c.wasHelpCalled());
- assertTrue(c.getStdErr().indexOf("Missing verb name.") != -1);
- }
-
- public final void testHelp() {
- MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);
-
- c.parseArgs(new String[] { "-h" });
- assertTrue(c.wasExitCalled());
- assertTrue(c.wasHelpCalled());
- assertTrue(c.getStdErr().indexOf("Missing verb name.") == -1);
-
- c = new MockCommandLineProcessor(mLog);
- c.parseArgs(new String[] { "--help" });
- assertTrue(c.wasExitCalled());
- assertTrue(c.wasHelpCalled());
- assertTrue(c.getStdErr().indexOf("Missing verb name.") == -1);
- }
-
- public final void testMandatory() {
- MockCommandLineProcessor c = new MockCommandLineProcessor(mLog);
-
- c.parseArgs(new String[] { "verb1", "action1", "-1", "value1", "-2", "value2" });
- assertFalse(c.wasExitCalled());
- assertFalse(c.wasHelpCalled());
- assertEquals("", c.getStdErr());
- assertEquals("value1", c.getValue("verb1", "action1", "first"));
- assertEquals("value2", c.getValue("verb1", "action1", "second"));
-
- c = new MockCommandLineProcessor(mLog);
- c.parseArgs(new String[] { "verb1", "action1", "-2", "value2" });
- assertFalse(c.wasExitCalled());
- assertFalse(c.wasHelpCalled());
- assertEquals("", c.getStdErr());
- assertEquals(null, c.getValue("verb1", "action1", "first"));
- assertEquals("value2", c.getValue("verb1", "action1", "second"));
-
- c = new MockCommandLineProcessor(mLog);
- c.parseArgs(new String[] { "verb1", "action1" });
- assertTrue(c.wasExitCalled());
- assertTrue(c.wasHelpCalled());
- assertTrue(c.getStdErr().indexOf("must be defined") != -1);
- assertEquals(null, c.getValue("verb1", "action1", "first"));
- assertEquals(null, c.getValue("verb1", "action1", "second"));
- }
-}
diff --git a/tools/sdkmanager/app/tests/com/android/sdkmanager/MockStdLogger.java b/tools/sdkmanager/app/tests/com/android/sdkmanager/MockStdLogger.java
deleted file mode 100644
index 961e88dae..000000000
--- a/tools/sdkmanager/app/tests/com/android/sdkmanager/MockStdLogger.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2008 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.sdkmanager;
-
-import com.android.sdklib.ISdkLog;
-
-/**
- *
- */
-public class MockStdLogger implements ISdkLog {
-
- public void error(Throwable t, String errorFormat, Object... args) {
- if (errorFormat != null) {
- System.err.printf("Error: " + errorFormat, args);
- if (!errorFormat.endsWith("\n")) {
- System.err.printf("\n");
- }
- }
- if (t != null) {
- System.err.printf("Error: %s\n", t.getMessage());
- }
- }
-
- public void warning(String warningFormat, Object... args) {
- System.out.printf("Warning: " + warningFormat, args);
- if (!warningFormat.endsWith("\n")) {
- System.out.printf("\n");
- }
- }
-
- public void printf(String msgFormat, Object... args) {
- System.out.printf(msgFormat, args);
- }
-}
diff --git a/tools/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java b/tools/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java
deleted file mode 100644
index 07a32e04e..000000000
--- a/tools/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
- *
- * 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.sdkmanager;
-
-import com.android.sdklib.ISdkLog;
-
-import junit.framework.TestCase;
-
-public class SdkCommandLineTest extends TestCase {
-
- private MockStdLogger mLog;
-
- /**
- * A mock version of the {@link SdkCommandLine} class that does not
- * exits and discards its stdout/stderr output.
- */
- public static class MockSdkCommandLine extends SdkCommandLine {
- private boolean mExitCalled;
- private boolean mHelpCalled;
-
- public MockSdkCommandLine(ISdkLog logger) {
- super(logger);
- }
-
- @Override
- public void printHelpAndExitForAction(String verb, String directObject,
- String errorFormat, Object... args) {
- mHelpCalled = true;
- super.printHelpAndExitForAction(verb, directObject, errorFormat, args);
- }
-
- @Override
- protected void exit() {
- mExitCalled = true;
- }
-
- @Override
- protected void stdout(String format, Object... args) {
- // discard
- }
-
- @Override
- protected void stderr(String format, Object... args) {
- // discard
- }
-
- public boolean wasExitCalled() {
- return mExitCalled;
- }
-
- public boolean wasHelpCalled() {
- return mHelpCalled;
- }
- }
-
- @Override
- protected void setUp() throws Exception {
- mLog = new MockStdLogger();
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /** Test list */
- public final void testList_Avd_Verbose() {
- MockSdkCommandLine c = new MockSdkCommandLine(mLog);
- c.parseArgs(new String[] { "-v", "list", "avd" });
- assertFalse(c.wasHelpCalled());
- assertFalse(c.wasExitCalled());
- assertEquals("list", c.getVerb());
- assertEquals("avd", c.getDirectObject());
- assertTrue(c.isVerbose());
- }
-
- public final void testList_Target() {
- MockSdkCommandLine c = new MockSdkCommandLine(mLog);
- c.parseArgs(new String[] { "list", "target" });
- assertFalse(c.wasHelpCalled());
- assertFalse(c.wasExitCalled());
- assertEquals("list", c.getVerb());
- assertEquals("target", c.getDirectObject());
- assertFalse(c.isVerbose());
- }
-
- public final void testList_None() {
- MockSdkCommandLine c = new MockSdkCommandLine(mLog);
- c.parseArgs(new String[] { "list" });
- assertFalse(c.wasHelpCalled());
- assertFalse(c.wasExitCalled());
- assertEquals("list", c.getVerb());
- assertEquals("", c.getDirectObject());
- assertFalse(c.isVerbose());
- }
-
- public final void testList_Invalid() {
- MockSdkCommandLine c = new MockSdkCommandLine(mLog);
- c.parseArgs(new String[] { "list", "unknown" });
- assertTrue(c.wasHelpCalled());
- assertTrue(c.wasExitCalled());
- assertEquals(null, c.getVerb());
- assertEquals(null, c.getDirectObject());
- assertFalse(c.isVerbose());
- }
-
- public final void testList_Plural() {
- MockSdkCommandLine c = new MockSdkCommandLine(mLog);
- c.parseArgs(new String[] { "list", "avds" });
- assertFalse(c.wasHelpCalled());
- assertFalse(c.wasExitCalled());
- assertEquals("list", c.getVerb());
- // we get the non-plural form
- assertEquals("avd", c.getDirectObject());
- assertFalse(c.isVerbose());
-
- c = new MockSdkCommandLine(mLog);
- c.parseArgs(new String[] { "list", "targets" });
- assertFalse(c.wasHelpCalled());
- assertFalse(c.wasExitCalled());
- assertEquals("list", c.getVerb());
- // we get the non-plural form
- assertEquals("target", c.getDirectObject());
- assertFalse(c.isVerbose());
- }
-}