<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
-->
<xsd:schema
    targetNamespace="http://schemas.android.com/sdk/android/addon/2"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:sdk="http://schemas.android.com/sdk/android/addon/2"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    version="1">

    <!-- The repository contains a collection of downloadable items known as
         "packages". Each package has a type and various attributes and contains
         a list of file "archives" that can be downloaded for specific OSes.

         An Android Addon repository is a web site that contains an "addon.xml"
         file that conforms to this XML Schema.

         History:
         - v1 is used by the SDK Updater in Tools r8. It is split out of the
           main SDK Repository XML Schema and can only contain <addon> and
           <extra> packages.

         - v2 is used by the SDK Updater in Tools r12.
            - <extra> element now has a <project-files> element that contains 1 or
              or more <path>, each indicating the relative path of a file that this package
              can contribute to installed projects.
            - <addon> element now has an optional <layoutlib> that indicates the API
              and revision of the layout library for this particular add-on, if any.
    -->

    <xsd:element name="sdk-addon" type="sdk:repositoryType" />

    <xsd:complexType name="repositoryType">
        <xsd:annotation>
            <xsd:documentation>
                The repository contains a collection of downloadable packages.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element name="add-on"  type="sdk:addonType"        />
            <xsd:element name="extra"   type="sdk:extraType"        />
            <xsd:element name="license" type="sdk:licenseType"      />
        </xsd:choice>
    </xsd:complexType>

    <!-- The definition of an SDK Add-on package. -->

    <xsd:complexType name="addonType">
        <xsd:annotation>
            <xsd:documentation>An SDK add-on package.</xsd:documentation>
        </xsd:annotation>
        <xsd:all>
            <!-- The name of the add-on. -->
            <xsd:element name="name"         type="xsd:normalizedString" />
            <!-- The vendor of the add-on. -->
            <xsd:element name="vendor"       type="xsd:normalizedString" />
            <!-- The Android API Level for the add-on. An int > 0. -->
            <xsd:element name="api-level"    type="xsd:positiveInteger"  />
            <!-- Note: Add-ons do not support 'codenames' (a.k.a. API previews). -->
            <!-- The revision, an int > 0, incremented each time a new
                 package is generated. -->
            <xsd:element name="revision"     type="xsd:positiveInteger" />

            <!-- An add-on can declare 0 or more libraries.
                 This element is mandatory but it can be empty.
            -->

            <xsd:element name="libs">
                <xsd:complexType>
                    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
                        <xsd:element name="lib">
                            <xsd:complexType>
                                <xsd:all>
                                    <!-- The name of the library. -->
                                    <xsd:element name="name" type="xsd:normalizedString" />
                                    <!-- The optional description of this add-on library. -->
                                    <xsd:element name="description" type="xsd:string" minOccurs="0" />
                                </xsd:all>
                            </xsd:complexType>
                        </xsd:element>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>

            <!-- optional elements -->

            <!-- The optional license of this package. If present, users will have
                 to agree to it before downloading. -->
            <xsd:element name="uses-license" type="sdk:usesLicenseType" minOccurs="0" />
            <!-- The optional description of this package. -->
            <xsd:element name="description"  type="xsd:string"      minOccurs="0" />
            <!-- The optional description URL of this package -->
            <xsd:element name="desc-url"     type="xsd:token"       minOccurs="0" />
            <!-- The optional release note for this package. -->
            <xsd:element name="release-note" type="xsd:string"      minOccurs="0" />
            <!-- The optional release note URL of this package -->
            <xsd:element name="release-url"  type="xsd:token"       minOccurs="0" />
            <!-- A list of file archives for this package. -->
            <xsd:element name="archives"     type="sdk:archivesType" />

            <!-- An optional element indicating the package is obsolete.
                 The string content is however currently not defined and ignored. -->
            <xsd:element name="obsolete"     type="xsd:string"      minOccurs="0" />

            <!-- Optional information on the layoutlib packaged in this platform. -->
            <xsd:element name="layoutlib" type="sdk:layoutlibType"  minOccurs="0" />
        </xsd:all>
    </xsd:complexType>


    <!-- The definition of a layout library used by an addon. -->

    <xsd:complexType name="layoutlibType" >
        <xsd:annotation>
            <xsd:documentation>
                Version information for a layoutlib included in an addon.
            .</xsd:documentation>
        </xsd:annotation>
        <xsd:all>
            <!-- The layoutlib API level, an int > 0,
                 incremented with each new incompatible lib. -->
            <xsd:element name="api"          type="xsd:positiveInteger" />
            <!-- The incremental minor revision for that API, e.g. in case of bug fixes.
                 Optional. An int >= 0, assumed to be 0 if the element is missing. -->
            <xsd:element name="revision"     type="xsd:nonNegativeInteger" minOccurs="0" />
        </xsd:all>
    </xsd:complexType>


    <!-- The definition of an SDK extra package. This kind of package is for
         "free" content. Such packages are installed in SDK/vendor/path.

         Important implementation detail: this element is duplicated in the
         sdk-repository-N.xsd schema and must be kept in sync there. This is
         simpler than trying to use some kind of of include or to request
         that clients use a third XML schema for common parts.
    -->

    <xsd:complexType name="extraType" >
        <xsd:annotation>
            <xsd:documentation>
                An SDK extra package. This kind of package is for "free" content.
                Such packages are installed in SDK/vendor/path.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:all>

            <!-- The install path top folder name. It must not be empty.
                 The segments "add-ons", "docs", "platforms", "platform-tools", "temp"
                 and "tools" are reserved and cannot be used.
            -->
            <xsd:element name="vendor" type="sdk:segmentType" />

            <!-- The install path sub-folder name. It must not be empty. -->
            <xsd:element name="path" type="sdk:segmentType" />

            <!-- The revision, an int > 0, incremented each time a new
                 package is generated. -->
            <xsd:element name="revision"     type="xsd:positiveInteger" />

            <!-- A list of file archives for this package. -->
            <xsd:element name="archives"     type="sdk:archivesType" />

            <!--  optional elements -->

            <!-- The optional license of this package. If present, users will have
                 to agree to it before downloading. -->
            <xsd:element name="uses-license" type="sdk:usesLicenseType"  minOccurs="0" />
            <!-- The optional description of this package. -->
            <xsd:element name="description"  type="xsd:string"           minOccurs="0" />
            <!-- The optional description URL of this package -->
            <xsd:element name="desc-url"     type="xsd:token"            minOccurs="0" />
            <!-- The optional release note for this package. -->
            <xsd:element name="release-note" type="xsd:string"           minOccurs="0" />
            <!-- The optional release note URL of this package -->
            <xsd:element name="release-url"  type="xsd:token"            minOccurs="0" />
            <!-- The minimal revision of tools required by this package.
                 Optional. If present, must be an int > 0. -->
            <xsd:element name="min-tools-rev" type="xsd:positiveInteger" minOccurs="0" />
            <!-- The minimal API level required by this package.
                 Optional. If present, must be an int > 0. -->
            <xsd:element name="min-api-level" type="xsd:positiveInteger" minOccurs="0" />
            <!-- An optional element indicating the package is obsolete.
                 The string content is however currently not defined and ignored. -->
            <xsd:element name="obsolete"      type="xsd:string"          minOccurs="0" />

            <!-- A list of project files contributed by this package. Optional. -->
            <xsd:element name="project-files" type="sdk:projectFilesType" minOccurs="0" />
        </xsd:all>
    </xsd:complexType>


    <!-- The definition of a path segment used by the extra element. -->

    <xsd:simpleType name="segmentType">
        <xsd:annotation>
            <xsd:documentation>
                One path segment for the install path of an extra element.
                It must be a single-segment path. It must not be empty.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:token">
            <xsd:pattern value="[a-zA-Z0-9_]+"/>
        </xsd:restriction>
    </xsd:simpleType>


    <!-- The definition of a license to be referenced by the uses-license element. -->

    <xsd:complexType name="licenseType">
        <xsd:annotation>
            <xsd:documentation>
                A license definition. Such a license must be used later as a reference
                using a uses-license element in one of the package elements.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="id"   type="xsd:ID" />
                <xsd:attribute name="type" type="xsd:token" fixed="text" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>


    <!-- Type describing the license used by a package.
         The license MUST be defined using a license node and referenced
         using the ref attribute of the license element inside a package.
     -->

    <xsd:complexType name="usesLicenseType">
        <xsd:annotation>
            <xsd:documentation>
                Describes the license used by a package. The license MUST be defined
                using a license node and referenced using the ref attribute of the
                license element inside a package.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:attribute name="ref" type="xsd:IDREF" />
    </xsd:complexType>


    <!-- A collection of files that can be downloaded for a given architecture.
         The <archives> node is mandatory in the repository elements and the
         collection must have at least one <archive> declared.
         Each archive is a zip file that will be unzipped in a location that depends
         on its package type.
     -->

    <xsd:complexType name="archivesType">
        <xsd:annotation>
            <xsd:documentation>
                A collection of files that can be downloaded for a given architecture.
                The &lt;archives&gt; node is mandatory in the repository packages and the
                collection must have at least one &lt;archive&gt; declared.
                Each archive is a zip file that will be unzipped in a location that depends
                on its package type.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence minOccurs="1" maxOccurs="unbounded">
            <!-- One archive file -->
            <xsd:element name="archive">
                <xsd:complexType>
                    <!-- Properties of the archive file -->
                    <xsd:all>
                        <!-- The size in bytes of the archive to download. -->
                        <xsd:element name="size"     type="xsd:positiveInteger" />
                        <!-- The checksum of the archive file. -->
                        <xsd:element name="checksum" type="sdk:checksumType" />
                        <!-- The URL is an absolute URL if it starts with http://, https://
                             or ftp://. Otherwise it is relative to the parent directory that
                             contains this repository.xml -->
                        <xsd:element name="url"      type="xsd:token" />
                    </xsd:all>

                    <!-- Attributes that identify the OS and architecture -->
                    <xsd:attribute name="os" use="required">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:token">
                                <xsd:enumeration value="any" />
                                <xsd:enumeration value="linux" />
                                <xsd:enumeration value="macosx" />
                                <xsd:enumeration value="windows" />
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:attribute>
                    <xsd:attribute name="arch" use="optional">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:token">
                                <xsd:enumeration value="any" />
                                <xsd:enumeration value="ppc" />
                                <xsd:enumeration value="x86" />
                                <xsd:enumeration value="x86_64" />
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:attribute>
                </xsd:complexType>
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>


    <!-- A collection of file paths available in an &lt;extra&gt; package
         that can be installed in an Android project.
         If present, the &lt;project-files&gt; collection must contain at least one path.
         Each path is relative to the root directory of the package.
     -->

    <xsd:complexType name="projectFilesType">
        <xsd:annotation>
            <xsd:documentation>
                A collection of file paths available in an &lt;extra&gt; package
                that can be installed in an Android project.
                If present, the &lt;project-files&gt; collection must contain at least one path.
                Each path is relative to the root directory of the package.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence minOccurs="1" maxOccurs="unbounded">
            <!-- One JAR Path, relative to the root folder of the package. -->
            <xsd:element name="path" type="xsd:string" />
        </xsd:sequence>
    </xsd:complexType>


    <!-- The definition of a file checksum -->

    <xsd:simpleType name="sha1Number">
        <xsd:annotation>
            <xsd:documentation>A SHA1 checksum.</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="([0-9a-fA-F]){40}"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="checksumType">
        <xsd:annotation>
            <xsd:documentation>A file checksum, currently only SHA1.</xsd:documentation>
        </xsd:annotation>
        <xsd:simpleContent>
            <xsd:extension base="sdk:sha1Number">
                <xsd:attribute name="type" type="xsd:token" fixed="sha1" />
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

</xsd:schema>