aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-05-05 15:31:14 -0700
committerXavier Ducrohet <xav@android.com>2010-05-05 15:50:49 -0700
commite9f516d878fc52120fa27cf8cf08ae84f5f43b57 (patch)
tree4b71699483492d16174365f52fe23c24836996ac /anttasks
parent95c454979ae3608d1b3f26e21f7e2b4aeabba2fe (diff)
downloadsdk-e9f516d878fc52120fa27cf8cf08ae84f5f43b57.zip
sdk-e9f516d878fc52120fa27cf8cf08ae84f5f43b57.tar.gz
sdk-e9f516d878fc52120fa27cf8cf08ae84f5f43b57.tar.bz2
Add support for using newer Ant rules distributed by the tools.
Right now, the Ant rules are packaged with each platform. This is a problem when we want to release newer versions of the rules, as we would have to respin newer rev for all major platforms just for that. The new mechanism has the Ant rules both in the tools folder and in the platforms. The platform indicates which versions it supports (support is based on the features of external tools such as aapt, aidl and dex). The custom tasks can figure out a newer but still compatible (ie not relying on newer options in aapt/aidl/dex) version from the tools folder and then uses this newer version. Change-Id: I763533ec85fa9647ecf96ac6cbaefbfd1ad68fb0
Diffstat (limited to 'anttasks')
-rw-r--r--anttasks/src/com/android/ant/SetupTask.java52
1 files changed, 46 insertions, 6 deletions
diff --git a/anttasks/src/com/android/ant/SetupTask.java b/anttasks/src/com/android/ant/SetupTask.java
index 5263f12..85ebea1 100644
--- a/anttasks/src/com/android/ant/SetupTask.java
+++ b/anttasks/src/com/android/ant/SetupTask.java
@@ -92,6 +92,24 @@ public final class SetupTask extends ImportTask {
// ref id to the <path> object containing all the boot classpaths.
private final static String REF_CLASSPATH = "android.target.classpath";
+ /**
+ * Compatibility range for the Ant rules.
+ * The goal is to specify range of the rules that are compatible between them. For instance if
+ * a range is 10-15 and a platform indicate that it supports rev 12, but the tools have rules
+ * revision 15, then the rev 15 will be used.
+ * Compatibility is broken when a new rev of the rules relies on a new option in the external
+ * tools contained in the platform.
+ *
+ * For instance if rules 10 uses a newly introduced aapt option, then it would be considered
+ * incompatible with 9, and therefore would be the start of a new compatibility range.
+ * A platform declaring it supports 9 would not be made to use 10, as its aapt version wouldn't
+ * support it.
+ */
+ private final static int ANT_COMPATIBILITY_RANGES[][] = new int[][] {
+ new int[] { 1, 1 },
+ new int[] { 2, 3 },
+ };
+
private boolean mDoImport = true;
@Override
@@ -278,16 +296,28 @@ public final class SetupTask extends ImportTask {
// Now the import section. This is only executed if the task actually has to import a file.
if (mDoImport) {
- // find the folder containing the file to import
- int folderID = antBuildVersion == 1 ? IAndroidTarget.TEMPLATES : IAndroidTarget.ANT;
- String rulesOSPath = androidTarget.getPath(folderID);
+ // check if there's a more recent version of the rules in the tools folder.
+ int toolsRulesRev = getAntRulesFromTools(antBuildVersion);
+
+ File rulesFolder;
+ if (toolsRulesRev == -1) {
+ // no more recent Ant rules from the tools, folder. Find them inside the platform.
+ // find the folder containing the file to import
+ int folderID = antBuildVersion == 1 ? IAndroidTarget.TEMPLATES : IAndroidTarget.ANT;
+ String rulesOSPath = androidTarget.getPath(folderID);
+ rulesFolder = new File(rulesOSPath);
+ } else {
+ // in this case we import the rules from the ant folder in the tools.
+ rulesFolder = new File(new File(sdkLocation, SdkConstants.FD_TOOLS),
+ SdkConstants.FD_ANT);
+ // the new rev is:
+ antBuildVersion = toolsRulesRev;
+ }
// make sure the file exists.
- File rulesFolder = new File(rulesOSPath);
-
if (rulesFolder.isDirectory() == false) {
throw new BuildException(String.format("Rules directory '%s' is missing.",
- rulesOSPath));
+ rulesFolder.getAbsolutePath()));
}
String importedRulesFileName;
@@ -327,6 +357,16 @@ public final class SetupTask extends ImportTask {
}
}
+ private int getAntRulesFromTools(int rulesRev) {
+ for (int[] range : ANT_COMPATIBILITY_RANGES) {
+ if (range[0] <= rulesRev && rulesRev <= range[1]) {
+ return range[1];
+ }
+ }
+
+ return -1;
+ }
+
/**
* Sets the value of the "import" attribute.
* @param value the value.