/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/RepoConstants.java

https://gitlab.com/Codeaurora/platform_sdk · Java · 158 lines · 56 code · 24 blank · 78 comment · 2 complexity · 1b347fce27af0261f19ffa25531f9ccc MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 The Android Open Source Project
  3. *
  4. * Licensed under the Eclipse Public License, Version 1.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.eclipse.org/org/documents/epl-v10.php
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.android.sdklib.repository;
  17. import java.io.InputStream;
  18. /**
  19. * Public constants common to the sdk-repository and sdk-addon XML Schemas.
  20. */
  21. public class RepoConstants {
  22. /** An extra package. */
  23. public static final String NODE_EXTRA = "extra"; //$NON-NLS-1$
  24. /** The license definition. */
  25. public static final String NODE_LICENSE = "license"; //$NON-NLS-1$
  26. /** The optional uses-license for all packages or for a lib. */
  27. public static final String NODE_USES_LICENSE = "uses-license"; //$NON-NLS-1$
  28. /** The revision, an int > 0, for all packages. */
  29. public static final String NODE_REVISION = "revision"; //$NON-NLS-1$
  30. /** The optional description for all packages or for a lib. */
  31. public static final String NODE_DESCRIPTION = "description"; //$NON-NLS-1$
  32. /** The optional description URL for all packages. */
  33. public static final String NODE_DESC_URL = "desc-url"; //$NON-NLS-1$
  34. /** The optional release note for all packages. */
  35. public static final String NODE_RELEASE_NOTE = "release-note"; //$NON-NLS-1$
  36. /** The optional release note URL for all packages. */
  37. public static final String NODE_RELEASE_URL = "release-url"; //$NON-NLS-1$
  38. /** The optional obsolete qualifier for all packages. */
  39. public static final String NODE_OBSOLETE = "obsolete"; //$NON-NLS-1$
  40. /** The optional project-files provided by extra packages. */
  41. public static final String NODE_PROJECT_FILES = "project-files"; //$NON-NLS-1$
  42. /** The optional minimal tools revision required by platform & extra packages. */
  43. public static final String NODE_MIN_TOOLS_REV = "min-tools-rev"; //$NON-NLS-1$
  44. /** The optional minimal platform-tools revision required by tool packages. */
  45. public static final String NODE_MIN_PLATFORM_TOOLS_REV = "min-platform-tools-rev"; //$NON-NLS-1$
  46. /** The optional minimal API level required by extra packages. */
  47. public static final String NODE_MIN_API_LEVEL = "min-api-level"; //$NON-NLS-1$
  48. /** The version, a string, for platform packages. */
  49. public static final String NODE_VERSION = "version"; //$NON-NLS-1$
  50. /** The api-level, an int > 0, for platform, add-on and doc packages. */
  51. public static final String NODE_API_LEVEL = "api-level"; //$NON-NLS-1$
  52. /** The codename, a string, for platform packages. */
  53. public static final String NODE_CODENAME = "codename"; //$NON-NLS-1$
  54. /** The vendor, a string, for add-on and extra packages. */
  55. public static final String NODE_VENDOR = "vendor"; //$NON-NLS-1$
  56. /** The name, a string, for add-on packages or for libraries. */
  57. public static final String NODE_NAME = "name"; //$NON-NLS-1$
  58. /** A layoutlib package. */
  59. public static final String NODE_LAYOUT_LIB = "layoutlib"; //$NON-NLS-1$
  60. /** The API integer for a layoutlib element. */
  61. public static final String NODE_API = "api"; //$NON-NLS-1$
  62. /** The libs container, optional for an add-on. */
  63. public static final String NODE_LIBS = "libs"; //$NON-NLS-1$
  64. /** A lib element in a libs container. */
  65. public static final String NODE_LIB = "lib"; //$NON-NLS-1$
  66. /** The path segment, a string, for extra packages. */
  67. public static final String NODE_PATH = "path"; //$NON-NLS-1$
  68. /** The archives container, for all packages. */
  69. public static final String NODE_ARCHIVES = "archives"; //$NON-NLS-1$
  70. /** An archive element, for the archives container. */
  71. public static final String NODE_ARCHIVE = "archive"; //$NON-NLS-1$
  72. /** An archive size, an int > 0. */
  73. public static final String NODE_SIZE = "size"; //$NON-NLS-1$
  74. /** A sha1 archive checksum, as a 40-char hex. */
  75. public static final String NODE_CHECKSUM = "checksum"; //$NON-NLS-1$
  76. /** A download archive URL, either absolute or relative to the repository xml. */
  77. public static final String NODE_URL = "url"; //$NON-NLS-1$
  78. /** An archive checksum type, mandatory. */
  79. public static final String ATTR_TYPE = "type"; //$NON-NLS-1$
  80. /** An archive OS attribute, mandatory. */
  81. public static final String ATTR_OS = "os"; //$NON-NLS-1$
  82. /** An optional archive Architecture attribute. */
  83. public static final String ATTR_ARCH = "arch"; //$NON-NLS-1$
  84. /** A license definition ID. */
  85. public static final String ATTR_ID = "id"; //$NON-NLS-1$
  86. /** A license reference. */
  87. public static final String ATTR_REF = "ref"; //$NON-NLS-1$
  88. /** Type of a sha1 checksum. */
  89. public static final String SHA1_TYPE = "sha1"; //$NON-NLS-1$
  90. /** Length of a string representing a SHA1 checksum; always 40 characters long. */
  91. public static final int SHA1_CHECKSUM_LEN = 40;
  92. /**
  93. * Temporary folder used to hold downloads and extract archives during installation.
  94. * This folder will be located in the SDK.
  95. */
  96. public static final String FD_TEMP = "temp"; //$NON-NLS-1$
  97. /**
  98. * Returns a stream to the requested XML Schema.
  99. * This is an internal helper. Users of the library should call
  100. * {@link SdkRepoConstants#getXsdStream(String, int)} or
  101. * {@link SdkAddonConstants#getXsdStream(String, int)}.
  102. *
  103. * @param rootElement The root of the filename of the XML schema.
  104. * This is by convention the same as the root element declared by the schema.
  105. * @param version The XML schema revision number, an integer >= 1.
  106. * @return An {@link InputStream} object for the local XSD file or
  107. * null if there is no schema for the requested version.
  108. * @see SdkRepoConstants#getXsdStream(int)
  109. * @see SdkAddonConstants#getXsdStream(int)
  110. */
  111. protected static InputStream getXsdStream(String rootElement, int version) {
  112. String filename = String.format("%1$s-%2$d.xsd", rootElement, version); //$NON-NLS-1$
  113. InputStream stream = null;
  114. try {
  115. stream = RepoConstants.class.getResourceAsStream(filename);
  116. } catch (Exception e) {
  117. // Some implementations seem to return null on failure,
  118. // others throw an exception. We want to return null.
  119. }
  120. if (stream == null) {
  121. // Try the alternate schemas that are not published yet.
  122. // This allows us to internally test with new schemas before the
  123. // public repository uses it.
  124. filename = String.format("-%1$s-%2$d.xsd", rootElement, version); //$NON-NLS-1$
  125. try {
  126. stream = RepoConstants.class.getResourceAsStream(filename);
  127. } catch (Exception e) {
  128. // Some implementations seem to return null on failure,
  129. // others throw an exception. We want to return null.
  130. }
  131. }
  132. return stream;
  133. }
  134. }