summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 5263f1265..85ebea127 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.