From 87107c5cb1fb5fdafdaa94460fb6797af60fcde9 Mon Sep 17 00:00:00 2001 From: Raphael Moll Date: Thu, 19 Apr 2012 16:27:03 -0700 Subject: 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 --- .../sdklib/src/com/android/sdklib/SdkManager.java | 2 +- .../internal/repository/packages/DocPackage.java | 10 +- .../internal/repository/packages/ExtraPackage.java | 8 +- .../internal/repository/packages/FullRevision.java | 187 ++++++++++++++++++++ .../repository/packages/FullRevisionPackage.java | 190 +++++++++++++++++++++ .../repository/packages/IFullRevisionProvider.java | 43 +++++ .../packages/IPreviewVersionProvider.java | 32 ---- .../repository/packages/MajorRevision.java | 37 ++++ .../internal/repository/packages/Package.java | 55 +++--- .../repository/packages/PlatformPackage.java | 8 +- .../repository/packages/PlatformToolPackage.java | 37 +++- .../repository/packages/PreviewVersion.java | 185 -------------------- .../repository/packages/PreviewVersionPackage.java | 158 ----------------- .../repository/packages/SamplePackage.java | 8 +- .../repository/packages/SourcePackage.java | 8 +- .../repository/packages/SystemImagePackage.java | 6 +- .../internal/repository/packages/ToolPackage.java | 37 +++- .../com/android/sdklib/repository/PkgProps.java | 15 +- .../packages/FullRevisionPackageTest.java | 60 +++++++ .../repository/packages/FullRevisionTest.java | 107 ++++++++++++ .../repository/packages/MockEmptyPackage.java | 2 +- .../packages/MockPlatformToolPackage.java | 14 +- .../repository/packages/MockToolPackage.java | 16 +- .../internal/repository/packages/PackageTest.java | 4 +- .../repository/packages/PreviewVersionTest.java | 107 ------------ 25 files changed, 771 insertions(+), 565 deletions(-) create mode 100755 sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java create mode 100755 sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java create mode 100755 sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/IFullRevisionProvider.java delete mode 100755 sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/IPreviewVersionProvider.java create mode 100755 sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java delete mode 100755 sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersion.java delete mode 100755 sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersionPackage.java create mode 100755 sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionPackageTest.java create mode 100755 sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionTest.java delete mode 100755 sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PreviewVersionTest.java (limited to 'sdkmanager/libs/sdklib') 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/FullRevision.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java new file mode 100755 index 0000000..f902001 --- /dev/null +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java @@ -0,0 +1,187 @@ +/* + * 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; + + +/** + * Package multi-part revision number composed of a tuple + * (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 FullRevision implements Comparable { + + public static final int IMPLICIT_MINOR_REV = 0; + public static final int IMPLICIT_MICRO_REV = 0; + public static final int NOT_A_PREVIEW = 0; + + private final int mMajor; + private final int mMinor; + private final int mMicro; + private final int mPreview; + + public FullRevision(int major) { + this(major, 0, 0); + } + + public FullRevision(int major, int minor, int micro) { + this(major, minor, micro, NOT_A_PREVIEW); + } + + public FullRevision(int major, int minor, int micro, int preview) { + mMajor = major; + mMinor = minor; + mMicro = micro; + mPreview = preview; + } + + public int getMajor() { + return mMajor; + } + + public int getMinor() { + return mMinor; + } + + public int getMicro() { + return mMicro; + } + + public boolean isPreview() { + return mPreview > NOT_A_PREVIEW; + } + + public int getPreview() { + return mPreview; + } + + /** + * Returns the version in a fixed format major.minor.micro + * with an optional "rc preview#". For example it would + * return "18.0.0", "18.1.0" or "18.1.2 rc5". + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(mMajor) + .append('.').append(mMinor) + .append('.').append(mMicro); + + if (mPreview != NOT_A_PREVIEW) { + sb.append(" rc").append(mPreview); + } + + return sb.toString(); + } + + /** + * Returns the version in a dynamic format "major.minor.micro rc#". + * This is similar to {@link #toString()} except it omits minor, micro + * or preview versions when they are zero. + * For example it would return "18 rc1" instead of "18.0.0 rc1", + * or "18.1 rc2" instead of "18.1.0 rc2". + */ + public String toShortString() { + StringBuilder sb = new StringBuilder(); + sb.append(mMajor); + if (mMinor > 0 || mMicro > 0) { + sb.append('.').append(mMinor); + } + if (mMicro > 0) { + sb.append('.').append(mMicro); + } + if (mPreview != NOT_A_PREVIEW) { + sb.append(" rc").append(mPreview); + } + + return sb.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + mMajor; + result = prime * result + mMinor; + result = prime * result + mMicro; + result = prime * result + mPreview; + return result; + } + + @Override + public boolean equals(Object rhs) { + if (this == rhs) { + return true; + } + if (rhs == null) { + return false; + } + if (!(rhs instanceof FullRevision)) { + return false; + } + FullRevision other = (FullRevision) rhs; + if (mMajor != other.mMajor) { + return false; + } + if (mMinor != other.mMinor) { + return false; + } + if (mMicro != other.mMicro) { + return false; + } + if (mPreview != other.mPreview) { + return false; + } + return true; + } + + /** + * 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 + * lack of preview number was "+inf": + * "18.1.2 rc5" => "18.1.2.5" so its less than "18.1.2.+INF" but more than "18.1.1.0" + * and more than "18.1.2.4" + */ + @Override + public int compareTo(FullRevision rhs) { + int delta = mMajor - rhs.mMajor; + if (delta != 0) { + return delta; + } + + delta = mMinor - rhs.mMinor; + if (delta != 0) { + return delta; + } + + delta = mMicro - rhs.mMicro; + if (delta != 0) { + return delta; + } + + int p1 = mPreview == NOT_A_PREVIEW ? Integer.MAX_VALUE : mPreview; + int p2 = rhs.mPreview == NOT_A_PREVIEW ? Integer.MAX_VALUE : rhs.mPreview; + delta = p1 - p2; + return delta; + } + + +} diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java new file mode 100755 index 0000000..9024af5 --- /dev/null +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevisionPackage.java @@ -0,0 +1,190 @@ +/* + * 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 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; + +import org.w3c.dom.Node; + +import java.util.Map; +import java.util.Properties; + +/** + * 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 FullRevisionPackage extends Package + implements IFullRevisionProvider { + + private final FullRevision mPreviewVersion; + + /** + * Creates a new package from the attributes and elements of the given XML node. + * This constructor should throw an exception if the package cannot be created. + * + * @param source The {@link SdkSource} where this is loaded from. + * @param packageNode The XML element being parsed. + * @param nsUri The namespace URI of the originating XML document, to be able to deal with + * parameters that vary according to the originating XML schema. + * @param licenses The licenses loaded from the XML originating document. + */ + FullRevisionPackage(SdkSource source, + Node packageNode, + String nsUri, + Map licenses) { + super(source, packageNode, nsUri, licenses); + + // The major revision is in Package.getRevision() + int majorRevision = super.getRevision().getMajor(); + int minorRevision = XmlParserUtils.getXmlInt(packageNode, + SdkRepoConstants.NODE_MINOR_REV, + FullRevision.IMPLICIT_MINOR_REV); + int microRevision = XmlParserUtils.getXmlInt(packageNode, + SdkRepoConstants.NODE_MICRO_REV, + FullRevision.IMPLICIT_MICRO_REV); + int preview = XmlParserUtils.getXmlInt(packageNode, + SdkRepoConstants.NODE_PREVIEW, + FullRevision.NOT_A_PREVIEW); + + mPreviewVersion = new FullRevision(majorRevision, minorRevision, microRevision, preview); + } + + /** + * Manually create a new package with one archive and the given attributes. + * This is used to create packages from local directories in which case there must be + * one archive which URL is the actual target location. + *

+ * Properties from props are used first when possible, e.g. if props is non null. + *

+ * By design, this creates a package with one and only one archive. + */ + public FullRevisionPackage( + SdkSource source, + Properties props, + int revision, + String license, + String description, + String descUrl, + Os archiveOs, + Arch archiveArch, + String archiveOsPath) { + super(source, props, revision, license, description, descUrl, + archiveOs, archiveArch, archiveOsPath); + + // The major revision is in Package.getRevision() + int majorRevision = super.getRevision().getMajor(); + int minorRevision = Integer.parseInt( + getProperty(props, + PkgProps.PKG_MINOR_REV, + Integer.toString(FullRevision.IMPLICIT_MINOR_REV))); + int microRevision = Integer.parseInt( + getProperty(props, + PkgProps.PKG_MICRO_REV, + Integer.toString(FullRevision.IMPLICIT_MINOR_REV))); + int preview = Integer.parseInt( + getProperty(props, + PkgProps.PKG_PREVIEW_REV, + Integer.toString(FullRevision.NOT_A_PREVIEW))); + + mPreviewVersion = new FullRevision(majorRevision, minorRevision, microRevision, preview); + } + + @Override + public FullRevision getRevision() { + return mPreviewVersion; + } + + @Override + public void saveProperties(Properties props) { + super.saveProperties(props); + + 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())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((mPreviewVersion == null) ? 0 : mPreviewVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (!(obj instanceof FullRevisionPackage)) { + return false; + } + FullRevisionPackage other = (FullRevisionPackage) obj; + if (mPreviewVersion == null) { + if (other.mPreviewVersion != null) { + return false; + } + } else if (!mPreviewVersion.equals(other.mPreviewVersion)) { + return false; + } + return true; + } + + /** + * Computes whether the given package is a suitable update for the current package. + *

+ * A specific case here is that a release package can update a preview, whereas + * a preview can only update another preview. + *

+ * {@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. + *

+ * This interface is a tag. It indicates that {@link Package#getRevision()} returns a + * {@link FullRevision} instead of a limited {@link MajorRevision}.
+ * 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. + *

+ * 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/IPreviewVersionProvider.java deleted file mode 100755 index 5a9f8a0..0000000 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/IPreviewVersionProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.sdklib.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. - */ -public interface IPreviewVersionProvider { - - /** - * Returns a {@link PreviewVersion} for this package. Never null. - */ - public abstract @NonNull PreviewVersion getPreviewVersion(); -} diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java new file mode 100755 index 0000000..2678b1f --- /dev/null +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/MajorRevision.java @@ -0,0 +1,37 @@ +/* + * 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; + + +/** + * Package revision number composed of a single major revision. + *

+ * Contrary to a {@link FullRevision}, a {@link MajorRevision} does not + * provide minor, micro and preview revision numbers -- these are all + * set to zero. + */ +public class MajorRevision extends FullRevision { + + public MajorRevision(int major) { + super(major, 0, 0); + } + + @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 { - 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(SdkSource source, Node packageNode, String nsUri, Map 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 { 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 { * 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 { * 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 { 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 { *

* 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 { } // 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 { } /** - * Returns an ordering like this:
+ * Returns an ordering suitable for display like this:
* - Tools
* - Platform-Tools
* - Docs.
@@ -668,6 +669,10 @@ public abstract class Package implements IDescription, Comparable { * 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)}. *

+ * 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. + *

* 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. *

@@ -679,7 +684,8 @@ public abstract class Package implements IDescription, Comparable { 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 { // 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 { // 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 { 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 { } 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. *

* {@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 and 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/PreviewVersion.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersion.java deleted file mode 100755 index a75eb4b..0000000 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersion.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * 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; - - -/** - * Package multi-part revision number composed of a tuple - * (major.minor.micro) and an optional preview revision - * (the lack of a preview number indicates it's not a preview - * but a final package.) - */ -public class PreviewVersion implements Comparable { - - public static final int IMPLICIT_MINOR_REV = 0; - public static final int IMPLICIT_MICRO_REV = 0; - public static final int NOT_A_PREVIEW = 0; - - private final int mMajor; - private final int mMinor; - private final int mMicro; - private final int mPreview; - - public PreviewVersion(int major) { - this(major, 0, 0); - } - - public PreviewVersion(int major, int minor, int micro) { - this(major, minor, micro, NOT_A_PREVIEW); - } - - public PreviewVersion(int major, int minor, int micro, int preview) { - mMajor = major; - mMinor = minor; - mMicro = micro; - mPreview = preview; - } - - public int getMajor() { - return mMajor; - } - - public int getMinor() { - return mMinor; - } - - public int getMicro() { - return mMicro; - } - - public boolean isPreview() { - return mPreview > NOT_A_PREVIEW; - } - - public int getPreview() { - return mPreview; - } - - /** - * Returns the version in a fixed format major.minor.micro - * with an optional "rc preview#". For example it would - * return "18.0.0", "18.1.0" or "18.1.2 rc5". - */ - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(mMajor) - .append('.').append(mMinor) - .append('.').append(mMicro); - - if (mPreview != NOT_A_PREVIEW) { - sb.append(" rc").append(mPreview); - } - - return sb.toString(); - } - - /** - * Returns the version in a dynamic format "major.minor.micro rc#". - * This is similar to {@link #toString()} except it omits minor, micro - * or preview versions when they are zero. - * For example it would return "18 rc1" instead of "18.0.0 rc1", - * or "18.1 rc2" instead of "18.1.0 rc2". - */ - public String toShortString() { - StringBuilder sb = new StringBuilder(); - sb.append(mMajor); - if (mMinor > 0 || mMicro > 0) { - sb.append('.').append(mMinor); - } - if (mMicro > 0) { - sb.append('.').append(mMicro); - } - if (mPreview != NOT_A_PREVIEW) { - sb.append(" rc").append(mPreview); - } - - return sb.toString(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + mMajor; - result = prime * result + mMinor; - result = prime * result + mMicro; - result = prime * result + mPreview; - return result; - } - - @Override - public boolean equals(Object rhs) { - if (this == rhs) { - return true; - } - if (rhs == null) { - return false; - } - if (!(rhs instanceof PreviewVersion)) { - return false; - } - PreviewVersion other = (PreviewVersion) rhs; - if (mMajor != other.mMajor) { - return false; - } - if (mMinor != other.mMinor) { - return false; - } - if (mMicro != other.mMicro) { - return false; - } - if (mPreview != other.mPreview) { - return false; - } - return true; - } - - /** - * Trivial comparision 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 - * lack of preview number was "+inf": - * "18.1.2 rc5" => "18.1.2.5" so its less than "18.1.2.+INF" but more than "18.1.1.0" - * and more than "18.1.2.4" - */ - @Override - public int compareTo(PreviewVersion rhs) { - int delta = mMajor - rhs.mMajor; - if (delta != 0) { - return delta; - } - - delta = mMinor - rhs.mMinor; - if (delta != 0) { - return delta; - } - - delta = mMicro - rhs.mMicro; - if (delta != 0) { - return delta; - } - - int p1 = mPreview == NOT_A_PREVIEW ? Integer.MAX_VALUE : mPreview; - int p2 = rhs.mPreview == NOT_A_PREVIEW ? Integer.MAX_VALUE : rhs.mPreview; - delta = p1 - p2; - 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/PreviewVersionPackage.java deleted file mode 100755 index eac548e..0000000 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/PreviewVersionPackage.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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 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.sources.SdkSource; -import com.android.sdklib.repository.PkgProps; -import com.android.sdklib.repository.SdkRepoConstants; - -import org.w3c.dom.Node; - -import java.util.Map; -import java.util.Properties; - -/** - * Represents a package in an SDK repository that has a {@link PreviewVersion}, - * which is a multi-part revision number (major.minor.micro) and an optional preview revision. - */ -public abstract class PreviewVersionPackage extends Package - implements IPreviewVersionProvider { - - private final PreviewVersion mPreviewVersion; - - /** - * Creates a new package from the attributes and elements of the given XML node. - * This constructor should throw an exception if the package cannot be created. - * - * @param source The {@link SdkSource} where this is loaded from. - * @param packageNode The XML element being parsed. - * @param nsUri The namespace URI of the originating XML document, to be able to deal with - * parameters that vary according to the originating XML schema. - * @param licenses The licenses loaded from the XML originating document. - */ - PreviewVersionPackage(SdkSource source, - Node packageNode, - String nsUri, - Map licenses) { - super(source, packageNode, nsUri, licenses); - - // The major revision is getRevision(), already handled by Package. - - int minorRevision = XmlParserUtils.getXmlInt(packageNode, - SdkRepoConstants.NODE_MINOR_REV, - PreviewVersion.IMPLICIT_MINOR_REV); - int microRevision = XmlParserUtils.getXmlInt(packageNode, - SdkRepoConstants.NODE_MICRO_REV, - PreviewVersion.IMPLICIT_MICRO_REV); - int preview = XmlParserUtils.getXmlInt(packageNode, - SdkRepoConstants.NODE_PREVIEW, - PreviewVersion.NOT_A_PREVIEW); - - mPreviewVersion = new PreviewVersion(getRevision(), minorRevision, microRevision, preview); - } - - /** - * Manually create a new package with one archive and the given attributes. - * This is used to create packages from local directories in which case there must be - * one archive which URL is the actual target location. - *

- * Properties from props are used first when possible, e.g. if props is non null. - *

- * By design, this creates a package with one and only one archive. - */ - public PreviewVersionPackage( - SdkSource source, - Properties props, - int revision, - String license, - String description, - String descUrl, - Os archiveOs, - Arch archiveArch, - String archiveOsPath) { - super(source, props, revision, license, description, descUrl, - archiveOs, archiveArch, archiveOsPath); - - // The major revision is getRevision(), already handled by Package. - - int minorRevision = Integer.parseInt( - getProperty(props, - PkgProps.PKG_MINOR_REV, - Integer.toString(PreviewVersion.IMPLICIT_MINOR_REV))); - int microRevision = Integer.parseInt( - getProperty(props, - PkgProps.PKG_MICRO_REV, - Integer.toString(PreviewVersion.IMPLICIT_MINOR_REV))); - int preview = Integer.parseInt( - getProperty(props, - PkgProps.PKG_PREVIEW_REV, - Integer.toString(PreviewVersion.NOT_A_PREVIEW))); - - mPreviewVersion = new PreviewVersion(getRevision(), minorRevision, microRevision, preview); - } - - @Override @NonNull - public PreviewVersion getPreviewVersion() { - return mPreviewVersion; - } - - @Override - 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_PREVIEW_REV, Integer.toString(mPreviewVersion.getPreview())); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((mPreviewVersion == null) ? 0 : mPreviewVersion.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof PreviewVersionPackage)) { - return false; - } - PreviewVersionPackage other = (PreviewVersionPackage) obj; - if (mPreviewVersion == null) { - if (other.mPreviewVersion != null) { - return false; - } - } else if (!mPreviewVersion.equals(other.mPreviewVersion)) { - return false; - } - return true; - } -} 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. *

* {@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 and 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 list = new ArrayList(); + + 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/FullRevisionTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionTest.java new file mode 100755 index 0000000..97e76bb --- /dev/null +++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionTest.java @@ -0,0 +1,107 @@ +/* + * 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 junit.framework.TestCase; + +public class FullRevisionTest extends TestCase { + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + public final void testFullRevision() { + FullRevision p = new FullRevision(5); + assertEquals(5, p.getMajor()); + 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 FullRevision(5, 0, 0, 6); + assertEquals(5, p.getMajor()); + 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 FullRevision(6, 7, 0); + assertEquals(6, p.getMajor()); + assertEquals(7, p.getMinor()); + assertEquals(0, p.getMicro()); + assertEquals(0, p.getPreview()); + assertFalse (p.isPreview()); + assertEquals("6.7", p.toShortString()); + assertEquals("6.7.0", p.toString()); + + p = new FullRevision(10, 11, 12, FullRevision.NOT_A_PREVIEW); + assertEquals(10, p.getMajor()); + assertEquals(11, p.getMinor()); + assertEquals(12, p.getMicro()); + assertEquals(0, p.getPreview()); + assertFalse (p.isPreview()); + assertEquals("10.11.12", p.toShortString()); + assertEquals("10.11.12", p.toString()); + + p = new FullRevision(10, 11, 12, 13); + assertEquals(10, p.getMajor()); + assertEquals(11, p.getMinor()); + assertEquals(12, p.getMicro()); + assertEquals(13, p.getPreview()); + assertTrue (p.isPreview()); + assertEquals("10.11.12 rc13", p.toShortString()); + assertEquals("10.11.12 rc13", p.toString()); + } + + public final void testCompareTo() { + 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 + + assertFalse(y5.equals(p5)); // 5.0.0-0 != 5.1.0-0 + assertFalse(g5.equals(p5)); // 5.1.0-6 != 5.1.0-0 + assertTrue (s4.compareTo(i4) == 0); // 4.0.0-0 == 4.0.0-0 + assertTrue (s4.compareTo(y5) < 0); // 4.0.0-0 < 5.0.0-0 + assertTrue (y5.compareTo(y5) == 0); // 5.0.0-0 == 5.0.0-0 + assertTrue (y5.compareTo(p5) < 0); // 5.0.0-0 < 5.1.0-0 + assertTrue (o5.compareTo(y5) < 0); // 5.0.0-7 < 5.0.0-0 + assertTrue (p5.compareTo(p5) == 0); // 5.1.0-0 == 5.1.0-0 + assertTrue (c5.compareTo(p5) < 0); // 5.1.0-6 < 5.1.0-0 + assertTrue (p5.compareTo(c5) > 0); // 5.1.0-0 > 5.1.0-6 + assertTrue (p5.compareTo(o5) > 0); // 5.1.0-0 > 5.0.0-7 + assertTrue (c5.compareTo(o5) > 0); // 5.1.0-6 > 5.0.0-7 + assertTrue (o5.compareTo(o5) == 0); // 5.0.0-7 > 5.0.0-7 + } + +} 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 { *

* 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/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PreviewVersionTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PreviewVersionTest.java deleted file mode 100755 index daa4704..0000000 --- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/PreviewVersionTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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 junit.framework.TestCase; - -public class PreviewVersionTest extends TestCase { - - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public final void testPreviewVersion() { - PreviewVersion p = new PreviewVersion(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()); - assertFalse (p.isPreview()); - assertEquals("5", p.toShortString()); - assertEquals("5.0.0", p.toString()); - - p = new PreviewVersion(5, 0, 0, 6); - assertEquals(5, p.getMajor()); - assertEquals(PreviewVersion.IMPLICIT_MINOR_REV, p.getMinor()); - assertEquals(PreviewVersion.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); - assertEquals(6, p.getMajor()); - assertEquals(7, p.getMinor()); - assertEquals(0, p.getMicro()); - assertEquals(0, p.getPreview()); - assertFalse (p.isPreview()); - assertEquals("6.7", p.toShortString()); - assertEquals("6.7.0", p.toString()); - - p = new PreviewVersion(10, 11, 12, PreviewVersion.NOT_A_PREVIEW); - assertEquals(10, p.getMajor()); - assertEquals(11, p.getMinor()); - assertEquals(12, p.getMicro()); - assertEquals(0, p.getPreview()); - assertFalse (p.isPreview()); - assertEquals("10.11.12", p.toShortString()); - assertEquals("10.11.12", p.toString()); - - p = new PreviewVersion(10, 11, 12, 13); - assertEquals(10, p.getMajor()); - assertEquals(11, p.getMinor()); - assertEquals(12, p.getMicro()); - assertEquals(13, p.getPreview()); - assertTrue (p.isPreview()); - assertEquals("10.11.12 rc13", p.toShortString()); - assertEquals("10.11.12 rc13", p.toString()); - } - - 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); - - assertEquals(s4, i4); // 4.0.0-0 == 4.0.0-0 - assertEquals(g5, c5); // 5.1.0-6 == 5.1.0-6 - - assertFalse(y5.equals(p5)); // 5.0.0-0 != 5.1.0-0 - assertFalse(g5.equals(p5)); // 5.1.0-6 != 5.1.0-0 - assertTrue (s4.compareTo(i4) == 0); // 4.0.0-0 == 4.0.0-0 - assertTrue (s4.compareTo(y5) < 0); // 4.0.0-0 < 5.0.0-0 - assertTrue (y5.compareTo(y5) == 0); // 5.0.0-0 == 5.0.0-0 - assertTrue (y5.compareTo(p5) < 0); // 5.0.0-0 < 5.1.0-0 - assertTrue (o5.compareTo(y5) < 0); // 5.0.0-7 < 5.0.0-0 - assertTrue (p5.compareTo(p5) == 0); // 5.1.0-0 == 5.1.0-0 - assertTrue (c5.compareTo(p5) < 0); // 5.1.0-6 < 5.1.0-0 - assertTrue (p5.compareTo(c5) > 0); // 5.1.0-0 > 5.1.0-6 - assertTrue (p5.compareTo(o5) > 0); // 5.1.0-0 > 5.0.0-7 - assertTrue (c5.compareTo(o5) > 0); // 5.1.0-6 > 5.0.0-7 - assertTrue (o5.compareTo(o5) == 0); // 5.0.0-7 > 5.0.0-7 - } - -} -- cgit v1.1