diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-15 16:12:07 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-15 16:12:07 -0800 |
commit | 4d360cae64d0e9b5fe962cd339eb1bb933941920 (patch) | |
tree | 8fced5080aa04316ac99f6082499c96d70097a9a /anttasks/src/com | |
parent | a1514dae8668c48feae5436285e3db0ba2133ec3 (diff) | |
download | sdk-4d360cae64d0e9b5fe962cd339eb1bb933941920.zip sdk-4d360cae64d0e9b5fe962cd339eb1bb933941920.tar.gz sdk-4d360cae64d0e9b5fe962cd339eb1bb933941920.tar.bz2 |
auto import from //branches/cupcake/...@126645
Diffstat (limited to 'anttasks/src/com')
-rw-r--r-- | anttasks/src/com/android/ant/AndroidInitTask.java | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/anttasks/src/com/android/ant/AndroidInitTask.java b/anttasks/src/com/android/ant/AndroidInitTask.java index 84c1d27..30779c5 100644 --- a/anttasks/src/com/android/ant/AndroidInitTask.java +++ b/anttasks/src/com/android/ant/AndroidInitTask.java @@ -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); |