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 17package com.android.sdklib.repository; 18 19 20import com.android.sdklib.internal.repository.sources.SdkSource; 21 22import java.io.InputStream; 23 24/** 25 * Public constants for the sdk-repository XML Schema. 26 */ 27public 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 = 7; 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 /* The major revision for tool and platform-tool package 84 * (the full revision number is revision.minor.micro + preview#.) 85 * Mandatory int > 0. 0 when missing, which should not happen in 86 * a valid document. */ 87 public static final String NODE_MAJOR_REV = "major"; //$NON-NLS-1$ 88 /* The minor revision for tool and platform-tool package 89 * (the full revision number is revision.minor.micro + preview#.) 90 * Optional int >= 0. Implied to be 0 when missing. */ 91 public static final String NODE_MINOR_REV = "minor"; //$NON-NLS-1$ 92 /* The micro revision for tool and platform-tool package 93 * (the full revision number is revision.minor.micro + preview#.) 94 * Optional int >= 0. Implied to be 0 when missing. */ 95 public static final String NODE_MICRO_REV = "micro"; //$NON-NLS-1$ 96 /* The preview revision for tool and platform-tool package. 97 * Int > 0, only present for "preview / release candidate" packages. */ 98 public static final String NODE_PREVIEW = "preview"; //$NON-NLS-1$ 99 100 /** A platform package. */ 101 public static final String NODE_PLATFORM = "platform"; //$NON-NLS-1$ 102 /** A tool package. */ 103 public static final String NODE_TOOL = "tool"; //$NON-NLS-1$ 104 /** A platform-tool package. */ 105 public static final String NODE_PLATFORM_TOOL = "platform-tool"; //$NON-NLS-1$ 106 /** A doc package. */ 107 public static final String NODE_DOC = "doc"; //$NON-NLS-1$ 108 /** A sample package. */ 109 public static final String NODE_SAMPLE = "sample"; //$NON-NLS-1$ 110 /** A source package. */ 111 public static final String NODE_SOURCE = "source"; //$NON-NLS-1$ 112 113 114 /** 115 * List of possible nodes in a repository XML. Used to populate options automatically 116 * in the no-GUI mode. 117 */ 118 public static final String[] NODES = { 119 NODE_PLATFORM, 120 NODE_SYSTEM_IMAGE, 121 NODE_TOOL, 122 NODE_PLATFORM_TOOL, 123 NODE_DOC, 124 NODE_SAMPLE, 125 NODE_SOURCE, 126 }; 127 128 /** 129 * Returns a stream to the requested {@code sdk-repository} XML Schema. 130 * 131 * @param version Between 1 and {@link #NS_LATEST_VERSION}, included. 132 * @return An {@link InputStream} object for the local XSD file or 133 * null if there is no schema for the requested version. 134 */ 135 public static InputStream getXsdStream(int version) { 136 return getXsdStream(NODE_SDK_REPOSITORY, version); 137 } 138 139 /** 140 * Returns the URI of the SDK Repository schema for the given version number. 141 * @param version Between 1 and {@link #NS_LATEST_VERSION} included. 142 */ 143 public static String getSchemaUri(int version) { 144 return String.format(NS_BASE + "%d", version); //$NON-NLS-1$ 145 } 146} 147