aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--anttasks/src/com/android/ant/TaskHelper.java18
-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
3 files changed, 46 insertions, 9 deletions
diff --git a/anttasks/src/com/android/ant/TaskHelper.java b/anttasks/src/com/android/ant/TaskHelper.java
index fe154cf..43ea33a 100644
--- a/anttasks/src/com/android/ant/TaskHelper.java
+++ b/anttasks/src/com/android/ant/TaskHelper.java
@@ -22,6 +22,8 @@ import com.android.annotations.Nullable;
import com.android.sdklib.internal.project.ProjectProperties;
import com.android.sdklib.internal.project.ProjectProperties.PropertyType;
import com.android.sdklib.internal.project.ProjectPropertiesWorkingCopy;
+import com.android.sdklib.internal.repository.packages.FullRevision;
+import com.android.sdklib.repository.PkgProps;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -91,19 +93,17 @@ final class TaskHelper {
}
}
- String value = p.getProperty("Pkg.Revision"); //$NON-NLS-1$
+ String value = p.getProperty(PkgProps.PKG_REVISION);
if (value != null) {
- value = value.trim();
- int space = value.indexOf(' ');
- if (space != -1) {
- value = value.substring(0, space);
- }
- return new DeweyDecimal(value);
+ FullRevision rev = FullRevision.parseRevision(value);
+ return new DeweyDecimal(rev.toIntArray(false /*includePreview*/));
}
+ } catch (NumberFormatException e) {
+ // couldn't parse the version number.
} catch (FileNotFoundException e) {
- // couldn't find the file? return -1 below.
+ // couldn't find the file.
} catch (IOException e) {
- // couldn't find the file? return -1 below.
+ // couldn't find the file.
}
return null;
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() {