Merge change 8064 into donut

* changes:
  Generalize usage of AndroidVersion instead of Api level in the SDK packages.
This commit is contained in:
Android (Google) Code Review
2009-07-21 13:55:53 -07:00
10 changed files with 59 additions and 37 deletions

View File

@@ -45,13 +45,29 @@ public class AndroidVersion {
private final int mApiLevel;
private final String mCodename;
/**
* Creates an {@link AndroidVersion} with the given api level and codename.
*/
public AndroidVersion(int apiLevel, String codename) {
mApiLevel = apiLevel;
mCodename = codename;
}
public AndroidVersion(Properties properties) {
throw new UnsupportedOperationException("TODO");
/**
* Creates an {@link AndroidVersion} from {@link Properties}, with default values if the
* {@link Properties} object doesn't contain the expected values.
* <p/>The {@link Properties} is expected to have been filled with
* {@link #saveProperties(Properties)}.
*/
public AndroidVersion(Properties properties, int defaultApiLevel, String defaultCodeName) {
if (properties == null) {
mApiLevel = defaultApiLevel;
mCodename = defaultCodeName;
} else {
mApiLevel = Integer.parseInt(properties.getProperty(PROP_API_LEVEL,
Integer.toString(defaultApiLevel)));
mCodename = properties.getProperty(PROP_CODENAME, defaultCodeName);
}
}
public void saveProperties(Properties props) {

View File

@@ -168,10 +168,9 @@ public class AddonPackage extends Package {
return mName;
}
/** Returns the api-level, an int > 0, for platform, add-on and doc packages. */
public int getApiLevel() {
// FIXME: return the AndroidVersion instead.
return mVersion.getApiLevel();
/** Returns the version, for platform, add-on and doc packages. */
public AndroidVersion getVersion() {
return mVersion;
}
/** Returns the libs defined in this add-on. Can be an empty array but not null. */
@@ -185,7 +184,7 @@ public class AddonPackage extends Package {
return String.format("%1$s by %2$s for Android API %3$d",
getName(),
getVendor(),
getApiLevel());
mVersion.getApiLevel());
}
/** Returns a long description for an {@link IDescription}. */
@@ -230,7 +229,7 @@ public class AddonPackage extends Package {
String name = suggestedDir;
if (suggestedDir == null || suggestedDir.length() == 0) {
name = String.format("addon-%s-%s-%d", getName(), getVendor(), getApiLevel()); //$NON-NLS-1$
name = String.format("addon-%s-%s-%d", getName(), getVendor(), mVersion.getApiLevel()); //$NON-NLS-1$
name = name.toLowerCase();
name = name.replaceAll("[^a-z0-9_-]+", "_"); //$NON-NLS-1$ //$NON-NLS-2$
name = name.replaceAll("_+", "_"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -272,6 +271,7 @@ public class AddonPackage extends Package {
String newId = newPkg.getName() + "+" + newPkg.getVendor(); //$NON-NLS-1$
return thisId.equalsIgnoreCase(newId) &&
newPkg.getRevision() > this.getRevision();
mVersion.getApiLevel() == newPkg.getVersion().getApiLevel() &&
newPkg.getRevision() > this.getRevision();
}
}

View File

@@ -16,6 +16,7 @@
package com.android.sdklib.internal.repository;
import com.android.sdklib.AndroidVersion;
import com.android.sdklib.SdkConstants;
import com.android.sdklib.SdkManager;
import com.android.sdklib.internal.repository.Archive.Arch;
@@ -33,9 +34,7 @@ import java.util.Properties;
*/
public class DocPackage extends Package {
private static final String PROP_API_LEVEL = "Doc.ApiLevel"; //$NON-NLS-1$
private final int mApiLevel;
private final AndroidVersion mVersion;
/**
* Creates a new doc package from the attributes and elements of the given XML node.
@@ -44,7 +43,13 @@ public class DocPackage extends Package {
*/
DocPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
super(source, packageNode, licenses);
mApiLevel = XmlParserUtils.getXmlInt(packageNode, SdkRepository.NODE_API_LEVEL, 0);
int apiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);
String codeName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_CODENAME);
if (codeName.length() == 0) {
codeName = null;
}
mVersion = new AndroidVersion(apiLevel, codeName);
}
/**
@@ -55,6 +60,7 @@ public class DocPackage extends Package {
DocPackage(RepoSource source,
Properties props,
int apiLevel,
String codename,
int revision,
String license,
String description,
@@ -71,8 +77,7 @@ public class DocPackage extends Package {
archiveOs,
archiveArch,
archiveOsPath);
mApiLevel = Integer.parseInt(
getProperty(props, PROP_API_LEVEL, Integer.toString(apiLevel)));
mVersion = new AndroidVersion(props, apiLevel, codename);
}
/**
@@ -83,20 +88,23 @@ public class DocPackage extends Package {
void saveProperties(Properties props) {
super.saveProperties(props);
props.setProperty(PROP_API_LEVEL, Integer.toString(mApiLevel));
mVersion.saveProperties(props);
}
/** Returns the api-level, an int > 0, for platform, add-on and doc packages.
/** Returns the version, for platform, add-on and doc packages.
* Can be 0 if this is a local package of unknown api-level. */
public int getApiLevel() {
return mApiLevel;
public AndroidVersion getVersion() {
return mVersion;
}
/** Returns a short description for an {@link IDescription}. */
@Override
public String getShortDescription() {
if (mApiLevel != 0) {
return String.format("Documentation for Android SDK, API %1$d", mApiLevel);
if (mVersion.isPreview()) {
return String.format("Documentation for Android '%1$s' Preview SDK",
mVersion.getCodename());
} else if (mVersion.getApiLevel() != 0) {
return String.format("Documentation for Android SDK, API %1$d", mVersion.getApiLevel());
} else {
return String.format("Documentation for Android SDK");
}
@@ -147,6 +155,6 @@ public class DocPackage extends Package {
DocPackage newPkg = (DocPackage) replacementPackage;
return newPkg.getRevision() > this.getRevision() &&
newPkg.getApiLevel() >= this.getApiLevel();
newPkg.getVersion().equals(this.getVersion());
}
}

View File

@@ -212,6 +212,7 @@ public class LocalSdkParser {
null, //source
props, //properties
0, //apiLevel
null, // codename
0, //revision
null, //license
null, //description

View File

@@ -49,7 +49,7 @@ public class PlatformPackage extends Package {
super(source, packageNode, licenses);
mVersionName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_VERSION);
int apiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);
String codeName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_API_CODENAME);
String codeName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_CODENAME);
if (codeName.length() == 0) {
codeName = null;
}
@@ -95,10 +95,9 @@ public class PlatformPackage extends Package {
return mVersionName;
}
/** Returns the api-level, an int > 0, for platform, add-on and doc packages. */
public int getApiLevel() {
// FIXME: return the AndroidVersion instead.
return mVersion.getApiLevel();
/** Returns the package version, for platform, add-on and doc packages. */
public AndroidVersion getVersion() {
return mVersion;
}
/** Returns a short description for an {@link IDescription}. */
@@ -111,7 +110,7 @@ public class PlatformPackage extends Package {
return String.format("SDK Platform Android %1$s, API %2$d",
getVersionName(),
getApiLevel());
mVersion.getApiLevel());
}
/** Returns a long description for an {@link IDescription}. */
@@ -174,7 +173,7 @@ public class PlatformPackage extends Package {
PlatformPackage newPkg = (PlatformPackage) replacementPackage;
return newPkg.getVersionName().equalsIgnoreCase(this.getVersionName()) &&
newPkg.getApiLevel() == this.getApiLevel() &&
newPkg.getVersion().equals(this.getVersion()) &&
newPkg.getRevision() > this.getRevision();
}
}

View File

@@ -63,8 +63,8 @@ public class SdkRepository {
public static final String NODE_VERSION = "version"; //$NON-NLS-1$
/** The api-level, an int > 0, for platform, add-on and doc packages. */
public static final String NODE_API_LEVEL = "api-level"; //$NON-NLS-1$
/** The api-codename, a string, for platform packages. */
public static final String NODE_API_CODENAME = "api-codename"; //$NON-NLS-1$
/** The codename, a string, for platform packages. */
public static final String NODE_CODENAME = "codename"; //$NON-NLS-1$
/** The vendor, a string, for add-on packages. */
public static final String NODE_VENDOR = "vendor"; //$NON-NLS-1$
/** The name, a string, for add-on packages or for libraries. */

View File

@@ -53,7 +53,7 @@
<!-- The Android API Level for the platform. An int > 0. -->
<xsd:element name="api-level" type="xsd:positiveInteger" />
<!-- The optional codename for this platform, if it's a preview. -->
<xsd:element name="api-codename" type="xsd:string" minOccurs="0" />
<xsd:element name="codename" type="xsd:string" minOccurs="0" />
<!-- The revision, an int > 0, incremented each time a new
package is generated. -->
@@ -158,6 +158,8 @@
<xsd:all>
<!-- The Android API Level for the documentation. An int > 0. -->
<xsd:element name="api-level" type="xsd:positiveInteger" />
<!-- The optional codename for this doc, if it's a preview. -->
<xsd:element name="codename" type="xsd:string" minOccurs="0" />
<!-- The revision, an int > 0, incremented each time a new
package is generated. -->

View File

@@ -16,8 +16,6 @@
package com.android.sdklib.repository;
import com.android.sdklib.SdkConstants;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

View File

@@ -160,7 +160,7 @@
<sdk:platform>
<sdk:version>Pastry</sdk:version>
<sdk:api-level>5</sdk:api-level>
<sdk:api-codename>Pastry</sdk:api-codename>
<sdk:codename>Pastry</sdk:codename>
<sdk:revision>3</sdk:revision>
<sdk:uses-license ref="license1" />
<sdk:description>Preview version for Pastry</sdk:description>

View File

@@ -785,7 +785,6 @@ public final class AvdSelector {
mDetailsButton.setEnabled(hasSelection);
mStartButton.setEnabled(mOsSdkPath != null &&
hasSelection &&
selection != null &&
selection.getStatus() == AvdStatus.OK);
if (mDeleteButton != null) {
@@ -793,7 +792,6 @@ public final class AvdSelector {
}
if (mUpdateButton != null) {
mUpdateButton.setEnabled(hasSelection &&
selection != null &&
selection.getStatus() == AvdStatus.ERROR_IMAGE_DIR);
}
}