Add a checkbox to only show packages that are updates or new.
This commit is contained in:
@@ -44,7 +44,6 @@ 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";
|
||||
|
||||
private final static String ADDON_NAME = "name";
|
||||
private final static String ADDON_VENDOR = "vendor";
|
||||
@@ -62,9 +61,6 @@ public final class SdkManager {
|
||||
private final static Pattern PATTERN_LIB_DATA = Pattern.compile(
|
||||
"^([a-zA-Z0-9._-]+\\.jar);(.*)$", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private final static Pattern PATTERN_LOCAL_BUILD_PATTERN = Pattern.compile(
|
||||
"^\\S+\\.\\S+\\.(\\d+)\\.\\d+$");
|
||||
|
||||
// usb ids are 16-bit hexadecimal values.
|
||||
private final static Pattern PATTERN_USB_IDS = Pattern.compile(
|
||||
"^0x[a-f0-9]{4}$", Pattern.CASE_INSENSITIVE);
|
||||
@@ -312,45 +308,7 @@ public final class SdkManager {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
revision = Integer.parseInt(stringValue);
|
||||
} catch (NumberFormatException e) {
|
||||
// looks like the revision does not parse to a number.
|
||||
// we look if it's a local build in the format
|
||||
// <buildtype>.<username>.<date>.<time>
|
||||
Matcher m = PATTERN_LOCAL_BUILD_PATTERN.matcher(stringValue);
|
||||
boolean valid = false;
|
||||
if (m.matches()) {
|
||||
String date = m.group(1);
|
||||
try {
|
||||
revision = Integer.parseInt(date);
|
||||
valid = true;
|
||||
} catch (NumberFormatException e2) {
|
||||
// do nothing, we'll display an error and return below
|
||||
}
|
||||
}
|
||||
|
||||
if (valid == false) {
|
||||
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);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
// FIXME: properly parse the platform revision.
|
||||
|
||||
// api number and name look valid, perform a few more checks
|
||||
if (checkPlatformContent(platform, log) == false) {
|
||||
|
||||
@@ -250,31 +250,17 @@ public class AddonPackage extends Package {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes whether the given addon package is a suitable update for the current package.
|
||||
* The base method checks the class type.
|
||||
* The addon package also tests that the name+vendor is the same and
|
||||
* the revision number is greater.
|
||||
* <p/>
|
||||
* An update is just that: a new package that supersedes the current one. If the new
|
||||
* package has the same revision as the current one, it's not an update.
|
||||
*
|
||||
* @param replacementPackage The potential replacement package.
|
||||
* @return True if the replacement package is a suitable update for this one.
|
||||
*/
|
||||
@Override
|
||||
public boolean canBeUpdatedBy(Package replacementPackage) {
|
||||
if (!super.canBeUpdatedBy(replacementPackage)) {
|
||||
return false;
|
||||
public boolean sameItemAs(Package pkg) {
|
||||
if (pkg instanceof AddonPackage) {
|
||||
AddonPackage newPkg = (AddonPackage)pkg;
|
||||
|
||||
// check they are the same add-on.
|
||||
return getName().equals(newPkg.getName()) &&
|
||||
getVendor().equals(newPkg.getVendor()) &&
|
||||
getVersion().equals(newPkg.getVersion());
|
||||
}
|
||||
|
||||
AddonPackage newPkg = (AddonPackage) replacementPackage;
|
||||
|
||||
String thisId = getName() + "+" + getVendor(); //$NON-NLS-1$
|
||||
String newId = newPkg.getName() + "+" + newPkg.getVendor(); //$NON-NLS-1$
|
||||
|
||||
return thisId.equalsIgnoreCase(newId) &&
|
||||
mVersion.equals(newPkg.getVersion()) &&
|
||||
newPkg.getRevision() > this.getRevision();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,26 +135,9 @@ public class DocPackage extends Package {
|
||||
return new File(osSdkRoot, SdkConstants.FD_DOCS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes whether the given doc package is a suitable update for the current package.
|
||||
* The base method checks the class type.
|
||||
* The doc package also tests the API level and revision number: the revision number must
|
||||
* always be bumped. The API level can be the same or greater.
|
||||
* <p/>
|
||||
* An update is just that: a new package that supersedes the current one. If the new
|
||||
* package has the same revision as the current one, it's not an update.
|
||||
*
|
||||
* @param replacementPackage The potential replacement package.
|
||||
* @return True if the replacement package is a suitable update for this one.
|
||||
*/
|
||||
@Override
|
||||
public boolean canBeUpdatedBy(Package replacementPackage) {
|
||||
if (!super.canBeUpdatedBy(replacementPackage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DocPackage newPkg = (DocPackage) replacementPackage;
|
||||
return newPkg.getRevision() > this.getRevision() &&
|
||||
newPkg.getVersion().equals(this.getVersion());
|
||||
public boolean sameItemAs(Package pkg) {
|
||||
// only one doc package so any doc package is the same item.
|
||||
return pkg instanceof DocPackage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,25 +141,9 @@ public class ExtraPackage extends Package {
|
||||
return new File(osSdkRoot, getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes whether the given extra package is a suitable update for the current package.
|
||||
* The base method checks the class type.
|
||||
* The tools package also tests that the revision number is greater and the path is the
|
||||
* same.
|
||||
* <p/>
|
||||
* An update is just that: a new package that supersedes the current one. If the new
|
||||
* package has the same revision as the current one, it's not an update.
|
||||
*
|
||||
* @param replacementPackage The potential replacement package.
|
||||
* @return True if the replacement package is a suitable update for this one.
|
||||
*/
|
||||
@Override
|
||||
public boolean canBeUpdatedBy(Package replacementPackage) {
|
||||
if (!super.canBeUpdatedBy(replacementPackage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ExtraPackage newPkg = (ExtraPackage) replacementPackage;
|
||||
return newPkg.getRevision() > this.getRevision() && newPkg.getPath().equals(this.getPath());
|
||||
public boolean sameItemAs(Package pkg) {
|
||||
// Extra packages are similar if they have the same path.
|
||||
return pkg instanceof ExtraPackage && ((ExtraPackage)pkg).mPath.equals(mPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,21 @@ public abstract class Package implements IDescription {
|
||||
private final Archive[] mArchives;
|
||||
private final RepoSource mSource;
|
||||
|
||||
/**
|
||||
* Enum for the result of {@link Package#canBeUpdatedBy(Package)}. This used so that we can
|
||||
* differentiate between a package that is totally incompatible, and one that is the same item
|
||||
* but just not an update.
|
||||
* @see #canBeUpdatedBy(Package)
|
||||
*/
|
||||
public static enum UpdateInfo {
|
||||
/** Means that the 2 packages are not the same thing */
|
||||
INCOMPATIBLE,
|
||||
/** Means that the 2 packages are the same thing but one does not upgrade the other */
|
||||
NOT_UPDATE,
|
||||
/** Means that the 2 packages are the same thing, and one is the upgrade of the other */
|
||||
UPDATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new package from the attributes and elements of the given XML node.
|
||||
* <p/>
|
||||
@@ -245,6 +260,20 @@ public abstract class Package implements IDescription {
|
||||
return mArchives;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the {@link Package} has at least one {@link Archive} compatible with
|
||||
* the host platform.
|
||||
*/
|
||||
public boolean hasCompatibleArchive() {
|
||||
for (Archive archive : mArchives) {
|
||||
if (archive.isCompatible()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a short description for an {@link IDescription}.
|
||||
* Can be empty but not null.
|
||||
@@ -279,21 +308,44 @@ public abstract class Package implements IDescription {
|
||||
public abstract File getInstallFolder(
|
||||
String osSdkRoot, String suggestedDir, SdkManager sdkManager);
|
||||
|
||||
/**
|
||||
* Returns whether the give package represents the same item as the current package.
|
||||
* <p/>
|
||||
* Two packages are considered the same if they represent the same thing, except for the
|
||||
* revision number.
|
||||
* @param pkg the package to compare
|
||||
* @return true if the item
|
||||
*/
|
||||
public abstract boolean sameItemAs(Package pkg);
|
||||
|
||||
/**
|
||||
* Computes whether the given package is a suitable update for the current package.
|
||||
* The base class method only checks that the {@link Package} class type is the same.
|
||||
* Derived classes must add more specific checks, including the revision number.
|
||||
* <p/>
|
||||
* An update is just that: a new package that supersedes the current one. If the new
|
||||
* package has the same revision as the current one, it's not an update.
|
||||
* package does not represent the same item or if it has the same or lower revision as the
|
||||
* current one, it's not an update.
|
||||
*
|
||||
* @param replacementPackage The potential replacement package.
|
||||
* @return True if the replacement package is a suitable update for this one.
|
||||
* @return
|
||||
*
|
||||
* @see #sameItemAs(Package)
|
||||
*/
|
||||
public boolean canBeUpdatedBy(Package replacementPackage) {
|
||||
return replacementPackage != null &&
|
||||
replacementPackage.getClass() == this.getClass() &&
|
||||
replacementPackage.getRevision() > this.getRevision();
|
||||
}
|
||||
public final UpdateInfo canBeUpdatedBy(Package replacementPackage) {
|
||||
if (replacementPackage == null) {
|
||||
return UpdateInfo.INCOMPATIBLE;
|
||||
}
|
||||
|
||||
// check they are the same item.
|
||||
if (sameItemAs(replacementPackage) == false) {
|
||||
return UpdateInfo.INCOMPATIBLE;
|
||||
}
|
||||
|
||||
// check revision number
|
||||
if (replacementPackage.getRevision() > this.getRevision()) {
|
||||
return UpdateInfo.UPDATE;
|
||||
}
|
||||
|
||||
// not an upgrade but not incompatible either.
|
||||
return UpdateInfo.NOT_UPDATE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,27 +153,15 @@ public class PlatformPackage extends Package {
|
||||
return folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes whether the given platform package is a suitable update for the current package.
|
||||
* The base method checks the class type.
|
||||
* The platform package also tests that the version and API level are the same and
|
||||
* the revision number is greater
|
||||
* <p/>
|
||||
* An update is just that: a new package that supersedes the current one. If the new
|
||||
* package has the same revision as the current one, it's not an update.
|
||||
*
|
||||
* @param replacementPackage The potential replacement package.
|
||||
* @return True if the replacement package is a suitable update for this one.
|
||||
*/
|
||||
@Override
|
||||
public boolean canBeUpdatedBy(Package replacementPackage) {
|
||||
if (!super.canBeUpdatedBy(replacementPackage)) {
|
||||
return false;
|
||||
public boolean sameItemAs(Package pkg) {
|
||||
if (pkg instanceof PlatformPackage) {
|
||||
PlatformPackage newPkg = (PlatformPackage)pkg;
|
||||
|
||||
// check they are the same platform.
|
||||
return newPkg.getVersion().equals(this.getVersion());
|
||||
}
|
||||
|
||||
PlatformPackage newPkg = (PlatformPackage) replacementPackage;
|
||||
return newPkg.getVersionName().equalsIgnoreCase(this.getVersionName()) &&
|
||||
newPkg.getVersion().equals(this.getVersion()) &&
|
||||
newPkg.getRevision() > this.getRevision();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,24 +98,9 @@ public class ToolPackage extends Package {
|
||||
return new File(osSdkRoot, SdkConstants.FD_TOOLS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes whether the given tools package is a suitable update for the current package.
|
||||
* The base method checks the class type.
|
||||
* The tools package also tests that the revision number is greater.
|
||||
* <p/>
|
||||
* An update is just that: a new package that supersedes the current one. If the new
|
||||
* package has the same revision as the current one, it's not an update.
|
||||
*
|
||||
* @param replacementPackage The potential replacement package.
|
||||
* @return True if the replacement package is a suitable update for this one.
|
||||
*/
|
||||
@Override
|
||||
public boolean canBeUpdatedBy(Package replacementPackage) {
|
||||
if (!super.canBeUpdatedBy(replacementPackage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ToolPackage newPkg = (ToolPackage) replacementPackage;
|
||||
return newPkg.getRevision() > this.getRevision();
|
||||
public boolean sameItemAs(Package pkg) {
|
||||
// only one tool package so any tool package is the same item.
|
||||
return pkg instanceof ToolPackage;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user