aboutsummaryrefslogtreecommitdiffstats
path: root/anttasks/src/com/android/ant/CheckEnvTask.java
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-03-29 19:28:25 -0700
committerXavier Ducrohet <xav@android.com>2012-04-16 12:54:55 -0700
commit1daa8f999d87443d14f698ca8ccc103e3309fa3e (patch)
tree29f034c67acbecc4933e35a46484edf1f9c9d055 /anttasks/src/com/android/ant/CheckEnvTask.java
parent4a8a17e5f23eace570b54084318b30bdd593fbc0 (diff)
downloadsdk-1daa8f999d87443d14f698ca8ccc103e3309fa3e.zip
sdk-1daa8f999d87443d14f698ca8ccc103e3309fa3e.tar.gz
sdk-1daa8f999d87443d14f698ca8ccc103e3309fa3e.tar.bz2
Fix "ant test" + misc clean up / reorganization of build.xml
- Split NewSetupTask in several tasks to make things more flexible. Particularly this allows more targets to get access to the project type (app, lib, test, ...) as it's not so computive intensive. - Fix test project to give them access to the full tested project's classpath. - Fix support for projects that test themselves. - Make sure library projects are instrumented when using the emma target. Change-Id: Ia0c9564eacee2521e7cbd5154b8a85ea287ad4fd
Diffstat (limited to 'anttasks/src/com/android/ant/CheckEnvTask.java')
-rw-r--r--anttasks/src/com/android/ant/CheckEnvTask.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/anttasks/src/com/android/ant/CheckEnvTask.java b/anttasks/src/com/android/ant/CheckEnvTask.java
new file mode 100644
index 0000000..d6b6cc4
--- /dev/null
+++ b/anttasks/src/com/android/ant/CheckEnvTask.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.ant;
+
+import com.android.sdklib.SdkConstants;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.util.DeweyDecimal;
+
+import java.io.File;
+
+/**
+ * Checks the Ant environment to make sure Android builds
+ * can run.
+ *
+ * No parameters are neeed.
+ *
+ */
+public class CheckEnvTask extends Task {
+
+ private final static String ANT_MIN_VERSION = "1.8.0";
+
+ @Override
+ public void execute() {
+
+ 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);
+
+ // detect that the platform tools is there.
+ File platformTools = new File(sdkDir, SdkConstants.FD_PLATFORM_TOOLS);
+ if (platformTools.isDirectory() == false) {
+ throw new BuildException(String.format(
+ "SDK Platform Tools component is missing. " +
+ "Please install it with the SDK Manager (%1$s%2$c%3$s)",
+ SdkConstants.FD_TOOLS,
+ File.separatorChar,
+ SdkConstants.androidCmdName()));
+ }
+
+ // display SDK Tools revision
+ int toolsRevison = TaskHelper.getToolsRevision(sdkDir);
+ if (toolsRevison != -1) {
+ System.out.println("Android SDK Tools Revision " + toolsRevison);
+ System.out.println("Installed at " + sdkDir.getAbsolutePath());
+ }
+ }
+
+ /**
+ * 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();
+ StringBuilder sb = new StringBuilder();
+ 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());
+ }
+
+}