Exemplo n.º 1
0
  /**
   * Creates a new tool package from the attributes and elements of the given XML node. This
   * constructor should throw an exception if the package cannot be created.
   *
   * @param source The {@link SdkSource} where this is loaded from.
   * @param packageNode The XML element being parsed.
   * @param nsUri The namespace URI of the originating XML document, to be able to deal with
   *     parameters that vary according to the originating XML schema.
   * @param licenses The licenses loaded from the XML originating document.
   */
  ToolPackage(SdkSource source, Node packageNode, String nsUri, Map<String, String> licenses) {
    super(source, packageNode, nsUri, licenses);

    mMinPlatformToolsRevision =
        XmlParserUtils.getXmlInt(
            packageNode,
            SdkRepoConstants.NODE_MIN_PLATFORM_TOOLS_REV,
            MIN_PLATFORM_TOOLS_REV_INVALID);
    if (mMinPlatformToolsRevision == MIN_PLATFORM_TOOLS_REV_INVALID) {
      // This revision number is mandatory starting with sdk-repository-3.xsd
      // and did not exist before. Complain if the URI has level >= 3.

      boolean needRevision = false;

      Pattern nsPattern = Pattern.compile(SdkRepoConstants.NS_PATTERN);
      Matcher m = nsPattern.matcher(nsUri);
      if (m.matches()) {
        String version = m.group(1);
        try {
          needRevision = Integer.parseInt(version) >= 3;
        } catch (NumberFormatException e) {
          // ignore. needRevision defaults to false
        }
      }

      if (needRevision) {
        throw new IllegalArgumentException(
            String.format(
                "Missing %1$s element in %2$s package",
                SdkRepoConstants.NODE_MIN_PLATFORM_TOOLS_REV, SdkRepoConstants.NODE_PLATFORM_TOOL));
      }
    }
  }
Exemplo n.º 2
0
  /** Parses one <archive> element from an <archives> container. */
  private Archive parseArchive(Node archiveNode) {
    Archive a =
        new Archive(
            this,
            (Os)
                XmlParserUtils.getEnumAttribute(
                    archiveNode, SdkRepository.ATTR_OS, Os.values(), null),
            (Arch)
                XmlParserUtils.getEnumAttribute(
                    archiveNode, SdkRepository.ATTR_ARCH, Arch.values(), Arch.ANY),
            XmlParserUtils.getXmlString(archiveNode, SdkRepository.NODE_URL),
            XmlParserUtils.getXmlLong(archiveNode, SdkRepository.NODE_SIZE, 0),
            XmlParserUtils.getXmlString(archiveNode, SdkRepository.NODE_CHECKSUM));

    return a;
  }
Exemplo n.º 3
0
 /**
  * Parses the uses-licence node of this package, if any, and returns the license definition if
  * there's one. Returns null if there's no uses-license element or no license of this name
  * defined.
  */
 private String parseLicense(Node packageNode, Map<String, String> licenses) {
   Node usesLicense = XmlParserUtils.getFirstChild(packageNode, SdkRepository.NODE_USES_LICENSE);
   if (usesLicense != null) {
     Node ref = usesLicense.getAttributes().getNamedItem(SdkRepository.ATTR_REF);
     if (ref != null) {
       String licenseRef = ref.getNodeValue();
       return licenses.get(licenseRef);
     }
   }
   return null;
 }
Exemplo n.º 4
0
  /**
   * Creates a new package from the attributes and elements of the given XML node.
   *
   * <p>This constructor should throw an exception if the package cannot be created.
   */
  Package(RepoSource source, Node packageNode, Map<String, String> licenses) {
    mSource = source;
    mRevision = XmlParserUtils.getXmlInt(packageNode, SdkRepository.NODE_REVISION, 0);
    mDescription = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_DESCRIPTION);
    mDescUrl = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_DESC_URL);
    mReleaseNote = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_RELEASE_NOTE);
    mReleaseUrl = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_RELEASE_URL);
    mObsolete = XmlParserUtils.getOptionalXmlString(packageNode, SdkRepository.NODE_OBSOLETE);

    mLicense = parseLicense(packageNode, licenses);
    mArchives =
        parseArchives(XmlParserUtils.getFirstChild(packageNode, SdkRepository.NODE_ARCHIVES));
  }