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

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.SourcePackage
All Implemented Interfaces:
IDescription, IAndroidVersionProvider, java.lang.Comparable<Package>

public class SourcePackage
extends MajorRevisionPackage
implements IAndroidVersionProvider

Represents a source XML node in an SDK repository.

Note that a source package has a version and thus implements IAndroidVersionProvider. However there is no mandatory dependency that limits installation so this does not implement IPlatformDependency.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.android.sdklib.internal.repository.packages.Package
Package.License, Package.UpdateInfo
 
Constructor Summary
protected SourcePackage(AndroidVersion platformVersion, int revision, java.util.Properties props, java.lang.String localOsPath)
           
protected SourcePackage(SdkSource source, AndroidVersion platformVersion, int revision, java.util.Properties props, java.lang.String localOsPath)
           
  SourcePackage(SdkSource source, org.w3c.dom.Node packageNode, java.lang.String nsUri, java.util.Map<java.lang.String,java.lang.String> licenses)
          Creates a new source package from the attributes and elements of the given XML node.
 
Method Summary
static Package create(java.io.File srcDir, java.util.Properties props)
          Creates either a valid SourcePackage or a BrokenPackage.
 boolean equals(java.lang.Object obj)
           
 AndroidVersion getAndroidVersion()
          Returns the android version of this package.
 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.
 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 getShortDescription()
          Returns a short description for an IDescription.
 int hashCode()
           
 java.lang.String installId()
          Returns a string identifier to install this package from the command line.
 void postUnzipFileHook(Archive archive, ITaskMonitor monitor, IFileOp fileOp, java.io.File unzippedFile, org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry)
          Set all the files from a source package as read-only so that users don't end up modifying sources by mistake in Eclipse.
 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, comparisonKey, getArchives, getDescription, getDescUrl, getLicense, getParentSource, getReleaseNote, getReleaseNoteUrl, hasArchive, hasCompatibleArchive, initializeArchives, isLocal, isObsolete, postInstallHook, preInstallHook, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SourcePackage

public SourcePackage(SdkSource source,
                     org.w3c.dom.Node packageNode,
                     java.lang.String nsUri,
                     java.util.Map<java.lang.String,java.lang.String> licenses)
Creates a new source 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.

SourcePackage

protected SourcePackage(AndroidVersion platformVersion,
                        int revision,
                        java.util.Properties props,
                        java.lang.String localOsPath)

SourcePackage

protected SourcePackage(SdkSource source,
                        AndroidVersion platformVersion,
                        int revision,
                        java.util.Properties props,
                        java.lang.String localOsPath)
Method Detail

create

public static Package create(java.io.File srcDir,
                             java.util.Properties props)
Creates either a valid SourcePackage or a BrokenPackage.

If the source directory contains valid properties, this creates a new SourcePackage with the android version listed in the properties. Otherwise returns a new BrokenPackage with some explanation on what failed.

Parameters:
srcDir - The SDK/sources/android-N folder
props - The properties located in srcDir or null if not found.
Returns:
A new SourcePackage or a new BrokenPackage.

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

getAndroidVersion

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

Specified by:
getAndroidVersion in interface IAndroidVersionProvider

installId

public java.lang.String installId()
Returns a string identifier to install this package from the command line. For sources, we use "source-N" where N is the API or the preview codename.

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.

A sources package is typically installed in SDK/sources/platform.

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.

postUnzipFileHook

public void postUnzipFileHook(Archive archive,
                              ITaskMonitor monitor,
                              IFileOp fileOp,
                              java.io.File unzippedFile,
                              org.apache.commons.compress.archivers.zip.ZipArchiveEntry zipEntry)
Set all the files from a source package as read-only so that users don't end up modifying sources by mistake in Eclipse.

Overrides:
postUnzipFileHook in class Package
Parameters:
archive - The archive that is being installed.
monitor - The ITaskMonitor to display errors.
fileOp - The IFileOp used by the archive installer.
unzippedFile - The file that has just been unzipped in the install temp directory.
zipEntry - The ZipArchiveEntry that has just been unzipped.

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