com.android.sdklib.internal.repository.sources
Class SdkRepoSource

java.lang.Object
  extended by com.android.sdklib.internal.repository.sources.SdkSource
      extended by com.android.sdklib.internal.repository.sources.SdkRepoSource
All Implemented Interfaces:
IDescription, java.lang.Comparable<SdkSource>

public class SdkRepoSource
extends SdkSource

An sdk-repository source, i.e. a download site. A repository describes one or more Packages available for download.


Constructor Summary
SdkRepoSource(java.lang.String url, java.lang.String uiName)
          Constructs a new source for the given repository URL.
 
Method Summary
protected  org.w3c.dom.Document findAlternateToolsXml(java.io.InputStream xml)
          The purpose of this method is to support forward evolution of our schema.
protected  org.w3c.dom.Document findAlternateToolsXml(java.io.InputStream xml, org.xml.sax.ErrorHandler errorHandler)
          An alternate version of findAlternateToolsXml(InputStream) that allows the caller to specify the XML error handler.
protected  java.lang.String[] getDefaultXmlFileUrls()
          Returns the basename of the default URLs to try to download the XML manifest.
protected  int getNsLatestVersion()
          Returns SdkRepoConstants.NS_LATEST_VERSION or SdkAddonConstants.NS_LATEST_VERSION.
protected  java.lang.String getNsPattern()
          Returns SdkRepoConstants.NS_PATTERN or SdkAddonConstants.NS_PATTERN.
protected  java.lang.String getNsUri()
          Returns SdkRepoConstants.NS_URI or SdkAddonConstants.NS_URI.
protected  java.lang.String getRootElementName()
           
protected  java.lang.String getSchemaUri(int version)
          Returns SdkRepoConstants.getSchemaUri() or SdkAddonConstants.getSchemaUri().
protected  java.io.InputStream getXsdStream(int version)
          Returns SdkRepoConstants.getXsdStream() or SdkAddonConstants.getXsdStream().
 boolean isAddonSource()
          Returns true if this is an addon source.
 boolean isSysImgSource()
          Returns true if this is a system-image source.
 
Methods inherited from class com.android.sdklib.internal.repository.sources.SdkSource
clearPackages, compareTo, equals, getDocument, getFetchError, getLongDescription, getPackages, getShortDescription, getUiName, getUrl, getXmlSchemaVersion, hashCode, isEnabled, load, parsePackages, setEnabled, setPackages, toString, validateXml
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SdkRepoSource

public SdkRepoSource(java.lang.String url,
                     java.lang.String uiName)
Constructs a new source for the given repository URL.

Parameters:
url - The source URL. Cannot be null. If the URL ends with a /, the default repository.xml filename will be appended automatically.
uiName - The UI-visible name of the source. Can be null.
Method Detail

isAddonSource

public boolean isAddonSource()
Returns true if this is an addon source. We only load addons and extras from these sources.

Specified by:
isAddonSource in class SdkSource

isSysImgSource

public boolean isSysImgSource()
Returns true if this is a system-image source. We only load system-images from these sources.

Specified by:
isSysImgSource in class SdkSource

getDefaultXmlFileUrls

protected java.lang.String[] getDefaultXmlFileUrls()
Description copied from class: SdkSource
Returns the basename of the default URLs to try to download the XML manifest. E.g. this is typically SdkRepoConstants.URL_DEFAULT_XML_FILE or SdkAddonConstants.URL_DEFAULT_XML_FILE

Specified by:
getDefaultXmlFileUrls in class SdkSource

getNsLatestVersion

protected int getNsLatestVersion()
Description copied from class: SdkSource
Returns SdkRepoConstants.NS_LATEST_VERSION or SdkAddonConstants.NS_LATEST_VERSION.

Specified by:
getNsLatestVersion in class SdkSource

getNsUri

protected java.lang.String getNsUri()
Description copied from class: SdkSource
Returns SdkRepoConstants.NS_URI or SdkAddonConstants.NS_URI.

Specified by:
getNsUri in class SdkSource

getNsPattern

protected java.lang.String getNsPattern()
Description copied from class: SdkSource
Returns SdkRepoConstants.NS_PATTERN or SdkAddonConstants.NS_PATTERN.

Specified by:
getNsPattern in class SdkSource

getSchemaUri

protected java.lang.String getSchemaUri(int version)
Description copied from class: SdkSource
Returns SdkRepoConstants.getSchemaUri() or SdkAddonConstants.getSchemaUri().

Specified by:
getSchemaUri in class SdkSource

getRootElementName

protected java.lang.String getRootElementName()
Specified by:
getRootElementName in class SdkSource

getXsdStream

protected java.io.InputStream getXsdStream(int version)
Description copied from class: SdkSource
Returns SdkRepoConstants.getXsdStream() or SdkAddonConstants.getXsdStream().

Specified by:
getXsdStream in class SdkSource

findAlternateToolsXml

protected org.w3c.dom.Document findAlternateToolsXml(@Nullable
                                                     java.io.InputStream xml)
                                              throws java.io.IOException
The purpose of this method is to support forward evolution of our schema.

At this point, we know that xml does not point to any schema that this version of the tool knows how to process, so it's not one of the possible 1..N versions of our XSD schema.

We thus try to interpret the byte stream as a possible XML stream. It may not be one at all in the first place. If it looks anything line an XML schema, we try to find its <tool> and the <platform-tools> elements. If we find any, we recreate a suitable document that conforms to what we expect from our XSD schema with only those elements.

To be valid, the <tool> and the <platform-tools> elements must have at least one <archive> compatible with this platform.

Starting the sdk-repository schema v3, <tools> has a <min-platform-tools-rev> node, so technically the corresponding XML schema will be usable only if there's a <platform-tools> with the request revision number. We don't enforce that here, as this is done at install time.

If we don't find anything suitable, we drop the whole thing.

Specified by:
findAlternateToolsXml in class SdkSource
Parameters:
xml - The input XML stream. Can be null.
Returns:
Either a new XML document conforming to our schema with at least one <tool> and <platform-tools> element or null.
Throws:
java.io.IOException - if InputStream.reset() fails

findAlternateToolsXml

protected org.w3c.dom.Document findAlternateToolsXml(@Nullable
                                                     java.io.InputStream xml,
                                                     @Nullable
                                                     org.xml.sax.ErrorHandler errorHandler)
                                              throws java.io.IOException
An alternate version of findAlternateToolsXml(InputStream) that allows the caller to specify the XML error handler. The default from the underlying Java XML Xerces parser will dump to stdout/stderr, which is not convenient during unit tests.

Parameters:
xml - The input XML stream. Can be null.
errorHandler - An optional XML error handler. If null, the default will be used.
Returns:
Either a new XML document conforming to our schema with at least one <tool> and <platform-tools> element or null.
Throws:
java.io.IOException - if InputStream.reset() fails
See Also:
findAlternateToolsXml() provides more details.