Home | History | Annotate | Download | only in repository
      1 /*
      2  * Copyright (C) 2009 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 
     20 import java.io.InputStream;
     21 
     22 /**
     23  * Public constants for the sdk-repository XML Schema.
     24  */
     25 public class SdkRepository {
     26 
     27     /** The URL of the official Google sdk-repository site. */
     28     public static final String URL_GOOGLE_SDK_REPO_SITE =
     29         "https://dl-ssl.google.com/android/repository/";                        //$NON-NLS-1$
     30 
     31     public static final String URL_DEFAULT_XML_FILE = "repository.xml";         //$NON-NLS-1$
     32 
     33     /** The base of our XML namespace. */
     34     private static final String NS_SDK_REPOSITORY_BASE =
     35         "http://schemas.android.com/sdk/android/repository/";                   //$NON-NLS-1$
     36 
     37     /** The pattern of our XML namespace. */
     38     public static final String NS_SDK_REPOSITORY_PATTERN =
     39         NS_SDK_REPOSITORY_BASE + "[1-9][0-9]*";        //$NON-NLS-1$
     40 
     41     /** The latest version of the sdk-repository XML Schema.
     42      *  Valid version numbers are between 1 and this number, included. */
     43     public static final int NS_LATEST_VERSION = 2;
     44 
     45     /** The XML namespace of the latest sdk-repository XML. */
     46     public static final String NS_SDK_REPOSITORY = getSchemaUri(NS_LATEST_VERSION);
     47 
     48     /** The root sdk-repository element */
     49     public static final String NODE_SDK_REPOSITORY = "sdk-repository";          //$NON-NLS-1$
     50 
     51     /** A platform package. */
     52     public static final String NODE_PLATFORM = "platform";                      //$NON-NLS-1$
     53     /** An add-on package. */
     54     public static final String NODE_ADD_ON   = "add-on";                        //$NON-NLS-1$
     55     /** A tool package. */
     56     public static final String NODE_TOOL     = "tool";                          //$NON-NLS-1$
     57     /** A doc package. */
     58     public static final String NODE_DOC      = "doc";                           //$NON-NLS-1$
     59     /** A sample package. */
     60     public static final String NODE_SAMPLE   = "sample";                        //$NON-NLS-1$
     61     /** An extra package. */
     62     public static final String NODE_EXTRA    = "extra";                         //$NON-NLS-1$
     63 
     64     // Warning: if you edit this list, please also update the package-to-class map
     65     // com.android.sdkuilib.internal.repository.UpdaterData.updateOrInstallAll_NoGUI().
     66     public static final String[] NODES = {
     67         NODE_PLATFORM,
     68         NODE_ADD_ON,
     69         NODE_TOOL,
     70         NODE_DOC,
     71         NODE_SAMPLE,
     72         NODE_EXTRA
     73     };
     74 
     75     /** The license definition. */
     76     public static final String NODE_LICENSE       = "license";                  //$NON-NLS-1$
     77     /** The optional uses-license for all packages or for a lib. */
     78     public static final String NODE_USES_LICENSE  = "uses-license";             //$NON-NLS-1$
     79     /** The revision, an int > 0, for all packages. */
     80     public static final String NODE_REVISION      = "revision";                 //$NON-NLS-1$
     81     /** The optional description for all packages or for a lib. */
     82     public static final String NODE_DESCRIPTION   = "description";              //$NON-NLS-1$
     83     /** The optional description URL for all packages. */
     84     public static final String NODE_DESC_URL      = "desc-url";                 //$NON-NLS-1$
     85     /** The optional release note for all packages. */
     86     public static final String NODE_RELEASE_NOTE  = "release-note";             //$NON-NLS-1$
     87     /** The optional release note URL for all packages. */
     88     public static final String NODE_RELEASE_URL   = "release-url";              //$NON-NLS-1$
     89     /** The optional obsolete qualifier for all packages. */
     90     public static final String NODE_OBSOLETE      = "obsolete";                 //$NON-NLS-1$
     91 
     92     /** The optional minimal tools revision required by platform & extra packages. */
     93     public static final String NODE_MIN_TOOLS_REV = "min-tools-rev";            //$NON-NLS-1$
     94     /** The optional minimal API level required by extra packages. */
     95     public static final String NODE_MIN_API_LEVEL = "min-api-level";            //$NON-NLS-1$
     96 
     97     /** The version, a string, for platform packages. */
     98     public static final String NODE_VERSION   = "version";                      //$NON-NLS-1$
     99     /** The api-level, an int > 0, for platform, add-on and doc packages. */
    100     public static final String NODE_API_LEVEL = "api-level";                    //$NON-NLS-1$
    101     /** The codename, a string, for platform packages. */
    102     public static final String NODE_CODENAME = "codename";                      //$NON-NLS-1$
    103     /** The vendor, a string, for add-on packages. */
    104     public static final String NODE_VENDOR    = "vendor";                       //$NON-NLS-1$
    105     /** The name, a string, for add-on packages or for libraries. */
    106     public static final String NODE_NAME      = "name";                         //$NON-NLS-1$
    107 
    108     /** The libs container, optional for an add-on. */
    109     public static final String NODE_LIBS      = "libs";                         //$NON-NLS-1$
    110     /** A lib element in a libs container. */
    111     public static final String NODE_LIB       = "lib";                          //$NON-NLS-1$
    112 
    113     /** The path, a string, for extra packages. */
    114     public static final String NODE_PATH = "path";                              //$NON-NLS-1$
    115 
    116     /** The archives container, for all packages. */
    117     public static final String NODE_ARCHIVES = "archives";                      //$NON-NLS-1$
    118     /** An archive element, for the archives container. */
    119     public static final String NODE_ARCHIVE  = "archive";                       //$NON-NLS-1$
    120 
    121     /** An archive size, an int > 0. */
    122     public static final String NODE_SIZE     = "size";                          //$NON-NLS-1$
    123     /** A sha1 archive checksum, as a 40-char hex. */
    124     public static final String NODE_CHECKSUM = "checksum";                      //$NON-NLS-1$
    125     /** A download archive URL, either absolute or relative to the repository xml. */
    126     public static final String NODE_URL      = "url";                           //$NON-NLS-1$
    127 
    128     /** An archive checksum type, mandatory. */
    129     public static final String ATTR_TYPE = "type";                              //$NON-NLS-1$
    130     /** An archive OS attribute, mandatory. */
    131     public static final String ATTR_OS   = "os";                                //$NON-NLS-1$
    132     /** An optional archive Architecture attribute. */
    133     public static final String ATTR_ARCH = "arch";                              //$NON-NLS-1$
    134 
    135     /** A license definition ID. */
    136     public static final String ATTR_ID = "id";                                  //$NON-NLS-1$
    137     /** A license reference. */
    138     public static final String ATTR_REF = "ref";                                //$NON-NLS-1$
    139 
    140     /** Type of a sha1 checksum. */
    141     public static final String SHA1_TYPE = "sha1";                              //$NON-NLS-1$
    142 
    143     /** Length of a string representing a SHA1 checksum; always 40 characters long. */
    144     public static final int SHA1_CHECKSUM_LEN = 40;
    145 
    146 
    147     /**
    148      * Returns a stream to the requested repository XML Schema.
    149      *
    150      * @param version Between 1 and {@link #NS_LATEST_VERSION}, included.
    151      * @return An {@link InputStream} object for the local XSD file or
    152      *         null if there is no schema for the requested version.
    153      */
    154     public static InputStream getXsdStream(int version) {
    155         String filename = String.format("sdk-repository-%d.xsd", version);      //$NON-NLS-1$
    156         return SdkRepository.class.getResourceAsStream(filename);
    157     }
    158 
    159     /**
    160      * Returns the URI of the SDK Repository schema for the given version number.
    161      * @param version Between 1 and {@link #NS_LATEST_VERSION} included.
    162      */
    163     public static String getSchemaUri(int version) {
    164         return String.format(NS_SDK_REPOSITORY_BASE + "%d", version);           //$NON-NLS-1$
    165     }
    166 
    167 }
    168