auto import from //branches/cupcake/...@126645

This commit is contained in:
The Android Open Source Project
2009-01-15 16:12:07 -08:00
parent 95cf464c5a
commit b8d704a517
62 changed files with 1680 additions and 668 deletions

View File

@@ -19,25 +19,30 @@ package com.android.ant;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.ISdkLog;
import com.android.sdklib.SdkManager;
import com.android.sdklib.IAndroidTarget.IOptionalLibrary;
import com.android.sdklib.project.ProjectProperties;
import org.apache.tools.ant.BuildException;
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 java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
/**
* Import Target Ant task. This task accomplishes:
* <ul>
* <li>Gets the project target hash string from {@link ProjectProperties#PROPERTY_TARGET},
* and resolves it.</li>
* <li>Sets up ant properties so that the rest of the Ant scripts finds:
* <ul>
* <li>Path to the underlying platform to access the build rules ('android-platform')<li>
* </ul>
* </li>
* and resolves it to get the project's {@link IAndroidTarget}.</li>
* <li>Sets up properties so that aapt can find the android.jar in the resolved target.</li>
* <li>Sets up the boot classpath ref so that the <code>javac</code> task knows where to find
* the libraries. This includes the default android.jar from the resolved target but also optional
* libraries provided by the target (if any, when the target is an add-on).</li>
* <li>Imports the build rules located in the resolved target so that the build actually does
* something.</li>
* </ul>
*
* This is used in build.xml/template.
@@ -46,8 +51,12 @@ import java.util.ArrayList;
public class AndroidInitTask extends ImportTask {
private final static String ANDROID_RULES = "android_rules.xml";
// ant property with the path to the android.jar
private final static String PROPERTY_ANDROID_JAR = "android-jar";
// ant property with the path to the framework.jar
private final static String PROPERTY_ANDROID_AIDL = "android-aidl";
// ref id to the <path> object containing all the boot classpaths.
private final static String REF_CLASSPATH = "android.target.classpath";
@Override
public void execute() throws BuildException {
@@ -117,13 +126,39 @@ public class AndroidInitTask extends ImportTask {
System.out.println("Platform Version: " + androidTarget.getApiVersionName());
System.out.println("API level: " + androidTarget.getApiVersionNumber());
// sets up the properties.
// sets up the properties to find android.jar/framework.aidl
String androidJar = androidTarget.getPath(IAndroidTarget.ANDROID_JAR);
String androidAidl = androidTarget.getPath(IAndroidTarget.ANDROID_AIDL);
antProject.setProperty(PROPERTY_ANDROID_JAR, androidJar);
antProject.setProperty(PROPERTY_ANDROID_AIDL, androidAidl);
// sets up the boot classpath
// create the Path object
Path bootclasspath = new Path(antProject);
// create a PathElement for the framework jar
PathElement element = bootclasspath.createPathElement();
element.setPath(androidJar);
// create PathElement for each optional library.
IOptionalLibrary[] libraries = androidTarget.getOptionalLibraries();
if (libraries != null) {
HashSet<String> visitedJars = new HashSet<String>();
for (IOptionalLibrary library : libraries) {
String jarPath = library.getJarPath();
if (visitedJars.contains(jarPath) == false) {
visitedJars.add(jarPath);
element = bootclasspath.createPathElement();
element.setPath(library.getJarPath());
}
}
}
// finally sets the path in the project with a reference
antProject.addReference(REF_CLASSPATH, bootclasspath);
// find the file to import, and import it.
String templateFolder = androidTarget.getPath(IAndroidTarget.TEMPLATES);