aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'anttasks/src/com/android')
-rw-r--r--anttasks/src/com/android/ant/SetupTask.java46
1 files changed, 45 insertions, 1 deletions
diff --git a/anttasks/src/com/android/ant/SetupTask.java b/anttasks/src/com/android/ant/SetupTask.java
index 2b371a6..8facf62 100644
--- a/anttasks/src/com/android/ant/SetupTask.java
+++ b/anttasks/src/com/android/ant/SetupTask.java
@@ -39,8 +39,10 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilenameFilter;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Properties;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
@@ -62,6 +64,9 @@ import javax.xml.xpath.XPathExpressionException;
*
*/
public final class SetupTask extends ImportTask {
+ /** current max version of the Ant rules that is supported */
+ private final static int ANT_RULES_MAX_VERSION = 2;
+
private final static String ANDROID_RULES = "android_rules.xml";
// additional android rules for test project - depends on android_rules.xml
private final static String ANDROID_TEST_RULES = "android_test_rules.xml";
@@ -109,6 +114,12 @@ public final class SetupTask extends ImportTask {
throw new BuildException(String.format("SDK Location '%s' is not valid.", sdkLocation));
}
+ // display SDK Tools revision
+ int toolsRevison = getToolsRevision(sdk);
+ if (toolsRevison != -1) {
+ System.out.println("Android SDK Tools Revision " + toolsRevison);
+ }
+
// get the target property value
String targetHashString = antProject.getProperty(ProjectProperties.PROPERTY_TARGET);
@@ -159,6 +170,14 @@ public final class SetupTask extends ImportTask {
"Unable to resolve target '%s'", targetHashString));
}
+ // check that this version of the custom Ant task can build this target
+ int antBuildVersion = androidTarget.getAntBuildRevision();
+ if (antBuildVersion > ANT_RULES_MAX_VERSION) {
+ throw new BuildException(String.format(
+ "The project target (%1$s) requires a more recent version of the tools. Please update.",
+ androidTarget.getName()));
+ }
+
// check if the project is a library
boolean isLibrary = false;
@@ -170,7 +189,7 @@ public final class SetupTask extends ImportTask {
// look for referenced libraries.
processReferencedLibraries(antProject, androidTarget);
- // display it
+ // display the project info
System.out.println("Project Target: " + androidTarget.getName());
if (isLibrary) {
System.out.println("Type: Android Library");
@@ -443,4 +462,29 @@ public final class SetupTask extends ImportTask {
antProject.setProperty("android.libraries.package", sb.toString());
}
}
+
+ /**
+ * Returns the revision of the tools for a given SDK.
+ * @param sdkFile the {@link File} for the root folder of the SDK
+ * @return the tools revision or -1 if not found.
+ */
+ private int getToolsRevision(File sdkFile) {
+ Properties p = new Properties();
+ try{
+ // tools folder must exist, or this custom task wouldn't run!
+ File toolsFolder= new File(sdkFile, SdkConstants.FD_TOOLS);
+ File sourceProp = new File(toolsFolder, SdkConstants.FN_SOURCE_PROP);
+ p.load(new FileInputStream(sourceProp));
+ String value = p.getProperty("Pkg.Revision"); //$NON-NLS-1$
+ if (value != null) {
+ return Integer.parseInt(value);
+ }
+ } catch (FileNotFoundException e) {
+ // couldn't find the file? return -1 below.
+ } catch (IOException e) {
+ // couldn't find the file? return -1 below.
+ }
+
+ return -1;
+ }
}