diff --git a/.gitignore b/.gitignore
index f4c6af0ed..452fd8161 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*~
+*.bak
*.pyc
Thumbs.db
diff --git a/tools/sdkmanager/app/src/com/android/sdkmanager/repository/SdkRepositoryConstants.java b/tools/sdkmanager/app/src/com/android/sdkmanager/repository/SdkRepositoryConstants.java
new file mode 100755
index 000000000..f9119890c
--- /dev/null
+++ b/tools/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/tools/sdkmanager/app/src/com/android/sdkmanager/repository/sdk-repository.xsd b/tools/sdkmanager/app/src/com/android/sdkmanager/repository/sdk-repository.xsd
new file mode 100755
index 000000000..c59197f9f
--- /dev/null
+++ b/tools/sdkmanager/app/src/com/android/sdkmanager/repository/sdk-repository.xsd
@@ -0,0 +1,181 @@
+
+
+
+
+
+
+
+
+ A SHA1 checksum.
+
+
+
+
+
+
+
+
+ A file checksum, currently only SHA1.
+
+
+
+
+
+
+
+
+
+
+
+
+
+ The repository contains collections of downloadable items.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A collection of architecture-dependent archives.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tools/sdkmanager/app/tests/com/android/sdkmanager/repository/TestXml.java b/tools/sdkmanager/app/tests/com/android/sdkmanager/repository/TestXml.java
new file mode 100755
index 000000000..482ef2691
--- /dev/null
+++ b/tools/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/tools/sdkmanager/app/tests/com/android/sdkmanager/repository/repository_sample.xml b/tools/sdkmanager/app/tests/com/android/sdkmanager/repository/repository_sample.xml
new file mode 100755
index 000000000..0643185b5
--- /dev/null
+++ b/tools/sdkmanager/app/tests/com/android/sdkmanager/repository/repository_sample.xml
@@ -0,0 +1,186 @@
+
+
+
+
+ 1.0
+ 1
+ 3
+ Some optional description
+ http://www.example.com/platform1.html
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ http://www.example.com/files/plat1.zip
+
+
+
+
+ 1.1
+ 2
+ 12
+
+
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/platform-2-12-win.zip
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/platform-2-12-mac.zip
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/platform-2-12-mac.zip
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/platform-2-12-linux.tar.bz2
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/platform-2-12-linux.tar.bz2
+
+
+
+
+ My First add-on
+ 1
+ John Doe
+ 1
+ Some optional description
+ http://www.example.com/myfirstaddon
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ http://www.example.com/add-ons/first.zip
+
+
+
+
+ android.blah.somelib
+ The description for this library.
+
+
+
+ com.android.mymaps
+
+
+
+
+ My Second add-on
+ 2
+ John Deer
+ 42
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/second-42-win.zip
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/second-42-linux.tar.bz2
+
+
+
+
+ android.blah.somelib
+ The description for this library.
+
+
+ com.android.mymaps
+
+
+
+
+ 1
+ 1
+ Some optional description
+ http://www.example.com/docs.html
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ http://www.example.com/docs/docs1.zip
+
+
+
+
+ 2
+ 42
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/docs/2.zip
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/docs2-linux.tar.bz2
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/docs2-mac.tar.bz2
+
+
+
+
+ 1
+ Some optional description
+ http://www.example.com/tools.html
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ http://www.example.com/files/tools1.zip
+
+
+
+
+ 42
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/tools/2.zip
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/tools2-linux.tar.bz2
+
+
+ 65536
+ 2822ae37115ebf13412bbef91339ee0d9454525e
+ distrib/tools2-mac.tar.bz2
+
+
+
+