sdkmanager

16:52:18.696 INFO  jd.cli.Main - Decompiling sdkmanager.jar
package com.android.sdkmanager;

import com.android.sdklib.repository.SdkRepoConstants;
import com.android.sdklib.util.CommandLineParser;
import com.android.sdklib.util.CommandLineParser.Mode;
import com.android.utils.ILogger;
import java.util.Arrays;

class SdkCommandLine
  extends CommandLineParser
{
  public static final String VERB_LIST = "list";
  public static final String VERB_CREATE = "create";
  public static final String VERB_MOVE = "move";
  public static final String VERB_DELETE = "delete";
  public static final String VERB_UPDATE = "update";
  public static final String VERB_SDK = "sdk";
  public static final String VERB_AVD = "avd";
  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_DEVICE = "device";
  public static final String OBJECT_DEVICES = "devices";
  public static final String OBJECT_PROJECT = "project";
  public static final String OBJECT_TEST_PROJECT = "test-project";
  public static final String OBJECT_UITEST_PROJECT = "uitest-project";
  public static final String OBJECT_LIB_PROJECT = "lib-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 = "activity";
  public static final String KEY_PACKAGE = "package";
  public static final String KEY_MODE = "mode";
  public static final String KEY_TARGET_ID = "target";
  public static final String KEY_NAME = "name";
  public static final String KEY_LIBRARY = "library";
  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";
  public static final String KEY_NO_UI = "no-ui";
  public static final String KEY_NO_HTTPS = "no-https";
  public static final String KEY_PROXY_PORT = "proxy-port";
  public static final String KEY_PROXY_HOST = "proxy-host";
  public static final String KEY_DRY_MODE = "dry-mode";
  public static final String KEY_ALL = "all";
  public static final String KEY_EXTENDED = "extended";
  public static final String KEY_SNAPSHOT = "snapshot";
  public static final String KEY_COMPACT = "compact";
  public static final String KEY_EOL_NULL = "null";
  public static final String KEY_TAG = "tag";
  public static final String KEY_ABI = "abi";
  public static final String KEY_ACCOUNT = "account";
  public static final String KEY_KEYSTORE = "keystore";
  public static final String KEY_ALIAS = "alias";
  public static final String KEY_STOREPASS = "storepass";
  public static final String KEY_KEYPASS = "keypass";
  public static final String KEY_CLEAR_CACHE = "clear-cache";
  public static final String KEY_GRADLE = "gradle";
  public static final String KEY_GRADLE_VERSION = "gradle-version";
  public static final String KEY_DEVICE = "device";
  private static final String[][] ACTIONS = { { "sdk", "", "Displays the SDK Manager window." }, { "avd", "", "Displays the AVD Manager window." }, { "list", "", "Lists existing targets or virtual devices." }, { "list", "avd", "Lists existing Android Virtual Devices.", "avds" }, { "list", "target", "Lists existing targets.", "targets" }, { "list", "device", "Lists existing devices.", "devices" }, { "list", "sdk", "Lists remote SDK repository." }, { "create", "avd", "Creates a new Android Virtual Device." }, { "move", "avd", "Moves or renames an Android Virtual Device." }, { "delete", "avd", "Deletes an Android Virtual Device." }, { "update", "avd", "Updates an Android Virtual Device to match the folders of a new SDK." }, { "create", "project", "Creates a new Android project." }, { "update", "project", "Updates an Android project (must already have an AndroidManifest.xml)." }, { "create", "test-project", "Creates a new Android project for a test package." }, { "update", "test-project", "Updates the Android project for a test package (must already have an AndroidManifest.xml)." }, { "create", "lib-project", "Creates a new Android library project." }, { "update", "lib-project", "Updates an Android library project (must already have an AndroidManifest.xml)." }, { "create", "uitest-project", "Creates a new UI test project." }, { "update", "adb", "Updates adb to support the USB devices declared in the SDK add-ons." }, { "update", "sdk", "Updates the SDK by suggesting new platforms to install if available." } };
  
  public SdkCommandLine(ILogger logger)
  {
    super(logger, ACTIONS);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "@@internal@@", "", "", "clear-cache", "Clear the SDK Manager repository manifest cache.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "avd", "c", "compact", "Compact output (suitable for scripts)", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "avd", "0", "null", "Terminates lines with \\0 instead of \\n (e.g. for xargs -0). Only used by --compact.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "target", "c", "compact", "Compact output (suitable for scripts)", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "target", "0", "null", "Terminates lines with \\0 instead of \\n (e.g. for xargs -0) Only used by --compact.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "device", "c", "compact", "Compact output (suitable for scripts)", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "device", "0", "null", "Terminates lines with \\0 instead of \\n (e.g. for xargs -0) Only used by --compact.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, false, "create", "avd", "p", "path", "Directory where the new AVD will be created.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "avd", "n", "name", "Name of the new AVD.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "avd", "t", "target", "Target ID of the new AVD.", null);
    
    define(CommandLineParser.Mode.STRING, false, "create", "avd", "s", "skin", "Skin for the new AVD.", null);
    
    define(CommandLineParser.Mode.STRING, false, "create", "avd", "c", "sdcard", "Path to a shared SD card image, or size of a new sdcard for the new AVD.", null);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "create", "avd", "f", "force", "Forces creation (overwrites an existing AVD)", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "create", "avd", "a", "snapshot", "Place a snapshots file in the AVD, to enable persistence.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, false, "create", "avd", "b", "abi", "The ABI to use for the AVD. The default is to auto-select the ABI if the platform has only one ABI for its system images.", null);
    
    define(CommandLineParser.Mode.STRING, false, "create", "avd", "g", "tag", "The sys-img tag to use for the AVD. The default is to auto-select if the platform has only one tag for its system images.", null);
    
    define(CommandLineParser.Mode.STRING, false, "create", "avd", "d", "device", "The optional device definition to use. Can be a device index or id.", null);
    
    define(CommandLineParser.Mode.STRING, true, "delete", "avd", "n", "name", "Name of the AVD to delete.", null);
    
    define(CommandLineParser.Mode.STRING, true, "move", "avd", "n", "name", "Name of the AVD to move or rename.", null);
    
    define(CommandLineParser.Mode.STRING, false, "move", "avd", "r", "rename", "New name of the AVD.", null);
    
    define(CommandLineParser.Mode.STRING, false, "move", "avd", "p", "path", "Path to the AVD's new directory.", null);
    
    define(CommandLineParser.Mode.STRING, true, "update", "avd", "n", "name", "Name of the AVD to update", null);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "sdk", "u", "no-ui", "Displays list result on console (no GUI)", Boolean.valueOf(true));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "sdk", "s", "no-https", "Uses HTTP instead of HTTPS (the default) for downloads.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, false, "list", "sdk", "", "proxy-port", "HTTP/HTTPS proxy port (overrides settings if defined)", null);
    
    define(CommandLineParser.Mode.STRING, false, "list", "sdk", "", "proxy-host", "HTTP/HTTPS proxy host (overrides settings if defined)", null);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "sdk", "a", "all", "Lists all available packages (including obsolete and installed ones)", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "sdk", "o", "obsolete", "Deprecated. Please use --all instead.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "list", "sdk", "e", "extended", "Displays extended details on each package", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "update", "sdk", "u", "no-ui", "Updates from command-line (does not display the GUI)", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "update", "sdk", "s", "no-https", "Uses HTTP instead of HTTPS (the default) for downloads.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, false, "update", "sdk", "", "proxy-port", "HTTP/HTTPS proxy port (overrides settings if defined)", null);
    
    define(CommandLineParser.Mode.STRING, false, "update", "sdk", "", "proxy-host", "HTTP/HTTPS proxy host (overrides settings if defined)", null);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "update", "sdk", "f", "force", "Forces replacement of a package or its parts, even if something has been modified.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, false, "update", "sdk", "t", "filter", "A filter that limits the update to the specified types of packages in the form of a comma-separated list of " + Arrays.toString(SdkRepoConstants.NODES) + ". This also accepts the identifiers returned by 'list sdk --extended'.", null);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "update", "sdk", "a", "all", "Includes all packages (such as obsolete and non-dependent ones.)", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "update", "sdk", "p", "obsolete", "Deprecated. Please use --all instead.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.BOOLEAN, false, "update", "sdk", "n", "dry-mode", "Simulates the update but does not download or install anything.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, true, "create", "project", "p", "path", "The new project's directory.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "project", "t", "target", "Target ID of the new project.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "project", "k", "package", "Android package name for the application.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "project", "a", "activity", "Name of the default Activity that is created.", null);
    
    define(CommandLineParser.Mode.STRING, false, "create", "project", "n", "name", "Project name.", null);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "create", "project", "g", "gradle", "Use gradle template.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, false, "create", "project", "v", "gradle-version", "Gradle Android plugin version.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "test-project", "p", "path", "The new project's directory.", null);
    
    define(CommandLineParser.Mode.STRING, false, "create", "test-project", "n", "name", "Project name.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "test-project", "m", "main", "Path to directory of the app under test, relative to the test project directory.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "uitest-project", "p", "path", "The new project's directory.", null);
    
    define(CommandLineParser.Mode.STRING, false, "create", "uitest-project", "n", "name", "Project name.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "uitest-project", "t", "target", "Target ID of the new project.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "lib-project", "p", "path", "The new project's directory.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "lib-project", "t", "target", "Target ID of the new project.", null);
    
    define(CommandLineParser.Mode.STRING, false, "create", "lib-project", "n", "name", "Project name.", null);
    
    define(CommandLineParser.Mode.STRING, true, "create", "lib-project", "k", "package", "Android package name for the library.", null);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "create", "lib-project", "g", "gradle", "Use gradle template.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, false, "create", "lib-project", "v", "gradle-version", "Gradle Android plugin version.", null);
    
    define(CommandLineParser.Mode.STRING, true, "update", "project", "p", "path", "The project's directory.", null);
    
    define(CommandLineParser.Mode.STRING, false, "update", "project", "t", "target", "Target ID to set for the project.", null);
    
    define(CommandLineParser.Mode.STRING, false, "update", "project", "n", "name", "Project name.", null);
    
    define(CommandLineParser.Mode.BOOLEAN, false, "update", "project", "s", "subprojects", "Also updates any projects in sub-folders, such as test projects.", Boolean.valueOf(false));
    
    define(CommandLineParser.Mode.STRING, false, "update", "project", "l", "library", "Directory of an Android library to add, relative to this project's directory.", null);
    
    define(CommandLineParser.Mode.STRING, true, "update", "test-project", "p", "path", "The project's directory.", null);
    
    define(CommandLineParser.Mode.STRING, true, "update", "test-project", "m", "main", "Directory of the app under test, relative to the test project directory.", null);
    
    define(CommandLineParser.Mode.STRING, true, "update", "lib-project", "p", "path", "The project's directory.", null);
    
    define(CommandLineParser.Mode.STRING, false, "update", "lib-project", "t", "target", "Target ID to set for the project.", null);
  }
  
  public boolean acceptLackOfVerb()
  {
    return true;
  }
  
  public boolean hasClearCache()
  {
    return ((Boolean)getValue("@@internal@@", "", "clear-cache")).booleanValue();
  }
  
  public String getParamLocationPath()
  {
    return (String)getValue(null, null, "path");
  }
  
  public String getParamTargetId()
  {
    return (String)getValue(null, null, "target");
  }
  
  public String getParamName()
  {
    return (String)getValue(null, null, "name");
  }
  
  public String getParamSkin()
  {
    return (String)getValue(null, null, "skin");
  }
  
  public String getParamSdCard()
  {
    return (String)getValue(null, null, "sdcard");
  }
  
  public boolean getFlagForce()
  {
    return ((Boolean)getValue(null, null, "force")).booleanValue();
  }
  
  public boolean getFlagSnapshot()
  {
    return ((Boolean)getValue(null, null, "snapshot")).booleanValue();
  }
  
  public String getParamMoveNewName()
  {
    return (String)getValue("move", null, "rename");
  }
  
  public String getParamProjectPackage(String directObject)
  {
    return (String)getValue(null, directObject, "package");
  }
  
  public String getParamProjectActivity()
  {
    return (String)getValue(null, "project", "activity");
  }
  
  public String getParamProjectLibrary(String directObject)
  {
    return (String)getValue(null, directObject, "library");
  }
  
  public boolean getParamSubProject()
  {
    return ((Boolean)getValue(null, "project", "subprojects")).booleanValue();
  }
  
  public boolean getParamGradle()
  {
    return ((Boolean)getValue(null, null, "gradle")).booleanValue();
  }
  
  public String getParamGradleVersion()
  {
    return (String)getValue(null, null, "gradle-version");
  }
  
  public String getParamTestProjectMain()
  {
    return (String)getValue(null, null, "main");
  }
  
  public boolean getFlagNoUI(String verb)
  {
    return ((Boolean)getValue(verb, null, "no-ui")).booleanValue();
  }
  
  public boolean getFlagNoHttps()
  {
    return ((Boolean)getValue(null, null, "no-https")).booleanValue();
  }
  
  public boolean getFlagDryMode()
  {
    return ((Boolean)getValue(null, null, "dry-mode")).booleanValue();
  }
  
  public boolean getFlagObsolete()
  {
    return ((Boolean)getValue(null, null, "obsolete")).booleanValue();
  }
  
  public boolean getFlagAll()
  {
    return ((Boolean)getValue(null, null, "all")).booleanValue();
  }
  
  public boolean getFlagExtended()
  {
    return ((Boolean)getValue(null, null, "extended")).booleanValue();
  }
  
  public String getParamFilter()
  {
    return (String)getValue(null, null, "filter");
  }
  
  public String getParamAbi()
  {
    return (String)getValue(null, null, "abi");
  }
  
  public String getParamTag()
  {
    return (String)getValue(null, null, "tag");
  }
  
  public String getParamDevice()
  {
    return (String)getValue(null, null, "device");
  }
  
  public String getParamProxyHost()
  {
    return (String)getValue(null, null, "proxy-host");
  }
  
  public String getParamProxyPort()
  {
    return (String)getValue(null, null, "proxy-port");
  }
  
  public boolean getFlagCompact()
  {
    return ((Boolean)getValue(null, null, "compact")).booleanValue();
  }
  
  public boolean getFlagEolNull()
  {
    return ((Boolean)getValue(null, null, "null")).booleanValue();
  }
}

/* Location:
 * Qualified Name:     com.android.sdkmanager.SdkCommandLine
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.sdkmanager;

import com.android.sdklib.internal.avd.AvdInfo;
import java.util.Comparator;

class Main$2
  implements Comparator<AvdInfo>
{
  Main$2(Main paramMain) {}
  
  public int compare(AvdInfo a1, AvdInfo a2)
  {
    return a1.getName().compareToIgnoreCase(a2.getName());
  }
}

/* Location:
 * Qualified Name:     com.android.sdkmanager.Main.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.sdkmanager;

import com.android.annotations.NonNull;
import com.android.utils.IReaderLogger;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;

class Main$1
  implements IReaderLogger
{
  Main$1(Main paramMain) {}
  
  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", new Object[0]);
      }
    }
    if (t != null) {
      System.err.printf("Error: %s\n", new Object[] { t.getMessage() });
    }
  }
  
  public void warning(@NonNull String warningFormat, Object... args)
  {
    if (Main.access$000(this$0).isVerbose())
    {
      System.out.printf("Warning: " + warningFormat, args);
      if (!warningFormat.endsWith("\n")) {
        System.out.printf("\n", new Object[0]);
      }
    }
  }
  
  public void info(@NonNull String msgFormat, Object... args)
  {
    System.out.printf(msgFormat, args);
  }
  
  public void verbose(@NonNull String msgFormat, Object... args)
  {
    System.out.printf(msgFormat, args);
  }
  
  public int readLine(byte[] inputBuffer)
    throws IOException
  {
    return System.in.read(inputBuffer);
  }
}

/* Location:
 * Qualified Name:     com.android.sdkmanager.Main.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.sdkmanager;

class Main$4 {}

/* Location:
 * Qualified Name:     com.android.sdkmanager.Main.4
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.sdkmanager;

import com.android.SdkConstants;
import com.android.annotations.NonNull;
import com.android.annotations.Nullable;
import com.android.io.FileWrapper;
import com.android.prefs.AndroidLocation;
import com.android.prefs.AndroidLocation.AndroidLocationException;
import com.android.sdklib.AndroidVersion;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.IAndroidTarget.IOptionalLibrary;
import com.android.sdklib.ISystemImage;
import com.android.sdklib.SdkManager;
import com.android.sdklib.SystemImage;
import com.android.sdklib.devices.Device;
import com.android.sdklib.devices.DeviceManager;
import com.android.sdklib.internal.avd.AvdInfo;
import com.android.sdklib.internal.avd.AvdManager;
import com.android.sdklib.internal.avd.HardwareProperties;
import com.android.sdklib.internal.avd.HardwareProperties.HardwareProperty;
import com.android.sdklib.internal.project.ProjectCreator;
import com.android.sdklib.internal.project.ProjectCreator.OutputLevel;
import com.android.sdklib.internal.project.ProjectProperties;
import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
import com.android.sdklib.internal.project.ProjectPropertiesWorkingCopy;
import com.android.sdklib.internal.repository.DownloadCache;
import com.android.sdklib.internal.repository.DownloadCache.Strategy;
import com.android.sdklib.internal.repository.updater.SdkUpdaterNoWindow;
import com.android.sdklib.repository.SdkAddonConstants;
import com.android.sdklib.repository.SdkRepoConstants;
import com.android.sdklib.repository.descriptors.IdDisplay;
import com.android.sdklib.repository.local.LocalSysImgPkgInfo;
import com.android.sdkuilib.internal.widgets.MessageBoxLog;
import com.android.sdkuilib.repository.AvdManagerWindow;
import com.android.sdkuilib.repository.AvdManagerWindow.AvdInvocationContext;
import com.android.sdkuilib.repository.SdkUpdaterWindow;
import com.android.sdkuilib.repository.SdkUpdaterWindow.SdkInvocationContext;
import com.android.utils.ILogger;
import com.android.utils.IReaderLogger;
import com.android.utils.Pair;
import com.android.xml.AndroidXPathFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import org.eclipse.swt.widgets.Display;
import org.xml.sax.InputSource;

public class Main
{
  public static final String TOOLSDIR = "com.android.sdkmanager.toolsdir";
  private static final String WORKDIR = "com.android.sdkmanager.workdir";
  private static final int INVALID_TARGET_ID = 0;
  private static final String[] BOOLEAN_YES_REPLIES = { "yes", "y" };
  private static final String[] BOOLEAN_NO_REPLIES = { "no", "n" };
  private String mOsSdkFolder;
  private ILogger mSdkLog;
  private SdkManager mSdkManager;
  private SdkCommandLine mSdkCommandLine;
  private File mWorkDir;
  private AvdManager mAvdManager;
  
  public static void main(String[] args)
  {
    new Main().run(args);
  }
  
  void setupForTest(@Nullable SdkManager sdkManager, @Nullable ILogger logger, @Nullable SdkCommandLine cmdLineParser, @Nullable String... args)
  {
    if (logger != null) {
      setLogger(logger);
    }
    if (cmdLineParser != null) {
      mSdkCommandLine = cmdLineParser;
    }
    if (args != null)
    {
      if (mSdkCommandLine == null) {
        mSdkCommandLine = new SdkCommandLine(logger);
      }
      mSdkCommandLine.parseArgs(args);
    }
    if (sdkManager != null) {
      mSdkManager = sdkManager;
    }
  }
  
  private void run(String[] args)
  {
    createLogger();
    init();
    mSdkCommandLine.parseArgs(args);
    parseSdk();
    doAction();
  }
  
  private void createLogger()
  {
    mSdkLog = new IReaderLogger()
    {
      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", new Object[0]);
          }
        }
        if (t != null) {
          System.err.printf("Error: %s\n", new Object[] { t.getMessage() });
        }
      }
      
      public void warning(@NonNull String warningFormat, Object... args)
      {
        if (mSdkCommandLine.isVerbose())
        {
          System.out.printf("Warning: " + warningFormat, args);
          if (!warningFormat.endsWith("\n")) {
            System.out.printf("\n", new Object[0]);
          }
        }
      }
      
      public void info(@NonNull String msgFormat, Object... args)
      {
        System.out.printf(msgFormat, args);
      }
      
      public void verbose(@NonNull String msgFormat, Object... args)
      {
        System.out.printf(msgFormat, args);
      }
      
      public int readLine(byte[] inputBuffer)
        throws IOException
      {
        return System.in.read(inputBuffer);
      }
    };
  }
  
  public void setLogger(ILogger logger)
  {
    mSdkLog = logger;
  }
  
  protected ILogger getLogger()
  {
    return mSdkLog;
  }
  
  private void init()
  {
    mSdkCommandLine = new SdkCommandLine(mSdkLog);
    
    String toolsDirProp = System.getProperty("com.android.sdkmanager.toolsdir");
    if (toolsDirProp == null) {
      toolsDirProp = System.getenv("com.android.sdkmanager.toolsdir");
    }
    if (toolsDirProp != null) {
      if (toolsDirProp.length() > 0)
      {
        File tools = new File(toolsDirProp);
        mOsSdkFolder = tools.getParent();
      }
      else
      {
        try
        {
          File tools = new File(".").getCanonicalFile();
          mOsSdkFolder = tools.getParent();
        }
        catch (IOException e) {}
      }
    }
    if (mOsSdkFolder == null) {
      errorAndExit("The tools directory property is not set, please make sure you are executing %1$s", new Object[] { SdkConstants.androidCmdName() });
    }
    String workDirProp = System.getProperty("com.android.sdkmanager.workdir");
    if (workDirProp == null) {
      workDirProp = System.getenv("com.android.sdkmanager.workdir");
    }
    if (workDirProp != null)
    {
      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", new Object[] { workDirProp });
      }
    }
  }
  
  private void parseSdk()
  {
    mSdkManager = SdkManager.createManager(mOsSdkFolder, mSdkLog);
    if (mSdkManager == null) {
      errorAndExit("Unable to parse SDK content.", new Object[0]);
    }
  }
  
  @NonNull
  protected AvdManager getAvdManager()
    throws AndroidLocation.AndroidLocationException
  {
    if (mAvdManager == null) {
      mAvdManager = AvdManager.getInstance(mSdkManager, mSdkLog);
    }
    return mAvdManager;
  }
  
  void doAction()
  {
    if (mSdkCommandLine.hasClearCache())
    {
      DownloadCache d = new DownloadCache(DownloadCache.Strategy.SERVE_CACHE);
      d.clearCache();
      mSdkLog.info("SDK Manager repository: manifest cache cleared.\n", new Object[0]);
    }
    String verb = mSdkCommandLine.getVerb();
    String directObject = mSdkCommandLine.getDirectObject();
    if ("list".equals(verb))
    {
      if ("target".equals(directObject))
      {
        displayTargetList();
      }
      else if ("avd".equals(directObject))
      {
        displayAvdList();
      }
      else if ("sdk".equals(directObject))
      {
        displayRemoteSdkListNoUI();
      }
      else if ("device".equals(directObject))
      {
        displayDeviceList();
      }
      else
      {
        displayTargetList();
        displayAvdList();
        displayDeviceList();
      }
    }
    else if ("create".equals(verb))
    {
      if ("avd".equals(directObject)) {
        createAvd();
      } else if ("project".equals(directObject)) {
        createProject(false);
      } else if ("test-project".equals(directObject)) {
        createTestProject();
      } else if ("lib-project".equals(directObject)) {
        createProject(true);
      } else if ("uitest-project".equals(directObject)) {
        createUiTestProject();
      }
    }
    else if ("update".equals(verb))
    {
      if ("avd".equals(directObject)) {
        updateAvd();
      } else if ("project".equals(directObject)) {
        updateProject(false);
      } else if ("test-project".equals(directObject)) {
        updateTestProject();
      } else if ("lib-project".equals(directObject)) {
        updateProject(true);
      } else if ("sdk".equals(directObject))
      {
        if (mSdkCommandLine.getFlagNoUI(verb)) {
          updateSdkNoUI();
        } else {
          showSdkManagerWindow();
        }
      }
      else if ("adb".equals(directObject)) {
        updateAdb();
      }
    }
    else if ("sdk".equals(verb)) {
      showSdkManagerWindow();
    } else if ("avd".equals(verb)) {
      showAvdManagerWindow();
    } else if (("delete".equals(verb)) && ("avd".equals(directObject))) {
      deleteAvd();
    } else if (("move".equals(verb)) && ("avd".equals(directObject))) {
      moveAvd();
    } else if ((verb == null) && (directObject == null)) {
      showSdkManagerWindow();
    } else {
      mSdkCommandLine.printHelpAndExit(null, new Object[0]);
    }
  }
  
  private void showSdkManagerWindow()
  {
    try
    {
      MessageBoxLog errorLogger = new MessageBoxLog("SDK Manager", Display.getCurrent(), true);
      
      SdkUpdaterWindow window = new SdkUpdaterWindow(null, errorLogger, mOsSdkFolder, SdkUpdaterWindow.SdkInvocationContext.STANDALONE);
      
      window.open();
      
      errorLogger.displayResult(true);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  private void showAvdManagerWindow()
  {
    try
    {
      MessageBoxLog errorLogger = new MessageBoxLog("AVD Manager", Display.getCurrent(), true);
      
      AvdManagerWindow window = new AvdManagerWindow(null, errorLogger, mOsSdkFolder, AvdManagerWindow.AvdInvocationContext.STANDALONE);
      
      window.open();
      
      errorLogger.displayResult(true);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
  
  private void displayRemoteSdkListNoUI()
  {
    boolean force = mSdkCommandLine.getFlagForce();
    boolean useHttp = mSdkCommandLine.getFlagNoHttps();
    boolean all = mSdkCommandLine.getFlagAll();
    boolean extended = mSdkCommandLine.getFlagExtended();
    String proxyHost = mSdkCommandLine.getParamProxyHost();
    String proxyPort = mSdkCommandLine.getParamProxyPort();
    
    boolean obsolete = mSdkCommandLine.getFlagObsolete();
    all |= obsolete;
    
    SdkUpdaterNoWindow upd = new SdkUpdaterNoWindow(mOsSdkFolder, mSdkManager, mSdkLog, force, useHttp, proxyHost, proxyPort);
    
    upd.listRemotePackages(all, extended);
    if (obsolete) {
      mSdkLog.info("Note: Flag --obsolete is deprecated and will be removed in the next version.\n      Please use --all instead.\n", new Object[0]);
    }
  }
  
  private void updateSdkNoUI()
  {
    boolean force = mSdkCommandLine.getFlagForce();
    boolean useHttp = mSdkCommandLine.getFlagNoHttps();
    boolean dryMode = mSdkCommandLine.getFlagDryMode();
    boolean all = mSdkCommandLine.getFlagAll();
    String proxyHost = mSdkCommandLine.getParamProxyHost();
    String proxyPort = mSdkCommandLine.getParamProxyPort();
    
    String acceptLicense = null;
    
    boolean obsolete = mSdkCommandLine.getFlagObsolete();
    all |= obsolete;
    
    Pair<String, ArrayList<String>> filterResult = checkFilterValues(mSdkCommandLine.getParamFilter());
    if (filterResult.getFirst() != null) {
      errorAndExit((String)filterResult.getFirst(), new Object[0]);
    }
    SdkUpdaterNoWindow upd = new SdkUpdaterNoWindow(mOsSdkFolder, mSdkManager, mSdkLog, force, useHttp, proxyHost, proxyPort);
    
    upd.updateAll((ArrayList)filterResult.getSecond(), all, dryMode, acceptLicense);
    if (obsolete) {
      mSdkLog.info("Note: Flag --obsolete is deprecated and will be removed in the next version.\n      Please use --all instead.\n", new Object[0]);
    }
  }
  
  Pair<String, ArrayList<String>> checkFilterValues(String filter)
  {
    ArrayList<String> pkgFilter = new ArrayList();
    if ((filter != null) && (filter.length() > 0))
    {
      Set<String> filterTypes = new TreeSet();
      filterTypes.addAll(Arrays.asList(SdkRepoConstants.NODES));
      filterTypes.addAll(Arrays.asList(SdkAddonConstants.NODES));
      for (String t : filter.split(",")) {
        if (t != null)
        {
          t = t.trim();
          if (t.length() > 0) {
            if ((t.indexOf('-') > 0) || (t.equals("tools")) || (t.equals("platform-tools"))) {
              pkgFilter.add(t);
            } else if (t.replaceAll("[0-9]+", "").length() == 0) {
              pkgFilter.add(t);
            } else if (filterTypes.contains(t)) {
              pkgFilter.add(t);
            } else {
              return Pair.of(String.format("Unknown package filter type '%1$s'.\nAccepted values are: %2$s", new Object[] { t, Arrays.toString(filterTypes.toArray()) }), null);
            }
          }
        }
      }
    }
    return Pair.of(null, pkgFilter);
  }
  
  private ProjectCreator getProjectCreator()
  {
    ProjectCreator creator = new ProjectCreator(mSdkManager, mOsSdkFolder, mSdkCommandLine.isSilent() ? ProjectCreator.OutputLevel.SILENT : mSdkCommandLine.isVerbose() ? ProjectCreator.OutputLevel.VERBOSE : ProjectCreator.OutputLevel.NORMAL, mSdkLog);
    
    return creator;
  }
  
  private void createProject(boolean library)
  {
    String directObject = library ? "lib-project" : "project";
    
    int targetId = resolveTargetName(mSdkCommandLine.getParamTargetId());
    IAndroidTarget[] targets = mSdkManager.getTargets();
    if ((targetId == 0) || (targetId > targets.length)) {
      errorAndExit("Target id is not valid. Use '%s list targets' to get the target ids.", new Object[] { SdkConstants.androidCmdName() });
    }
    IAndroidTarget target = targets[(targetId - 1)];
    
    ProjectCreator creator = getProjectCreator();
    
    String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
    
    String projectName = mSdkCommandLine.getParamName();
    String packageName = mSdkCommandLine.getParamProjectPackage(directObject);
    String activityName = null;
    if (!library) {
      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", new Object[] { projectName, "a-z A-Z 0-9 _" });
      
      return;
    }
    if ((activityName != null) && (!ProjectCreator.RE_ACTIVITY_NAME.matcher(activityName).matches()))
    {
      errorAndExit("Activity name '%1$s' contains invalid characters.\nAllowed characters are: %2$s", new Object[] { activityName, "a-z A-Z 0-9 _" });
      
      return;
    }
    if ((packageName != null) && (!ProjectCreator.RE_PACKAGE_NAME.matcher(packageName).matches()))
    {
      errorAndExit("Package name '%1$s' contains invalid characters.\nA package name must be constitued of two Java identifiers.\nEach identifier allowed characters are: %2$s", new Object[] { packageName, "a-z A-Z 0-9 _" });
      
      return;
    }
    if (mSdkCommandLine.getParamGradle())
    {
      String gradleVersion = mSdkCommandLine.getParamGradleVersion();
      if (gradleVersion == null)
      {
        errorAndExit("Using the gradle template requires specifying the Gradle Android plugin version.", new Object[0]);
        
        return;
      }
      creator.createGradleProject(projectDir, projectName, packageName, activityName, target, library, gradleVersion);
    }
    else
    {
      creator.createProject(projectDir, projectName, packageName, activityName, target, library, null);
    }
  }
  
  private void createTestProject()
  {
    String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
    
    String pathToMainProject = mSdkCommandLine.getParamTestProjectMain();
    
    File parentProject = new File(pathToMainProject);
    if (!parentProject.isAbsolute()) {
      try
      {
        parentProject = new File(projectDir, pathToMainProject).getCanonicalFile();
      }
      catch (IOException e)
      {
        errorAndExit("Unable to resolve Main project's directory: %1$s", new Object[] { pathToMainProject });
        
        return;
      }
    }
    if (!parentProject.isDirectory())
    {
      errorAndExit("Main project's directory does not exist: %1$s", new Object[] { pathToMainProject });
      
      return;
    }
    File manifest = new File(parentProject, "AndroidManifest.xml");
    if (!manifest.isFile())
    {
      errorAndExit("No AndroidManifest.xml file found in the main project directory: %1$s", new Object[] { parentProject.getAbsolutePath() });
      
      return;
    }
    XPath xpath = AndroidXPathFactory.newXPath();
    String packageName;
    String activityName;
    try
    {
      packageName = xpath.evaluate("/manifest/@package", new InputSource(new FileInputStream(manifest)));
      
      mSdkLog.info("Found main project package: %1$s\n", new Object[] { packageName });
      
      activityName = xpath.evaluate("/manifest/application/activity[1]/@android:name", new InputSource(new FileInputStream(manifest)));
      if ((activityName == null) || (activityName.length() == 0)) {
        activityName = null;
      } else {
        mSdkLog.info("Found main project activity: %1$s\n", new Object[] { activityName });
      }
    }
    catch (FileNotFoundException e)
    {
      errorAndExit("No AndroidManifest.xml file found in main project.", new Object[0]);
      return;
    }
    catch (XPathExpressionException e)
    {
      errorAndExit("Unable to parse main project manifest to get information.", new Object[0]);
      return;
    }
    ProjectProperties p = ProjectProperties.load(parentProject.getAbsolutePath(), ProjectProperties.PropertyType.PROJECT);
    if (p == null)
    {
      errorAndExit("Unable to load the main project's %1$s", new Object[] { ProjectProperties.PropertyType.PROJECT.getFilename() });
      
      return;
    }
    String targetHash = p.getProperty("target");
    if (targetHash == null)
    {
      errorAndExit("Couldn't find the main project target", new Object[0]);
      return;
    }
    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.", new Object[] { targetHash });
      
      return;
    }
    mSdkLog.info("
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd