diff options
author | Raphael Moll <ralf@android.com> | 2012-04-19 16:27:03 -0700 |
---|---|---|
committer | Raphael Moll <ralf@android.com> | 2012-05-03 12:12:22 -0700 |
commit | 87107c5cb1fb5fdafdaa94460fb6797af60fcde9 (patch) | |
tree | 01f99d040165bb3144321902d61e42399689dbc9 /sdkmanager/libs | |
parent | ea0e2af1c398ad3b189a163fa574ca3d255e5895 (diff) | |
download | sdk-87107c5cb1fb5fdafdaa94460fb6797af60fcde9.zip sdk-87107c5cb1fb5fdafdaa94460fb6797af60fcde9.tar.gz sdk-87107c5cb1fb5fdafdaa94460fb6797af60fcde9.tar.bz2 |
Rework SDK Manager support for major.minor.micro revisions.
2 things in this CL:
- There's a bit of refactoring:
- PreviewVersion becomes FullVersion (which is
a full major.minor.micro.preview)
- And I introduce a MajorRevision (which is just
a major number)
- Package.getRevision() returns one of these
revision objects instead of an integer which
leads to a multide of small boring changes.
- Changed the PackageDiffLogic and its test to
adequately use the new revision; "tools preview"
packages are placed in their own category and
releases can update previews but not the reverse.
Change-Id: Ia80fd9a3791919e827ce0d183c0f297f0d27f2e6
Diffstat (limited to 'sdkmanager/libs')
29 files changed, 812 insertions, 228 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java index 8284054..a786728 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java @@ -463,7 +463,7 @@ public class SdkManager { int revision = 1; LayoutlibVersion layoutlibVersion = null; try { - revision = Integer.parseInt(platformProp.get(PkgProps.PKG_REVISION)); + revision = Integer.parseInt(platformProp.get(PkgProps.PKG_MAJOR_REV)); } catch (NumberFormatException e) { // do nothing, we'll keep the default value of 1. } diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/DocPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/DocPackage.java index 635dff9..9d6c02c 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/DocPackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/DocPackage.java @@ -170,12 +170,12 @@ public class DocPackage extends Package implements IAndroidVersionProvider { if (mVersion.isPreview()) {
return String.format("Documentation for Android '%1$s' Preview SDK, revision %2$s%3$s",
mVersion.getCodename(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
} else {
return String.format("Documentation for Android SDK, API %1$d, revision %2$s%3$s",
mVersion.getApiLevel(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
}
@@ -194,8 +194,8 @@ public class DocPackage extends Package implements IAndroidVersionProvider { }
if (s.indexOf("revision") == -1) {
- s += String.format("\nRevision %1$d%2$s",
- getRevision(),
+ s += String.format("\nRevision %1$s%2$s",
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
@@ -257,7 +257,7 @@ public class DocPackage extends Package implements IAndroidVersionProvider { // Check if they're the same exact (api and codename)
if (replacementVersion.equals(mVersion)) {
// exact same version, so check the revision level
- if (replacementPackage.getRevision() > this.getRevision()) {
+ if (replacementPackage.getRevision().compareTo(this.getRevision()) > 0) {
return UpdateInfo.UPDATE;
}
} else {
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java index cc27853..3b921ae 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ExtraPackage.java @@ -490,9 +490,9 @@ public class ExtraPackage extends MinToolsPackage */
@Override
public String getShortDescription() {
- String s = String.format("%1$s, revision %2$d%3$s",
+ String s = String.format("%1$s, revision %2$s%3$s",
getDisplayName(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : ""); //$NON-NLS-2$
return s;
@@ -506,9 +506,9 @@ public class ExtraPackage extends MinToolsPackage */
@Override
public String getLongDescription() {
- String s = String.format("%1$s, revision %2$d%3$s\nBy %4$s",
+ String s = String.format("%1$s, revision %2$s%3$s\nBy %4$s",
getDisplayName(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "", //$NON-NLS-2$
getVendorDisplay());
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersion.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java index a75eb4b..f902001 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersion.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java @@ -22,8 +22,10 @@ package com.android.sdklib.internal.repository.packages; * (major.minor.micro) and an optional preview revision
* (the lack of a preview number indicates it's not a preview
* but a final package.)
+ *
+ * @see MajorRevision
*/
-public class PreviewVersion implements Comparable<PreviewVersion> {
+public class FullRevision implements Comparable<FullRevision> {
public static final int IMPLICIT_MINOR_REV = 0;
public static final int IMPLICIT_MICRO_REV = 0;
@@ -34,15 +36,15 @@ public class PreviewVersion implements Comparable<PreviewVersion> { private final int mMicro;
private final int mPreview;
- public PreviewVersion(int major) {
+ public FullRevision(int major) {
this(major, 0, 0);
}
- public PreviewVersion(int major, int minor, int micro) {
+ public FullRevision(int major, int minor, int micro) {
this(major, minor, micro, NOT_A_PREVIEW);
}
- public PreviewVersion(int major, int minor, int micro, int preview) {
+ public FullRevision(int major, int minor, int micro, int preview) {
mMajor = major;
mMinor = minor;
mMicro = micro;
@@ -130,10 +132,10 @@ public class PreviewVersion implements Comparable<PreviewVersion> { if (rhs == null) {
return false;
}
- if (!(rhs instanceof PreviewVersion)) {
+ if (!(rhs instanceof FullRevision)) {
return false;
}
- PreviewVersion other = (PreviewVersion) rhs;
+ FullRevision other = (FullRevision) rhs;
if (mMajor != other.mMajor) {
return false;
}
@@ -150,7 +152,7 @@ public class PreviewVersion implements Comparable<PreviewVersion> { }
/**
- * Trivial comparision of a version, e.g 17.1.2 < 18.0.0.
+ * Trivial comparison of a version, e.g 17.1.2 < 18.0.0.
*
* Note that preview/release candidate are released before their final version,
* so "18.0.0 rc1" comes below "18.0.0". The best way to think of it as if the
@@ -159,7 +161,7 @@ public class PreviewVersion implements Comparable<PreviewVersion> { * and more than "18.1.2.4"
*/
@Override
- public int compareTo(PreviewVersion rhs) {
+ public int compareTo(FullRevision rhs) {
int delta = mMajor - rhs.mMajor;
if (delta != 0) {
return delta;
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersionPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java index eac548e..9024af5 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersionPackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java @@ -16,10 +16,10 @@ package com.android.sdklib.internal.repository.packages;
-import com.android.annotations.NonNull;
import com.android.sdklib.internal.repository.XmlParserUtils;
import com.android.sdklib.internal.repository.archives.Archive.Arch;
import com.android.sdklib.internal.repository.archives.Archive.Os;
+import com.android.sdklib.internal.repository.packages.Package.UpdateInfo;
import com.android.sdklib.internal.repository.sources.SdkSource;
import com.android.sdklib.repository.PkgProps;
import com.android.sdklib.repository.SdkRepoConstants;
@@ -30,13 +30,13 @@ import java.util.Map; import java.util.Properties;
/**
- * Represents a package in an SDK repository that has a {@link PreviewVersion},
+ * Represents a package in an SDK repository that has a {@link FullRevision},
* which is a multi-part revision number (major.minor.micro) and an optional preview revision.
*/
-public abstract class PreviewVersionPackage extends Package
- implements IPreviewVersionProvider {
+public abstract class FullRevisionPackage extends Package
+ implements IFullRevisionProvider {
- private final PreviewVersion mPreviewVersion;
+ private final FullRevision mPreviewVersion;
/**
* Creates a new package from the attributes and elements of the given XML node.
@@ -48,25 +48,25 @@ public abstract class PreviewVersionPackage extends Package * parameters that vary according to the originating XML schema.
* @param licenses The licenses loaded from the XML originating document.
*/
- PreviewVersionPackage(SdkSource source,
+ FullRevisionPackage(SdkSource source,
Node packageNode,
String nsUri,
Map<String,String> licenses) {
super(source, packageNode, nsUri, licenses);
- // The major revision is getRevision(), already handled by Package.
-
+ // The major revision is in Package.getRevision()
+ int majorRevision = super.getRevision().getMajor();
int minorRevision = XmlParserUtils.getXmlInt(packageNode,
SdkRepoConstants.NODE_MINOR_REV,
- PreviewVersion.IMPLICIT_MINOR_REV);
+ FullRevision.IMPLICIT_MINOR_REV);
int microRevision = XmlParserUtils.getXmlInt(packageNode,
SdkRepoConstants.NODE_MICRO_REV,
- PreviewVersion.IMPLICIT_MICRO_REV);
+ FullRevision.IMPLICIT_MICRO_REV);
int preview = XmlParserUtils.getXmlInt(packageNode,
SdkRepoConstants.NODE_PREVIEW,
- PreviewVersion.NOT_A_PREVIEW);
+ FullRevision.NOT_A_PREVIEW);
- mPreviewVersion = new PreviewVersion(getRevision(), minorRevision, microRevision, preview);
+ mPreviewVersion = new FullRevision(majorRevision, minorRevision, microRevision, preview);
}
/**
@@ -78,7 +78,7 @@ public abstract class PreviewVersionPackage extends Package * <p/>
* By design, this creates a package with one and only one archive.
*/
- public PreviewVersionPackage(
+ public FullRevisionPackage(
SdkSource source,
Properties props,
int revision,
@@ -91,26 +91,26 @@ public abstract class PreviewVersionPackage extends Package super(source, props, revision, license, description, descUrl,
archiveOs, archiveArch, archiveOsPath);
- // The major revision is getRevision(), already handled by Package.
-
+ // The major revision is in Package.getRevision()
+ int majorRevision = super.getRevision().getMajor();
int minorRevision = Integer.parseInt(
getProperty(props,
PkgProps.PKG_MINOR_REV,
- Integer.toString(PreviewVersion.IMPLICIT_MINOR_REV)));
+ Integer.toString(FullRevision.IMPLICIT_MINOR_REV)));
int microRevision = Integer.parseInt(
getProperty(props,
PkgProps.PKG_MICRO_REV,
- Integer.toString(PreviewVersion.IMPLICIT_MINOR_REV)));
+ Integer.toString(FullRevision.IMPLICIT_MINOR_REV)));
int preview = Integer.parseInt(
getProperty(props,
PkgProps.PKG_PREVIEW_REV,
- Integer.toString(PreviewVersion.NOT_A_PREVIEW)));
+ Integer.toString(FullRevision.NOT_A_PREVIEW)));
- mPreviewVersion = new PreviewVersion(getRevision(), minorRevision, microRevision, preview);
+ mPreviewVersion = new FullRevision(majorRevision, minorRevision, microRevision, preview);
}
- @Override @NonNull
- public PreviewVersion getPreviewVersion() {
+ @Override
+ public FullRevision getRevision() {
return mPreviewVersion;
}
@@ -118,11 +118,9 @@ public abstract class PreviewVersionPackage extends Package public void saveProperties(Properties props) {
super.saveProperties(props);
- // The major revision is getRevision(), already handled by Package.
- assert mPreviewVersion.getMajor() == getRevision();
-
- props.setProperty(PkgProps.PKG_MINOR_REV, Integer.toString(mPreviewVersion.getMinor()));
- props.setProperty(PkgProps.PKG_MICRO_REV, Integer.toString(mPreviewVersion.getMicro()));
+ props.setProperty(PkgProps.PKG_MAJOR_REV, Integer.toString(mPreviewVersion.getMajor()));
+ props.setProperty(PkgProps.PKG_MINOR_REV, Integer.toString(mPreviewVersion.getMinor()));
+ props.setProperty(PkgProps.PKG_MICRO_REV, Integer.toString(mPreviewVersion.getMicro()));
props.setProperty(PkgProps.PKG_PREVIEW_REV, Integer.toString(mPreviewVersion.getPreview()));
}
@@ -142,10 +140,10 @@ public abstract class PreviewVersionPackage extends Package if (!super.equals(obj)) {
return false;
}
- if (!(obj instanceof PreviewVersionPackage)) {
+ if (!(obj instanceof FullRevisionPackage)) {
return false;
}
- PreviewVersionPackage other = (PreviewVersionPackage) obj;
+ FullRevisionPackage other = (FullRevisionPackage) obj;
if (mPreviewVersion == null) {
if (other.mPreviewVersion != null) {
return false;
@@ -155,4 +153,38 @@ public abstract class PreviewVersionPackage extends Package }
return true;
}
+
+ /**
+ * Computes whether the given package is a suitable update for the current package.
+ * <p/>
+ * A specific case here is that a release package can update a preview, whereas
+ * a preview can only update another preview.
+ * <p/>
+ * {@inheritDoc}
+ */
+ @Override
+ public UpdateInfo canBeUpdatedBy(Package replacementPackage) {
+ if (replacementPackage == null) {
+ return UpdateInfo.INCOMPATIBLE;
+ }
+
+ // check they are the same item, ignoring the preview bit.
+ if (!sameItemAs(replacementPackage, true /*ignorePreviews*/)) {
+ return UpdateInfo.INCOMPATIBLE;
+ }
+
+ // a preview cannot update a non-preview
+ if (!getRevision().isPreview() && replacementPackage.getRevision().isPreview()) {
+ return UpdateInfo.INCOMPATIBLE;
+ }
+
+ // check revision number
+ if (replacementPackage.getRevision().compareTo(this.getRevision()) > 0) {
+ return UpdateInfo.UPDATE;
+ }
+
+ // not an upgrade but not incompatible either.
+ return UpdateInfo.NOT_UPDATE;
+ }
+
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/IFullRevisionProvider.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/IFullRevisionProvider.java new file mode 100755 index 0000000..497b2f8 --- /dev/null +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/IFullRevisionProvider.java @@ -0,0 +1,43 @@ +/*
+ * Copyright (C) 2012 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.internal.repository.packages;
+
+
+
+/**
+ * Interface for packages that provide a {@link FullRevision},
+ * which is a multi-part revision number (major.minor.micro) and an optional preview revision.
+ * <p/>
+ * This interface is a tag. It indicates that {@link Package#getRevision()} returns a
+ * {@link FullRevision} instead of a limited {@link MajorRevision}. <br/>
+ * The preview version number is available via {@link Package#getRevision()}.
+ */
+public interface IFullRevisionProvider {
+
+ /**
+ * 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
+ * @param ignorePreviews true if 2 packages should be considered the same even if one
+ * is a preview and the other one is not.
+ * @return true if the item are the same.
+ */
+ public abstract boolean sameItemAs(Package pkg, boolean ignorePreviews);
+
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/IPreviewVersionProvider.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java index 5a9f8a0..2678b1f 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/IPreviewVersionProvider.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java @@ -1,5 +1,5 @@ /*
- * Copyright (C) 2009 The Android Open Source Project
+ * Copyright (C) 2012 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.
@@ -16,17 +16,22 @@ package com.android.sdklib.internal.repository.packages;
-import com.android.annotations.NonNull;
-
/**
- * Interface for packages that provide a {@link PreviewVersion},
- * which is a multi-part revision number (major.minor.micro) and an optional preview revision.
+ * Package revision number composed of a <em>single</em> major revision.
+ * <p/>
+ * Contrary to a {@link FullRevision}, a {@link MajorRevision} does not
+ * provide minor, micro and preview revision numbers -- these are all
+ * set to zero.
*/
-public interface IPreviewVersionProvider {
+public class MajorRevision extends FullRevision {
+
+ public MajorRevision(int major) {
+ super(major, 0, 0);
+ }
- /**
- * Returns a {@link PreviewVersion} for this package. Never null.
- */
- public abstract @NonNull PreviewVersion getPreviewVersion();
+ @Override
+ public String toString() {
+ return super.toShortString();
+ }
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java index 6760747..9c2d30b 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/Package.java @@ -58,7 +58,7 @@ import java.util.Properties; */
public abstract class Package implements IDescription, Comparable<Package> {
- private final int mRevision;
+ private final MajorRevision mRevision;
private final String mObsolete;
private final String mLicense;
private final String mDescription;
@@ -104,7 +104,8 @@ public abstract class Package implements IDescription, Comparable<Package> { */
Package(SdkSource source, Node packageNode, String nsUri, Map<String,String> licenses) {
mSource = source;
- mRevision = XmlParserUtils.getXmlInt (packageNode, SdkRepoConstants.NODE_REVISION, 0);
+ mRevision = new MajorRevision(
+ XmlParserUtils.getXmlInt (packageNode, SdkRepoConstants.NODE_REVISION, 0));
mDescription = XmlParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_DESCRIPTION);
mDescUrl = XmlParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_DESC_URL);
mReleaseNote = XmlParserUtils.getXmlString(packageNode, SdkRepoConstants.NODE_RELEASE_NOTE);
@@ -144,8 +145,8 @@ public abstract class Package implements IDescription, Comparable<Package> { descUrl = "";
}
- mRevision = Integer.parseInt(
- getProperty(props, PkgProps.PKG_REVISION, Integer.toString(revision)));
+ mRevision = new MajorRevision(Integer.parseInt(
+ getProperty(props, PkgProps.PKG_MAJOR_REV, Integer.toString(revision))));
mLicense = getProperty(props, PkgProps.PKG_LICENSE, license);
mDescription = getProperty(props, PkgProps.PKG_DESC, description);
mDescUrl = getProperty(props, PkgProps.PKG_DESC_URL, descUrl);
@@ -222,7 +223,7 @@ public abstract class Package implements IDescription, Comparable<Package> { * These properties will later be give the constructor that takes a {@link Properties} object.
*/
public void saveProperties(Properties props) {
- props.setProperty(PkgProps.PKG_REVISION, Integer.toString(mRevision));
+ props.setProperty(PkgProps.PKG_MAJOR_REV, Integer.toString(mRevision.getMajor()));
if (mLicense != null && mLicense.length() > 0) {
props.setProperty(PkgProps.PKG_LICENSE, mLicense);
}
@@ -328,7 +329,7 @@ public abstract class Package implements IDescription, Comparable<Package> { * Returns the revision, an int > 0, for all packages (platform, add-on, tool, doc).
* Can be 0 if this is a local package of unknown revision.
*/
- public int getRevision() {
+ public FullRevision getRevision() {
return mRevision;
}
@@ -484,8 +485,8 @@ public abstract class Package implements IDescription, Comparable<Package> { sb.append("\n");
}
- sb.append(String.format("Revision %1$d%2$s",
- getRevision(),
+ sb.append(String.format("Revision %1$s%2$s",
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : ""));
s = getDescUrl();
@@ -615,8 +616,8 @@ public abstract class Package implements IDescription, Comparable<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
+ * @param pkg the package to compare.
+ * @return true if the item as equivalent.
*/
public abstract boolean sameItemAs(Package pkg);
@@ -638,12 +639,12 @@ public abstract class Package implements IDescription, Comparable<Package> { }
// check they are the same item.
- if (sameItemAs(replacementPackage) == false) {
+ if (!sameItemAs(replacementPackage)) {
return UpdateInfo.INCOMPATIBLE;
}
// check revision number
- if (replacementPackage.getRevision() > this.getRevision()) {
+ if (replacementPackage.getRevision().compareTo(this.getRevision()) > 0) {
return UpdateInfo.UPDATE;
}
@@ -652,7 +653,7 @@ public abstract class Package implements IDescription, Comparable<Package> { }
/**
- * Returns an ordering like this: <br/>
+ * Returns an ordering <b>suitable for display</b> like this: <br/>
* - Tools <br/>
* - Platform-Tools <br/>
* - Docs. <br/>
@@ -668,6 +669,10 @@ public abstract class Package implements IDescription, Comparable<Package> { * Important: this must NOT be used to compare if two packages are the same thing.
* This is achieved by {@link #sameItemAs(Package)} or {@link #canBeUpdatedBy(Package)}.
* <p/>
+ * The order done here is suitable for display, and this may not be the appropriate
+ * order when comparing whether packages are equal or of greater revision -- if you need
+ * to compare revisions, then use {@link #getRevision()}{@code .compareTo(rev)} directly.
+ * <p/>
* This {@link #compareTo(Package)} method is purely an implementation detail to
* perform the right ordering of the packages in the list of available or installed packages.
* <p/>
@@ -679,7 +684,8 @@ public abstract class Package implements IDescription, Comparable<Package> { String s1 = this.comparisonKey();
String s2 = other.comparisonKey();
- return s1.compareTo(s2);
+ int r = s1.compareTo(s2);
+ return r;
}
/**
@@ -728,7 +734,8 @@ public abstract class Package implements IDescription, Comparable<Package> { // We insert the package version here because it is more important
- // than the revision number. We want package version to be sorted
+ // than the revision number.
+ // In the list display, we want package version to be sorted
// top-down, so we'll use 10k-api as the sorting key. The day we
// reach 10k APIs, we'll need to revisit this.
sb.append("|v:"); //$NON-NLS-1$
@@ -743,10 +750,18 @@ public abstract class Package implements IDescription, Comparable<Package> { // Append revision number
sb.append("|r:"); //$NON-NLS-1$
- if (this instanceof IPreviewVersionProvider) {
- sb.append(String.format("%1$s", ((IPreviewVersionProvider) this).getPreviewVersion()));
+ FullRevision rev = getRevision();
+ sb.append(rev.getMajor()).append('.')
+ .append(rev.getMinor()).append('.')
+ .append(rev.getMicro()).append('.');
+ // Hack: When comparing packages for installation purposes, we want to treat
+ // "final releases" packages as more important than rc/preview packages.
+ // However like for the API level above, when sorting for list display purposes
+ // we want the final release package listed before its rc/preview packages.
+ if (rev.isPreview()) {
+ sb.append(rev.getPreview());
} else {
- sb.append(String.format("%1$04d", getRevision())); //$NON-NLS-1$
+ sb.append('0'); // 0=Final (!preview), to make "18.0" < "18.1" (18 Final < 18 RC1)
}
sb.append('|');
@@ -759,7 +774,7 @@ public abstract class Package implements IDescription, Comparable<Package> { int result = 1;
result = prime * result + Arrays.hashCode(mArchives);
result = prime * result + ((mObsolete == null) ? 0 : mObsolete.hashCode());
- result = prime * result + mRevision;
+ result = prime * result + mRevision.hashCode();
result = prime * result + ((mSource == null) ? 0 : mSource.hashCode());
return result;
}
@@ -786,7 +801,7 @@ public abstract class Package implements IDescription, Comparable<Package> { } else if (!mObsolete.equals(other.mObsolete)) {
return false;
}
- if (mRevision != other.mRevision) {
+ if (!mRevision.equals(other.mRevision)) {
return false;
}
if (mSource == null) {
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PlatformPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PlatformPackage.java index 2f75610..6efb620 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PlatformPackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PlatformPackage.java @@ -222,13 +222,13 @@ public class PlatformPackage extends MinToolsPackage if (mVersion.isPreview()) {
s = String.format("SDK Platform Android %1$s Preview, revision %2$s%3$s",
getVersionName(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : ""); //$NON-NLS-2$
} else {
s = String.format("SDK Platform Android %1$s, API %2$d, revision %3$s%4$s",
getVersionName(),
mVersion.getApiLevel(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : ""); //$NON-NLS-2$
}
@@ -249,8 +249,8 @@ public class PlatformPackage extends MinToolsPackage }
if (s.indexOf("revision") == -1) {
- s += String.format("\nRevision %1$d%2$s",
- getRevision(),
+ s += String.format("\nRevision %1$s%2$s",
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PlatformToolPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PlatformToolPackage.java index 2566ce3..fdacfcc 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PlatformToolPackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PlatformToolPackage.java @@ -39,10 +39,12 @@ import java.util.Set; /** * Represents a platform-tool XML node in an SDK repository. */ -public class PlatformToolPackage extends PreviewVersionPackage { +public class PlatformToolPackage extends FullRevisionPackage { /** The value returned by {@link PlatformToolPackage#installId()}. */ public static final String INSTALL_ID = "platform-tools"; //$NON-NLS-1$ + /** The value returned by {@link PlatformToolPackage#installId()}. */ + public static final String INSTALL_ID_PREVIEW = "platform-tools-preview"; //$NON-NLS-1$ /** * Creates a new platform-tool package from the attributes and elements of the given XML node. @@ -153,13 +155,18 @@ public class PlatformToolPackage extends PreviewVersionPackage { /** * Returns a string identifier to install this package from the command line. - * For platform-tools, we use "platform-tools" since this package type is unique. + * For platform-tools, we use "platform-tools" or "platform-tools-preview" since + * this package type is unique. * <p/> * {@inheritDoc} */ @Override public String installId() { - return INSTALL_ID; + if (getRevision().isPreview()) { + return INSTALL_ID_PREVIEW; + } else { + return INSTALL_ID; + } } /** @@ -179,7 +186,7 @@ public class PlatformToolPackage extends PreviewVersionPackage { @Override public String getShortDescription() { return String.format("Android SDK Platform-tools, revision %1$s%2$s", - getPreviewVersion().toShortString(), + getRevision().toShortString(), isObsolete() ? " (Obsolete)" : ""); } @@ -193,7 +200,7 @@ public class PlatformToolPackage extends PreviewVersionPackage { if (s.indexOf("revision") == -1) { s += String.format("\nRevision %1$s%2$s", - getPreviewVersion().toShortString(), + getRevision().toShortString(), isObsolete() ? " (Obsolete)" : ""); } @@ -215,10 +222,28 @@ public class PlatformToolPackage extends PreviewVersionPackage { return new File(osSdkRoot, SdkConstants.FD_PLATFORM_TOOLS); } + /** + * Check whether 2 platform-tool packages are the same <em>and</em> have the + * same preview bit. + */ @Override public boolean sameItemAs(Package pkg) { + return sameItemAs(pkg, false /*ignorePreviews*/); + } + + @Override + public boolean sameItemAs(Package pkg, boolean ignorePreviews) { // only one platform-tool package so any platform-tool package is the same item. - return pkg instanceof PlatformToolPackage; + if (pkg instanceof PlatformToolPackage) { + if (ignorePreviews) { + return true; + } else { + // however previews can only match previews by default, unless we ignore that check. + return ((PlatformToolPackage) pkg).getRevision().isPreview() == + getRevision().isPreview(); + } + } + return false; } /** diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java index e95c12e..59d6adc 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SamplePackage.java @@ -222,10 +222,10 @@ public class SamplePackage extends MinToolsPackage */
@Override
public String getShortDescription() {
- String s = String.format("Samples for SDK API %1$s%2$s, revision %3$d%4$s",
+ String s = String.format("Samples for SDK API %1$s%2$s, revision %3$s%4$s",
mVersion.getApiString(),
mVersion.isPreview() ? " Preview" : "",
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
return s;
}
@@ -244,8 +244,8 @@ public class SamplePackage extends MinToolsPackage }
if (s.indexOf("revision") == -1) {
- s += String.format("\nRevision %1$d%2$s",
- getRevision(),
+ s += String.format("\nRevision %1$s%2$s",
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SourcePackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SourcePackage.java index cf280f8..fc4d8af 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SourcePackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SourcePackage.java @@ -227,12 +227,12 @@ public class SourcePackage extends Package implements IAndroidVersionProvider { if (mVersion.isPreview()) {
return String.format("Sources for Android '%1$s' Preview SDK, revision %2$s%3$s",
mVersion.getCodename(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
} else {
return String.format("Sources for Android SDK, API %1$d, revision %2$s%3$s",
mVersion.getApiLevel(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
}
@@ -251,8 +251,8 @@ public class SourcePackage extends Package implements IAndroidVersionProvider { }
if (s.indexOf("revision") == -1) {
- s += String.format("\nRevision %1$d%2$s",
- getRevision(),
+ s += String.format("\nRevision %1$s%2$s",
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SystemImagePackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SystemImagePackage.java index e1e441c..963b80e 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SystemImagePackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/SystemImagePackage.java @@ -254,7 +254,7 @@ public class SystemImagePackage extends Package return String.format("%1$s System Image, Android API %2$s, revision %3$s%4$s",
getAbiDisplayName(),
mVersion.getApiString(),
- getRevision(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
@@ -272,8 +272,8 @@ public class SystemImagePackage extends Package }
if (s.indexOf("revision") == -1) {
- s += String.format("\nRevision %1$d%2$s",
- getRevision(),
+ s += String.format("\nRevision %1$s%2$s",
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java index 763ed43..c34a3d0 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/ToolPackage.java @@ -44,10 +44,12 @@ import java.util.regex.Pattern; /**
* Represents a tool XML node in an SDK repository.
*/
-public class ToolPackage extends PreviewVersionPackage implements IMinPlatformToolsDependency {
+public class ToolPackage extends FullRevisionPackage implements IMinPlatformToolsDependency {
/** The value returned by {@link ToolPackage#installId()}. */
public static final String INSTALL_ID = "tools"; //$NON-NLS-1$
+ /** The value returned by {@link ToolPackage#installId()}. */
+ private static final String INSTALL_ID_PREVIEW = "tools-preview"; //$NON-NLS-1$
/**
* The minimal revision of the platform-tools package required by this package
@@ -163,13 +165,17 @@ public class ToolPackage extends PreviewVersionPackage implements IMinPlatformTo /**
* Returns a string identifier to install this package from the command line.
- * For tools, we use "tools" since this package is unique.
+ * For tools, we use "tools" or "tools-preview" since this package is unique.
* <p/>
* {@inheritDoc}
*/
@Override
public String installId() {
- return INSTALL_ID;
+ if (getRevision().isPreview()) {
+ return INSTALL_ID_PREVIEW;
+ } else {
+ return INSTALL_ID;
+ }
}
/**
@@ -189,7 +195,7 @@ public class ToolPackage extends PreviewVersionPackage implements IMinPlatformTo @Override
public String getShortDescription() {
return String.format("Android SDK Tools, revision %1$s%2$s",
- getPreviewVersion().toShortString(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
@@ -203,7 +209,7 @@ public class ToolPackage extends PreviewVersionPackage implements IMinPlatformTo if (s.indexOf("revision") == -1) {
s += String.format("\nRevision %1$s%2$s",
- getPreviewVersion().toShortString(),
+ getRevision().toShortString(),
isObsolete() ? " (Obsolete)" : "");
}
@@ -225,10 +231,29 @@ public class ToolPackage extends PreviewVersionPackage implements IMinPlatformTo return new File(osSdkRoot, SdkConstants.FD_TOOLS);
}
+ /**
+ * Check whether 2 tool packages are the same <em>and</em> have the
+ * same preview bit.
+ */
@Override
public boolean sameItemAs(Package pkg) {
+ // Only one tool package so any tool package is the same item
+ return sameItemAs(pkg, false /*ignorePreviews*/);
+ }
+
+ @Override
+ public boolean sameItemAs(Package pkg, boolean ignorePreviews) {
// only one tool package so any tool package is the same item.
- return pkg instanceof ToolPackage;
+ if (pkg instanceof ToolPackage) {
+ if (ignorePreviews) {
+ return true;
+ } else {
+ // however previews can only match previews by default, unless we ignore that check.
+ return ((ToolPackage) pkg).getRevision().isPreview() ==
+ getRevision().isPreview();
+ }
+ }
+ return false;
}
@Override
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/PkgProps.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/PkgProps.java index a570153..5b39e89 100755 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/PkgProps.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/repository/PkgProps.java @@ -29,8 +29,7 @@ package com.android.sdklib.repository; public class PkgProps {
// Base Package
-
- public static final String PKG_REVISION = "Pkg.Revision"; //$NON-NLS-1$
+ public static final String PKG_MAJOR_REV = "Pkg.Revision"; //$NON-NLS-1$
public static final String PKG_LICENSE = "Pkg.License"; //$NON-NLS-1$
public static final String PKG_DESC = "Pkg.Desc"; //$NON-NLS-1$
public static final String PKG_DESC_URL = "Pkg.DescUrl"; //$NON-NLS-1$
@@ -39,17 +38,17 @@ public class PkgProps { public static final String PKG_SOURCE_URL = "Pkg.SourceUrl"; //$NON-NLS-1$
public static final String PKG_OBSOLETE = "Pkg.Obsolete"; //$NON-NLS-1$
+ // FullRevision
+
+ public static final String PKG_MINOR_REV = "Pkg.MinorRev"; //$NON-NLS-1$
+ public static final String PKG_MICRO_REV = "Pkg.MicroRev"; //$NON-NLS-1$
+ public static final String PKG_PREVIEW_REV = "Pkg.PreviewRev"; //$NON-NLS-1$
+
// AndroidVersion
public static final String VERSION_API_LEVEL = "AndroidVersion.ApiLevel";//$NON-NLS-1$
public static final String VERSION_CODENAME = "AndroidVersion.CodeName";//$NON-NLS-1$
- // PreviewVersion
-
- public static final String PKG_MINOR_REV = "PreviewVersion.MinorRev";//$NON-NLS-1$
- public static final String PKG_MICRO_REV = "PreviewVersion.MicroRev";//$NON-NLS-1$
- public static final String PKG_PREVIEW_REV = "PreviewVersion.Preview"; //$NON-NLS-1$
-
// AddonPackage
diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionPackageTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionPackageTest.java new file mode 100755 index 0000000..63e1d05 --- /dev/null +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionPackageTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2012 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.internal.repository.packages; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +import junit.framework.TestCase; + +public class FullRevisionPackageTest extends TestCase { + + public void testCompareTo() throws Exception { + // Test order of full revision packages. + // + // Note that Package.compareTo() is designed to return the desired + // ordering for a list display and as such a final/release package + // needs to be listed before its rc/preview package. + // + // This differs from the order used by FullRevision.compareTo(). + + ArrayList<Package> list = new ArrayList<Package>(); + + list.add(new MockToolPackage(null, new FullRevision(1, 0, 0, 0), 8)); + list.add(new MockToolPackage(null, new FullRevision(1, 0, 0, 1), 8)); + list.add(new MockToolPackage(null, new FullRevision(1, 0, 1, 0), 8)); + list.add(new MockToolPackage(null, new FullRevision(1, 0, 1, 1), 8)); + list.add(new MockToolPackage(null, new FullRevision(1, 1, 0, 0), 8)); + list.add(new MockToolPackage(null, new FullRevision(1, 1, 0, 1), 8)); + list.add(new MockToolPackage(null, new FullRevision(2, 1, 1, 0), 8)); + list.add(new MockToolPackage(null, new FullRevision(2, 1, 1, 1), 8)); + + Collections.sort(list); + + assertEquals( + "[Android SDK Tools, revision 1, " + + "Android SDK Tools, revision 1 rc1, " + + "Android SDK Tools, revision 1.0.1, " + + "Android SDK Tools, revision 1.0.1 rc1, " + + "Android SDK Tools, revision 1.1, " + + "Android SDK Tools, revision 1.1 rc1, " + + "Android SDK Tools, revision 2.1.1, " + + "Android SDK Tools, revision 2.1.1 rc1]", + Arrays.toString(list.toArray())); + } +} diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PreviewVersionTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionTest.java index daa4704..97e76bb 100755 --- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PreviewVersionTest.java +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionTest.java @@ -18,7 +18,7 @@ package com.android.sdklib.internal.repository.packages; import junit.framework.TestCase; -public class PreviewVersionTest extends TestCase { +public class FullRevisionTest extends TestCase { @Override protected void setUp() throws Exception { @@ -30,26 +30,26 @@ public class PreviewVersionTest extends TestCase { super.tearDown(); } - public final void testPreviewVersion() { - PreviewVersion p = new PreviewVersion(5); + public final void testFullRevision() { + FullRevision p = new FullRevision(5); assertEquals(5, p.getMajor()); - assertEquals(PreviewVersion.IMPLICIT_MINOR_REV, p.getMinor()); - assertEquals(PreviewVersion.IMPLICIT_MICRO_REV, p.getMicro()); - assertEquals(PreviewVersion.NOT_A_PREVIEW, p.getPreview()); + assertEquals(FullRevision.IMPLICIT_MINOR_REV, p.getMinor()); + assertEquals(FullRevision.IMPLICIT_MICRO_REV, p.getMicro()); + assertEquals(FullRevision.NOT_A_PREVIEW, p.getPreview()); assertFalse (p.isPreview()); assertEquals("5", p.toShortString()); assertEquals("5.0.0", p.toString()); - p = new PreviewVersion(5, 0, 0, 6); + p = new FullRevision(5, 0, 0, 6); assertEquals(5, p.getMajor()); - assertEquals(PreviewVersion.IMPLICIT_MINOR_REV, p.getMinor()); - assertEquals(PreviewVersion.IMPLICIT_MICRO_REV, p.getMicro()); + assertEquals(FullRevision.IMPLICIT_MINOR_REV, p.getMinor()); + assertEquals(FullRevision.IMPLICIT_MICRO_REV, p.getMicro()); assertEquals(6, p.getPreview()); assertTrue (p.isPreview()); assertEquals("5 rc6", p.toShortString()); assertEquals("5.0.0 rc6", p.toString()); - p = new PreviewVersion(6, 7, 0); + p = new FullRevision(6, 7, 0); assertEquals(6, p.getMajor()); assertEquals(7, p.getMinor()); assertEquals(0, p.getMicro()); @@ -58,7 +58,7 @@ public class PreviewVersionTest extends TestCase { assertEquals("6.7", p.toShortString()); assertEquals("6.7.0", p.toString()); - p = new PreviewVersion(10, 11, 12, PreviewVersion.NOT_A_PREVIEW); + p = new FullRevision(10, 11, 12, FullRevision.NOT_A_PREVIEW); assertEquals(10, p.getMajor()); assertEquals(11, p.getMinor()); assertEquals(12, p.getMicro()); @@ -67,7 +67,7 @@ public class PreviewVersionTest extends TestCase { assertEquals("10.11.12", p.toShortString()); assertEquals("10.11.12", p.toString()); - p = new PreviewVersion(10, 11, 12, 13); + p = new FullRevision(10, 11, 12, 13); assertEquals(10, p.getMajor()); assertEquals(11, p.getMinor()); assertEquals(12, p.getMicro()); @@ -78,13 +78,13 @@ public class PreviewVersionTest extends TestCase { } public final void testCompareTo() { - PreviewVersion s4 = new PreviewVersion(4); - PreviewVersion i4 = new PreviewVersion(4); - PreviewVersion g5 = new PreviewVersion(5, 1, 0, 6); - PreviewVersion y5 = new PreviewVersion(5); - PreviewVersion c5 = new PreviewVersion(5, 1, 0, 6); - PreviewVersion o5 = new PreviewVersion(5, 0, 0, 7); - PreviewVersion p5 = new PreviewVersion(5, 1, 0, 0); + FullRevision s4 = new FullRevision(4); + FullRevision i4 = new FullRevision(4); + FullRevision g5 = new FullRevision(5, 1, 0, 6); + FullRevision y5 = new FullRevision(5); + FullRevision c5 = new FullRevision(5, 1, 0, 6); + FullRevision o5 = new FullRevision(5, 0, 0, 7); + FullRevision p5 = new FullRevision(5, 1, 0, 0); assertEquals(s4, i4); // 4.0.0-0 == 4.0.0-0 assertEquals(g5, c5); // 5.1.0-6 == 5.1.0-6 diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockEmptyPackage.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockEmptyPackage.java index f1e4344..5c7bfe3 100755 --- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockEmptyPackage.java +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockEmptyPackage.java @@ -134,7 +134,7 @@ public class MockEmptyPackage extends Package { public String getShortDescription() { StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()); sb.append(" '").append(mTestHandle).append('\''); - if (getRevision() > 0) { + if (getRevision().getMajor() > 0) { sb.append(" rev=").append(getRevision()); } return sb.toString(); diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockPlatformToolPackage.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockPlatformToolPackage.java index 0b46876..7ed5114 100755 --- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockPlatformToolPackage.java +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockPlatformToolPackage.java @@ -67,11 +67,11 @@ public class MockPlatformToolPackage extends PlatformToolPackage { * <p/>
* By design, this creates a package with one and only one archive.
*/
- public MockPlatformToolPackage(SdkSource source, PreviewVersion previewVersion) {
+ public MockPlatformToolPackage(SdkSource source, FullRevision revision) {
super(
source, // source,
- createProps(previewVersion), // props,
- previewVersion.getMajor(),
+ createProps(revision), // props,
+ revision.getMajor(),
null, // license,
"desc", // description,
"url", // descUrl,
@@ -81,14 +81,14 @@ public class MockPlatformToolPackage extends PlatformToolPackage { );
}
- private static Properties createProps(PreviewVersion previewVersion) {
+ private static Properties createProps(FullRevision revision) {
Properties props = new Properties();
props.setProperty(PkgProps.PKG_MINOR_REV,
- Integer.toString(previewVersion.getMinor()));
+ Integer.toString(revision.getMinor()));
props.setProperty(PkgProps.PKG_MICRO_REV,
- Integer.toString(previewVersion.getMicro()));
+ Integer.toString(revision.getMicro()));
props.setProperty(PkgProps.PKG_PREVIEW_REV,
- Integer.toString(previewVersion.getPreview()));
+ Integer.toString(revision.getPreview()));
return props;
}
}
diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockToolPackage.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockToolPackage.java index e4bd9c6..cdccbb8 100755 --- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockToolPackage.java +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/MockToolPackage.java @@ -69,12 +69,12 @@ public class MockToolPackage extends ToolPackage { */
public MockToolPackage(
SdkSource source,
- PreviewVersion previewVersion,
+ FullRevision revision,
int minPlatformToolsRev) {
super(
source, // source,
- createProps(previewVersion, minPlatformToolsRev), // props,
- previewVersion.getMajor(),
+ createProps(revision, minPlatformToolsRev), // props,
+ revision.getMajor(),
null, // license,
"desc", // description,
"url", // descUrl,
@@ -84,17 +84,17 @@ public class MockToolPackage extends ToolPackage { );
}
- private static Properties createProps(PreviewVersion previewVersion, int minPlatformToolsRev) {
+ private static Properties createProps(FullRevision revision, int minPlatformToolsRev) {
Properties props = new Properties();
props.setProperty(PkgProps.MIN_PLATFORM_TOOLS_REV,
Integer.toString((minPlatformToolsRev)));
- if (previewVersion != null) {
+ if (revision != null) {
props.setProperty(PkgProps.PKG_MINOR_REV,
- Integer.toString(previewVersion.getMinor()));
+ Integer.toString(revision.getMinor()));
props.setProperty(PkgProps.PKG_MICRO_REV,
- Integer.toString(previewVersion.getMicro()));
+ Integer.toString(revision.getMicro()));
props.setProperty(PkgProps.PKG_PREVIEW_REV,
- Integer.toString(previewVersion.getPreview()));
+ Integer.toString(revision.getPreview()));
}
return props;
}
diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java index ce41a4d..cfe70c1 100755 --- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PackageTest.java @@ -136,7 +136,7 @@ public class PackageTest extends TestCase { Properties props = new Properties(); // Package properties - props.setProperty(PkgProps.PKG_REVISION, "42"); + props.setProperty(PkgProps.PKG_MAJOR_REV, "42"); props.setProperty(PkgProps.PKG_LICENSE, "The License"); props.setProperty(PkgProps.PKG_DESC, "Some description."); props.setProperty(PkgProps.PKG_DESC_URL, "http://description/url"); @@ -155,7 +155,7 @@ public class PackageTest extends TestCase { */ protected void testCreatedPackage(Package p) { // Package properties - assertEquals(42, p.getRevision()); + assertEquals("42", p.getRevision().toShortString()); assertEquals("The License", p.getLicense()); assertEquals("Some description.", p.getDescription()); assertEquals("http://description/url", p.getDescUrl()); diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/AboutDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/AboutDialog.java index 35e3420..6352bdb 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/AboutDialog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/AboutDialog.java @@ -107,7 +107,7 @@ public class AboutDialog extends UpdaterBaseDialog { }
}
- String revision = p.getProperty(PkgProps.PKG_REVISION);
+ String revision = p.getProperty(PkgProps.PKG_MAJOR_REV);
if (revision != null) {
return revision;
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterChooserDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterChooserDialog.java index 55e7db2..a41a952 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterChooserDialog.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterChooserDialog.java @@ -21,6 +21,7 @@ import com.android.sdklib.SdkConstants; import com.android.sdklib.internal.repository.archives.Archive;
import com.android.sdklib.internal.repository.packages.IAndroidVersionProvider;
import com.android.sdklib.internal.repository.packages.Package;
+import com.android.sdklib.internal.repository.packages.FullRevision;
import com.android.sdklib.internal.repository.sources.SdkSource;
import com.android.sdkuilib.internal.repository.icons.ImageFactory;
import com.android.sdkuilib.ui.GridDialog;
@@ -423,8 +424,8 @@ final class SdkUpdaterChooserDialog extends GridDialog { if (aOld != null) {
Package pOld = aOld.getParentPackage();
- int rOld = pOld.getRevision();
- int rNew = pNew.getRevision();
+ FullRevision rOld = pOld.getRevision();
+ FullRevision rNew = pNew.getRevision();
boolean showRev = true;
@@ -435,17 +436,17 @@ final class SdkUpdaterChooserDialog extends GridDialog { if (!vOld.equals(vNew)) {
// Versions are different, so indicate more than just the revision.
- addText(String.format("This update will replace API %1$s revision %2$d with API %3$s revision %4$d.\n\n",
- vOld.getApiString(), rOld,
- vNew.getApiString(), rNew));
+ addText(String.format("This update will replace API %1$s revision %2$s with API %3$s revision %4$s.\n\n",
+ vOld.getApiString(), rOld.toShortString(),
+ vNew.getApiString(), rNew.toShortString()));
showRev = false;
}
}
if (showRev) {
- addText(String.format("This update will replace revision %1$d with revision %2$d.\n\n",
- rOld,
- rNew));
+ addText(String.format("This update will replace revision %1$s with revision %2$s.\n\n",
+ rOld.toShortString(),
+ rNew.toShortString()));
}
}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java index 97de564..d5ad456 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterLogic.java @@ -23,12 +23,14 @@ import com.android.sdklib.internal.repository.archives.Archive; import com.android.sdklib.internal.repository.packages.AddonPackage;
import com.android.sdklib.internal.repository.packages.DocPackage;
import com.android.sdklib.internal.repository.packages.ExtraPackage;
+import com.android.sdklib.internal.repository.packages.FullRevision;
+import com.android.sdklib.internal.repository.packages.IAndroidVersionProvider;
import com.android.sdklib.internal.repository.packages.IExactApiLevelDependency;
import com.android.sdklib.internal.repository.packages.IMinApiLevelDependency;
import com.android.sdklib.internal.repository.packages.IMinPlatformToolsDependency;
import com.android.sdklib.internal.repository.packages.IMinToolsDependency;
import com.android.sdklib.internal.repository.packages.IPlatformDependency;
-import com.android.sdklib.internal.repository.packages.IAndroidVersionProvider;
+import com.android.sdklib.internal.repository.packages.MajorRevision;
import com.android.sdklib.internal.repository.packages.MinToolsPackage;
import com.android.sdklib.internal.repository.packages.Package;
import com.android.sdklib.internal.repository.packages.Package.UpdateInfo;
@@ -184,6 +186,14 @@ class SdkUpdaterLogic { return archives;
}
+ private double getRevisionRank(FullRevision rev) {
+ int p = rev.isPreview() ? 999 : 999 - rev.getPreview();
+ return rev.getMajor() +
+ rev.getMinor() / 1000.d +
+ rev.getMicro() / 1000000.d +
+ p / 1000000000.d;
+ }
+
/**
* Finds new packages that the user does not have in his/her local SDK
* and adds them to the list of archives to install.
@@ -212,15 +222,15 @@ class SdkUpdaterLogic { ArchiveInfo[] localArchives = createLocalArchives(localPkgs);
// Find the highest platform installed
- float currentPlatformScore = 0;
- float currentSampleScore = 0;
- float currentAddonScore = 0;
- float currentDocScore = 0;
- HashMap<String, Float> currentExtraScore = new HashMap<String, Float>();
+ double currentPlatformScore = 0;
+ double currentSampleScore = 0;
+ double currentAddonScore = 0;
+ double currentDocScore = 0;
+ HashMap<String, Double> currentExtraScore = new HashMap<String, Double>();
if (!includeAll) {
if (localPkgs != null) {
for (Package p : localPkgs) {
- int rev = p.getRevision();
+ double rev = getRevisionRank(p.getRevision());
int api = 0;
boolean isPreview = false;
if (p instanceof IAndroidVersionProvider) {
@@ -229,10 +239,10 @@ class SdkUpdaterLogic { isPreview = vers.isPreview();
}
- // The score is 10*api + (1 if preview) + rev/100
+ // The score is 1000*api + (999 if preview) + rev
// This allows previews to rank above a non-preview and
// allows revisions to rank appropriately.
- float score = api * 10 + (isPreview ? 1 : 0) + rev/100.f;
+ double score = api * 1000 + (isPreview ? 999 : 0) + rev;
if (p instanceof PlatformPackage) {
currentPlatformScore = Math.max(currentPlatformScore, score);
@@ -261,7 +271,7 @@ class SdkUpdaterLogic { continue;
}
- int rev = p.getRevision();
+ double rev = getRevisionRank(p.getRevision());
int api = 0;
boolean isPreview = false;
if (p instanceof IAndroidVersionProvider) {
@@ -270,7 +280,7 @@ class SdkUpdaterLogic { isPreview = vers.isPreview();
}
- float score = api * 10 + (isPreview ? 1 : 0) + rev/100.f;
+ double score = api * 1000 + (isPreview ? 999 : 0) + rev;
boolean shouldAdd = false;
if (p instanceof PlatformPackage) {
@@ -282,7 +292,7 @@ class SdkUpdaterLogic { } else if (p instanceof ExtraPackage) {
String key = ((ExtraPackage) p).getPath();
shouldAdd = !currentExtraScore.containsKey(key) ||
- score > currentExtraScore.get(key).floatValue();
+ score > currentExtraScore.get(key).doubleValue();
} else if (p instanceof DocPackage) {
// We don't want all the doc, only the most recent one
if (score > currentDocScore) {
@@ -673,20 +683,22 @@ class SdkUpdaterLogic { SdkSource[] remoteSources,
ArchiveInfo[] localArchives) {
// This is the requirement to match.
- int rev = pkg.getMinToolsRevision();
+ int revInt = pkg.getMinToolsRevision(); // FIXME support micro min-tools-rev
- if (rev == MinToolsPackage.MIN_TOOLS_REV_NOT_SPECIFIED) {
+ if (revInt == MinToolsPackage.MIN_TOOLS_REV_NOT_SPECIFIED) {
// Well actually there's no requirement.
return null;
}
+ MajorRevision rev = new MajorRevision(revInt);
+
// First look in locally installed packages.
for (ArchiveInfo ai : localArchives) {
Archive a = ai.getNewArchive();
if (a != null) {
Package p = a.getParentPackage();
if (p instanceof ToolPackage) {
- if (((ToolPackage) p).getRevision() >= rev) {
+ if (((ToolPackage) p).getRevision().compareTo(rev) >= 0) {
// We found one already installed.
return null;
}
@@ -700,7 +712,7 @@ class SdkUpdaterLogic { if (a != null) {
Package p = a.getParentPackage();
if (p instanceof ToolPackage) {
- if (((ToolPackage) p).getRevision() >= rev) {
+ if (((ToolPackage) p).getRevision().compareTo(rev) >= 0) {
// The dependency is already scheduled for install, nothing else to do.
return ai;
}
@@ -713,7 +725,7 @@ class SdkUpdaterLogic { for (Archive a : selectedArchives) {
Package p = a.getParentPackage();
if (p instanceof ToolPackage) {
- if (((ToolPackage) p).getRevision() >= rev) {
+ if (((ToolPackage) p).getRevision().compareTo(rev) >= 0) {
// It's not already in the list of things to install, so add it now
return insertArchive(a,
outArchives,
@@ -731,7 +743,7 @@ class SdkUpdaterLogic { fetchRemotePackages(remotePkgs, remoteSources);
for (Package p : remotePkgs) {
if (p instanceof ToolPackage) {
- if (((ToolPackage) p).getRevision() >= rev) {
+ if (((ToolPackage) p).getRevision().compareTo(rev) >= 0) {
// It's not already in the list of things to install, so add the
// first compatible archive we can find.
for (Archive a : p.getArchives()) {
@@ -752,7 +764,7 @@ class SdkUpdaterLogic { // We end up here if nothing matches. We don't have a good platform to match.
// We need to indicate this extra depends on a missing platform archive
// so that it can be impossible to install later on.
- return new MissingArchiveInfo(MissingArchiveInfo.TITLE_TOOL, rev);
+ return new MissingArchiveInfo(MissingArchiveInfo.TITLE_TOOL, revInt);
}
/**
@@ -771,12 +783,13 @@ class SdkUpdaterLogic { SdkSource[] remoteSources,
ArchiveInfo[] localArchives) {
// This is the requirement to match.
- int rev = pkg.getMinPlatformToolsRevision();
+ int revInt = pkg.getMinPlatformToolsRevision(); // FIXME support micro min-plat-tools-rev
+ FullRevision rev = new MajorRevision(revInt);
boolean findMax = false;
ArchiveInfo aiMax = null;
Archive aMax = null;
- if (rev == IMinPlatformToolsDependency.MIN_PLATFORM_TOOLS_REV_INVALID) {
+ if (revInt == IMinPlatformToolsDependency.MIN_PLATFORM_TOOLS_REV_INVALID) {
// The requirement is invalid, which is not supposed to happen since this
// property is mandatory. However in a typical upgrade scenario we can end
// up with the previous updater managing a new package and not dealing
@@ -792,11 +805,11 @@ class SdkUpdaterLogic { if (a != null) {
Package p = a.getParentPackage();
if (p instanceof PlatformToolPackage) {
- int r = ((PlatformToolPackage) p).getRevision();
- if (findMax && r > rev) {
+ FullRevision r = ((PlatformToolPackage) p).getRevision();
+ if (findMax && r.compareTo(rev) > 0) {
rev = r;
aiMax = ai;
- } else if (!findMax && r >= rev) {
+ } else if (!findMax && r.compareTo(rev) >= 0) {
// We found one already installed.
return null;
}
@@ -810,11 +823,11 @@ class SdkUpdaterLogic { if (a != null) {
Package p = a.getParentPackage();
if (p instanceof PlatformToolPackage) {
- int r = ((PlatformToolPackage) p).getRevision();
- if (findMax && r > rev) {
+ FullRevision r = ((PlatformToolPackage) p).getRevision();
+ if (findMax && r.compareTo(rev) > 0) {
rev = r;
aiMax = ai;
- } else if (!findMax && r >= rev) {
+ } else if (!findMax && r.compareTo(rev) >= 0) {
// The dependency is already scheduled for install, nothing else to do.
return ai;
}
@@ -827,12 +840,12 @@ class SdkUpdaterLogic { for (Archive a : selectedArchives) {
Package p = a.getParentPackage();
if (p instanceof PlatformToolPackage) {
- int r = ((PlatformToolPackage) p).getRevision();
- if (findMax && r > rev) {
+ FullRevision r = ((PlatformToolPackage) p).getRevision();
+ if (findMax && r.compareTo(rev) > 0) {
rev = r;
aiMax = null;
aMax = a;
- } else if (!findMax && r >= rev) {
+ } else if (!findMax && r.compareTo(rev) >= 0) {
// It's not already in the list of things to install, so add it now
return insertArchive(a,
outArchives,
@@ -850,16 +863,16 @@ class SdkUpdaterLogic { fetchRemotePackages(remotePkgs, remoteSources);
for (Package p : remotePkgs) {
if (p instanceof PlatformToolPackage) {
- int r = ((PlatformToolPackage) p).getRevision();
- if (r >= rev) {
+ FullRevision r = ((PlatformToolPackage) p).getRevision();
+ if (r.compareTo(rev) >= 0) {
// Make sure there's at least one valid archive here
for (Archive a : p.getArchives()) {
if (a.isCompatible()) {
- if (findMax && r > rev) {
+ if (findMax && r.compareTo(rev) > 0) {
rev = r;
aiMax = null;
aMax = a;
- } else if (!findMax && r >= rev) {
+ } else if (!findMax && r.compareTo(rev) >= 0) {
// It's not already in the list of things to install, so add the
// first compatible archive we can find.
return insertArchive(a,
@@ -893,7 +906,7 @@ class SdkUpdaterLogic { // We end up here if nothing matches. We don't have a good platform to match.
// We need to indicate this package depends on a missing platform archive
// so that it can be impossible to install later on.
- return new MissingArchiveInfo(MissingArchiveInfo.TITLE_PLATFORM_TOOL, rev);
+ return new MissingArchiveInfo(MissingArchiveInfo.TITLE_PLATFORM_TOOL, revInt);
}
/**
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java index 687238b..8e1cbb3 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogic.java @@ -21,7 +21,9 @@ import com.android.sdklib.IAndroidTarget; import com.android.sdklib.SdkConstants; import com.android.sdklib.internal.repository.packages.ExtraPackage; import com.android.sdklib.internal.repository.packages.IAndroidVersionProvider; +import com.android.sdklib.internal.repository.packages.IFullRevisionProvider; import com.android.sdklib.internal.repository.packages.Package; +import com.android.sdklib.internal.repository.packages.Package.UpdateInfo; import com.android.sdklib.internal.repository.packages.PlatformPackage; import com.android.sdklib.internal.repository.packages.PlatformToolPackage; import com.android.sdklib.internal.repository.packages.SystemImagePackage; @@ -80,11 +82,12 @@ class PackagesDiffLogic { /** * Mark all new and update PkgItems as checked. * - * @param selectNew If true, select all new packages - * @param selectUpdates If true, select all update packages - * @param selectTop If true, select the top platform. If the top platform has nothing installed, - * select all items in it; if it is partially installed, at least select the platform and - * system images if none of the system images are installed. + * @param selectNew If true, select all new packages (except the rc/preview ones). + * @param selectUpdates If true, select all update packages. + * @param selectTop If true, select the top platform. + * If the top platform has nothing installed, select all items in it (except the rc/preview); + * If it is partially installed, at least select the platform and system images if none of + * the system images are installed. * @param currentPlatform The {@link SdkConstants#currentPlatform()} value. */ public void checkNewUpdateItems( @@ -97,7 +100,8 @@ class PackagesDiffLogic { SparseArray<List<PkgItem>> platformItems = new SparseArray<List<PkgItem>>(); // sort items in platforms... directly deal with new/update items - for (PkgItem item : getAllPkgItems(true /*byApi*/, true /*bySource*/)) { + List<PkgItem> allItems = getAllPkgItems(true /*byApi*/, true /*bySource*/); + for (PkgItem item : allItems) { if (!item.hasCompatibleArchive()) { // Ignore items that have no archive compatible with the current platform. continue; @@ -129,8 +133,42 @@ class PackagesDiffLogic { items.add(item); } - if ((selectNew && item.getState() == PkgState.NEW) || - (selectUpdates && item.hasUpdatePkg())) { + if ((selectUpdates || selectNew) && + item.getState() == PkgState.NEW && + !item.getRevision().isPreview()) { + boolean sameFound = false; + Package newPkg = item.getMainPackage(); + if (newPkg instanceof IFullRevisionProvider) { + // We have a potential new non-preview package; but this kind of package + // supports having previews, which means we want to make sure we're not + // offering an older "new" non-preview if there's a newer preview installed. + // + // We should get into this odd situation only when updating an RC/preview + // by a final release pkg. + + IFullRevisionProvider newPkg2 = (IFullRevisionProvider) newPkg; + for (PkgItem item2 : allItems) { + if (item2.getState() == PkgState.INSTALLED) { + Package installed = item2.getMainPackage(); + + if (installed.getRevision().isPreview() && + newPkg2.sameItemAs(installed, true /*ignorePreviews*/)) { + sameFound = true; + + if (installed.canBeUpdatedBy(newPkg) == UpdateInfo.UPDATE) { + item.setChecked(true); + break; + } + } + } + } + } + + if (selectNew && !sameFound) { + item.setChecked(true); + } + + } else if (selectUpdates && item.hasUpdatePkg()) { item.setChecked(true); } } @@ -140,7 +178,8 @@ class PackagesDiffLogic { if (!installedPlatforms.contains(maxApi)) { // If the top platform has nothing installed at all, select everything in it for (PkgItem item : items) { - if (item.getState() == PkgState.NEW || item.hasUpdatePkg()) { + if ((item.getState() == PkgState.NEW && !item.getRevision().isPreview()) || + item.hasUpdatePkg()) { item.setChecked(true); } } @@ -151,7 +190,8 @@ class PackagesDiffLogic { // First make sure the platform package itself is installed, or select it. for (PkgItem item : items) { Package p = item.getMainPackage(); - if (p instanceof PlatformPackage && item.getState() == PkgState.NEW) { + if (p instanceof PlatformPackage && + item.getState() == PkgState.NEW && !item.getRevision().isPreview()) { item.setChecked(true); break; } @@ -163,7 +203,7 @@ class PackagesDiffLogic { Package p = item.getMainPackage(); if (p instanceof PlatformPackage && item.getState() == PkgState.INSTALLED) { if (item.hasUpdatePkg() && item.isChecked()) { - // If the installed platform is schedule for update, look for the + // If the installed platform is scheduled for update, look for the // system image in the update package, not the current one. p = item.getUpdatePkg(); if (p instanceof PlatformPackage) { @@ -190,6 +230,7 @@ class PackagesDiffLogic { Package p = item.getMainPackage(); if (p instanceof PlatformPackage) { if (item.getState() == PkgState.NEW && + !item.getRevision().isPreview() && ((PlatformPackage) p).getIncludedAbi() != null) { item.setChecked(true); hasSysImg = true; @@ -220,7 +261,9 @@ class PackagesDiffLogic { // On Windows, we'll also auto-select the USB driver for (PkgItem item : getAllPkgItems(true /*byApi*/, true /*bySource*/)) { Package p = item.getMainPackage(); - if (p instanceof ExtraPackage && item.getState() == PkgState.NEW) { + if (p instanceof ExtraPackage && + item.getState() == PkgState.NEW && + !item.getRevision().isPreview()) { ExtraPackage ep = (ExtraPackage) p; if (ep.getVendorId().equals("google") && //$NON-NLS-1$ ep.getPath().equals("usb_driver")) { //$NON-NLS-1$ @@ -519,7 +562,7 @@ class PackagesDiffLogic { switch (currItem.getState()) { case NEW: - if (newPkg.getRevision() < mainPkg.getRevision()) { + if (newPkg.getRevision().compareTo(mainPkg.getRevision()) < 0) { if (!op.isKeep(currItem)) { // The new item has a lower revision than the current one, // but the current one hasn't been marked as being kept so @@ -528,7 +571,7 @@ class PackagesDiffLogic { addNewItem(op, newPkg, PkgState.NEW); hasChanged = true; } - } else if (newPkg.getRevision() > mainPkg.getRevision()) { + } else if (newPkg.getRevision().compareTo(mainPkg.getRevision()) > 0) { // We have a more recent new version, remove the current one // and replace by a new one currItemIt.remove(); @@ -538,7 +581,7 @@ class PackagesDiffLogic { break; case INSTALLED: // if newPkg.revision<=mainPkg.revision: it's already installed, ignore. - if (newPkg.getRevision() > mainPkg.getRevision()) { + if (newPkg.getRevision().compareTo(mainPkg.getRevision()) > 0) { // This is a new update for the main package. if (currItem.mergeUpdate(newPkg)) { op.keep(currItem.getUpdatePkg()); @@ -611,8 +654,11 @@ class PackagesDiffLogic { return ((IAndroidVersionProvider) pkg).getAndroidVersion(); } else if (pkg instanceof ToolPackage || pkg instanceof PlatformToolPackage) { - return PkgCategoryApi.KEY_TOOLS; - + if (pkg.getRevision().isPreview()) { + return PkgCategoryApi.KEY_TOOLS_PREVIEW; + } else { + return PkgCategoryApi.KEY_TOOLS; + } } else { return PkgCategoryApi.KEY_EXTRA; } diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesPage.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesPage.java index ea02e3a..51543e8 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesPage.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PackagesPage.java @@ -1313,7 +1313,7 @@ public class PackagesPage extends UpdaterPage implements ISdkChangeListener { } else if (mColumn == mColumnRevision) { if (element instanceof PkgItem) { PkgItem pkg = (PkgItem) element; - return pkg.getRevisionStr(); + return pkg.getRevision().toShortString(); } } else if (mColumn == mColumnStatus) { @@ -1343,7 +1343,7 @@ public class PackagesPage extends UpdaterPage implements ISdkChangeListener { } else if (element instanceof Package) { // This is an update package. - return "New revision " + Integer.toString(((Package) element).getRevision()); + return "New revision " + ((Package) element).getRevision().toShortString(); } } diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgCategoryApi.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgCategoryApi.java index 5bb4917..d1e3a28 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgCategoryApi.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgCategoryApi.java @@ -31,7 +31,9 @@ class PkgCategoryApi extends PkgCategory { // them. // (Note: don't use integer.max to avoid integers wrapping in comparisons. We can // revisit the day we get 2^30 platforms.) - public final static AndroidVersion KEY_TOOLS = new AndroidVersion(Integer.MAX_VALUE / 2, null);; + public final static AndroidVersion KEY_TOOLS = new AndroidVersion(Integer.MAX_VALUE / 2, null); + public final static AndroidVersion KEY_TOOLS_PREVIEW = + new AndroidVersion(Integer.MAX_VALUE / 2 - 1, null); public final static AndroidVersion KEY_EXTRA = new AndroidVersion(-1, null); public PkgCategoryApi(AndroidVersion version, String platformName, Object iconRef) { @@ -55,6 +57,8 @@ class PkgCategoryApi extends PkgCategory { AndroidVersion key = (AndroidVersion) getKey(); if (key.equals(KEY_TOOLS)) { return "TOOLS"; //$NON-NLS-1$ // for internal debug use only + } else if (key.equals(KEY_TOOLS_PREVIEW)) { + return "TOOLS-PREVIEW"; //$NON-NLS-1$ // for internal debug use only } else if (key.equals(KEY_EXTRA)) { return "EXTRAS"; //$NON-NLS-1$ // for internal debug use only } else { @@ -70,6 +74,8 @@ class PkgCategoryApi extends PkgCategory { if (key.equals(KEY_TOOLS)) { label = "Tools"; + } else if (key.equals(KEY_TOOLS_PREVIEW)) { + label = "Tools (Beta Channel)"; } else if (key.equals(KEY_EXTRA)) { label = "Extras"; } else { diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgItem.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgItem.java index ae20deb..89910cd 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgItem.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/PkgItem.java @@ -17,8 +17,8 @@ package com.android.sdkuilib.internal.repository.sdkman2; import com.android.sdklib.internal.repository.archives.Archive; +import com.android.sdklib.internal.repository.packages.FullRevision; import com.android.sdklib.internal.repository.packages.IAndroidVersionProvider; -import com.android.sdklib.internal.repository.packages.IPreviewVersionProvider; import com.android.sdklib.internal.repository.packages.Package; import com.android.sdklib.internal.repository.packages.Package.UpdateInfo; import com.android.sdklib.internal.repository.sources.SdkSource; @@ -90,17 +90,10 @@ public class PkgItem implements Comparable<PkgItem> { return mMainPkg.getListDescription(); } - public int getRevision() { + public FullRevision getRevision() { return mMainPkg.getRevision(); } - public String getRevisionStr() { - if (mMainPkg instanceof IPreviewVersionProvider) { - return ((IPreviewVersionProvider) mMainPkg).getPreviewVersion().toShortString(); - } - return Integer.toString(mMainPkg.getRevision()); - } - public String getDescription() { return mMainPkg.getDescription(); } @@ -157,24 +150,24 @@ public class PkgItem implements Comparable<PkgItem> { /** * Checks whether the main packages are of the same type and are - * not an update of each other. + * not an update of each other and have the same revision number. */ public boolean isSameMainPackageAs(Package pkg) { if (mMainPkg.canBeUpdatedBy(pkg) == UpdateInfo.NOT_UPDATE) { // package revision numbers must match - return mMainPkg.getRevision() == pkg.getRevision(); + return mMainPkg.getRevision().equals(pkg.getRevision()); } return false; } /** * Checks whether the update packages are of the same type and are - * not an update of each other. + * not an update of each other and have the same revision numbers. */ public boolean isSameUpdatePackageAs(Package pkg) { if (mUpdatePkg != null && mUpdatePkg.canBeUpdatedBy(pkg) == UpdateInfo.NOT_UPDATE) { // package revision numbers must match - return mUpdatePkg.getRevision() == pkg.getRevision(); + return mUpdatePkg.getRevision().equals(pkg.getRevision()); } return false; } diff --git a/sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java b/sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java index a328ef1..26b39ed 100755 --- a/sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java +++ b/sdkmanager/libs/sdkuilib/tests/com/android/sdkuilib/internal/repository/sdkman2/PackagesDiffLogicTest.java @@ -18,6 +18,7 @@ package com.android.sdkuilib.internal.repository.sdkman2; import com.android.sdklib.SdkConstants; import com.android.sdklib.internal.repository.packages.BrokenPackage; +import com.android.sdklib.internal.repository.packages.FullRevision; import com.android.sdklib.internal.repository.packages.MockAddonPackage; import com.android.sdklib.internal.repository.packages.MockBrokenPackage; import com.android.sdklib.internal.repository.packages.MockEmptyPackage; @@ -1290,7 +1291,6 @@ public class PackagesDiffLogicTest extends TestCase { } public void testBrokenAddon() { - SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); SdkSource src2 = new SdkRepoSource("http://2.example.com/url2", "repo2"); @@ -1383,8 +1383,6 @@ public class PackagesDiffLogicTest extends TestCase { } public void testToolsUpdate() { - // - SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); SdkSource src2 = new SdkRepoSource("http://2.example.com/url2", "repo2"); MockPlatformPackage p1; @@ -1427,6 +1425,327 @@ public class PackagesDiffLogicTest extends TestCase { "-- <NEW, pkg:The addon B from vendor 1, Android API 1, revision 6>\n", getTree(m, false /*displaySortByApi*/)); } + + public void testToolsMinorUpdate() { + // Test: Check a minor revision updates an installed major revision. + + SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); + + m.updateStart(); + m.updateSourcePackages(true /*sortByApi*/, null /*locals*/, new Package[] { + new MockToolPackage(3, 3), // Tools 3.0.0 + new MockPlatformToolPackage(src1, 3), + }); + m.updateSourcePackages(true /*sortByApi*/, src1, new Package[] { + new MockToolPackage(src1, new FullRevision(3, 0, 1), 3), // Tools 3.0.1 + }); + m.updateEnd(true /*sortByApi*/); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3, updated by:Android SDK Tools, revision 3.0.1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 3>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + assertEquals( + "PkgCategorySource <source=Local Packages (no.source), #items=1>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3, updated by:Android SDK Tools, revision 3.0.1>\n" + + "PkgCategorySource <source=repo1 (1.example.com), #items=1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 3>\n", + getTree(m, false /*displaySortByApi*/)); + } + + public void testToolsPreviews() { + // Test: No local tools installed. The remote server has both tools and platforms + // in release and RC versions. + + SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); + + m.updateStart(); + m.updateSourcePackages(true /*sortByApi*/, src1, new Package[] { + new MockToolPackage(src1, new FullRevision(2, 0, 0), 3), // Tools 2 + new MockToolPackage(src1, new FullRevision(4, 0, 0, 1), 3), // Tools 4 rc1 + new MockPlatformToolPackage(src1, new FullRevision(3, 0, 0)), // Plat-T 3 + new MockPlatformToolPackage(src1, new FullRevision(5, 0, 0, 1)), // Plat-T 5 rc1 + }); + m.updateEnd(true /*sortByApi*/); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 2>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 3>\n" + + "PkgCategoryApi <API=TOOLS-PREVIEW, label=Tools (Beta Channel), #items=2>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 4 rc1>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 5 rc1>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + assertEquals( + "PkgCategorySource <source=repo1 (1.example.com), #items=4>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 2>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 4 rc1>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 3>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 5 rc1>\n", + getTree(m, false /*displaySortByApi*/)); + } + + public void testPreviewUpdateInstalledRelease() { + // Test: Local release Tools 3.0.0 installed, server has both a release 3.0.1 available + // and a Tools Preview 4.0.0 rc1 available. + // => v3 is updated by 3.0.1 + // => v4.0.0rc1 does not update 3.0.0, instead it's a separate download. + + SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); + + m.updateStart(); + m.updateSourcePackages(true /*sortByApi*/, null /*locals*/, new Package[] { + new MockToolPackage(3, 3), // tool package has no source defined + new MockPlatformToolPackage(src1, 3), + new MockPlatformPackage(src1, 1, 2, 3), // API 1 + }); + m.updateSourcePackages(true /*sortByApi*/, src1, new Package[] { + new MockToolPackage(src1, 3, 3), // Tools 3 + new MockToolPackage(src1, new FullRevision(3, 0, 1), 3), // Tools 3.0.1 + new MockToolPackage(src1, new FullRevision(4, 0, 0, 1), 3), // Tools 4 rc1 + new MockPlatformToolPackage(src1, new FullRevision(3, 0, 1)), // PT 3.0.1 + new MockPlatformToolPackage(src1, new FullRevision(4, 0, 0, 1)), // PT 4 rc1 + }); + m.updateEnd(true /*sortByApi*/); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3, updated by:Android SDK Tools, revision 3.0.1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 3, updated by:Android SDK Platform-tools, revision 3.0.1>\n" + + "PkgCategoryApi <API=TOOLS-PREVIEW, label=Tools (Beta Channel), #items=2>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 4 rc1>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4 rc1>\n" + + "PkgCategoryApi <API=API 1, label=Android android-1 (API 1), #items=1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + assertEquals( + "PkgCategorySource <source=Local Packages (no.source), #items=1>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3, updated by:Android SDK Tools, revision 3.0.1>\n" + + "PkgCategorySource <source=repo1 (1.example.com), #items=4>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 4 rc1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 3, updated by:Android SDK Platform-tools, revision 3.0.1>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4 rc1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n", + getTree(m, false /*displaySortByApi*/)); + + // Now request to check new items and updates: + // Tools 4 rc1 is greater than the installed Tools 3, but it's a preview so we will NOT + // auto-select it by default even though we requested to select "NEW" packages. We + // want the user to manually opt-in into the rc/preview package. + // However Tools 3 has a 3.0.1 update that we'll auto-select. + m.checkNewUpdateItems(true, true, false, SdkConstants.PLATFORM_LINUX); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- < * INSTALLED, pkg:Android SDK Tools, revision 3, updated by:Android SDK Tools, revision 3.0.1>\n" + + "-- < * INSTALLED, pkg:Android SDK Platform-tools, revision 3, updated by:Android SDK Platform-tools, revision 3.0.1>\n" + + "PkgCategoryApi <API=TOOLS-PREVIEW, label=Tools (Beta Channel), #items=2>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 4 rc1>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4 rc1>\n" + + "PkgCategoryApi <API=API 1, label=Android android-1 (API 1), #items=1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + assertEquals( + "PkgCategorySource <source=Local Packages (no.source), #items=1>\n" + + "-- < * INSTALLED, pkg:Android SDK Tools, revision 3, updated by:Android SDK Tools, revision 3.0.1>\n" + + "PkgCategorySource <source=repo1 (1.example.com), #items=4>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 4 rc1>\n" + + "-- < * INSTALLED, pkg:Android SDK Platform-tools, revision 3, updated by:Android SDK Platform-tools, revision 3.0.1>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4 rc1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n", + getTree(m, false /*displaySortByApi*/)); + + } + + public void testPreviewUpdateInstalledPreview() { + // Test: Local preview Tools 3.0.1rc1 installed, server has both a release 3.0.0 available + // and a Tools Preview 3.0.1 rc2 available. + // => Installed 3.0.1rc1 can be updated by 3.0.1rc2 + // => There's a separate "new" download for 3.0.0, not installed and NOT updating 3.0.1rc1. + + SdkSource src1 = new SdkRepoSource("http://1.example.com/url1", "repo1"); + + m.updateStart(); + m.updateSourcePackages(true /*sortByApi*/, null /*locals*/, new Package[] { + new MockToolPackage(src1, new FullRevision(3, 0, 1, 1), 4), // T 3.0.1rc1 + new MockPlatformToolPackage(src1, new FullRevision(4, 0, 1, 1)), // PT 4.0.1rc1 + new MockPlatformPackage(src1, 1, 2, 3), // API 1 + }); + m.updateSourcePackages(true /*sortByApi*/, src1, new Package[] { + new MockToolPackage(src1, new FullRevision(3, 0, 0), 4), // T 3.0.0 + new MockToolPackage(src1, new FullRevision(3, 0, 1, 2), 4), // T 3.0.1rc2 + new MockPlatformToolPackage(src1, new FullRevision(4, 0, 0)), // PT 4.0.0 + new MockPlatformToolPackage(src1, new FullRevision(4, 0, 1, 2)), // PT 4.0.1 rc2 + }); + m.updateEnd(true /*sortByApi*/); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 3>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4>\n" + + "PkgCategoryApi <API=TOOLS-PREVIEW, label=Tools (Beta Channel), #items=2>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3.0.1 rc1, updated by:Android SDK Tools, revision 3.0.1 rc2>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1 rc1, updated by:Android SDK Platform-tools, revision 4.0.1 rc2>\n" + + "PkgCategoryApi <API=API 1, label=Android android-1 (API 1), #items=1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + assertEquals( + "PkgCategorySource <source=repo1 (1.example.com), #items=5>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 3>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3.0.1 rc1, updated by:Android SDK Tools, revision 3.0.1 rc2>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1 rc1, updated by:Android SDK Platform-tools, revision 4.0.1 rc2>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n", + getTree(m, false /*displaySortByApi*/)); + + // Auto select new and update items. In this case: + // - the previews have updates available. + // - we're not selecting the non-installed "3.0" version that is older than the + // currently installed "3.0.1rc1" version since that would be a downgrade. + m.checkNewUpdateItems(true, true, false, SdkConstants.PLATFORM_LINUX); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 3>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4>\n" + + "PkgCategoryApi <API=TOOLS-PREVIEW, label=Tools (Beta Channel), #items=2>\n" + + "-- < * INSTALLED, pkg:Android SDK Tools, revision 3.0.1 rc1, updated by:Android SDK Tools, revision 3.0.1 rc2>\n" + + "-- < * INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1 rc1, updated by:Android SDK Platform-tools, revision 4.0.1 rc2>\n" + + "PkgCategoryApi <API=API 1, label=Android android-1 (API 1), #items=1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + assertEquals( + "PkgCategorySource <source=repo1 (1.example.com), #items=5>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 3>\n" + + "-- < * INSTALLED, pkg:Android SDK Tools, revision 3.0.1 rc1, updated by:Android SDK Tools, revision 3.0.1 rc2>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4>\n" + + "-- < * INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1 rc1, updated by:Android SDK Platform-tools, revision 4.0.1 rc2>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n", + getTree(m, false /*displaySortByApi*/)); + + // ----- + + // Now simulate that the server has a final package (3.0.1) to replace the + // installed 3.0.1rc1 package. It's not installed yet, just available. + // - A new 3.0.1 will be available. + // - The server no longer lists the RC since there's a final package, yet it is + // still locally installed. + // - The 3.0.1 rc1 is not listed as having an update, since we treat the previews + // separately. TODO: consider having the 3.0.1 show up as both a new item /and/ + // as an update to the 3.0.1rc1. That may have some other side effects. + + m.uncheckAllItems(); + m.updateStart(); + m.updateSourcePackages(true /*sortByApi*/, null /*locals*/, new Package[] { + new MockToolPackage(src1, new FullRevision(3, 0, 1, 1), 4), // T 3.0.1rc1 + new MockPlatformToolPackage(src1, new FullRevision(4, 0, 1, 1)), // PT 4.0.1rc1 + new MockPlatformPackage(src1, 1, 2, 3), // API 1 + }); + m.updateSourcePackages(true /*sortByApi*/, src1, new Package[] { + new MockToolPackage(src1, new FullRevision(3, 0, 1), 4), // T 3.0.1 + new MockPlatformToolPackage(src1, new FullRevision(4, 0, 1)), // PT 4.0.1 + }); + m.updateEnd(true /*sortByApi*/); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 3.0.1>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4.0.1>\n" + + "PkgCategoryApi <API=TOOLS-PREVIEW, label=Tools (Beta Channel), #items=2>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3.0.1 rc1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1 rc1>\n" + + "PkgCategoryApi <API=API 1, label=Android android-1 (API 1), #items=1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + assertEquals( + "PkgCategorySource <source=repo1 (1.example.com), #items=5>\n" + + "-- <NEW, pkg:Android SDK Tools, revision 3.0.1>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3.0.1 rc1>\n" + + "-- <NEW, pkg:Android SDK Platform-tools, revision 4.0.1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1 rc1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n", + getTree(m, false /*displaySortByApi*/)); + + // Auto select new and update items. In this case the new items are considered + // updates and yet new at the same time. + // Test by selecting new items only: + m.checkNewUpdateItems(true, false, false, SdkConstants.PLATFORM_LINUX); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- < * NEW, pkg:Android SDK Tools, revision 3.0.1>\n" + + "-- < * NEW, pkg:Android SDK Platform-tools, revision 4.0.1>\n" + + "PkgCategoryApi <API=TOOLS-PREVIEW, label=Tools (Beta Channel), #items=2>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3.0.1 rc1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1 rc1>\n" + + "PkgCategoryApi <API=API 1, label=Android android-1 (API 1), #items=1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + + // Test by selecting update items only: + m.uncheckAllItems(); + m.checkNewUpdateItems(false, true, false, SdkConstants.PLATFORM_LINUX); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- < * NEW, pkg:Android SDK Tools, revision 3.0.1>\n" + + "-- < * NEW, pkg:Android SDK Platform-tools, revision 4.0.1>\n" + + "PkgCategoryApi <API=TOOLS-PREVIEW, label=Tools (Beta Channel), #items=2>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3.0.1 rc1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1 rc1>\n" + + "PkgCategoryApi <API=API 1, label=Android android-1 (API 1), #items=1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + + + // ----- + + // Now simulate that the user has installed the final package (3.0.1) to replace the + // installed 3.0.1rc1 package. + // - The 3.0.1 is installed. + // - The 3.0.1 rc1 isn't listed anymore by the server. + + m.uncheckAllItems(); + m.updateStart(); + m.updateSourcePackages(true /*sortByApi*/, null /*locals*/, new Package[] { + new MockToolPackage(src1, new FullRevision(3, 0, 1), 4), // T 3.0.1 + new MockPlatformToolPackage(src1, new FullRevision(4, 0, 1)), // PT 4.0.1 + new MockPlatformPackage(src1, 1, 2, 3), // API 1 + }); + m.updateSourcePackages(true /*sortByApi*/, src1, new Package[] { + new MockToolPackage(src1, new FullRevision(3, 0, 1), 4), // T 3.0.1 + new MockPlatformToolPackage(src1, new FullRevision(4, 0, 1)), // PT 4.0.1 + }); + m.updateEnd(true /*sortByApi*/); + + assertEquals( + "PkgCategoryApi <API=TOOLS, label=Tools, #items=2>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3.0.1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1>\n" + + "PkgCategoryApi <API=API 1, label=Android android-1 (API 1), #items=1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n" + + "PkgCategoryApi <API=EXTRAS, label=Extras, #items=0>\n", + getTree(m, true /*displaySortByApi*/)); + assertEquals( + "PkgCategorySource <source=repo1 (1.example.com), #items=3>\n" + + "-- <INSTALLED, pkg:Android SDK Tools, revision 3.0.1>\n" + + "-- <INSTALLED, pkg:Android SDK Platform-tools, revision 4.0.1>\n" + + "-- <INSTALLED, pkg:SDK Platform Android android-1, API 1, revision 2>\n", + getTree(m, false /*displaySortByApi*/)); + } + + + // ---- /** |