com.android.sdklib.internal.repository.packages
Class AddonPackage

java.lang.Object
  extended by com.android.sdklib.internal.repository.packages.Package
      extended by com.android.sdklib.internal.repository.packages.MajorRevisionPackage
          extended by com.android.sdklib.internal.repository.packages.AddonPackage
All Implemented Interfaces:
IDescription, IAndroidVersionProvider, IExactApiLevelDependency, ILayoutlibVersion, IPlatformDependency, java.lang.Comparable<Package>

public class AddonPackage
extends MajorRevisionPackage
implements IAndroidVersionProvider, IPlatformDependency, IExactApiLevelDependency, ILayoutlibVersion

Represents an add-on XML node in an SDK repository.


Nested Class Summary
static class AddonPackage.Lib
          An add-on library.
 
Nested classes/interfaces inherited from class com.android.sdklib.internal.repository.packages.Package
Package.License, Package.UpdateInfo
 
Field Summary
 
Fields inherited from interface com.android.sdklib.internal.repository.packages.IExactApiLevelDependency
API_LEVEL_INVALID
 
Fields inherited from interface com.android.sdklib.internal.repository.packages.ILayoutlibVersion
LAYOUTLIB_API_NOT_SPECIFIED, LAYOUTLIB_REV_NOT_SPECIFIED
 
Constructor Summary
protected AddonPackage(IAndroidTarget target, java.util.Properties props)
           
protected AddonPackage(SdkSource source, IAndroidTarget target, java.util.Properties props)
           
  AddonPackage(SdkSource source, org.w3c.dom.Node packageNode, java.lang.String nsUri, java.util.Map<java.lang.String,java.lang.String> licenses)
          Creates a new add-on package from the attributes and elements of the given XML node.
 
Method Summary
protected  java.lang.String comparisonKey()
          For addon packages, we want to add vendor|name to the sorting key before the revision number.
static Package create(IAndroidTarget target, java.util.Properties props)
          Creates a new platform package based on an actual IAndroidTarget (which IAndroidTarget.isPlatform() false) from the SdkManager.
static Package createBroken(java.lang.String archiveOsPath, java.util.Properties sourceProps, java.util.Map<java.lang.String,java.lang.String> addonProps, java.lang.String error)
          Creates a broken addon which we know failed to load properly.
 boolean equals(java.lang.Object obj)
           
 AndroidVersion getAndroidVersion()
          Returns the version of the platform dependency of this package.
 java.lang.String getDisplayName()
          Returns the name, a string for display purposes.
 java.lang.String getDisplayVendor()
          Returns the vendor, a string for display purposes.
 int getExactApiLevel()
          Returns the exact API level required by this package, if > 0, or IExactApiLevelDependency.API_LEVEL_INVALID if the value was missing.
 java.io.File getInstallFolder(java.lang.String osSdkRoot, SdkManager sdkManager)
          Computes a potential installation folder if an archive of this package were to be installed right away in the given SDK root.
 com.android.utils.Pair<java.lang.Integer,java.lang.Integer> getLayoutlibVersion()
          Returns the layoutlib version.
 AddonPackage.Lib[] getLibs()
          Returns the libs defined in this add-on.
 java.lang.String getListDescription()
          Returns a description of this package that is suitable for a list display.
 java.lang.String getLongDescription()
          Returns a long description for an IDescription.
 java.lang.String getNameId()
          Returns the name id, a string, for add-on packages or for libraries.
 java.lang.String getShortDescription()
          Returns a short description for an IDescription.
 java.lang.String getVendorId()
          Returns the vendor id, a string, for add-on packages.
 int hashCode()
           
 java.lang.String installId()
          Returns a string identifier to install this package from the command line.
 boolean sameItemAs(Package pkg)
          Returns whether the give package represents the same item as the current package.
 void saveProperties(java.util.Properties props)
          Save the properties of the current packages in the given Properties object.
 
Methods inherited from class com.android.sdklib.internal.repository.packages.MajorRevisionPackage
canBeUpdatedBy, getRevision
 
Methods inherited from class com.android.sdklib.internal.repository.packages.Package
compareTo, getArchives, getDescription, getDescUrl, getLicense, getParentSource, getReleaseNote, getReleaseNoteUrl, hasArchive, hasCompatibleArchive, initializeArchives, isLocal, isObsolete, postInstallHook, postUnzipFileHook, preInstallHook, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AddonPackage

public AddonPackage(SdkSource source,
                    org.w3c.dom.Node packageNode,
                    java.lang.String nsUri,
                    java.util.Map<java.lang.String,java.lang.String> licenses)
Creates a new add-on package from the attributes and elements of the given XML node. This constructor should throw an exception if the package cannot be created.

Parameters:
source - The SdkSource where this is loaded from.
packageNode - The XML element being parsed.
nsUri - The namespace URI of the originating XML document, to be able to deal with parameters that vary according to the originating XML schema.
licenses - The licenses loaded from the XML originating document.

AddonPackage

protected AddonPackage(IAndroidTarget target,
                       java.util.Properties props)

AddonPackage

protected AddonPackage(SdkSource source,
                       IAndroidTarget target,
                       java.util.Properties props)
Method Detail

create

public static Package create(IAndroidTarget target,
                             java.util.Properties props)
Creates a new platform package based on an actual IAndroidTarget (which IAndroidTarget.isPlatform() false) from the SdkManager. This is used to list local SDK folders in which case there is one archive which URL is the actual target location.

By design, this creates a package with one and only one archive.


createBroken

public static Package createBroken(java.lang.String archiveOsPath,
                                   java.util.Properties sourceProps,
                                   java.util.Map<java.lang.String,java.lang.String> addonProps,
                                   java.lang.String error)
Creates a broken addon which we know failed to load properly.

Parameters:
archiveOsPath - The absolute OS path of the addon folder.
sourceProps - The properties parsed from the addon's source.properties. Can be null.
addonProps - The properties parsed from the addon manifest (NOT the source.properties).
error - The error indicating why this addon failed to be loaded.

getExactApiLevel

public int getExactApiLevel()
Description copied from interface: IExactApiLevelDependency
Returns the exact API level required by this package, if > 0, or IExactApiLevelDependency.API_LEVEL_INVALID if the value was missing.

This attribute is mandatory and should not be normally missing. It can only happen when dealing with an invalid repository XML.

Specified by:
getExactApiLevel in interface IExactApiLevelDependency

saveProperties

public void saveProperties(java.util.Properties props)
Save the properties of the current packages in the given Properties object. These properties will later be given to a constructor that takes a Properties object.

Overrides:
saveProperties in class MajorRevisionPackage

getVendorId

@NonNull
public java.lang.String getVendorId()
Returns the vendor id, a string, for add-on packages.


getDisplayVendor

@NonNull
public java.lang.String getDisplayVendor()
Returns the vendor, a string for display purposes.


getNameId

@NonNull
public java.lang.String getNameId()
Returns the name id, a string, for add-on packages or for libraries.


getDisplayName

@NonNull
public java.lang.String getDisplayName()
Returns the name, a string for display purposes.


getAndroidVersion

@NonNull
public AndroidVersion getAndroidVersion()
Returns the version of the platform dependency of this package.

An add-on has the same AndroidVersion as the platform it depends on.

Specified by:
getAndroidVersion in interface IAndroidVersionProvider
Specified by:
getAndroidVersion in interface IPlatformDependency

getLibs

@NonNull
public AddonPackage.Lib[] getLibs()
Returns the libs defined in this add-on. Can be an empty array but not null.


getLayoutlibVersion

@NonNull
public com.android.utils.Pair<java.lang.Integer,java.lang.Integer> getLayoutlibVersion()
Returns the layoutlib version.

The first integer is the API of layoublib, which should be > 0. It will be equal to ILayoutlibVersion.LAYOUTLIB_API_NOT_SPECIFIED (0) if the layoutlib version isn't specified.

The second integer is the revision for that given API. It is >= 0 and works as a minor revision number, incremented for the same API level.

Specified by:
getLayoutlibVersion in interface ILayoutlibVersion
Since:
sdk-addon-2.xsd

installId

@NonNull
public java.lang.String installId()
Returns a string identifier to install this package from the command line. For add-ons, we use "addon-vendor-name-N" where N is the base platform API.

Returns a short, reasonably unique string identifier that can be used to identify this package when installing from the command-line interface. 'android list sdk' will show these IDs and then in turn they can be provided to 'android update sdk --no-ui --filter' to select some specific packages.

The identifiers must have the following properties:
- They must contain only simple alphanumeric characters.
- Commas, whitespace and any special character that could be obviously problematic to a shell interface should be avoided (so dash/underscore are OK, but things like colon, pipe or dollar should be avoided.)
- The name must be consistent across calls and reasonably unique for the package type. Collisions can occur but should be rare.
- Different package types should have a clearly different name pattern.
- The revision number should not be included, as this would prevent updates from being automated (which is the whole point.)
- It must remain reasonably human readable.
- If no such id can exist (for example for a local package that cannot be installed) then an empty string should be returned. Don't return null.

Important: This is not a strong unique identifier for the package. If you need a strong unique identifier, you should use Package.comparisonKey() and the Comparable interface.

Specified by:
installId in class Package

getListDescription

public java.lang.String getListDescription()
Returns a description of this package that is suitable for a list display.

Returns a description of this package that is suitable for a list display. Should not be empty. Must never be null.

Note that this is the "base" name for the package with no specific revision nor API mentioned. In contrast, Package.getShortDescription() should be used if you want more details such as the package revision number or the API, if applicable.

Specified by:
getListDescription in class Package

getShortDescription

public java.lang.String getShortDescription()
Returns a short description for an IDescription.

Specified by:
getShortDescription in interface IDescription
Specified by:
getShortDescription in class Package

getLongDescription

public java.lang.String getLongDescription()
Returns a long description for an IDescription. The long description is whatever the XML contains for the <description> field, or the short description if the former is empty.

Specified by:
getLongDescription in interface IDescription
Overrides:
getLongDescription in class Package

getInstallFolder

public java.io.File getInstallFolder(java.lang.String osSdkRoot,
                                     SdkManager sdkManager)
Computes a potential installation folder if an archive of this package were to be installed right away in the given SDK root.

An add-on package is typically installed in SDK/add-ons/"addon-name"-"api-level". The name needs to be sanitized to be acceptable as a directory name. However if we can find a different directory under SDK/add-ons that already has this add-ons installed, we'll use that one.

Specified by:
getInstallFolder in class Package
Parameters:
osSdkRoot - The OS path of the SDK root folder.
sdkManager - An existing SDK manager to list current platforms and addons.
Returns:
A new File corresponding to the directory to use to install this package.

sameItemAs

public boolean sameItemAs(Package pkg)
Description copied from class: Package
Returns whether the give package represents the same item as the current package.

Two packages are considered the same if they represent the same thing, except for the revision number.

Specified by:
sameItemAs in class Package
Parameters:
pkg - the package to compare.
Returns:
true if the item as equivalent.

hashCode

public int hashCode()
Overrides:
hashCode in class Package

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class Package

comparisonKey

protected java.lang.String comparisonKey()
For addon packages, we want to add vendor|name to the sorting key before the revision number.

Computes a comparison key for each package used by Package.compareTo(Package). The key is a string. The base package class return a string that encodes the package type, the revision number and the platform version, if applicable, in the form:

      t:N|v:NNNN.P|r:NNNN|
 
All fields must start by a "letter colon" prefix and end with a vertical pipe (|, ASCII 124).

The string format may change between releases and clients should not store them outside of the session or expect them to be consistent between different releases. They are purely an internal implementation details of the Package.compareTo(Package) method.

Derived classes should get the string from the super class and then append or insert their own |-separated content. For example an extra vendor name & path can be inserted before the revision number, since it has more sorting weight.

Overrides:
comparisonKey in class Package