aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2012-03-07 11:01:27 -0800
committerRaphael <raphael@google.com>2012-03-07 11:01:27 -0800
commit19f29f1ae89d40cb4b5ab06134621a8a1c19aa96 (patch)
treea14c971c9debb4c2ceeea9c24db3dc654bfd9884 /sdkmanager/libs
parent09d4a9a0b4d3e20c30b08fee46d1c03ff45fdc0b (diff)
downloadsdk-19f29f1ae89d40cb4b5ab06134621a8a1c19aa96.zip
sdk-19f29f1ae89d40cb4b5ab06134621a8a1c19aa96.tar.gz
sdk-19f29f1ae89d40cb4b5ab06134621a8a1c19aa96.tar.bz2
SDK Manager: tweak addon comparison to support new schema.
This slightly tweaks the comparison between addons so that the SDK Manager list can properly support a list containing addons with solely <vendor> vs similar ones that have <vendor-id> and <vendor-display> without creating duplicates. Change-Id: Id1639f73466d7e3f9912e3a0d730bfc74444e27e
Diffstat (limited to 'sdkmanager/libs')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java57
1 files changed, 34 insertions, 23 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java
index 56bf492..606775f 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/AddonPackage.java
@@ -16,6 +16,7 @@
package com.android.sdklib.internal.repository;
+import com.android.annotations.NonNull;
import com.android.annotations.VisibleForTesting;
import com.android.annotations.VisibleForTesting.Visibility;
import com.android.sdklib.AndroidVersion;
@@ -178,7 +179,8 @@ public class AddonPackage extends Package
// For a missing id, we simply use a sanitized version of the display vendor
if (vendorId.length() == 0) {
- vendorId = sanitizeDisplayToNameId(vendor.length() > 0 ? vendor : vendorDisp);
+ boolean hasVendor = vendor.length() > 0;
+ vendorId = sanitizeDisplayToNameId(hasVendor ? vendor : vendorDisp);
}
assert vendorId.length() > 0;
@@ -267,7 +269,8 @@ public class AddonPackage extends Package
// For a missing id, we simply use a sanitized version of the display vendor
if (vendorId.length() == 0) {
- vendorId = sanitizeDisplayToNameId(vendor.length() > 0 ? vendor : vendorDisp);
+ boolean hasVendor = vendor.length() > 0;
+ vendorId = sanitizeDisplayToNameId(hasVendor ? vendor : vendorDisp);
}
assert vendorId.length() > 0;
@@ -398,22 +401,22 @@ public class AddonPackage extends Package
}
/** Returns the vendor id, a string, for add-on packages. */
- public String getVendorId() {
+ public @NonNull String getVendorId() {
return mVendorId;
}
/** Returns the vendor, a string for display purposes. */
- public String getDisplayVendor() {
+ public @NonNull String getDisplayVendor() {
return mVendorDisplay;
}
/** Returns the name id, a string, for add-on packages or for libraries. */
- public String getNameId() {
+ public @NonNull String getNameId() {
return mNameId;
}
/** Returns the name, a string for display purposes. */
- public String getDisplayName() {
+ public @NonNull String getDisplayName() {
return mDisplayName;
}
@@ -423,12 +426,12 @@ public class AddonPackage extends Package
* An add-on has the same {@link AndroidVersion} as the platform it depends on.
*/
@Override
- public AndroidVersion getVersion() {
+ public @NonNull AndroidVersion getVersion() {
return mVersion;
}
/** Returns the libs defined in this add-on. Can be an empty array but not null. */
- public Lib[] getLibs() {
+ public @NonNull Lib[] getLibs() {
return mLibs;
}
@@ -445,7 +448,7 @@ public class AddonPackage extends Package
* @since sdk-addon-2.xsd
*/
@Override
- public Pair<Integer, Integer> getLayoutlibVersion() {
+ public @NonNull Pair<Integer, Integer> getLayoutlibVersion() {
return mLayoutlibVersion.getLayoutlibVersion();
}
@@ -456,7 +459,7 @@ public class AddonPackage extends Package
* {@inheritDoc}
*/
@Override
- public String installId() {
+ public @NonNull String installId() {
return encodeAddonName();
}
@@ -578,16 +581,13 @@ public class AddonPackage extends Package
name = name.replaceAll("[^a-z0-9_-]+", "_"); //$NON-NLS-1$ //$NON-NLS-2$
name = name.replaceAll("_+", "_"); //$NON-NLS-1$ //$NON-NLS-2$
- // NOTE: ideally we would want to trim leading and trailing _ but in fact
- // this MUST NOT be done, otherwise it will break <vendor-id> tags that were
- // auto converted from the old <vendor> tag when switching from the addon
- // schema v3 to v4.
- // if (name.length() > 1) {
- // name = name.replaceAll("^_+", ""); //$NON-NLS-1$ //$NON-NLS-2$
- // }
- // if (name.length() > 1) {
- // name = name.replaceAll("_+$", ""); //$NON-NLS-1$ //$NON-NLS-2$
- // }
+ // Trim leading and trailing underscores
+ if (name.length() > 1) {
+ name = name.replaceAll("^_+", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ if (name.length() > 1) {
+ name = name.replaceAll("_+$", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ }
return name;
}
@@ -597,9 +597,20 @@ public class AddonPackage extends Package
AddonPackage newPkg = (AddonPackage)pkg;
// check they are the same add-on.
- return getNameId().equals(newPkg.getNameId()) &&
- getVendorId().equals(newPkg.getVendorId()) &&
- getVersion().equals(newPkg.getVersion());
+ if (getNameId().equals(newPkg.getNameId()) &&
+ getVersion().equals(newPkg.getVersion())) {
+ // Check the vendor-id field.
+ if (getVendorId().equals(newPkg.getVendorId())) {
+ return true;
+ }
+
+ // When loading addons from the v3 schema that only had a <vendor>
+ // field, the vendor field has been converted to vendor-display so
+ // as a transition mechanism we should test this also.
+ // TODO: in a couple iterations of the SDK Manager, remove this check
+ // and only compare using the vendor-id field.
+ return getDisplayVendor().equals(newPkg.getDisplayVendor());
+ }
}
return false;