From 4d360cae64d0e9b5fe962cd339eb1bb933941920 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Thu, 15 Jan 2009 16:12:07 -0800 Subject: auto import from //branches/cupcake/...@126645 --- anttasks/src/com/android/ant/AndroidInitTask.java | 51 +++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'anttasks/src/com') 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: * * * 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 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 visitedJars = new HashSet(); + 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); -- cgit v1.1