diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:51:19 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:51:19 -0800 |
commit | a1514dae8668c48feae5436285e3db0ba2133ec3 (patch) | |
tree | 115c685f5c4c810cd317e8a6903e8d2d96749051 /anttasks | |
parent | 9ca1c0b33cc3fc28c21a915730797ec01e71a152 (diff) | |
download | sdk-a1514dae8668c48feae5436285e3db0ba2133ec3.zip sdk-a1514dae8668c48feae5436285e3db0ba2133ec3.tar.gz sdk-a1514dae8668c48feae5436285e3db0ba2133ec3.tar.bz2 |
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'anttasks')
-rw-r--r-- | anttasks/.classpath | 8 | ||||
-rw-r--r-- | anttasks/.project | 17 | ||||
-rw-r--r-- | anttasks/Android.mk | 17 | ||||
-rw-r--r-- | anttasks/src/Android.mk | 28 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/AndroidInitTask.java | 150 |
5 files changed, 220 insertions, 0 deletions
diff --git a/anttasks/.classpath b/anttasks/.classpath new file mode 100644 index 0000000..08ced21 --- /dev/null +++ b/anttasks/.classpath @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry combineaccessrules="false" kind="src" path="/SdkLib"/> + <classpathentry kind="var" path="ANDROID_SRC/prebuilt/common/ant/ant.jar"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/anttasks/.project b/anttasks/.project new file mode 100644 index 0000000..aed1b61 --- /dev/null +++ b/anttasks/.project @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>ant-tasks</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/anttasks/Android.mk b/anttasks/Android.mk new file mode 100644 index 0000000..15ee903 --- /dev/null +++ b/anttasks/Android.mk @@ -0,0 +1,17 @@ +# +# Copyright (C) 2008 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. +# +ANTTASKS_LOCAL_DIR := $(call my-dir) +include $(ANTTASKS_LOCAL_DIR)/src/Android.mk diff --git a/anttasks/src/Android.mk b/anttasks/src/Android.mk new file mode 100644 index 0000000..dbaf2bc --- /dev/null +++ b/anttasks/src/Android.mk @@ -0,0 +1,28 @@ +# +# Copyright (C) 2008 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. +# +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-subdir-java-files) + +LOCAL_JAVA_LIBRARIES := \ + sdklib \ + ant + +LOCAL_MODULE := anttasks + +include $(BUILD_HOST_JAVA_LIBRARY) + diff --git a/anttasks/src/com/android/ant/AndroidInitTask.java b/anttasks/src/com/android/ant/AndroidInitTask.java new file mode 100644 index 0000000..84c1d27 --- /dev/null +++ b/anttasks/src/com/android/ant/AndroidInitTask.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php + * + * 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.IAndroidTarget; +import com.android.sdklib.ISdkLog; +import com.android.sdklib.SdkManager; +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 java.io.File; +import java.util.ArrayList; + +/** + * 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> + * </ul> + * + * This is used in build.xml/template. + * + */ +public class AndroidInitTask extends ImportTask { + private final static String ANDROID_RULES = "android_rules.xml"; + + private final static String PROPERTY_ANDROID_JAR = "android-jar"; + private final static String PROPERTY_ANDROID_AIDL = "android-aidl"; + + @Override + public void execute() throws BuildException { + Project antProject = getProject(); + + // get the SDK location + String sdkLocation = antProject.getProperty(ProjectProperties.PROPERTY_SDK); + + // check if it's valid and exists + if (sdkLocation == null || sdkLocation.length() == 0) { + throw new BuildException("SDK Location is not set."); + } + + File sdk = new File(sdkLocation); + if (sdk.isDirectory() == false) { + throw new BuildException(String.format("SDK Location '%s' is not valid.", sdkLocation)); + } + + // get the target property value + String targetHashString = antProject.getProperty(ProjectProperties.PROPERTY_TARGET); + if (targetHashString == null) { + throw new BuildException("Android Target is not set."); + } + + // load up the sdk targets. + final ArrayList<String> messages = new ArrayList<String>(); + SdkManager manager = SdkManager.createManager(sdkLocation, new ISdkLog() { + public void error(Throwable t, String errorFormat, Object... args) { + if (errorFormat != null) { + messages.add(String.format("Error: " + errorFormat, args)); + } + if (t != null) { + messages.add("Error: " + t.getMessage()); + } + } + + public void printf(String msgFormat, Object... args) { + messages.add(String.format(msgFormat, args)); + } + + public void warning(String warningFormat, Object... args) { + messages.add(String.format("Warning: " + warningFormat, args)); + } + }); + + if (manager == null) { + // since we failed to parse the SDK, lets display the parsing output. + for (String msg : messages) { + System.out.println(msg); + } + throw new BuildException("Failed to parse SDK content."); + } + + // resolve it + IAndroidTarget androidTarget = manager.getTargetFromHashString(targetHashString); + + if (androidTarget == null) { + throw new BuildException(String.format( + "Unable to resolve target '%s'", targetHashString)); + } + + // display it + System.out.println("Project Target: " + androidTarget.getName()); + if (androidTarget.isPlatform() == false) { + System.out.println("Vendor: " + androidTarget.getVendor()); + } + System.out.println("Platform Version: " + androidTarget.getApiVersionName()); + System.out.println("API level: " + androidTarget.getApiVersionNumber()); + + // sets up the properties. + 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); + + // find the file to import, and import it. + String templateFolder = androidTarget.getPath(IAndroidTarget.TEMPLATES); + + // make sure the file exists. + File templates = new File(templateFolder); + if (templates.isDirectory() == false) { + throw new BuildException(String.format("Template directory '%s' is missing.", + templateFolder)); + } + + // now check the rules file exists. + File rules = new File(templateFolder, ANDROID_RULES); + if (rules.isFile() == false) { + throw new BuildException(String.format("Build rules file '%s' is missing.", + templateFolder)); + } + + // set the file location to import + setFile(rules.getAbsolutePath()); + + // and import it + super.execute(); + } +} |