aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2012-11-26 13:29:42 -0800
committerGerrit Code Review <noreply-gerritcodereview@google.com>2012-11-26 13:29:42 -0800
commit6a8afbef9e33a52728e5d19c7347cd073bc860cb (patch)
tree07566ca933f3ebc068b3dcbf773db400b0ac7ec5 /sdkmanager/libs
parent8023be9de57693fbb87aa20c6d1a28eb0c8e439b (diff)
parent9093160c8aa3e3832c4db09f57f640055b964bdb (diff)
downloadsdk-6a8afbef9e33a52728e5d19c7347cd073bc860cb.zip
sdk-6a8afbef9e33a52728e5d19c7347cd073bc860cb.tar.gz
sdk-6a8afbef9e33a52728e5d19c7347cd073bc860cb.tar.bz2
Merge "TaskHelper: properly parse Pkg.Revision property."
Diffstat (limited to 'sdkmanager/libs')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/packages/FullRevision.java25
-rwxr-xr-xsdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/packages/FullRevisionTest.java12
2 files changed, 37 insertions, 0 deletions
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
index 4c4387b..715028e 100755
--- 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
@@ -169,6 +169,31 @@ public class FullRevision implements Comparable<FullRevision> {
return sb.toString();
}
+ /**
+ * Returns the version number as an integer array, in the form
+ * [major, minor, micro] or [major, minor, micro, preview].
+ *
+ * This is useful to initialize an instance of
+ * {@code org.apache.tools.ant.util.DeweyDecimal} using a
+ * {@link FullRevision}.
+ *
+ * @param includePreview If true the output will contain 4 fields
+ * to include the preview number (even if 0.) If false the output
+ * will contain only 3 fields (major, minor and micro.)
+ * @return A new int array, never null, with either 3 or 4 fields.
+ */
+ public int[] toIntArray(boolean includePreview) {
+ int size = includePreview ? 4 : 3;
+ int[] result = new int[size];
+ result[0] = mMajor;
+ result[1] = mMinor;
+ result[2] = mMicro;
+ if (result.length > 3) {
+ result[3] = mPreview;
+ }
+ return result;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
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
index d072d05..07e8186 100755
--- 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
@@ -16,6 +16,8 @@
package com.android.sdklib.internal.repository.packages;
+import java.util.Arrays;
+
import junit.framework.TestCase;
public class FullRevisionTest extends TestCase {
@@ -31,6 +33,8 @@ public class FullRevisionTest extends TestCase {
assertEquals(p, FullRevision.parseRevision("5"));
assertEquals("5.0.0", p.toString());
assertEquals(p, FullRevision.parseRevision("5.0.0"));
+ assertEquals("[5, 0, 0]", Arrays.toString(p.toIntArray(false /*includePreview*/)));
+ assertEquals("[5, 0, 0, 0]", Arrays.toString(p.toIntArray(true /*includePreview*/)));
p = new FullRevision(5, 0, 0, 6);
assertEquals(5, p.getMajor());
@@ -42,6 +46,8 @@ public class FullRevisionTest extends TestCase {
assertEquals(p, FullRevision.parseRevision("5 rc6"));
assertEquals("5.0.0 rc6", p.toString());
assertEquals(p, FullRevision.parseRevision("5.0.0 rc6"));
+ assertEquals("[5, 0, 0]", Arrays.toString(p.toIntArray(false /*includePreview*/)));
+ assertEquals("[5, 0, 0, 6]", Arrays.toString(p.toIntArray(true /*includePreview*/)));
p = new FullRevision(6, 7, 0);
assertEquals(6, p.getMajor());
@@ -53,6 +59,8 @@ public class FullRevisionTest extends TestCase {
assertEquals(p, FullRevision.parseRevision("6.7"));
assertEquals("6.7.0", p.toString());
assertEquals(p, FullRevision.parseRevision("6.7.0"));
+ assertEquals("[6, 7, 0]", Arrays.toString(p.toIntArray(false /*includePreview*/)));
+ assertEquals("[6, 7, 0, 0]", Arrays.toString(p.toIntArray(true /*includePreview*/)));
p = new FullRevision(10, 11, 12, FullRevision.NOT_A_PREVIEW);
assertEquals(10, p.getMajor());
@@ -63,6 +71,8 @@ public class FullRevisionTest extends TestCase {
assertEquals("10.11.12", p.toShortString());
assertEquals("10.11.12", p.toString());
assertEquals(p, FullRevision.parseRevision("10.11.12"));
+ assertEquals("[10, 11, 12]", Arrays.toString(p.toIntArray(false /*includePreview*/)));
+ assertEquals("[10, 11, 12, 0]", Arrays.toString(p.toIntArray(true /*includePreview*/)));
p = new FullRevision(10, 11, 12, 13);
assertEquals(10, p.getMajor());
@@ -76,6 +86,8 @@ public class FullRevisionTest extends TestCase {
assertEquals(p, FullRevision.parseRevision(" 10.11.12 rc13"));
assertEquals(p, FullRevision.parseRevision("10.11.12 rc13 "));
assertEquals(p, FullRevision.parseRevision(" 10.11.12 rc13 "));
+ assertEquals("[10, 11, 12]", Arrays.toString(p.toIntArray(false /*includePreview*/)));
+ assertEquals("[10, 11, 12, 13]", Arrays.toString(p.toIntArray(true /*includePreview*/)));
}
public final void testParseError() {