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