Home | History | Annotate | Download | only in repository
      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 
     17 package com.android.sdklib.repository;
     18 
     19 import java.io.InputStream;
     20 
     21 
     22 
     23 /**
     24  * Public constants common to the sdk-repository and sdk-addon XML Schemas.
     25  */
     26 public class RepoConstants {
     27 
     28     /** The license definition. */
     29     public static final String NODE_LICENSE       = "license";                  //$NON-NLS-1$
     30     /** The optional uses-license for all packages or for a lib. */
     31     public static final String NODE_USES_LICENSE  = "uses-license";             //$NON-NLS-1$
     32     /** The revision, an int > 0, for all packages. */
     33     public static final String NODE_REVISION      = "revision";                 //$NON-NLS-1$
     34     /** The optional description for all packages or for a lib. */
     35     public static final String NODE_DESCRIPTION   = "description";              //$NON-NLS-1$
     36     /** The optional description URL for all packages. */
     37     public static final String NODE_DESC_URL      = "desc-url";                 //$NON-NLS-1$
     38     /** The optional release note for all packages. */
     39     public static final String NODE_RELEASE_NOTE  = "release-note";             //$NON-NLS-1$
     40     /** The optional release note URL for all packages. */
     41     public static final String NODE_RELEASE_URL   = "release-url";              //$NON-NLS-1$
     42     /** The optional obsolete qualifier for all packages. */
     43     public static final String NODE_OBSOLETE      = "obsolete";                 //$NON-NLS-1$
     44     /** The optional project-files provided by extra packages. */
     45     public static final String NODE_PROJECT_FILES = "project-files";            //$NON-NLS-1$
     46 
     47     /** The optional minimal tools revision required by platform & extra packages. */
     48     public static final String NODE_MIN_TOOLS_REV = "min-tools-rev";            //$NON-NLS-1$
     49     /** The optional minimal platform-tools revision required by tool packages. */
     50     public static final String NODE_MIN_PLATFORM_TOOLS_REV = "min-platform-tools-rev"; //$NON-NLS-1$
     51     /** The optional minimal API level required by extra packages. */
     52     public static final String NODE_MIN_API_LEVEL = "min-api-level";            //$NON-NLS-1$
     53 
     54     /** The version, a string, for platform packages. */
     55     public static final String NODE_VERSION   = "version";                      //$NON-NLS-1$
     56     /** The api-level, an int > 0, for platform, add-on and doc packages. */
     57     public static final String NODE_API_LEVEL = "api-level";                    //$NON-NLS-1$
     58     /** The codename, a string, for platform packages. */
     59     public static final String NODE_CODENAME = "codename";                      //$NON-NLS-1$
     60     /** The *old* vendor, a string, for add-on and extra packages.
     61      *  Replaced by {@link #NODE_VENDOR_DISPLAY} and {@link #NODE_VENDOR_ID} in addon-v4.xsd. */
     62     public static final String NODE_VENDOR    = "vendor";                       //$NON-NLS-1$
     63     /** The vendor display string, for add-on and extra packages. */
     64     public static final String NODE_VENDOR_DISPLAY    = "vendor-display";       //$NON-NLS-1$
     65     /** The unique vendor id string, for add-on and extra packages. */
     66     public static final String NODE_VENDOR_ID    = "vendor-id";                 //$NON-NLS-1$
     67     /** The name, a string, for add-on packages or for libraries.
     68      *  Replaced by {@link #NODE_NAME_DISPLAY} and {@link #NODE_NAME_ID} in addon-v4.xsd. */
     69     public static final String NODE_NAME      = "name";                         //$NON-NLS-1$
     70     /** The name display string, for add-on packages or for libraries. */
     71     public static final String NODE_NAME_DISPLAY      = "name-display";         //$NON-NLS-1$
     72     /** The unique name id string, for add-on packages or for libraries. */
     73     public static final String NODE_NAME_ID      = "name-id";                   //$NON-NLS-1$
     74 
     75 
     76     /** A layoutlib package. */
     77     public static final String NODE_LAYOUT_LIB      = "layoutlib";              //$NON-NLS-1$
     78     /** The API integer for a layoutlib element. */
     79     public static final String NODE_API             = "api";                    //$NON-NLS-1$
     80 
     81     /** The libs container, optional for an add-on. */
     82     public static final String NODE_LIBS      = "libs";                         //$NON-NLS-1$
     83     /** A lib element in a libs container. */
     84     public static final String NODE_LIB       = "lib";                          //$NON-NLS-1$
     85 
     86     /** The path segment, a string, for extra packages. */
     87     public static final String NODE_PATH      = "path";                         //$NON-NLS-1$
     88 
     89     /** The old_path segments, a string, for extra packages. */
     90     public static final String NODE_OLD_PATHS = "old-paths";                    //$NON-NLS-1$
     91 
     92     /** The archives container, for all packages. */
     93     public static final String NODE_ARCHIVES = "archives";                      //$NON-NLS-1$
     94     /** An archive element, for the archives container. */
     95     public static final String NODE_ARCHIVE  = "archive";                       //$NON-NLS-1$
     96 
     97     /** An archive size, an int > 0. */
     98     public static final String NODE_SIZE     = "size";                          //$NON-NLS-1$
     99     /** A sha1 archive checksum, as a 40-char hex. */
    100     public static final String NODE_CHECKSUM = "checksum";                      //$NON-NLS-1$
    101     /** A download archive URL, either absolute or relative to the repository xml. */
    102     public static final String NODE_URL      = "url";                           //$NON-NLS-1$
    103 
    104     /** An archive checksum type, mandatory. */
    105     public static final String ATTR_TYPE = "type";                              //$NON-NLS-1$
    106     /** An archive OS attribute, mandatory. */
    107     public static final String ATTR_OS   = "os";                                //$NON-NLS-1$
    108     /** An optional archive Architecture attribute. */
    109     public static final String ATTR_ARCH = "arch";                              //$NON-NLS-1$
    110 
    111     /** A license definition ID. */
    112     public static final String ATTR_ID = "id";                                  //$NON-NLS-1$
    113     /** A license reference. */
    114     public static final String ATTR_REF = "ref";                                //$NON-NLS-1$
    115 
    116     /** Type of a sha1 checksum. */
    117     public static final String SHA1_TYPE = "sha1";                              //$NON-NLS-1$
    118 
    119     /** Length of a string representing a SHA1 checksum; always 40 characters long. */
    120     public static final int SHA1_CHECKSUM_LEN = 40;
    121 
    122     /**
    123      * Temporary folder used to hold downloads and extract archives during installation.
    124      * This folder will be located in the SDK.
    125      */
    126     public static final String FD_TEMP = "temp";     //$NON-NLS-1$
    127 
    128     /**
    129      * Returns a stream to the requested XML Schema.
    130      * This is an internal helper. Users of the library should call
    131      * {@link SdkRepoConstants#getXsdStream(String, int)} or
    132      * {@link SdkAddonConstants#getXsdStream(String, int)}.
    133      *
    134      * @param rootElement The root of the filename of the XML schema.
    135      *   This is by convention the same as the root element declared by the schema.
    136      * @param version The XML schema revision number, an integer >= 1.
    137      * @return An {@link InputStream} object for the local XSD file or
    138      *         null if there is no schema for the requested version.
    139      * @see SdkRepoConstants#getXsdStream(int)
    140      * @see SdkAddonConstants#getXsdStream(int)
    141      */
    142     protected static InputStream getXsdStream(String rootElement, int version) {
    143         String filename = String.format("%1$s-%2$d.xsd", rootElement, version);      //$NON-NLS-1$
    144 
    145         InputStream stream = null;
    146         try {
    147             stream = RepoConstants.class.getResourceAsStream(filename);
    148         } catch (Exception e) {
    149             // Some implementations seem to return null on failure,
    150             // others throw an exception. We want to return null.
    151         }
    152         if (stream == null) {
    153             // Try the alternate schemas that are not published yet.
    154             // This allows us to internally test with new schemas before the
    155             // public repository uses it.
    156             filename = String.format("-%1$s-%2$d.xsd", rootElement, version);      //$NON-NLS-1$
    157             try {
    158                 stream = RepoConstants.class.getResourceAsStream(filename);
    159             } catch (Exception e) {
    160                 // Some implementations seem to return null on failure,
    161                 // others throw an exception. We want to return null.
    162             }
    163         }
    164 
    165         return stream;
    166     }
    167 
    168 }
    169