diff options
author | Xavier Ducrohet <xav@android.com> | 2010-12-08 17:32:19 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-12-08 17:33:52 -0800 |
commit | b283eb12b1fe7e8cda57a3477be86bd863750457 (patch) | |
tree | 2b3e470476fefa4fc69914385a1ed5b2ada2fb39 /anttasks | |
parent | 59306ee67b6b6d685c2f615615e136299f16515b (diff) | |
download | sdk-b283eb12b1fe7e8cda57a3477be86bd863750457.zip sdk-b283eb12b1fe7e8cda57a3477be86bd863750457.tar.gz sdk-b283eb12b1fe7e8cda57a3477be86bd863750457.tar.bz2 |
Add Ant version check in setup task.
Change-Id: Id2237ae2fd64a1ccae5b1a1957099c218cdaf9a5
Diffstat (limited to 'anttasks')
-rw-r--r-- | anttasks/src/com/android/ant/SetupTask.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/anttasks/src/com/android/ant/SetupTask.java b/anttasks/src/com/android/ant/SetupTask.java index 4f14d62..4d1bac6 100644 --- a/anttasks/src/com/android/ant/SetupTask.java +++ b/anttasks/src/com/android/ant/SetupTask.java @@ -34,6 +34,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.ImportTask; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Path.PathElement; +import org.apache.tools.ant.util.DeweyDecimal; import org.xml.sax.InputSource; import java.io.File; @@ -64,6 +65,7 @@ import javax.xml.xpath.XPathExpressionException; * */ public final class SetupTask extends ImportTask { + private final static String ANT_MIN_VERSION = "1.8.0"; // main rules file private final static String RULES_MAIN = "main_rules.xml"; // test rules file - depends on android_rules.xml @@ -77,6 +79,17 @@ public final class SetupTask extends ImportTask { public void execute() throws BuildException { Project antProject = getProject(); + // check the Ant version + DeweyDecimal version = getVersion(antProject); + DeweyDecimal atLeast = new DeweyDecimal(ANT_MIN_VERSION); + if (atLeast.isGreaterThan(version)) { + throw new BuildException( + "The Android Ant-based build system requires Ant " + + ANT_MIN_VERSION + + " or later. Current version is " + + version); + } + // get the SDK location File sdkDir = TaskHelper.getSdkLocation(antProject); String sdkOsPath = sdkDir.getPath(); @@ -548,4 +561,33 @@ public final class SetupTask extends ImportTask { return libraries; } + + /** + * Returns the Ant version as a {@link DeweyDecimal} object. + * + * This is based on the implementation of + * org.apache.tools.ant.taskdefs.condition.AntVersion.getVersion() + * + * @param antProject the current ant project. + * @return the ant version. + */ + private DeweyDecimal getVersion(Project antProject) { + char[] versionString = antProject.getProperty("ant.version").toCharArray(); + StringBuffer sb = new StringBuffer(); + boolean foundFirstDigit = false; + for (int i = 0; i < versionString.length; i++) { + if (Character.isDigit(versionString[i])) { + sb.append(versionString[i]); + foundFirstDigit = true; + } + if (versionString[i] == '.' && foundFirstDigit) { + sb.append(versionString[i]); + } + if (Character.isLetter(versionString[i]) && foundFirstDigit) { + break; + } + } + return new DeweyDecimal(sb.toString()); + } + } |