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) {
return mName;\r
}\r
\r
- /** Returns the api-level, an int > 0, for platform, add-on and doc packages. */\r
- public int getApiLevel() {\r
- // FIXME: return the AndroidVersion instead.\r
- return mVersion.getApiLevel();\r
+ /** Returns the version, for platform, add-on and doc packages. */\r
+ public AndroidVersion getVersion() {\r
+ return mVersion;\r
}\r
\r
/** Returns the libs defined in this add-on. Can be an empty array but not null. */\r
return String.format("%1$s by %2$s for Android API %3$d",\r
getName(),\r
getVendor(),\r
- getApiLevel());\r
+ mVersion.getApiLevel());\r
}\r
\r
/** Returns a long description for an {@link IDescription}. */\r
String name = suggestedDir;\r
\r
if (suggestedDir == null || suggestedDir.length() == 0) {\r
- name = String.format("addon-%s-%s-%d", getName(), getVendor(), getApiLevel()); //$NON-NLS-1$\r
+ name = String.format("addon-%s-%s-%d", getName(), getVendor(), mVersion.getApiLevel()); //$NON-NLS-1$\r
name = name.toLowerCase();\r
name = name.replaceAll("[^a-z0-9_-]+", "_"); //$NON-NLS-1$ //$NON-NLS-2$\r
name = name.replaceAll("_+", "_"); //$NON-NLS-1$ //$NON-NLS-2$\r
String newId = newPkg.getName() + "+" + newPkg.getVendor(); //$NON-NLS-1$\r
\r
return thisId.equalsIgnoreCase(newId) &&\r
- newPkg.getRevision() > this.getRevision();\r
+ mVersion.getApiLevel() == newPkg.getVersion().getApiLevel() &&\r
+ newPkg.getRevision() > this.getRevision();\r
}\r
}\r
\r
package com.android.sdklib.internal.repository;\r
\r
+import com.android.sdklib.AndroidVersion;\r
import com.android.sdklib.SdkConstants;\r
import com.android.sdklib.SdkManager;\r
import com.android.sdklib.internal.repository.Archive.Arch;\r
*/\r
public class DocPackage extends Package {\r
\r
- private static final String PROP_API_LEVEL = "Doc.ApiLevel"; //$NON-NLS-1$\r
-\r
- private final int mApiLevel;\r
+ private final AndroidVersion mVersion;\r
\r
/**\r
* Creates a new doc package from the attributes and elements of the given XML node.\r
*/\r
DocPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {\r
super(source, packageNode, licenses);\r
- mApiLevel = XmlParserUtils.getXmlInt(packageNode, SdkRepository.NODE_API_LEVEL, 0);\r
+\r
+ int apiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);\r
+ String codeName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_CODENAME);\r
+ if (codeName.length() == 0) {\r
+ codeName = null;\r
+ }\r
+ mVersion = new AndroidVersion(apiLevel, codeName);\r
}\r
\r
/**\r
DocPackage(RepoSource source,\r
Properties props,\r
int apiLevel,\r
+ String codename,\r
int revision,\r
String license,\r
String description,\r
archiveOs,\r
archiveArch,\r
archiveOsPath);\r
- mApiLevel = Integer.parseInt(\r
- getProperty(props, PROP_API_LEVEL, Integer.toString(apiLevel)));\r
+ mVersion = new AndroidVersion(props, apiLevel, codename);\r
}\r
\r
/**\r
void saveProperties(Properties props) {\r
super.saveProperties(props);\r
\r
- props.setProperty(PROP_API_LEVEL, Integer.toString(mApiLevel));\r
+ mVersion.saveProperties(props);\r
}\r
\r
- /** Returns the api-level, an int > 0, for platform, add-on and doc packages.\r
+ /** Returns the version, for platform, add-on and doc packages.\r
* Can be 0 if this is a local package of unknown api-level. */\r
- public int getApiLevel() {\r
- return mApiLevel;\r
+ public AndroidVersion getVersion() {\r
+ return mVersion;\r
}\r
\r
/** Returns a short description for an {@link IDescription}. */\r
@Override\r
public String getShortDescription() {\r
- if (mApiLevel != 0) {\r
- return String.format("Documentation for Android SDK, API %1$d", mApiLevel);\r
+ if (mVersion.isPreview()) {\r
+ return String.format("Documentation for Android '%1$s' Preview SDK",\r
+ mVersion.getCodename());\r
+ } else if (mVersion.getApiLevel() != 0) {\r
+ return String.format("Documentation for Android SDK, API %1$d", mVersion.getApiLevel());\r
} else {\r
return String.format("Documentation for Android SDK");\r
}\r
\r
DocPackage newPkg = (DocPackage) replacementPackage;\r
return newPkg.getRevision() > this.getRevision() &&\r
- newPkg.getApiLevel() >= this.getApiLevel();\r
+ newPkg.getVersion().equals(this.getVersion());\r
}\r
}\r
null, //source\r
props, //properties\r
0, //apiLevel\r
+ null, // codename\r
0, //revision\r
null, //license\r
null, //description\r
super(source, packageNode, licenses);\r
mVersionName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_VERSION);\r
int apiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);\r
- String codeName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_API_CODENAME);\r
+ String codeName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_CODENAME);\r
if (codeName.length() == 0) {\r
codeName = null;\r
}\r
return mVersionName;\r
}\r
\r
- /** Returns the api-level, an int > 0, for platform, add-on and doc packages. */\r
- public int getApiLevel() {\r
- // FIXME: return the AndroidVersion instead.\r
- return mVersion.getApiLevel();\r
+ /** Returns the package version, for platform, add-on and doc packages. */\r
+ public AndroidVersion getVersion() {\r
+ return mVersion;\r
}\r
\r
/** Returns a short description for an {@link IDescription}. */\r
\r
return String.format("SDK Platform Android %1$s, API %2$d",\r
getVersionName(),\r
- getApiLevel());\r
+ mVersion.getApiLevel());\r
}\r
\r
/** Returns a long description for an {@link IDescription}. */\r
\r
PlatformPackage newPkg = (PlatformPackage) replacementPackage;\r
return newPkg.getVersionName().equalsIgnoreCase(this.getVersionName()) &&\r
- newPkg.getApiLevel() == this.getApiLevel() &&\r
+ newPkg.getVersion().equals(this.getVersion()) &&\r
newPkg.getRevision() > this.getRevision();\r
}\r
}\r
public static final String NODE_VERSION = "version"; //$NON-NLS-1$\r
/** The api-level, an int > 0, for platform, add-on and doc packages. */\r
public static final String NODE_API_LEVEL = "api-level"; //$NON-NLS-1$\r
- /** The api-codename, a string, for platform packages. */\r
- public static final String NODE_API_CODENAME = "api-codename"; //$NON-NLS-1$\r
+ /** The codename, a string, for platform packages. */\r
+ public static final String NODE_CODENAME = "codename"; //$NON-NLS-1$\r
/** The vendor, a string, for add-on packages. */\r
public static final String NODE_VENDOR = "vendor"; //$NON-NLS-1$\r
/** The name, a string, for add-on packages or for libraries. */\r
<!-- 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. -->
<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. -->
\r
package com.android.sdklib.repository;\r
\r
-import com.android.sdklib.SdkConstants;\r
-\r
import org.xml.sax.ErrorHandler;\r
import org.xml.sax.SAXException;\r
import org.xml.sax.SAXParseException;\r
<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>
mDetailsButton.setEnabled(hasSelection);
mStartButton.setEnabled(mOsSdkPath != null &&
hasSelection &&
- selection != null &&
selection.getStatus() == AvdStatus.OK);
if (mDeleteButton != null) {
}
if (mUpdateButton != null) {
mUpdateButton.setEnabled(hasSelection &&
- selection != null &&
selection.getStatus() == AvdStatus.ERROR_IMAGE_DIR);
}
}