Add support for preview versions of platforms.
ro.build.version.codename is a new property indicating whether a platform is in its release form (value = REL) or in development (value = dev branch name such as Donut). When the codename indicates a development/preview version then the API level must be ignored and this codename is used as a unique identifier of the platform. IAndroidTarget has been changed to return an instance of a new class AndroidVersion instead of the api level directly. This class helps deals with the logic of comparing version from targets or devices. This change impacts all of the sdk manager to deal with targets identified by codename instead of api level. This in turn impacts everything that relies on the sdkmanager: ADT (build, launch, project creation), the AVD manager, the SDK updater.
This commit is contained in:
@@ -137,14 +137,13 @@ final class AddOnTarget implements IAndroidTarget {
|
||||
return mDescription;
|
||||
}
|
||||
|
||||
public String getApiVersionName() {
|
||||
public AndroidVersion getVersion() {
|
||||
// this is always defined by the base platform
|
||||
return mBasePlatform.getApiVersionName();
|
||||
return mBasePlatform.getVersion();
|
||||
}
|
||||
|
||||
public int getApiVersionNumber() {
|
||||
// this is always defined by the base platform
|
||||
return mBasePlatform.getApiVersionNumber();
|
||||
public String getVersionName() {
|
||||
return mBasePlatform.getVersionName();
|
||||
}
|
||||
|
||||
public int getRevision() {
|
||||
@@ -182,7 +181,7 @@ final class AddOnTarget implements IAndroidTarget {
|
||||
return sampleLoc.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
// INTENT FALL-THROUGH
|
||||
// INTENDED FALL-THROUGH
|
||||
default :
|
||||
return mBasePlatform.getPath(pathId);
|
||||
}
|
||||
@@ -222,21 +221,22 @@ final class AddOnTarget implements IAndroidTarget {
|
||||
// if the receiver has no optional library, then anything with api version number >= to
|
||||
// the receiver is compatible.
|
||||
if (mLibraries.length == 0) {
|
||||
return target.getApiVersionNumber() >= getApiVersionNumber();
|
||||
return target.getVersion().getApiLevel() >= getVersion().getApiLevel();
|
||||
}
|
||||
|
||||
// Otherwise, target is only compatible if the vendor and name are equals with the api
|
||||
// number greater or equal (ie target is a newer version of this add-on).
|
||||
if (target.isPlatform() == false) {
|
||||
return (mVendor.equals(target.getVendor()) && mName.equals(target.getName()) &&
|
||||
target.getApiVersionNumber() >= getApiVersionNumber());
|
||||
target.getVersion().getApiLevel() >= getVersion().getApiLevel());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String hashString() {
|
||||
return String.format(ADD_ON_FORMAT, mVendor, mName, mBasePlatform.getApiVersionNumber());
|
||||
return String.format(ADD_ON_FORMAT, mVendor, mName,
|
||||
mBasePlatform.getVersion().getApiLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -250,7 +250,7 @@ final class AddOnTarget implements IAndroidTarget {
|
||||
AddOnTarget addon = (AddOnTarget)obj;
|
||||
|
||||
return mVendor.equals(addon.mVendor) && mName.equals(addon.mName) &&
|
||||
mBasePlatform.getApiVersionNumber() == addon.mBasePlatform.getApiVersionNumber();
|
||||
mBasePlatform.getVersion().getApiLevel() == addon.mBasePlatform.getVersion().getApiLevel();
|
||||
}
|
||||
|
||||
return super.equals(obj);
|
||||
@@ -277,7 +277,7 @@ final class AddOnTarget implements IAndroidTarget {
|
||||
|
||||
// api version
|
||||
if (value == 0) {
|
||||
value = getApiVersionNumber() - target.getApiVersionNumber();
|
||||
value = getVersion().getApiLevel() - target.getVersion().getApiLevel();
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.sdklib;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Represents the version of a target or device.
|
||||
* <p/>
|
||||
* A version is defined by an API level and an optional code name.
|
||||
* <ul><li>Release versions of the Android platform are identified by their API level (integer),
|
||||
* (technically the code name for release version is "REL" but this class will return
|
||||
* <code>null<code> instead.)</li>
|
||||
* <li>Preview versions of the platform are identified by a code name. Their API level
|
||||
* is usually set to the value of the previous platform.</li></ul>
|
||||
* <p/>
|
||||
* While this class contains both values, its goal is to abstract them, so that code comparing 2+
|
||||
* versions doesn't have to deal with the logic of handle both values.
|
||||
* <p/>
|
||||
* There are some cases where ones may want to access the values directly. This can be done
|
||||
* with {@link #getApiLevel()} and {@link #getCodename()}.
|
||||
* <p/>
|
||||
* For generic UI display of the API version, {@link #getApiString()} is to be used.
|
||||
*
|
||||
*/
|
||||
public class AndroidVersion {
|
||||
|
||||
private static final String PROP_API_LEVEL = "AndroidVersion.ApiLevel"; //$NON-NLS-1$
|
||||
private static final String PROP_CODENAME = "AndroidVersion.CodeName"; //$NON-NLS-1$
|
||||
|
||||
private final int mApiLevel;
|
||||
private final String mCodename;
|
||||
|
||||
public AndroidVersion(int apiLevel, String codename) {
|
||||
mApiLevel = apiLevel;
|
||||
mCodename = codename;
|
||||
}
|
||||
|
||||
public AndroidVersion(Properties properties) {
|
||||
throw new UnsupportedOperationException("TODO");
|
||||
}
|
||||
|
||||
public void saveProperties(Properties props) {
|
||||
props.setProperty(PROP_API_LEVEL, Integer.toString(mApiLevel));
|
||||
props.setProperty(PROP_CODENAME, mCodename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the api level as an integer.
|
||||
* <p/>For target that are in preview mode, this can be superseded by
|
||||
* {@link #getCodename()}.
|
||||
* <p/>To display the API level in the UI, use {@link #getApiString()}, which will use the
|
||||
* codename if applicable.
|
||||
* @see #getCodename()
|
||||
* @see #getApiString()
|
||||
*/
|
||||
public int getApiLevel() {
|
||||
return mApiLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version code name if applicable, null otherwise.
|
||||
* <p/>If the codename is non null, then the API level should be ignored, and this should be
|
||||
* used as a unique identifier of the target instead.
|
||||
*/
|
||||
public String getCodename() {
|
||||
return mCodename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representing the API level and/or the code name.
|
||||
*/
|
||||
public String getApiString() {
|
||||
if (mCodename != null) {
|
||||
return mCodename;
|
||||
}
|
||||
|
||||
return Integer.toString(mApiLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the version is a preview version.
|
||||
*/
|
||||
public boolean isPreview() {
|
||||
return mCodename != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a device running a version similar to the receiver can run a project compiled
|
||||
* for the given <var>version</var>.
|
||||
* <p/>
|
||||
* Be aware that this is not a perfect test, as other properties could break compatibility
|
||||
* despite this method returning true. For a more comprehensive test, see
|
||||
* {@link IAndroidTarget#isCompatibleBaseFor(IAndroidTarget)}.
|
||||
* <p/>
|
||||
* Nevertheless, when testing if an application can run on a device (where there is no
|
||||
* access to the list of optional libraries), this method can give a good indication of whether
|
||||
* there is a chance the application could run, or if there's a direct incompatibility.
|
||||
*/
|
||||
public boolean canRun(AndroidVersion appVersion) {
|
||||
// if the application is compiled for a preview version, the device must be running exactly
|
||||
// the same.
|
||||
if (appVersion.mCodename != null) {
|
||||
return appVersion.mCodename.equals(mCodename);
|
||||
}
|
||||
|
||||
// otherwise, we check the api level (note that a device running a preview version
|
||||
// will have the api level of the previous platform).
|
||||
return mApiLevel >= appVersion.mApiLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the AndroidVersion is an API level equals to
|
||||
* <var>apiLevel</var>.
|
||||
*/
|
||||
public boolean equals(int apiLevel) {
|
||||
return mCodename == null && apiLevel == mApiLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the receiver with either an {@link AndroidVersion} object or a {@link String}
|
||||
* object.
|
||||
* <p/>If <var>obj</var> is a {@link String}, then the method will first check if it's a string
|
||||
* representation of a number, in which case it'll compare it to the api level. Otherwise, it'll
|
||||
* compare it against the code name.
|
||||
* <p/>For all other type of object give as parameter, this method will return
|
||||
* <code>false</code>.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof AndroidVersion) {
|
||||
AndroidVersion version = (AndroidVersion)obj;
|
||||
|
||||
if (mCodename == null) {
|
||||
return version.mCodename == null &&
|
||||
mApiLevel == version.mApiLevel;
|
||||
} else {
|
||||
return mCodename.equals(version.mCodename) &&
|
||||
mApiLevel == version.mApiLevel;
|
||||
}
|
||||
|
||||
} else if (obj instanceof String) {
|
||||
try {
|
||||
int value = Integer.parseInt((String)obj);
|
||||
return value == mApiLevel;
|
||||
} catch (NumberFormatException e) {
|
||||
// not a number? compare to the code name
|
||||
return obj.equals(mCodename);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (mCodename != null) {
|
||||
return mCodename.hashCode();
|
||||
}
|
||||
|
||||
// there may be some collisions between the hashcode of the codename and the api level
|
||||
// but it's acceptable.
|
||||
return mApiLevel;
|
||||
}
|
||||
}
|
||||
@@ -119,14 +119,14 @@ public interface IAndroidTarget extends Comparable<IAndroidTarget> {
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* Returns the api version as an integer.
|
||||
* Returns the version of the target. This is guaranteed to be non-null.
|
||||
*/
|
||||
int getApiVersionNumber();
|
||||
AndroidVersion getVersion();
|
||||
|
||||
/**
|
||||
* Returns the platform version as a readable string.
|
||||
*/
|
||||
String getApiVersionName();
|
||||
public String getVersionName();
|
||||
|
||||
/** Returns the revision number for the target. */
|
||||
int getRevision();
|
||||
|
||||
@@ -26,32 +26,41 @@ import java.util.Map;
|
||||
*/
|
||||
final class PlatformTarget implements IAndroidTarget {
|
||||
/** String used to get a hash to the platform target */
|
||||
private final static String PLATFORM_HASH = "android-%d";
|
||||
private final static String PLATFORM_HASH_API_LEVEL = "android-%d";
|
||||
private final static String PLATFORM_HASH_CODENAME = "android-%s";
|
||||
|
||||
private final static String PLATFORM_VENDOR = "Android Open Source Project";
|
||||
|
||||
private final static String PLATFORM_NAME = "Android %s";
|
||||
private final static String PLATFORM_NAME_PREVIEW = "Android %s (Preview)";
|
||||
|
||||
private final String mLocation;
|
||||
private final String mName;
|
||||
private final int mApiVersionNumber;
|
||||
private final String mApiVersionName;
|
||||
private final AndroidVersion mVersion;
|
||||
private final String mVersionName;
|
||||
private final int mRevision;
|
||||
private final Map<String, String> mProperties;
|
||||
private final Map<Integer, String> mPaths = new HashMap<Integer, String>();
|
||||
private String[] mSkins;
|
||||
|
||||
|
||||
PlatformTarget(String location, Map<String, String> properties,
|
||||
int apiNumber, String apiName, int revision) {
|
||||
mName = String.format(PLATFORM_NAME, apiName);
|
||||
int apiLevel, String codeName, String versionName, int revision) {
|
||||
if (location.endsWith(File.separator) == false) {
|
||||
location = location + File.separator;
|
||||
}
|
||||
mLocation = location;
|
||||
mProperties = Collections.unmodifiableMap(properties);
|
||||
mApiVersionNumber = apiNumber;
|
||||
mApiVersionName = apiName;
|
||||
mVersion = new AndroidVersion(apiLevel, codeName);
|
||||
mVersionName = versionName;
|
||||
mRevision = revision;
|
||||
|
||||
if (mVersion.isPreview()) {
|
||||
mName = String.format(PLATFORM_NAME_PREVIEW, mVersionName);
|
||||
} else {
|
||||
mName = String.format(PLATFORM_NAME, mVersionName);
|
||||
}
|
||||
|
||||
// pre-build the path to the platform components
|
||||
mPaths.put(ANDROID_JAR, mLocation + SdkConstants.FN_FRAMEWORK_LIBRARY);
|
||||
mPaths.put(SOURCES, mLocation + SdkConstants.FD_ANDROID_SOURCES);
|
||||
@@ -119,15 +128,15 @@ final class PlatformTarget implements IAndroidTarget {
|
||||
* @see com.android.sdklib.IAndroidTarget#getDescription()
|
||||
*/
|
||||
public String getDescription() {
|
||||
return String.format("Standard Android platform %s", mApiVersionName);
|
||||
return String.format("Standard Android platform %s", mVersionName);
|
||||
}
|
||||
|
||||
public int getApiVersionNumber(){
|
||||
return mApiVersionNumber;
|
||||
public AndroidVersion getVersion() {
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
public String getApiVersionName() {
|
||||
return mApiVersionName;
|
||||
public String getVersionName() {
|
||||
return mVersionName;
|
||||
}
|
||||
|
||||
public int getRevision() {
|
||||
@@ -189,13 +198,23 @@ final class PlatformTarget implements IAndroidTarget {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if the platform has a codename (ie it's a preview of an upcoming platform), then
|
||||
// both platform must be exactly identical.
|
||||
if (mVersion.getCodename() != null) {
|
||||
return equals(target);
|
||||
}
|
||||
|
||||
// target is compatible wit the receiver as long as its api version number is greater or
|
||||
// equal.
|
||||
return target.getApiVersionNumber() >= mApiVersionNumber;
|
||||
return target.getVersion().getApiLevel() >= mVersion.getApiLevel();
|
||||
}
|
||||
|
||||
public String hashString() {
|
||||
return String.format(PLATFORM_HASH, mApiVersionNumber);
|
||||
if (mVersion.getCodename() != null) {
|
||||
return String.format(PLATFORM_HASH_CODENAME, mVersion.getCodename());
|
||||
}
|
||||
|
||||
return String.format(PLATFORM_HASH_API_LEVEL, mVersion.getApiLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -206,10 +225,12 @@ final class PlatformTarget implements IAndroidTarget {
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof PlatformTarget) {
|
||||
return mApiVersionNumber == ((PlatformTarget)obj).mApiVersionNumber;
|
||||
PlatformTarget platform = (PlatformTarget)obj;
|
||||
|
||||
return mVersion.equals(platform.getVersion());
|
||||
}
|
||||
|
||||
return super.equals(obj);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -223,7 +244,13 @@ final class PlatformTarget implements IAndroidTarget {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mApiVersionNumber - target.getApiVersionNumber();
|
||||
int apiDiff = mVersion.getApiLevel() - target.getVersion().getApiLevel();
|
||||
|
||||
if (mVersion.getCodename() != null && apiDiff == 0) {
|
||||
return mVersion.getCodename().compareTo(target.getVersion().getCodename());
|
||||
}
|
||||
|
||||
return apiDiff;
|
||||
}
|
||||
|
||||
// ---- platform only methods.
|
||||
|
||||
@@ -42,6 +42,7 @@ import java.util.regex.Pattern;
|
||||
public final class SdkManager {
|
||||
|
||||
public final static String PROP_VERSION_SDK = "ro.build.version.sdk";
|
||||
public final static String PROP_VERSION_CODENAME = "ro.build.version.codename";
|
||||
public final static String PROP_VERSION_RELEASE = "ro.build.version.release";
|
||||
public final static String PROP_VERSION_REVISION = "ro.build.version.incremental";
|
||||
|
||||
@@ -263,23 +264,28 @@ public final class SdkManager {
|
||||
|
||||
if (map != null) {
|
||||
// look for some specific values in the map.
|
||||
|
||||
// version string
|
||||
String apiName = map.get(PROP_VERSION_RELEASE);
|
||||
if (apiName == null) {
|
||||
if (log != null) {
|
||||
log.error(null,
|
||||
"Ignoring platform '%1$s': %2$s is missing from '%3$s'",
|
||||
platform.getName(), PROP_VERSION_RELEASE, SdkConstants.FN_BUILD_PROP);
|
||||
platform.getName(), PROP_VERSION_RELEASE,
|
||||
SdkConstants.FN_BUILD_PROP);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// api level
|
||||
int apiNumber;
|
||||
String stringValue = map.get(PROP_VERSION_SDK);
|
||||
if (stringValue == null) {
|
||||
if (log != null) {
|
||||
log.error(null,
|
||||
"Ignoring platform '%1$s': %2$s is missing from '%3$s'",
|
||||
platform.getName(), PROP_VERSION_SDK, SdkConstants.FN_BUILD_PROP);
|
||||
platform.getName(), PROP_VERSION_SDK,
|
||||
SdkConstants.FN_BUILD_PROP);
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
@@ -291,19 +297,28 @@ public final class SdkManager {
|
||||
if (log != null) {
|
||||
log.error(null,
|
||||
"Ignoring platform '%1$s': %2$s is not a valid number in %3$s.",
|
||||
platform.getName(), PROP_VERSION_SDK, SdkConstants.FN_BUILD_PROP);
|
||||
platform.getName(), PROP_VERSION_SDK,
|
||||
SdkConstants.FN_BUILD_PROP);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// codename (optional)
|
||||
String apiCodename = map.get(PROP_VERSION_CODENAME);
|
||||
if (apiCodename != null && apiCodename.equals("REL")) {
|
||||
apiCodename = null; // REL means it's a release version and therefore the
|
||||
// codename is irrelevant at this point.
|
||||
}
|
||||
|
||||
int revision = 1;
|
||||
stringValue = map.get(PROP_VERSION_REVISION);
|
||||
if (stringValue == null) {
|
||||
if (log != null) {
|
||||
log.error(null,
|
||||
"Ignoring platform '%1$s': %2$s is missing from '%3$s'",
|
||||
platform.getName(), PROP_VERSION_REVISION, SdkConstants.FN_BUILD_PROP);
|
||||
platform.getName(), PROP_VERSION_REVISION,
|
||||
SdkConstants.FN_BUILD_PROP);
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
@@ -346,6 +361,7 @@ public final class SdkManager {
|
||||
platform.getAbsolutePath(),
|
||||
map,
|
||||
apiNumber,
|
||||
apiCodename,
|
||||
apiName,
|
||||
revision);
|
||||
|
||||
@@ -435,8 +451,7 @@ public final class SdkManager {
|
||||
try {
|
||||
int apiValue = Integer.parseInt(api);
|
||||
for (IAndroidTarget target : targetList) {
|
||||
if (target.isPlatform() &&
|
||||
target.getApiVersionNumber() == apiValue) {
|
||||
if (target.isPlatform() && target.getVersion().equals(apiValue)) {
|
||||
baseTarget = (PlatformTarget)target;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.sdklib.internal.repository;
|
||||
|
||||
import com.android.sdklib.AndroidVersion;
|
||||
import com.android.sdklib.IAndroidTarget;
|
||||
import com.android.sdklib.SdkConstants;
|
||||
import com.android.sdklib.SdkManager;
|
||||
@@ -36,13 +37,12 @@ import java.util.Properties;
|
||||
*/
|
||||
public class AddonPackage extends Package {
|
||||
|
||||
private static final String PROP_API_LEVEL = "Addon.ApiLevel"; //$NON-NLS-1$
|
||||
private static final String PROP_NAME = "Addon.Name"; //$NON-NLS-1$
|
||||
private static final String PROP_VENDOR = "Addon.Vendor"; //$NON-NLS-1$
|
||||
|
||||
private final String mVendor;
|
||||
private final String mName;
|
||||
private final int mApiLevel;
|
||||
private final AndroidVersion mVersion;
|
||||
|
||||
/** An add-on library. */
|
||||
public static class Lib {
|
||||
@@ -74,7 +74,10 @@ public class AddonPackage extends Package {
|
||||
super(source, packageNode, licenses);
|
||||
mVendor = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_VENDOR);
|
||||
mName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_NAME);
|
||||
mApiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);
|
||||
mVersion = new AndroidVersion(
|
||||
XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0),
|
||||
null); // add-ons on platform previews is not supported, so the codename is always
|
||||
// null in this case.
|
||||
|
||||
mLibs = parseLibs(XmlParserUtils.getFirstChild(packageNode, SdkRepository.NODE_LIBS));
|
||||
}
|
||||
@@ -88,7 +91,7 @@ public class AddonPackage extends Package {
|
||||
AddonPackage(IAndroidTarget target, Properties props) {
|
||||
super( null, //source
|
||||
props, //properties
|
||||
0, //revision
|
||||
target.getRevision(), //revision
|
||||
null, //license
|
||||
target.getDescription(), //description
|
||||
null, //descUrl
|
||||
@@ -97,7 +100,7 @@ public class AddonPackage extends Package {
|
||||
target.getLocation() //archiveOsPath
|
||||
);
|
||||
|
||||
mApiLevel = target.getApiVersionNumber();
|
||||
mVersion = target.getVersion();
|
||||
mName = target.getName();
|
||||
mVendor = target.getVendor();
|
||||
|
||||
@@ -114,13 +117,13 @@ public class AddonPackage extends Package {
|
||||
|
||||
/**
|
||||
* Save the properties of the current packages in the given {@link Properties} object.
|
||||
* These properties will later be give the constructor that takes a {@link Properties} object.
|
||||
* These properties will later be given to a constructor that takes a {@link Properties} object.
|
||||
*/
|
||||
@Override
|
||||
void saveProperties(Properties props) {
|
||||
super.saveProperties(props);
|
||||
|
||||
props.setProperty(PROP_API_LEVEL, Integer.toString(mApiLevel));
|
||||
mVersion.saveProperties(props);
|
||||
props.setProperty(PROP_NAME, mName);
|
||||
props.setProperty(PROP_VENDOR, mVendor);
|
||||
}
|
||||
@@ -167,7 +170,8 @@ public class AddonPackage extends Package {
|
||||
|
||||
/** Returns the api-level, an int > 0, for platform, add-on and doc packages. */
|
||||
public int getApiLevel() {
|
||||
return mApiLevel;
|
||||
// FIXME: return the AndroidVersion instead.
|
||||
return mVersion.getApiLevel();
|
||||
}
|
||||
|
||||
/** Returns the libs defined in this add-on. Can be an empty array but not null. */
|
||||
@@ -214,7 +218,7 @@ public class AddonPackage extends Package {
|
||||
// First find if this add-on is already installed. If so, reuse the same directory.
|
||||
for (IAndroidTarget target : sdkManager.getTargets()) {
|
||||
if (!target.isPlatform() &&
|
||||
target.getApiVersionNumber() == getApiLevel() &&
|
||||
target.getVersion().equals(mVersion) &&
|
||||
target.getName().equals(getName()) &&
|
||||
target.getVendor().equals(getVendor())) {
|
||||
return new File(target.getLocation());
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.sdklib.internal.repository;
|
||||
|
||||
import com.android.sdklib.AndroidVersion;
|
||||
import com.android.sdklib.IAndroidTarget;
|
||||
import com.android.sdklib.SdkConstants;
|
||||
import com.android.sdklib.SdkManager;
|
||||
@@ -34,11 +35,10 @@ import java.util.Properties;
|
||||
*/
|
||||
public class PlatformPackage extends Package {
|
||||
|
||||
private static final String PROP_API_LEVEL = "Platform.ApiLevel"; //$NON-NLS-1$
|
||||
private static final String PROP_VERSION = "Platform.Version"; //$NON-NLS-1$
|
||||
|
||||
private final String mVersion;
|
||||
private final int mApiLevel;
|
||||
private final AndroidVersion mVersion;
|
||||
private final String mVersionName;
|
||||
|
||||
/**
|
||||
* Creates a new platform package from the attributes and elements of the given XML node.
|
||||
@@ -47,8 +47,13 @@ public class PlatformPackage extends Package {
|
||||
*/
|
||||
PlatformPackage(RepoSource source, Node packageNode, Map<String,String> licenses) {
|
||||
super(source, packageNode, licenses);
|
||||
mVersion = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_VERSION);
|
||||
mApiLevel = XmlParserUtils.getXmlInt (packageNode, SdkRepository.NODE_API_LEVEL, 0);
|
||||
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);
|
||||
if (codeName.length() == 0) {
|
||||
codeName = null;
|
||||
}
|
||||
mVersion = new AndroidVersion(apiLevel, codeName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +65,7 @@ public class PlatformPackage extends Package {
|
||||
PlatformPackage(IAndroidTarget target, Properties props) {
|
||||
super( null, //source
|
||||
props, //properties
|
||||
0, //revision
|
||||
target.getRevision(), //revision
|
||||
null, //license
|
||||
target.getDescription(), //description
|
||||
null, //descUrl
|
||||
@@ -69,37 +74,43 @@ public class PlatformPackage extends Package {
|
||||
target.getLocation() //archiveOsPath
|
||||
);
|
||||
|
||||
mApiLevel = target.getApiVersionNumber();
|
||||
mVersion = target.getApiVersionName();
|
||||
mVersion = target.getVersion();
|
||||
mVersionName = target.getVersionName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the properties of the current packages in the given {@link Properties} object.
|
||||
* These properties will later be give the constructor that takes a {@link Properties} object.
|
||||
* These properties will later be given to a constructor that takes a {@link Properties} object.
|
||||
*/
|
||||
@Override
|
||||
void saveProperties(Properties props) {
|
||||
super.saveProperties(props);
|
||||
|
||||
props.setProperty(PROP_API_LEVEL, Integer.toString(mApiLevel));
|
||||
props.setProperty(PROP_VERSION, mVersion);
|
||||
mVersion.saveProperties(props);
|
||||
props.setProperty(PROP_VERSION, mVersionName);
|
||||
}
|
||||
|
||||
/** Returns the version, a string, for platform packages. */
|
||||
public String getVersion() {
|
||||
return mVersion;
|
||||
public String getVersionName() {
|
||||
return mVersionName;
|
||||
}
|
||||
|
||||
/** Returns the api-level, an int > 0, for platform, add-on and doc packages. */
|
||||
public int getApiLevel() {
|
||||
return mApiLevel;
|
||||
// FIXME: return the AndroidVersion instead.
|
||||
return mVersion.getApiLevel();
|
||||
}
|
||||
|
||||
/** Returns a short description for an {@link IDescription}. */
|
||||
@Override
|
||||
public String getShortDescription() {
|
||||
if (mVersion.isPreview()) {
|
||||
return String.format("SDK Platform Android %1$s (Preview)",
|
||||
getVersionName());
|
||||
}
|
||||
|
||||
return String.format("SDK Platform Android %1$s, API %2$d",
|
||||
getVersion(),
|
||||
getVersionName(),
|
||||
getApiLevel());
|
||||
}
|
||||
|
||||
@@ -128,17 +139,17 @@ public class PlatformPackage extends Package {
|
||||
@Override
|
||||
public File getInstallFolder(String osSdkRoot, String suggestedDir, SdkManager sdkManager) {
|
||||
|
||||
// First find if this add-on is already installed. If so, reuse the same directory.
|
||||
// First find if this platform is already installed. If so, reuse the same directory.
|
||||
for (IAndroidTarget target : sdkManager.getTargets()) {
|
||||
if (target.isPlatform() &&
|
||||
target.getApiVersionNumber() == getApiLevel() &&
|
||||
target.getApiVersionName().equals(getVersion())) {
|
||||
target.getVersion().equals(mVersion) &&
|
||||
target.getVersionName().equals(getVersionName())) {
|
||||
return new File(target.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
File platforms = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);
|
||||
File folder = new File(platforms, String.format("android-%s", getVersion())); //$NON-NLS-1$
|
||||
File folder = new File(platforms, String.format("android-%s", getVersionName())); //$NON-NLS-1$
|
||||
|
||||
return folder;
|
||||
}
|
||||
@@ -162,7 +173,7 @@ public class PlatformPackage extends Package {
|
||||
}
|
||||
|
||||
PlatformPackage newPkg = (PlatformPackage) replacementPackage;
|
||||
return newPkg.getVersion().equalsIgnoreCase(this.getVersion()) &&
|
||||
return newPkg.getVersionName().equalsIgnoreCase(this.getVersionName()) &&
|
||||
newPkg.getApiLevel() == this.getApiLevel() &&
|
||||
newPkg.getRevision() > this.getRevision();
|
||||
}
|
||||
|
||||
@@ -63,6 +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 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. */
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
<xsd:element name="version" type="xsd:normalizedString" />
|
||||
<!-- 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" />
|
||||
|
||||
<!-- The revision, an int > 0, incremented each time a new
|
||||
package is generated. -->
|
||||
|
||||
Reference in New Issue
Block a user