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 com.android.sdklib.internal.repository.sources.SdkSource; 21 22 import java.io.InputStream; 23 24 /** 25 * Public constants for the sdk-repository XML Schema. 26 */ 27 public class SdkRepoConstants extends RepoConstants { 28 29 /** 30 * The latest version of the sdk-repository XML Schema. 31 * Valid version numbers are between 1 and this number, included. 32 */ 33 public static final int NS_LATEST_VERSION = 6; 34 35 /** 36 * The min version of the sdk-repository XML Schema we'll try to load. 37 * When looking for a repository-N.xml on the server, we'll check from 38 * {@link #NS_LATEST_VERSION} down to this revision. 39 * We only introduced the "repository-N.xml" pattern start with revision 40 * 5, so we know that <em>our</em> server will never contain a repository 41 * XML with a schema version lower than this one. 42 */ 43 public static final int NS_SERVER_MIN_VERSION = 5; 44 45 /** 46 * The URL of the official Google sdk-repository site. 47 * The URL ends with a /, allowing easy concatenation. 48 * */ 49 public static final String URL_GOOGLE_SDK_SITE = 50 "https://dl-ssl.google.com/android/repository/"; //$NON-NLS-1$ 51 52 /** 53 * The default name looked for by {@link SdkSource} when trying to load an 54 * sdk-repository XML if the URL doesn't match an existing resource. 55 */ 56 public static final String URL_DEFAULT_FILENAME = "repository.xml"; //$NON-NLS-1$ 57 58 /** 59 * The pattern name looked by {@link SdkSource} when trying to load 60 * an sdk-repository XML that is specific to a given XSD revision. 61 * <p/> 62 * This must be used with {@link String#format(String, Object...)} with 63 * one integer parameter between 1 and {@link #NS_LATEST_VERSION}. 64 */ 65 public static final String URL_FILENAME_PATTERN = "repository-%1$d.xml"; //$NON-NLS-1$ 66 67 /** The base of our sdk-repository XML namespace. */ 68 private static final String NS_BASE = 69 "http://schemas.android.com/sdk/android/repository/"; //$NON-NLS-1$ 70 71 /** 72 * The pattern of our sdk-repository XML namespace. 73 * Matcher's group(1) is the schema version (integer). 74 */ 75 public static final String NS_PATTERN = NS_BASE + "([1-9][0-9]*)"; //$NON-NLS-1$ 76 77 /** The XML namespace of the latest sdk-repository XML. */ 78 public static final String NS_URI = getSchemaUri(NS_LATEST_VERSION); 79 80 /** The root sdk-repository element */ 81 public static final String NODE_SDK_REPOSITORY = "sdk-repository"; //$NON-NLS-1$ 82 83 /** A platform package. */ 84 public static final String NODE_PLATFORM = "platform"; //$NON-NLS-1$ 85 /** A tool package. */ 86 public static final String NODE_TOOL = "tool"; //$NON-NLS-1$ 87 /** A platform-tool package. */ 88 public static final String NODE_PLATFORM_TOOL = "platform-tool"; //$NON-NLS-1$ 89 /** A doc package. */ 90 public static final String NODE_DOC = "doc"; //$NON-NLS-1$ 91 /** A sample package. */ 92 public static final String NODE_SAMPLE = "sample"; //$NON-NLS-1$ 93 /** A system-image package. */ 94 public static final String NODE_SYSTEM_IMAGE = "system-image"; //$NON-NLS-1$ 95 /** A source package. */ 96 public static final String NODE_SOURCE = "source"; //$NON-NLS-1$ 97 98 /* An included-ABI element for a system-image package. */ 99 public static final String NODE_ABI_INCLUDED = "included-abi"; //$NON-NLS-1$ 100 /* An ABI element for a system-image package. */ 101 public static final String NODE_ABI = "abi"; //$NON-NLS-1$ 102 103 104 /** 105 * List of possible nodes in a repository XML. Used to populate options automatically 106 * in the no-GUI mode. 107 */ 108 public static final String[] NODES = { 109 NODE_PLATFORM, 110 NODE_SYSTEM_IMAGE, 111 NODE_TOOL, 112 NODE_PLATFORM_TOOL, 113 NODE_DOC, 114 NODE_SAMPLE, 115 NODE_SOURCE, 116 }; 117 118 /** 119 * Returns a stream to the requested {@code sdk-repository} XML Schema. 120 * 121 * @param version Between 1 and {@link #NS_LATEST_VERSION}, included. 122 * @return An {@link InputStream} object for the local XSD file or 123 * null if there is no schema for the requested version. 124 */ getXsdStream(int version)125 public static InputStream getXsdStream(int version) { 126 return getXsdStream(NODE_SDK_REPOSITORY, version); 127 } 128 129 /** 130 * Returns the URI of the SDK Repository schema for the given version number. 131 * @param version Between 1 and {@link #NS_LATEST_VERSION} included. 132 */ getSchemaUri(int version)133 public static String getSchemaUri(int version) { 134 return String.format(NS_BASE + "%d", version); //$NON-NLS-1$ 135 } 136 } 137