Add support for add-on based on preview of platforms.

This commit is contained in:
Xavier Ducrohet
2009-07-22 17:39:44 -07:00
parent 76033864c5
commit a399a681d5
15 changed files with 156 additions and 114 deletions

View File

@@ -32,7 +32,7 @@ final class AddOnTarget implements IAndroidTarget {
* String to compute hash for add-on targets.
* Format is vendor:name:apiVersion
* */
private final static String ADD_ON_FORMAT = "%s:%s:%d"; //$NON-NLS-1$
private final static String ADD_ON_FORMAT = "%s:%s:%s"; //$NON-NLS-1$
private final static class OptionalLibrary implements IOptionalLibrary {
private final String mJarName;
@@ -218,25 +218,20 @@ final class AddOnTarget implements IAndroidTarget {
return true;
}
// if the receiver has no optional library, then anything with api version number >= to
// the receiver is compatible.
if (mLibraries.length == 0) {
return target.getVersion().getApiLevel() >= getVersion().getApiLevel();
// if the receiver has optional libraries, then the target is only compatible if the
// vendor and name are the same
if (mLibraries.length != 0 &&
(mVendor.equals(target.getVendor()) == false ||
mName.equals(target.getName()) == false)) {
return false;
}
// 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.getVersion().getApiLevel() >= getVersion().getApiLevel());
}
return false;
return mBasePlatform.equals(target);
}
public String hashString() {
return String.format(ADD_ON_FORMAT, mVendor, mName,
mBasePlatform.getVersion().getApiLevel());
mBasePlatform.getVersion().getApiString());
}
@Override
@@ -250,10 +245,10 @@ final class AddOnTarget implements IAndroidTarget {
AddOnTarget addon = (AddOnTarget)obj;
return mVendor.equals(addon.mVendor) && mName.equals(addon.mName) &&
mBasePlatform.getVersion().getApiLevel() == addon.mBasePlatform.getVersion().getApiLevel();
mBasePlatform.getVersion().equals(addon.mBasePlatform.getVersion());
}
return super.equals(obj);
return false;
}
/*
@@ -267,17 +262,25 @@ final class AddOnTarget implements IAndroidTarget {
return +1;
}
// vendor
// compare vendor
int value = mVendor.compareTo(target.getVendor());
// name
// if same vendor, compare name
if (value == 0) {
value = mName.compareTo(target.getName());
}
// api version
// if same vendor/name, compare version
if (value == 0) {
value = getVersion().getApiLevel() - target.getVersion().getApiLevel();
if (getVersion().isPreview() == true) {
value = target.getVersion().isPreview() == true ?
getVersion().getApiString().compareTo(target.getVersion().getApiString()) :
+1; // put the preview at the end.
} else {
value = target.getVersion().isPreview() == true ?
-1 : // put the preview at the end :
getVersion().getApiLevel() - target.getVersion().getApiLevel();
}
}
return value;

View File

@@ -172,12 +172,17 @@ public class AndroidVersion {
}
} else if (obj instanceof String) {
// if we have a code name, this must match.
if (mCodename != null) {
return mCodename.equals((String)obj);
}
// else we try to convert to a int and compare to the api level
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);
// not a number? we'll return false below.
}
}

View File

@@ -26,8 +26,7 @@ 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_API_LEVEL = "android-%d";
private final static String PLATFORM_HASH_CODENAME = "android-%s";
private final static String PLATFORM_HASH = "android-%s";
private final static String PLATFORM_VENDOR = "Android Open Source Project";
@@ -199,9 +198,9 @@ final class PlatformTarget implements IAndroidTarget {
}
// if the platform has a codename (ie it's a preview of an upcoming platform), then
// both platform must be exactly identical.
// both platforms must be exactly identical.
if (mVersion.getCodename() != null) {
return equals(target);
return mVersion.equals(target.getVersion());
}
// target is compatible wit the receiver as long as its api version number is greater or
@@ -210,11 +209,7 @@ final class PlatformTarget implements IAndroidTarget {
}
public String hashString() {
if (mVersion.getCodename() != null) {
return String.format(PLATFORM_HASH_CODENAME, mVersion.getCodename());
}
return String.format(PLATFORM_HASH_API_LEVEL, mVersion.getApiLevel());
return String.format(PLATFORM_HASH, mVersion.getApiString());
}
@Override

View File

@@ -448,31 +448,20 @@ public final class SdkManager {
displayAddonManifestError(log, addon.getName(), ADDON_API);
return null;
} else {
try {
int apiValue = Integer.parseInt(api);
for (IAndroidTarget target : targetList) {
if (target.isPlatform() && target.getVersion().equals(apiValue)) {
baseTarget = (PlatformTarget)target;
break;
}
// Look for a platform that has a matching api level or codename.
for (IAndroidTarget target : targetList) {
if (target.isPlatform() && target.getVersion().equals(api)) {
baseTarget = (PlatformTarget)target;
break;
}
}
if (baseTarget == null) {
if (log != null) {
log.error(null,
"Ignoring add-on '%1$s': Unable to find base platform with API level %2$d",
addon.getName(), apiValue);
}
return null;
}
} catch (NumberFormatException e) {
// looks like apiNumber does not parse to a number.
if (baseTarget == null) {
// Ignore this add-on.
if (log != null) {
log.error(null,
"Ignoring add-on '%1$s': %2$s is not a valid number in %3$s.",
addon.getName(), ADDON_API, SdkConstants.FN_BUILD_PROP);
"Ignoring add-on '%1$s': Unable to find base platform with API level '%2$s'",
addon.getName(), api);
}
return null;
}

View File

@@ -74,10 +74,12 @@ public class AddonPackage extends Package {
super(source, packageNode, licenses);
mVendor = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_VENDOR);
mName = XmlParserUtils.getXmlString(packageNode, SdkRepository.NODE_NAME);
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.
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);
mLibs = parseLibs(XmlParserUtils.getFirstChild(packageNode, SdkRepository.NODE_LIBS));
}
@@ -181,10 +183,10 @@ public class AddonPackage extends Package {
/** Returns a short description for an {@link IDescription}. */
@Override
public String getShortDescription() {
return String.format("%1$s by %2$s for Android API %3$d",
return String.format("%1$s by %2$s for Android API %3$s",
getName(),
getVendor(),
mVersion.getApiLevel());
mVersion.getApiString());
}
/** Returns a long description for an {@link IDescription}. */
@@ -229,7 +231,8 @@ public class AddonPackage extends Package {
String name = suggestedDir;
if (suggestedDir == null || suggestedDir.length() == 0) {
name = String.format("addon-%s-%s-%d", getName(), getVendor(), mVersion.getApiLevel()); //$NON-NLS-1$
name = String.format("addon-%s-%s-%s", getName(), getVendor(), //$NON-NLS-1$
mVersion.getApiString());
name = name.toLowerCase();
name = name.replaceAll("[^a-z0-9_-]+", "_"); //$NON-NLS-1$ //$NON-NLS-2$
name = name.replaceAll("_+", "_"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -271,7 +274,7 @@ public class AddonPackage extends Package {
String newId = newPkg.getName() + "+" + newPkg.getVendor(); //$NON-NLS-1$
return thisId.equalsIgnoreCase(newId) &&
mVersion.getApiLevel() == newPkg.getVersion().getApiLevel() &&
mVersion.equals(newPkg.getVersion()) &&
newPkg.getRevision() > this.getRevision();
}
}

View File

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

View File

@@ -86,6 +86,8 @@
<xsd:element name="vendor" type="xsd:normalizedString" />
<!-- The Android API Level for the add-on. An int > 0. -->
<xsd:element name="api-level" type="xsd:positiveInteger" />
<!-- The optional codename for this add-on, 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

@@ -0,0 +1,45 @@
/*
* 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.xml;
/**
* Constants for nodes and attributes of the AndroidManifest.xml file.
*
*/
public final class ManifestConstants {
public final static String NODE_MANIFEST = "manifest"; //$NON-NLS-1$
public final static String NODE_APPLICATION = "application"; //$NON-NLS-1$
public final static String NODE_ACTIVITY = "activity"; //$NON-NLS-1$
public final static String NODE_SERVICE = "service"; //$NON-NLS-1$
public final static String NODE_RECEIVER = "receiver"; //$NON-NLS-1$
public final static String NODE_PROVIDER = "provider"; //$NON-NLS-1$
public final static String NODE_INTENT = "intent-filter"; //$NON-NLS-1$
public final static String NODE_ACTION = "action"; //$NON-NLS-1$
public final static String NODE_CATEGORY = "category"; //$NON-NLS-1$
public final static String NODE_USES_SDK = "uses-sdk"; //$NON-NLS-1$
public final static String NODE_INSTRUMENTATION = "instrumentation"; //$NON-NLS-1$
public final static String NODE_USES_LIBRARY = "uses-library"; //$NON-NLS-1$
public final static String ATTRIBUTE_PACKAGE = "package"; //$NON-NLS-1$
public final static String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
public final static String ATTRIBUTE_PROCESS = "process"; //$NON-NLS-$
public final static String ATTRIBUTE_DEBUGGABLE = "debuggable"; //$NON-NLS-$
public final static String ATTRIBUTE_MIN_SDK_VERSION = "minSdkVersion"; //$NON-NLS-$
public final static String ATTRIBUTE_TARGET_PACKAGE = "targetPackage"; //$NON-NLS-1$
public final static String ATTRIBUTE_EXPORTED = "exported"; //$NON-NLS-1$
}