Example #1
0
  /**
   * Returns the highest build-tool revision known, or null if there are are no build-tools.
   *
   * <p>If no specific build-tool package is installed but the platform-tools is lower than 17, then
   * this creates and returns a "legacy" built-tool package using platform-tools. (We only split
   * build-tools out of platform-tools starting with revision 17, before they were both the same
   * thing.)
   *
   * @return The highest build-tool revision known, or null.
   */
  @Nullable
  public BuildToolInfo getLatestBuildTool() {
    if (mLegacyBuildTools != null) {
      return mLegacyBuildTools;
    }

    LocalPkgInfo[] pkgs = getPkgsInfos(PkgType.PKG_BUILD_TOOLS);

    if (pkgs.length == 0) {
      LocalPkgInfo ptPkg = getPkgInfo(PkgType.PKG_PLATFORM_TOOLS);
      if (ptPkg instanceof LocalPlatformToolPkgInfo
          && ptPkg.getDesc().getFullRevision().compareTo(new FullRevision(17)) < 0) {
        // older SDK, create a compatible build-tools
        mLegacyBuildTools = createLegacyBuildTools((LocalPlatformToolPkgInfo) ptPkg);
        return mLegacyBuildTools;
      }
      return null;
    }

    assert pkgs.length > 0;

    // Note: the pkgs come from a TreeMultimap so they should already be sorted.
    // Just in case, sort them again.
    Arrays.sort(pkgs);

    // LocalBuildToolPkgInfo's comparator sorts on its FullRevision so we just
    // need to take the latest element.
    LocalPkgInfo pkg = pkgs[pkgs.length - 1];
    if (pkg instanceof LocalBuildToolPkgInfo) {
      return ((LocalBuildToolPkgInfo) pkg).getBuildToolInfo();
    }

    return null;
  }
Example #2
0
  /**
   * Retrieves information on a package identified by an {@link IPkgDesc}.
   *
   * @param descriptor {@link IPkgDesc} describing a package.
   * @return The first package found with the same descriptor or null.
   */
  @Nullable
  public LocalPkgInfo getPkgInfo(@NonNull IPkgDesc descriptor) {

    for (LocalPkgInfo pkg : getPkgsInfos(EnumSet.of(descriptor.getType()))) {
      IPkgDesc d = pkg.getDesc();
      if (d.equals(descriptor)) {
        return pkg;
      }
    }

    return null;
  }
Example #3
0
  /**
   * Retrieves information on a package identified by its {@link String} path.
   *
   * <p>For add-ons and platforms, the path is the target hash string (see {@link AndroidTargetHash}
   * for helpers methods to generate this string.)
   *
   * @param filter {@link PkgType#PKG_ADDON}, {@link PkgType#PKG_PLATFORM}.
   * @param path The vendor/path uniquely identifying this package.
   * @return An existing package information or null if not found.
   */
  @Nullable
  public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull String path) {

    assert filter == PkgType.PKG_ADDON || filter == PkgType.PKG_PLATFORM;

    for (LocalPkgInfo pkg : getPkgsInfos(filter)) {
      IPkgDesc d = pkg.getDesc();
      if (d.hasPath() && path.equals(d.getPath())) {
        return pkg;
      }
    }
    return null;
  }
Example #4
0
  /**
   * Retrieves information on a package identified by its {@link FullRevision}.
   *
   * <p>Note that {@link PkgType#PKG_TOOLS} and {@link PkgType#PKG_PLATFORM_TOOLS} are unique in a
   * local SDK so you'll want to use {@link #getPkgInfo(PkgType)} to retrieve them instead.
   *
   * @param filter {@link PkgType#PKG_BUILD_TOOLS}.
   * @param revision The {@link FullRevision} uniquely identifying this package.
   * @return An existing package information or null if not found.
   */
  @Nullable
  public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull FullRevision revision) {

    assert filter == PkgType.PKG_BUILD_TOOLS;

    for (LocalPkgInfo pkg : getPkgsInfos(filter)) {
      IPkgDesc d = pkg.getDesc();
      if (d.hasFullRevision() && d.getFullRevision().equals(revision)) {
        return pkg;
      }
    }
    return null;
  }
Example #5
0
  /**
   * Retrieves information on a package identified by an {@link AndroidVersion}.
   *
   * <p>Note: don't use this for {@link PkgType#PKG_SYS_IMAGE} since there can be more than one ABI
   * and this method only returns a single package per filter type.
   *
   * @param filter {@link PkgType#PKG_PLATFORM}, {@link PkgType#PKG_SAMPLE} or {@link
   *     PkgType#PKG_SOURCE}.
   * @param version The {@link AndroidVersion} specific for this package type.
   * @return An existing package information or null if not found.
   */
  @Nullable
  public LocalPkgInfo getPkgInfo(@NonNull PkgType filter, @NonNull AndroidVersion version) {
    assert filter == PkgType.PKG_PLATFORM
        || filter == PkgType.PKG_SAMPLE
        || filter == PkgType.PKG_SOURCE;

    for (LocalPkgInfo pkg : getPkgsInfos(filter)) {
      IPkgDesc d = pkg.getDesc();
      if (d.hasAndroidVersion() && d.getAndroidVersion().equals(version)) {
        return pkg;
      }
    }

    return null;
  }
Example #6
0
  /**
   * Retrieves information on a package identified by both vendor and path strings.
   *
   * <p>For add-ons the path is target hash string (see {@link AndroidTargetHash} for helpers
   * methods to generate this string.)
   *
   * @param filter {@link PkgType#PKG_EXTRA}, {@link PkgType#PKG_ADDON}.
   * @param vendor The vendor id of the extra package.
   * @param path The path uniquely identifying this package for its vendor.
   * @return An existing package information or null if not found.
   */
  @Nullable
  public LocalPkgInfo getPkgInfo(
      @NonNull PkgType filter, @NonNull String vendor, @NonNull String path) {

    assert filter == PkgType.PKG_EXTRA || filter == PkgType.PKG_ADDON;

    for (LocalPkgInfo pkg : getPkgsInfos(filter)) {
      IPkgDesc d = pkg.getDesc();
      if (d.hasVendor() && vendor.equals(d.getVendor().getId())) {
        if (d.hasPath() && path.equals(d.getPath())) {
          return pkg;
        }
      }
    }
    return null;
  }