diff options
author | Raphael <raphael@google.com> | 2009-05-12 17:10:26 -0700 |
---|---|---|
committer | Raphael <raphael@google.com> | 2009-05-14 12:43:08 -0700 |
commit | 1647849f10140b218f1a4012609c072946c5d1f3 (patch) | |
tree | a3999797d772aabd2700b8f24be0437292f75828 /sdkmanager/app | |
parent | be8c17dbe6c9b8924fa74c088bf47486bf706215 (diff) | |
download | sdk-1647849f10140b218f1a4012609c072946c5d1f3.zip sdk-1647849f10140b218f1a4012609c072946c5d1f3.tar.gz sdk-1647849f10140b218f1a4012609c072946c5d1f3.tar.bz2 |
ADT #1844909: SDK manager, define XML schemas & sample XMLs
For reference, there's an XSD primer here:
- http://www.w3.org/TR/xmlschema-0/#NS
- http://www.w3schools.com/Schema/
Diffstat (limited to 'sdkmanager/app')
4 files changed, 513 insertions, 0 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/repository/SdkRepositoryConstants.java b/sdkmanager/app/src/com/android/sdkmanager/repository/SdkRepositoryConstants.java new file mode 100755 index 0000000..f911989 --- /dev/null +++ b/sdkmanager/app/src/com/android/sdkmanager/repository/SdkRepositoryConstants.java @@ -0,0 +1,33 @@ +/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
+ *
+ * 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.
+ */
+
+package com.android.sdkmanager.repository;
+
+import java.io.InputStream;
+
+/**
+ * Constants for the sdk-repository XML Schema
+ */
+public class SdkRepositoryConstants {
+
+ public static final String NS_SDK_REPOSITORY =
+ "http://schemas.android.com/sdk/android/repository/1";
+
+ public static InputStream getXsdStream() {
+ return SdkRepositoryConstants.class.getResourceAsStream("sdk-repository.xsd");
+ }
+
+}
diff --git a/sdkmanager/app/src/com/android/sdkmanager/repository/sdk-repository.xsd b/sdkmanager/app/src/com/android/sdkmanager/repository/sdk-repository.xsd new file mode 100755 index 0000000..c59197f --- /dev/null +++ b/sdkmanager/app/src/com/android/sdkmanager/repository/sdk-repository.xsd @@ -0,0 +1,181 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Copyright (C) 2009 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/repository/1" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:sdk="http://schemas.android.com/sdk/android/repository/1" + elementFormDefault="qualified" + attributeFormDefault="unqualified" + version="1"> + + <!-- 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> + + <!-- The repository contains a collection of downloadable items --> + + <xsd:element name="sdk-repository"> + <xsd:annotation> + <xsd:documentation> + The repository contains collections of downloadable items. + </xsd:documentation> + </xsd:annotation> + + <xsd:complexType> + <xsd:choice minOccurs="0" maxOccurs="unbounded"> + + <!-- The definition of an SDK platform item --> + + <xsd:element name="platform"> + <xsd:complexType> + <xsd:all> + <xsd:element name="version" type="xsd:normalizedString" /> + <xsd:element name="api-level" type="xsd:positiveInteger" /> + + <xsd:element name="revision" type="xsd:positiveInteger" /> + <xsd:element name="description" type="xsd:string" minOccurs="0" /> + <xsd:element name="desc-url" type="xsd:token" minOccurs="0" /> + <xsd:element name="archives" type="sdk:archivesType" /> + </xsd:all> + </xsd:complexType> + </xsd:element> + + <!-- The definition of an SDK Add-on item --> + + <xsd:element name="add-on"> + <xsd:complexType> + <xsd:all> + <xsd:element name="name" type="xsd:normalizedString" /> + <xsd:element name="vendor" type="xsd:normalizedString" /> + <xsd:element name="api-level" type="xsd:positiveInteger" /> + + <xsd:element name="revision" type="xsd:positiveInteger" /> + <xsd:element name="description" type="xsd:string" minOccurs="0" /> + <xsd:element name="desc-url" type="xsd:token" minOccurs="0" /> + <xsd:element name="archives" type="sdk:archivesType" /> + + <xsd:element name="libs"> + <xsd:complexType> + <xsd:sequence maxOccurs="unbounded"> + <xsd:element name="lib"> + <xsd:complexType> + <xsd:all> + <xsd:element name="name" type="xsd:normalizedString" /> + <xsd:element name="description" type="xsd:string" minOccurs="0" /> + </xsd:all> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + </xsd:all> + </xsd:complexType> + </xsd:element> + + <!-- The definition of an SDK tool item --> + + <xsd:element name="tool"> + <xsd:complexType> + <xsd:all> + <xsd:element name="revision" type="xsd:positiveInteger" /> + <xsd:element name="description" type="xsd:string" minOccurs="0" /> + <xsd:element name="desc-url" type="xsd:token" minOccurs="0" /> + <xsd:element name="archives" type="sdk:archivesType" /> + </xsd:all> + </xsd:complexType> + </xsd:element> + + <!-- The definition of an SDK doc item --> + + <xsd:element name="doc"> + <xsd:complexType> + <xsd:all> + <xsd:element name="api-level" type="xsd:positiveInteger" /> + + <xsd:element name="revision" type="xsd:positiveInteger" /> + <xsd:element name="description" type="xsd:string" minOccurs="0" /> + <xsd:element name="desc-url" type="xsd:token" minOccurs="0" /> + <xsd:element name="archives" type="sdk:archivesType" /> + </xsd:all> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + + <!-- A collection of files that can be downloaded for a given architectures --> + + <xsd:complexType name="archivesType"> + <xsd:annotation> + <xsd:documentation>A collection of architecture-dependent archives.</xsd:documentation> + </xsd:annotation> + <xsd:sequence maxOccurs="unbounded"> + <!-- One archive file --> + <xsd:element name="archive"> + <xsd:complexType> + <!-- Properties of the file --> + <xsd:all> + <xsd:element name="size" type="xsd:positiveInteger" /> + <xsd:element name="checksum" type="sdk:checksumType" /> + <xsd:element name="url" type="xsd:token" /> + </xsd:all> + + <!-- Attributes that identify the 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> + +</xsd:schema> diff --git a/sdkmanager/app/tests/com/android/sdkmanager/repository/TestXml.java b/sdkmanager/app/tests/com/android/sdkmanager/repository/TestXml.java new file mode 100755 index 0000000..482ef26 --- /dev/null +++ b/sdkmanager/app/tests/com/android/sdkmanager/repository/TestXml.java @@ -0,0 +1,113 @@ +/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
+ *
+ * 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.
+ */
+
+package com.android.sdkmanager.repository;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+import java.io.InputStream;
+
+import javax.xml.XMLConstants;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests local validation of an SDK Repository sample XMLs using an XML Schema validator.
+ *
+ * References:
+ * http://www.ibm.com/developerworks/xml/library/x-javaxmlvalidapi.html
+ */
+public class TestXml extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testValidateLocalRepositoryFile() throws Exception {
+
+ InputStream xsdStream = SdkRepositoryConstants.getXsdStream();
+ InputStream xmlStream = TestXml.class.getResourceAsStream("repository_sample.xml");
+
+ SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+
+ Schema schema = factory.newSchema(new StreamSource(xsdStream));
+
+ Validator validator = schema.newValidator();
+
+ CaptureErrorHandler handler = new CaptureErrorHandler();
+ validator.setErrorHandler(handler);
+
+ validator.validate(new StreamSource(xmlStream));
+
+ String warnings = handler.getWarnings();
+ if (warnings.length() > 0) {
+ System.err.println(warnings);
+ }
+
+ String errors = handler.getErrors();
+ if (errors.length() > 0) {
+ System.err.println(errors);
+ fail(errors);
+ }
+ }
+
+ private static class CaptureErrorHandler implements ErrorHandler {
+
+ private String mWarnings = "";
+ private String mErrors = "";
+
+ public String getErrors() {
+ return mErrors;
+ }
+
+ public String getWarnings() {
+ return mWarnings;
+ }
+
+ /**
+ * @throws SAXException
+ */
+ public void error(SAXParseException ex) throws SAXException {
+ mErrors += "Error: " + ex.getMessage() + "\n";
+ }
+
+ public void fatalError(SAXParseException ex) throws SAXException {
+ mErrors += "Fatal Error: " + ex.getMessage() + "\n";
+ throw ex;
+ }
+
+ /**
+ * @throws SAXException
+ */
+ public void warning(SAXParseException ex) throws SAXException {
+ mWarnings += "Warning: " + ex.getMessage() + "\n";
+ }
+
+ }
+
+}
diff --git a/sdkmanager/app/tests/com/android/sdkmanager/repository/repository_sample.xml b/sdkmanager/app/tests/com/android/sdkmanager/repository/repository_sample.xml new file mode 100755 index 0000000..0643185 --- /dev/null +++ b/sdkmanager/app/tests/com/android/sdkmanager/repository/repository_sample.xml @@ -0,0 +1,186 @@ +<?xml version="1.0"?>
+<!--
+ * Copyright (C) 2009 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.
+-->
+<sdk:sdk-repository
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:sdk="http://schemas.android.com/sdk/android/repository/1">
+ <sdk:platform>
+ <sdk:version>1.0</sdk:version>
+ <sdk:api-level>1</sdk:api-level>
+ <sdk:revision>3</sdk:revision>
+ <sdk:description>Some optional description</sdk:description>
+ <sdk:desc-url>http://www.example.com/platform1.html</sdk:desc-url>
+ <sdk:archives>
+ <sdk:archive os="any">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>http://www.example.com/files/plat1.zip</sdk:url>
+ </sdk:archive>
+ </sdk:archives>
+ </sdk:platform>
+ <sdk:platform>
+ <sdk:version>1.1</sdk:version>
+ <sdk:api-level>2</sdk:api-level>
+ <sdk:revision>12</sdk:revision>
+ <!-- sdk:description and sdk:desc-url are optional -->
+ <sdk:archives>
+ <sdk:archive os="windows">
+ <!-- arch attribute is optional -->
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/platform-2-12-win.zip</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="macosx" arch="any">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/platform-2-12-mac.zip</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="macosx" arch="ppc">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/platform-2-12-mac.zip</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="linux" arch="x86">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/platform-2-12-linux.tar.bz2</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="linux" arch="x86_64">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/platform-2-12-linux.tar.bz2</sdk:url>
+ </sdk:archive>
+ </sdk:archives>
+ </sdk:platform>
+ <sdk:add-on>
+ <sdk:name>My First add-on</sdk:name>
+ <sdk:api-level>1</sdk:api-level>
+ <sdk:vendor>John Doe</sdk:vendor>
+ <sdk:revision>1</sdk:revision>
+ <sdk:description>Some optional description</sdk:description>
+ <sdk:desc-url>http://www.example.com/myfirstaddon</sdk:desc-url>
+ <sdk:archives>
+ <sdk:archive os="any">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>http://www.example.com/add-ons/first.zip</sdk:url>
+ </sdk:archive>
+ </sdk:archives>
+ <sdk:libs>
+ <sdk:lib>
+ <sdk:name>android.blah.somelib</sdk:name>
+ <sdk:description>The description for this library.</sdk:description>
+ </sdk:lib>
+ <sdk:lib>
+ <!-- sdk:description is optional, name is not -->
+ <sdk:name>com.android.mymaps</sdk:name>
+ </sdk:lib>
+ </sdk:libs>
+ </sdk:add-on>
+ <sdk:add-on>
+ <sdk:name>My Second add-on</sdk:name>
+ <sdk:api-level>2</sdk:api-level>
+ <sdk:vendor>John Deer</sdk:vendor>
+ <sdk:revision>42</sdk:revision>
+ <sdk:archives>
+ <sdk:archive os="windows">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/second-42-win.zip</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="linux">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/second-42-linux.tar.bz2</sdk:url>
+ </sdk:archive>
+ </sdk:archives>
+ <sdk:libs>
+ <sdk:lib>
+ <sdk:name>android.blah.somelib</sdk:name>
+ <sdk:description>The description for this library.</sdk:description>
+ </sdk:lib>
+ <sdk:lib>
+ <sdk:name>com.android.mymaps</sdk:name>
+ </sdk:lib>
+ </sdk:libs>
+ </sdk:add-on>
+ <sdk:doc>
+ <sdk:api-level>1</sdk:api-level>
+ <sdk:revision>1</sdk:revision>
+ <sdk:description>Some optional description</sdk:description>
+ <sdk:desc-url>http://www.example.com/docs.html</sdk:desc-url>
+ <sdk:archives>
+ <sdk:archive os="any">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>http://www.example.com/docs/docs1.zip</sdk:url>
+ </sdk:archive>
+ </sdk:archives>
+ </sdk:doc>
+ <sdk:doc>
+ <sdk:api-level>2</sdk:api-level>
+ <sdk:revision>42</sdk:revision>
+ <sdk:archives>
+ <sdk:archive os="windows">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/docs/2.zip</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="linux">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/docs2-linux.tar.bz2</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="macosx">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/docs2-mac.tar.bz2</sdk:url>
+ </sdk:archive>
+ </sdk:archives>
+ </sdk:doc>
+ <sdk:tool>
+ <sdk:revision>1</sdk:revision>
+ <sdk:description>Some optional description</sdk:description>
+ <sdk:desc-url>http://www.example.com/tools.html</sdk:desc-url>
+ <sdk:archives>
+ <sdk:archive os="any">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>http://www.example.com/files/tools1.zip</sdk:url>
+ </sdk:archive>
+ </sdk:archives>
+ </sdk:tool>
+ <sdk:tool>
+ <sdk:revision>42</sdk:revision>
+ <sdk:archives>
+ <sdk:archive os="windows">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/tools/2.zip</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="linux">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/tools2-linux.tar.bz2</sdk:url>
+ </sdk:archive>
+ <sdk:archive os="macosx">
+ <sdk:size>65536</sdk:size>
+ <sdk:checksum type="sha1">2822ae37115ebf13412bbef91339ee0d9454525e</sdk:checksum>
+ <sdk:url>distrib/tools2-mac.tar.bz2</sdk:url>
+ </sdk:archive>
+ </sdk:archives>
+ </sdk:tool>
+</sdk:sdk-repository>
|