diff options
author | Raphael Moll <ralf@android.com> | 2013-03-12 10:39:00 -0700 |
---|---|---|
committer | Raphael Moll <ralf@android.com> | 2013-03-13 20:34:20 -0700 |
commit | f6a5b596f5473558ecc859e8af931a9f1b80a7ea (patch) | |
tree | 885f0080f18c5ba1a94781b9d61077d2c67e3add /anttasks | |
parent | bc982e5d2a6ffc0fa5c76eaf39e77e4ec415e637 (diff) | |
download | sdk-f6a5b596f5473558ecc859e8af931a9f1b80a7ea.zip sdk-f6a5b596f5473558ecc859e8af931a9f1b80a7ea.tar.gz sdk-f6a5b596f5473558ecc859e8af931a9f1b80a7ea.tar.bz2 |
SDK: Delete projects moved to tools/base or tools/swt.
Change-Id: Iba15f82cb00d19217382c78d8ff37dda1e97ea59
Diffstat (limited to 'anttasks')
39 files changed, 0 insertions, 6074 deletions
diff --git a/anttasks/.classpath b/anttasks/.classpath deleted file mode 100644 index f214a3b..0000000 --- a/anttasks/.classpath +++ /dev/null @@ -1,11 +0,0 @@ -<?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/prebuilts/tools/common/ant/ant.jar"/> - <classpathentry combineaccessrules="false" kind="src" path="/common"/> - <classpathentry kind="var" path="ANDROID_SRC/prebuilts/tools/common/guava-tools/guava-13.0.1.jar" sourcepath="ANDROID_SRC/prebuilts/tools/common/guava-tools/src.zip"/> - <classpathentry combineaccessrules="false" kind="src" path="/manifest-merger"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/anttasks/.gitignore b/anttasks/.gitignore deleted file mode 100644 index fe99505..0000000 --- a/anttasks/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -bin - diff --git a/anttasks/.project b/anttasks/.project deleted file mode 100644 index aed1b61..0000000 --- a/anttasks/.project +++ /dev/null @@ -1,17 +0,0 @@ -<?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/.settings/README.txt b/anttasks/.settings/README.txt deleted file mode 100644 index 9120b20..0000000 --- a/anttasks/.settings/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -Copy this in eclipse project as a .settings folder at the root. -This ensure proper compilation compliance and warning/error levels.
\ No newline at end of file diff --git a/anttasks/.settings/org.eclipse.jdt.core.prefs b/anttasks/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 9dbff07..0000000 --- a/anttasks/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,98 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore -org.eclipse.jdt.core.compiler.annotation.nonnull=com.android.annotations.NonNull -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=com.android.annotations.NonNullByDefault -org.eclipse.jdt.core.compiler.annotation.nonnullisdefault=disabled -org.eclipse.jdt.core.compiler.annotation.nullable=com.android.annotations.Nullable -org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning -org.eclipse.jdt.core.compiler.problem.deadCode=warning -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore -org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=warning -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning -org.eclipse.jdt.core.compiler.problem.forbiddenReference=error -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning -org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore -org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning -org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning -org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled -org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=error -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning -org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error -org.eclipse.jdt.core.compiler.problem.nullReference=error -org.eclipse.jdt.core.compiler.problem.nullSpecInsufficientInfo=warning -org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=ignore -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning -org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning -org.eclipse.jdt.core.compiler.problem.potentialNullSpecViolation=error -org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning -org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning -org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=enabled -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning -org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unclosedCloseable=error -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled -org.eclipse.jdt.core.compiler.problem.unusedImport=warning -org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -org.eclipse.jdt.core.compiler.problem.unusedLocal=warning -org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/anttasks/Android.mk b/anttasks/Android.mk deleted file mode 100644 index ae0c3a9..0000000 --- a/anttasks/Android.mk +++ /dev/null @@ -1,34 +0,0 @@ -# -# 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-java-files-under, src) -LOCAL_JAVA_RESOURCE_DIRS := src - -LOCAL_JAR_MANIFEST := etc/manifest.txt - -LOCAL_JAVA_LIBRARIES := \ - common \ - sdklib \ - manifmerger \ - ant \ - guava-tools - -LOCAL_MODULE := anttasks - -include $(BUILD_HOST_JAVA_LIBRARY) - diff --git a/anttasks/NOTICE b/anttasks/NOTICE deleted file mode 100644 index c5b1efa..0000000 --- a/anttasks/NOTICE +++ /dev/null @@ -1,190 +0,0 @@ - - Copyright (c) 2005-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. - - 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. - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/anttasks/etc/manifest.txt b/anttasks/etc/manifest.txt deleted file mode 100644 index e5449c8..0000000 --- a/anttasks/etc/manifest.txt +++ /dev/null @@ -1 +0,0 @@ -Class-Path: common.jar guava-tools.jar sdklib.jar manifmerger.jar diff --git a/anttasks/src/anttasks.properties b/anttasks/src/anttasks.properties deleted file mode 100644 index 458f355..0000000 --- a/anttasks/src/anttasks.properties +++ /dev/null @@ -1,22 +0,0 @@ -checkenv: com.android.ant.CheckEnvTask -gettype: com.android.ant.GetTypeTask -gettarget: com.android.ant.GetTargetTask -getuitarget: com.android.ant.GetUiTargetTask -getprojectpaths: com.android.ant.GetProjectPathsTask -getlibpath: com.android.ant.GetLibraryPathTask -dependency: com.android.ant.ComputeDependencyTask -testedprojectclasspath: com.android.ant.ComputeProjectClasspathTask -getemmafilter: com.android.ant.GetEmmaFilterTask -mergemanifest: com.android.ant.ManifestMergerTask -aapt: com.android.ant.AaptExecTask -aidl: com.android.ant.AidlExecTask -renderscript: com.android.ant.RenderScriptTask -buildconfig: com.android.ant.BuildConfigTask -dex: com.android.ant.DexExecTask -apkbuilder: com.android.ant.ApkBuilderTask -signapk: com.android.ant.SignApkTask -zipalign: com.android.ant.ZipAlignTask -xpath: com.android.ant.XPathTask -if: com.android.ant.IfElseTask -propertybyreplace: com.android.ant.PropertyByReplaceTask -lint: com.android.ant.LintExecTask diff --git a/anttasks/src/com/android/ant/AaptExecTask.java b/anttasks/src/com/android/ant/AaptExecTask.java deleted file mode 100644 index a1d44c4..0000000 --- a/anttasks/src/com/android/ant/AaptExecTask.java +++ /dev/null @@ -1,793 +0,0 @@ -/* - * Copyright (C) 2009 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.SdkConstants; -import com.android.sdklib.internal.build.SymbolLoader; -import com.android.sdklib.internal.build.SymbolWriter; -import com.android.xml.AndroidXPathFactory; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.ExecTask; -import org.apache.tools.ant.types.Path; -import org.xml.sax.InputSource; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; - -/** - * Task to execute aapt. - * - * <p>It does not follow the exec task format, instead it has its own parameters, which maps - * directly to aapt.</p> - * <p>It is able to run aapt several times if library setup requires generating several - * R.java files. - * <p>The following map shows how to use the task for each supported aapt command line - * parameter.</p> - * - * <table border="1"> - * <tr><td><b>Aapt Option</b></td><td><b>Ant Name</b></td><td><b>Type</b></td></tr> - * <tr><td>path to aapt</td><td>executable</td><td>attribute (Path)</td> - * <tr><td>command</td><td>command</td><td>attribute (String)</td> - * <tr><td>-v</td><td>verbose</td><td>attribute (boolean)</td></tr> - * <tr><td>-f</td><td>force</td><td>attribute (boolean)</td></tr> - * <tr><td>-M AndroidManifest.xml</td><td>manifest</td><td>attribute (Path)</td></tr> - * <tr><td>-I base-package</td><td>androidjar</td><td>attribute (Path)</td></tr> - * <tr><td>-A asset-source-dir</td><td>assets</td><td>attribute (Path</td></tr> - * <tr><td>-S resource-sources</td><td><res path=""></td><td>nested element(s)<br>with attribute (Path)</td></tr> - * <tr><td>-0 extension</td><td><nocompress extension=""><br><nocompress></td><td>nested element(s)<br>with attribute (String)</td></tr> - * <tr><td>-F apk-file</td><td>apkfolder<br>outfolder<br>apkbasename<br>basename</td><td>attribute (Path)<br>attribute (Path) deprecated<br>attribute (String)<br>attribute (String) deprecated</td></tr> - * <tr><td>-J R-file-dir</td><td>rfolder</td><td>attribute (Path)<br>-m always enabled</td></tr> - * <tr><td>--rename-manifest-package package-name</td><td>manifestpackage</td><td>attribute (String)</td></tr> - * <tr><td></td><td></td><td></td></tr> - * </table> - */ -public final class AaptExecTask extends SingleDependencyTask { - - /** - * Class representing a <nocompress> node in the main task XML. - * This let the developers prevent compression of some files in assets/ and res/raw/ - * by extension. - * If the extension is null, this will disable compression for all files in assets/ and - * res/raw/ - */ - public final static class NoCompress { - String mExtension; - - /** - * Sets the value of the "extension" attribute. - * @param extention the extension. - */ - public void setExtension(String extention) { - mExtension = extention; - } - } - - private String mExecutable; - private String mCommand; - private boolean mForce = true; // true due to legacy reasons - private boolean mDebug = false; - private boolean mVerbose = false; - private boolean mUseCrunchCache = false; - private int mVersionCode = 0; - private String mVersionName; - private String mManifestFile; - private String mManifestPackage; - private String mOriginalManifestPackage; - private ArrayList<Path> mResources; - private String mAssets; - private String mAndroidJar; - private String mApkFolder; - private String mApkName; - private String mResourceFilter; - private String mRFolder; - private final ArrayList<NoCompress> mNoCompressList = new ArrayList<NoCompress>(); - private String mLibraryResFolderPathRefid; - private String mLibraryPackagesRefid; - private String mLibraryRFileRefid; - private boolean mNonConstantId; - private String mIgnoreAssets; - private String mBinFolder; - private String mProguardFile; - - /** - * Input path that ignores the same folders/files that aapt does. - */ - private static class ResFolderInputPath extends InputPath { - public ResFolderInputPath(File file, Set<String> extensionsToCheck) { - super(file, extensionsToCheck); - } - - @Override - public boolean ignores(File file) { - String name = file.getName(); - char firstChar = name.charAt(0); - - if (firstChar == '.' || (firstChar == '_' && file.isDirectory()) || - name.charAt(name.length()-1) == '~') { - return true; - } - - if ("CVS".equals(name) || - "thumbs.db".equalsIgnoreCase(name) || - "picasa.ini".equalsIgnoreCase(name)) { - return true; - } - - String ext = getExtension(name); - if ("scc".equalsIgnoreCase(ext)) { - return true; - } - - return false; - } - } - - private final static InputPathFactory sPathFactory = new InputPathFactory() { - - @Override - public InputPath createPath(File file, Set<String> extensionsToCheck) { - return new ResFolderInputPath(file, extensionsToCheck); - } - }; - - /** - * Sets the value of the "executable" attribute. - * @param executable the value. - */ - public void setExecutable(Path executable) { - mExecutable = TaskHelper.checkSinglePath("executable", executable); - } - - /** - * Sets the value of the "command" attribute. - * @param command the value. - */ - public void setCommand(String command) { - mCommand = command; - } - - /** - * Sets the value of the "force" attribute. - * @param force the value. - */ - public void setForce(boolean force) { - mForce = force; - } - - /** - * Sets the value of the "verbose" attribute. - * @param verbose the value. - */ - public void setVerbose(boolean verbose) { - mVerbose = verbose; - } - - /** - * Sets the value of the "usecrunchcache" attribute - * @param usecrunch whether to use the crunch cache. - */ - public void setNoCrunch(boolean nocrunch) { - mUseCrunchCache = nocrunch; - } - - public void setNonConstantId(boolean nonConstantId) { - mNonConstantId = nonConstantId; - } - - public void setIgnoreAssets(String ignoreAssets) { - mIgnoreAssets = ignoreAssets; - } - - public void setVersioncode(String versionCode) { - if (versionCode.length() > 0) { - try { - mVersionCode = Integer.decode(versionCode); - } catch (NumberFormatException e) { - System.out.println(String.format( - "WARNING: Ignoring invalid version code value '%s'.", versionCode)); - } - } - } - - /** - * Sets the value of the "versionName" attribute - * @param versionName the value - */ - public void setVersionname(String versionName) { - mVersionName = versionName; - } - - public void setDebug(boolean value) { - mDebug = value; - } - - /** - * Sets the value of the "manifest" attribute. - * @param manifest the value. - */ - public void setManifest(Path manifest) { - mManifestFile = TaskHelper.checkSinglePath("manifest", manifest); - } - - /** - * Sets a custom manifest package ID to be used during packaging.<p> - * The manifest will be rewritten so that its package ID becomes the value given here. - * Relative class names in the manifest (e.g. ".Foo") will be rewritten to absolute names based - * on the existing package name, meaning that no code changes need to be made. - * - * @param packageName The package ID the APK should have. - */ - public void setManifestpackage(String packageName) { - if (packageName != null && packageName.length() != 0) { - mManifestPackage = packageName; - } - } - - /** - * Sets the original package name found in the manifest. This is the package name where - * the R class is created. - * - * This is merely a shortcut in case the package is known when calling the aapt task. If not - * provided (and needed) this task will recompute it. - * @param packageName the package name declared in the manifest. - */ - public void setOriginalManifestPackage(String packageName) { - mOriginalManifestPackage = packageName; - } - - /** - * Sets the value of the "resources" attribute. - * @param resources the value. - * - * @deprecated Use nested element(s) <res path="value" /> - */ - @Deprecated - public void setResources(Path resources) { - System.out.println("WARNNG: Using deprecated 'resources' attribute in AaptExecLoopTask." + - "Use nested element(s) <res path=\"value\" /> instead."); - if (mResources == null) { - mResources = new ArrayList<Path>(); - } - - mResources.add(new Path(getProject(), resources.toString())); - } - - /** - * Sets the value of the "assets" attribute. - * @param assets the value. - */ - public void setAssets(Path assets) { - mAssets = TaskHelper.checkSinglePath("assets", assets); - } - - /** - * Sets the value of the "androidjar" attribute. - * @param androidJar the value. - */ - public void setAndroidjar(Path androidJar) { - mAndroidJar = TaskHelper.checkSinglePath("androidjar", androidJar); - } - - /** - * Sets the value of the "outfolder" attribute. - * @param outFolder the value. - * @deprecated use {@link #setApkfolder(Path)} - */ - @Deprecated - public void setOutfolder(Path outFolder) { - System.out.println("WARNNG: Using deprecated 'outfolder' attribute in AaptExecLoopTask." + - "Use 'apkfolder' (path) instead."); - mApkFolder = TaskHelper.checkSinglePath("outfolder", outFolder); - } - - /** - * Sets the value of the "apkfolder" attribute. - * @param apkFolder the value. - */ - public void setApkfolder(Path apkFolder) { - mApkFolder = TaskHelper.checkSinglePath("apkfolder", apkFolder); - } - - /** - * Sets the value of the resourcefilename attribute - * @param apkName the value - */ - public void setResourcefilename(String apkName) { - mApkName = apkName; - } - - /** - * Sets the value of the "rfolder" attribute. - * @param rFolder the value. - */ - public void setRfolder(Path rFolder) { - mRFolder = TaskHelper.checkSinglePath("rfolder", rFolder); - } - - public void setresourcefilter(String filter) { - if (filter != null && filter.length() > 0) { - mResourceFilter = filter; - } - } - - /** - * Set the property name of the property that contains the list of res folder for - * Library Projects. This sets the name and not the value itself to handle the case where - * it doesn't exist. - * @param projectLibrariesResName - */ - public void setLibraryResFolderPathRefid(String libraryResFolderPathRefid) { - mLibraryResFolderPathRefid = libraryResFolderPathRefid; - } - - public void setLibraryPackagesRefid(String libraryPackagesRefid) { - mLibraryPackagesRefid = libraryPackagesRefid; - } - - public void setLibraryRFileRefid(String libraryRFileRefid) { - mLibraryRFileRefid = libraryRFileRefid; - } - - public void setBinFolder(Path binFolder) { - mBinFolder = TaskHelper.checkSinglePath("binFolder", binFolder); - } - - public void setProguardFile(Path proguardFile) { - mProguardFile = TaskHelper.checkSinglePath("proguardFile", proguardFile); - } - - /** - * Returns an object representing a nested <var>nocompress</var> element. - */ - public Object createNocompress() { - NoCompress nc = new NoCompress(); - mNoCompressList.add(nc); - return nc; - } - - /** - * Returns an object representing a nested <var>res</var> element. - */ - public Object createRes() { - if (mResources == null) { - mResources = new ArrayList<Path>(); - } - - Path path = new Path(getProject()); - mResources.add(path); - - return path; - } - - @Override - protected String getExecTaskName() { - return "aapt"; - } - - /* - * (non-Javadoc) - * - * Executes the loop. Based on the values inside project.properties, this will - * create alternate temporary ap_ files. - * - * @see org.apache.tools.ant.Task#execute() - */ - @SuppressWarnings("deprecation") - @Override - public void execute() throws BuildException { - if (mLibraryResFolderPathRefid == null) { - throw new BuildException("Missing attribute libraryResFolderPathRefid"); - } - if (mLibraryPackagesRefid == null) { - throw new BuildException("Missing attribute libraryPackagesRefid"); - } - if (mLibraryRFileRefid == null) { - throw new BuildException("Missing attribute libraryRFileRefid"); - } - - Project taskProject = getProject(); - - String libPkgProp = null; - Path libRFileProp = null; - - // if the parameters indicate generation of the R class, check if - // more R classes need to be created for libraries, only if this project itself - // is not a library - if (mNonConstantId == false && mRFolder != null && new File(mRFolder).isDirectory()) { - libPkgProp = taskProject.getProperty(mLibraryPackagesRefid); - Object rFilePath = taskProject.getReference(mLibraryRFileRefid); - - // if one is null, both should be - if ((libPkgProp == null || rFilePath == null) && - rFilePath != libPkgProp) { - throw new BuildException(String.format( - "Both %1$s and %2$s should resolve to valid values.", - mLibraryPackagesRefid, mLibraryRFileRefid)); - } - - if (rFilePath instanceof Path) { - libRFileProp = (Path) rFilePath; - } else if (rFilePath != null) { - throw new BuildException("attribute libraryRFileRefid must reference a Path object."); - } - } - - final boolean generateRClass = mRFolder != null && new File(mRFolder).isDirectory(); - - // Get whether we have libraries - Object libResRef = taskProject.getReference(mLibraryResFolderPathRefid); - - // Set up our input paths that matter for dependency checks - ArrayList<File> paths = new ArrayList<File>(); - - // the project res folder is an input path of course - for (Path pathList : mResources) { - for (String path : pathList.list()) { - paths.add(new File(path)); - } - } - - // and if libraries exist, their res folders folders too. - if (libResRef instanceof Path) { - for (String path : ((Path)libResRef).list()) { - paths.add(new File(path)); - } - } - - // Now we figure out what we need to do - if (generateRClass) { - // in this case we only want to run aapt if an XML file was touched, or if any - // file is added/removed - List<InputPath> inputPaths = getInputPaths(paths, Collections.singleton("xml"), - sPathFactory); - - // let's not forget the manifest as an input path (with no extension restrictions). - if (mManifestFile != null) { - inputPaths.add(new InputPath(new File(mManifestFile))); - } - - // Check to see if our dependencies have changed. If not, then skip - if (initDependencies(mRFolder + File.separator + "R.java.d", inputPaths) - && dependenciesHaveChanged() == false) { - System.out.println("No changed resources. R.java and Manifest.java untouched."); - return; - } else { - System.out.println("Generating resource IDs..."); - } - } else { - // in this case we want to run aapt if any file was updated/removed/added in any of the - // input paths - List<InputPath> inputPaths = getInputPaths(paths, null /*extensionsToCheck*/, - sPathFactory); - - // let's not forget the manifest as an input path. - if (mManifestFile != null) { - inputPaths.add(new InputPath(new File(mManifestFile))); - } - - // If we're here to generate a .ap_ file we need to use assets as an input path as well. - if (mAssets != null) { - File assetsDir = new File(mAssets); - if (assetsDir.isDirectory()) { - inputPaths.add(new InputPath(assetsDir)); - } - } - - // Find our dependency file. It should have the same name as our target .ap_ but - // with a .d extension - String dependencyFilePath = mApkFolder + File.separator + mApkName; - dependencyFilePath += ".d"; - - // Check to see if our dependencies have changed - if (initDependencies(dependencyFilePath, inputPaths) - && dependenciesHaveChanged() == false) { - System.out.println("No changed resources or assets. " + mApkName - + " remains untouched"); - return; - } - if (mResourceFilter == null) { - System.out.println("Creating full resource package..."); - } else { - System.out.println(String.format( - "Creating resource package with filter: (%1$s)...", - mResourceFilter)); - } - } - - // create a task for the default apk. - ExecTask task = new ExecTask(); - task.setExecutable(mExecutable); - task.setFailonerror(true); - - task.setTaskName(getExecTaskName()); - - // aapt command. Only "package" is supported at this time really. - task.createArg().setValue(mCommand); - - // No crunch flag - if (mUseCrunchCache) { - task.createArg().setValue("--no-crunch"); - } - - if (mNonConstantId) { - task.createArg().setValue("--non-constant-id"); - } - - // force flag - if (mForce) { - task.createArg().setValue("-f"); - } - - // verbose flag - if (mVerbose) { - task.createArg().setValue("-v"); - } - - if (mDebug) { - task.createArg().setValue("--debug-mode"); - } - - if (generateRClass) { - task.createArg().setValue("-m"); - } - - // filters if needed - if (mResourceFilter != null && mResourceFilter.length() > 0) { - task.createArg().setValue("-c"); - task.createArg().setValue(mResourceFilter); - } - - // no compress flag - // first look to see if there's a NoCompress object with no specified extension - boolean compressNothing = false; - for (NoCompress nc : mNoCompressList) { - if (nc.mExtension == null) { - task.createArg().setValue("-0"); - task.createArg().setValue(""); - compressNothing = true; - break; - } - } - - if (compressNothing == false) { - for (NoCompress nc : mNoCompressList) { - task.createArg().setValue("-0"); - task.createArg().setValue(nc.mExtension); - } - } - - // if this is a library or there are library dependencies - if (mNonConstantId || (libPkgProp != null && libPkgProp.length() > 0)) { - if (mBinFolder == null) { - throw new BuildException( - "Missing attribute binFolder when compiling libraries or projects with libraries."); - } - task.createArg().setValue("--output-text-symbols"); - task.createArg().setValue(mBinFolder); - } - - // if the project contains libraries, force auto-add-overlay - if (libResRef != null) { - task.createArg().setValue("--auto-add-overlay"); - } - - if (mVersionCode != 0) { - task.createArg().setValue("--version-code"); - task.createArg().setValue(Integer.toString(mVersionCode)); - } - - if (mVersionName != null && mVersionName.length() > 0) { - task.createArg().setValue("--version-name"); - task.createArg().setValue(mVersionName); - } - - // manifest location - if (mManifestFile != null && mManifestFile.length() > 0) { - task.createArg().setValue("-M"); - task.createArg().setValue(mManifestFile); - } - - // Rename manifest package - if (mManifestPackage != null) { - task.createArg().setValue("--rename-manifest-package"); - task.createArg().setValue(mManifestPackage); - } - - // resources locations. - if (mResources.size() > 0) { - for (Path pathList : mResources) { - for (String path : pathList.list()) { - // This may not exists, and aapt doesn't like it, so we check first. - File res = new File(path); - if (res.isDirectory()) { - task.createArg().setValue("-S"); - task.createArg().setValue(path); - } - } - } - } - - // add other resources coming from library project - if (libResRef instanceof Path) { - for (String path : ((Path)libResRef).list()) { - // This may not exists, and aapt doesn't like it, so we check first. - File res = new File(path); - if (res.isDirectory()) { - task.createArg().setValue("-S"); - task.createArg().setValue(path); - } - } - } - - // assets location. This may not exists, and aapt doesn't like it, so we check first. - if (mAssets != null && new File(mAssets).isDirectory()) { - task.createArg().setValue("-A"); - task.createArg().setValue(mAssets); - } - - // android.jar - if (mAndroidJar != null) { - task.createArg().setValue("-I"); - task.createArg().setValue(mAndroidJar); - } - - // apk file. This is based on the apkFolder, apkBaseName, and the configName (if applicable) - String filename = null; - if (mApkName != null) { - filename = mApkName; - } - - if (filename != null) { - File file = new File(mApkFolder, filename); - task.createArg().setValue("-F"); - task.createArg().setValue(file.getAbsolutePath()); - } - - // R class generation - if (generateRClass) { - task.createArg().setValue("-J"); - task.createArg().setValue(mRFolder); - } - - // ignore assets flag - if (mIgnoreAssets != null && mIgnoreAssets.length() > 0) { - task.createArg().setValue("--ignore-assets"); - task.createArg().setValue(mIgnoreAssets); - } - - // Use dependency generation - task.createArg().setValue("--generate-dependencies"); - - // use the proguard file - if (mProguardFile != null && mProguardFile.length() > 0) { - task.createArg().setValue("-G"); - task.createArg().setValue(mProguardFile); - } - - // final setup of the task - task.setProject(taskProject); - task.setOwningTarget(getOwningTarget()); - - // execute it. - task.execute(); - - // now if the project has libraries, R needs to be created for each libraries - // but only if the project is not a library. - try { - if (!mNonConstantId && libPkgProp != null && !libPkgProp.isEmpty()) { - File rFile = new File(mBinFolder, SdkConstants.FN_RESOURCE_TEXT); - if (rFile.isFile()) { - // Load the full symbols from the full R.txt file. - SymbolLoader fullSymbolValues = new SymbolLoader(rFile); - fullSymbolValues.load(); - - // we have two props which contains list of items. Both items represent - // 2 data of a single property. - // Don't want to use guava's splitter because it doesn't provide a list of the - // result. but we know the list starts with a ; so strip it. - if (libPkgProp.startsWith(";")) { - libPkgProp = libPkgProp.substring(1).trim(); - } - String[] packages = libPkgProp.split(";"); - String[] rFiles = libRFileProp.list(); - - if (packages.length != rFiles.length) { - throw new BuildException(String.format( - "%1$s and %2$s must contain the same number of items.", - mLibraryPackagesRefid, mLibraryRFileRefid)); - } - - if (mOriginalManifestPackage == null) { - mOriginalManifestPackage = getPackageName(mManifestFile); - } - - Multimap<String, SymbolLoader> libMap = ArrayListMultimap.create(); - - // First pass processing the libraries, collecting them by packageName, - // and ignoring the ones that have the same package name as the application - // (since that R class was already created). - for (int i = 0 ; i < packages.length ; i++) { - String libPackage = packages[i]; - - // skip libraries that have the same package name as the application. - if (mOriginalManifestPackage.equals(libPackage)) { - continue; - } - - File rText = new File(rFiles[i]); - if (rText.isFile()) { - // load the lib symbols - SymbolLoader libSymbols = new SymbolLoader(rText); - libSymbols.load(); - - // store these symbols by associating them with the package name. - libMap.put(libPackage, libSymbols); - } - } - - // now loop on all the package names, merge all the symbols to write, - // and write them - for (String packageName : libMap.keySet()) { - Collection<SymbolLoader> symbols = libMap.get(packageName); - - SymbolWriter writer = new SymbolWriter(mRFolder, packageName, - fullSymbolValues); - for (SymbolLoader symbolLoader : symbols) { - writer.addSymbolsToWrite(symbolLoader); - } - writer.write(); - } - } - } - } catch (Exception e) { - // HACK alert. - // in order for this step to happen again when this part fails, we delete - // the dependency file. - File f = new File(mRFolder, "R.java.d"); - f.delete(); - - throw (e instanceof BuildException) ? (BuildException)e : new BuildException(e); - } - } - - private String getPackageName(String manifest) { - XPath xpath = AndroidXPathFactory.newXPath(); - - try { - String s = xpath.evaluate("/manifest/@package", - new InputSource(new FileInputStream(manifest))); - return s; - } catch (XPathExpressionException e) { - throw new BuildException(e); - } catch (FileNotFoundException e) { - throw new BuildException(e); - } - } -} diff --git a/anttasks/src/com/android/ant/AidlExecTask.java b/anttasks/src/com/android/ant/AidlExecTask.java deleted file mode 100644 index 87ca599..0000000 --- a/anttasks/src/com/android/ant/AidlExecTask.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (C) 2010 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.SdkConstants; -import com.android.sdklib.io.FileOp; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.ExecTask; -import org.apache.tools.ant.types.Path; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -/** - * Task to execute aidl. - * <p> - * It expects 5 attributes:<br> - * 'executable' ({@link Path} with a single path) for the location of the aidl executable<br> - * 'framework' ({@link Path} with a single path) for the "preprocessed" file containing all the - * parcelables exported by the framework<br> - * 'genFolder' ({@link Path} with a single path) for the location of the gen folder. - * 'aidlOutFolder' ({@link Path} with a single path) for the location of the bin/aidl folder to - * copy the aidl files. - * 'libraryBinAidlFolderPathRefid' the name of the reference to a path object that contains - * libraries aidl output folder. - * - * It also expects one or more inner elements called "source" which are identical to {@link Path} - * elements. - */ -public class AidlExecTask extends MultiFilesTask { - - private String mExecutable; - private String mFramework; - private Path mLibraryBinAidlFolderPath; - private String mGenFolder; - private final ArrayList<Path> mPaths = new ArrayList<Path>(); - private String mAidlOutFolder; - - private class AidlProcessor implements SourceProcessor { - - @Override - public Set<String> getSourceFileExtensions() { - return Collections.singleton(SdkConstants.EXT_AIDL); - } - - @Override - public void process(String filePath, String sourceFolder, - List<String> sourceFolders, Project taskProject) { - ExecTask task = new ExecTask(); - task.setProject(taskProject); - task.setOwningTarget(getOwningTarget()); - task.setExecutable(mExecutable); - task.setTaskName("aidl"); - task.setFailonerror(true); - - task.createArg().setValue("-p" + mFramework); - task.createArg().setValue("-o" + mGenFolder); - // add all the source folders as import in case an aidl file in a source folder - // imports a parcelable from another source folder. - for (String importFolder : sourceFolders) { - task.createArg().setValue("-I" + importFolder); - } - - // add all the library aidl folders to access parcelables that are in libraries - if (mLibraryBinAidlFolderPath != null) { - for (String importFolder : mLibraryBinAidlFolderPath.list()) { - task.createArg().setValue("-I" + importFolder); - } - } - - // set auto dependency file creation - task.createArg().setValue("-a"); - - task.createArg().setValue(filePath); - - // execute it. - task.execute(); - - // if we reach here, it was successful (execute throws an exception otherwise). - // Copy the file into the bin/aidl directory. - String relative = filePath.substring(sourceFolder.length()); - if (relative.charAt(0) == '/' || relative.charAt(0) == File.separatorChar) { - relative = relative.substring(1); - } - - try { - File dest = new File(mAidlOutFolder, relative); - File parent = dest.getParentFile(); - parent.mkdirs(); - - FileOp op = new FileOp(); - op.copyFile(new File(filePath), dest); - } catch (IOException e) { - throw new BuildException(e); - } - } - - @Override - public void displayMessage(DisplayType type, int count) { - switch (type) { - case FOUND: - System.out.println(String.format("Found %1$d AIDL files.", count)); - break; - case COMPILING: - if (count > 0) { - System.out.println(String.format("Compiling %1$d AIDL files.", - count)); - } else { - System.out.println("No AIDL files to compile."); - } - break; - case REMOVE_OUTPUT: - System.out.println(String.format("Found %1$d obsolete output files to remove.", - count)); - break; - case REMOVE_DEP: - System.out.println( - String.format("Found %1$d obsolete dependency files to remove.", - count)); - break; - } - } - } - - /** - * Sets the value of the "executable" attribute. - * @param executable the value. - */ - public void setExecutable(Path executable) { - mExecutable = TaskHelper.checkSinglePath("executable", executable); - } - - public void setFramework(Path value) { - mFramework = TaskHelper.checkSinglePath("framework", value); - } - - public void setLibraryBinAidlFolderPathRefid(String libraryBinAidlFolderPathRefid) { - Object libBinAidlRef = getProject().getReference(libraryBinAidlFolderPathRefid); - if (libBinAidlRef instanceof Path) { - mLibraryBinAidlFolderPath = (Path) libBinAidlRef; - } - } - - public void setGenFolder(Path value) { - mGenFolder = TaskHelper.checkSinglePath("genFolder", value); - } - - public void setAidlOutFolder(Path value) { - mAidlOutFolder = TaskHelper.checkSinglePath("aidlOutFolder", value); - } - - public Path createSource() { - Path p = new Path(getProject()); - mPaths.add(p); - return p; - } - - @Override - public void execute() throws BuildException { - if (mExecutable == null) { - throw new BuildException("AidlExecTask's 'executable' is required."); - } - if (mFramework == null) { - throw new BuildException("AidlExecTask's 'framework' is required."); - } - if (mGenFolder == null) { - throw new BuildException("AidlExecTask's 'genFolder' is required."); - } - if (mAidlOutFolder == null) { - throw new BuildException("AidlExecTask's 'aidlOutFolder' is required."); - } - - processFiles(new AidlProcessor(), mPaths, mGenFolder); - } -} diff --git a/anttasks/src/com/android/ant/ApkBuilderTask.java b/anttasks/src/com/android/ant/ApkBuilderTask.java deleted file mode 100644 index 8997ad1..0000000 --- a/anttasks/src/com/android/ant/ApkBuilderTask.java +++ /dev/null @@ -1,393 +0,0 @@ -/* - * Copyright (C) 2009 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.build.ApkBuilder; -import com.android.sdklib.build.ApkBuilder.FileEntry; -import com.android.sdklib.build.ApkCreationException; -import com.android.sdklib.build.DuplicateFileException; -import com.android.sdklib.build.SealedApkException; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Path; - -import java.io.File; -import java.io.FilenameFilter; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -public class ApkBuilderTask extends SingleDependencyTask { - - private final static Pattern PATTERN_JAR_EXT = Pattern.compile("^.+\\.jar$", - Pattern.CASE_INSENSITIVE); - - private String mOutFolder; - private String mApkFilepath; - private String mResourceFile; - private boolean mVerbose = false; - private boolean mDebugPackaging = false; - private boolean mDebugSigning = false; - private boolean mHasCode = true; - - private Path mDexPath; - - private final ArrayList<Path> mZipList = new ArrayList<Path>(); - private final ArrayList<Path> mSourceList = new ArrayList<Path>(); - private final ArrayList<Path> mJarfolderList = new ArrayList<Path>(); - private final ArrayList<Path> mJarfileList = new ArrayList<Path>(); - private final ArrayList<Path> mNativeList = new ArrayList<Path>(); - - private static class SourceFolderInputPath extends InputPath { - public SourceFolderInputPath(File file) { - super(file); - } - - @Override - public boolean ignores(File file) { - if (file.isDirectory()) { - return !ApkBuilder.checkFolderForPackaging(file.getName()); - } else { - return !ApkBuilder.checkFileForPackaging(file.getName()); - } - } - } - - /** - * Sets the value of the "outfolder" attribute. - * @param outFolder the value. - */ - public void setOutfolder(Path outFolder) { - mOutFolder = TaskHelper.checkSinglePath("outfolder", outFolder); - } - - /** - * Sets the full filepath to the apk to generate. - * @param filepath - */ - public void setApkfilepath(String filepath) { - mApkFilepath = filepath; - } - - /** - * Sets the resourcefile attribute - * @param resourceFile - */ - public void setResourcefile(String resourceFile) { - mResourceFile = resourceFile; - } - - /** - * Sets the value of the "verbose" attribute. - * @param verbose the value. - */ - public void setVerbose(boolean verbose) { - mVerbose = verbose; - } - - /** - * Sets the value of the "debug" attribute. - * @param debug the debug mode value. - */ - public void setDebug(boolean debug) { - System.out.println("WARNNG: Using deprecated 'debug' attribute in ApkBuilderTask." + - "Use 'debugpackaging' and 'debugsigning' instead."); - mDebugPackaging = debug; - mDebugSigning = debug; - } - - /** - * Sets the value of the "debugpackaging" attribute. - * @param debug the debug mode value. - */ - public void setDebugpackaging(boolean debug) { - mDebugPackaging = debug; - } - - /** - * Sets the value of the "debugsigning" attribute. - * @param debug the debug mode value. - */ - public void setDebugsigning(boolean debug) { - mDebugSigning = debug; - } - - /** - * Sets the hascode attribute. Default is true. - * If set to false, then <dex> and <sourcefolder> nodes are ignored and not processed. - * @param hasCode the value of the attribute. - */ - public void setHascode(boolean hasCode) { - mHasCode = hasCode; - } - - /** - * Returns an object representing a nested <var>zip</var> element. - */ - public Object createZip() { - Path path = new Path(getProject()); - mZipList.add(path); - return path; - } - - /** - * Returns an object representing a nested <var>dex</var> element. - * This is similar to a nested <var>file</var> element, except when {@link #mHasCode} - * is <code>false</code> in which case it's ignored. - */ - public Object createDex() { - if (mDexPath == null) { - return mDexPath = new Path(getProject()); - } else { - throw new BuildException("Only one <dex> inner element can be provided"); - } - } - - /** - * Returns an object representing a nested <var>sourcefolder</var> element. - */ - public Object createSourcefolder() { - Path path = new Path(getProject()); - mSourceList.add(path); - return path; - } - - /** - * Returns an object representing a nested <var>jarfolder</var> element. - */ - public Object createJarfolder() { - Path path = new Path(getProject()); - mJarfolderList.add(path); - return path; - } - - /** - * Returns an object representing a nested <var>jarfile</var> element. - */ - public Object createJarfile() { - Path path = new Path(getProject()); - mJarfileList.add(path); - return path; - } - - /** - * Returns an object representing a nested <var>nativefolder</var> element. - */ - public Object createNativefolder() { - Path path = new Path(getProject()); - mNativeList.add(path); - return path; - } - - @Override - public void execute() throws BuildException { - - File outputFile; - if (mApkFilepath != null) { - outputFile = new File(mApkFilepath); - } else { - throw new BuildException("missing attribute 'apkFilepath'"); - } - - if (mResourceFile == null) { - throw new BuildException("missing attribute 'resourcefile'"); - } - - if (mOutFolder == null) { - throw new BuildException("missing attribute 'outfolder'"); - } - - // check dexPath is only one file. - File dexFile = null; - if (mHasCode) { - String[] dexFiles = mDexPath.list(); - if (dexFiles.length != 1) { - throw new BuildException(String.format( - "Expected one dex file but path value resolve to %d files.", - dexFiles.length)); - } - dexFile = new File(dexFiles[0]); - } - - try { - // build list of input files/folders to compute dependencies - // add the content of the zip files. - List<InputPath> inputPaths = new ArrayList<InputPath>(); - - // resource file - InputPath resourceInputPath = new InputPath(new File(mOutFolder, mResourceFile)); - inputPaths.add(resourceInputPath); - - // dex file - if (dexFile != null) { - inputPaths.add(new InputPath(dexFile)); - } - - // zip input files - List<File> zipFiles = new ArrayList<File>(); - for (Path pathList : mZipList) { - for (String path : pathList.list()) { - File f = new File(path); - zipFiles.add(f); - inputPaths.add(new InputPath(f)); - } - } - - // now go through the list of source folders used to add non java files. - List<File> sourceFolderList = new ArrayList<File>(); - if (mHasCode) { - for (Path pathList : mSourceList) { - for (String path : pathList.list()) { - File f = new File(path); - sourceFolderList.add(f); - // because this is a source folder but we only care about non - // java files. - inputPaths.add(new SourceFolderInputPath(f)); - } - } - } - - // now go through the list of jar folders. - List<File> jarFileList = new ArrayList<File>(); - for (Path pathList : mJarfolderList) { - for (String path : pathList.list()) { - // it's ok if top level folders are missing - File folder = new File(path); - if (folder.isDirectory()) { - String[] filenames = folder.list(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return PATTERN_JAR_EXT.matcher(name).matches(); - } - }); - - for (String filename : filenames) { - File f = new File(folder, filename); - jarFileList.add(f); - inputPaths.add(new InputPath(f)); - } - } - } - } - - // now go through the list of jar files. - for (Path pathList : mJarfileList) { - for (String path : pathList.list()) { - File f = new File(path); - jarFileList.add(f); - inputPaths.add(new InputPath(f)); - } - } - - // now the native lib folder. - List<FileEntry> nativeFileList = new ArrayList<FileEntry>(); - for (Path pathList : mNativeList) { - for (String path : pathList.list()) { - // it's ok if top level folders are missing - File folder = new File(path); - if (folder.isDirectory()) { - List<FileEntry> entries = ApkBuilder.getNativeFiles(folder, - mDebugPackaging); - // add the list to the list of native files and then create an input - // path for each file - nativeFileList.addAll(entries); - - for (FileEntry entry : entries) { - inputPaths.add(new InputPath(entry.mFile)); - } - } - } - } - - // Finally figure out the path to the dependency file. - String depFile = outputFile.getAbsolutePath() + ".d"; - - // check dependencies - if (initDependencies(depFile, inputPaths) && dependenciesHaveChanged() == false) { - System.out.println( - "No changes. No need to create apk."); - return; - } - - if (mDebugSigning) { - System.out.println(String.format( - "Creating %s and signing it with a debug key...", outputFile.getName())); - } else { - System.out.println(String.format( - "Creating %s for release...", outputFile.getName())); - } - - ApkBuilder apkBuilder = new ApkBuilder( - outputFile, - resourceInputPath.getFile(), - dexFile, - mDebugSigning ? ApkBuilder.getDebugKeystore() : null, - mVerbose ? System.out : null); - apkBuilder.setDebugMode(mDebugPackaging); - - - // add the content of the zip files. - for (File f : zipFiles) { - if (mVerbose) { - System.out.println("Zip Input: " + f.getAbsolutePath()); - } - apkBuilder.addZipFile(f); - } - - // now go through the list of file to directly add the to the list. - for (File f : sourceFolderList) { - if (mVerbose) { - System.out.println("Source Folder Input: " + f.getAbsolutePath()); - } - apkBuilder.addSourceFolder(f); - } - - // now go through the list of jar files. - for (File f : jarFileList) { - if (mVerbose) { - System.out.println("Jar Input: " + f.getAbsolutePath()); - } - apkBuilder.addResourcesFromJar(f); - } - - // and finally the native files - apkBuilder.addNativeLibraries(nativeFileList); - - // close the archive - apkBuilder.sealApk(); - - // and generate the dependency file - generateDependencyFile(depFile, inputPaths, outputFile.getAbsolutePath()); - } catch (DuplicateFileException e) { - System.err.println(String.format( - "Found duplicate file for APK: %1$s\nOrigin 1: %2$s\nOrigin 2: %3$s", - e.getArchivePath(), e.getFile1(), e.getFile2())); - throw new BuildException(e); - } catch (ApkCreationException e) { - throw new BuildException(e); - } catch (SealedApkException e) { - throw new BuildException(e); - } catch (IllegalArgumentException e) { - throw new BuildException(e); - } - } - - @Override - protected String getExecTaskName() { - return "apkbuilder"; - } -} diff --git a/anttasks/src/com/android/ant/BuildConfigTask.java b/anttasks/src/com/android/ant/BuildConfigTask.java deleted file mode 100644 index 4fee80c..0000000 --- a/anttasks/src/com/android/ant/BuildConfigTask.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2011 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.internal.build.BuildConfigGenerator; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Path; - -import java.io.File; -import java.io.IOException; - -public class BuildConfigTask extends BuildTypedTask { - - private String mGenFolder; - private String mAppPackage; - - public void setGenFolder(Path path) { - mGenFolder = TaskHelper.checkSinglePath("genFolder", path); - } - - public void setPackage(String appPackage) { - mAppPackage = appPackage; - } - - - @Override - public void execute() throws BuildException { - if (mGenFolder == null) { - throw new BuildException("Missing attribute genFolder"); - } - if (mAppPackage == null) { - throw new BuildException("Missing attribute package"); - } - - BuildConfigGenerator generator = new BuildConfigGenerator( - mGenFolder, mAppPackage, - Boolean.parseBoolean(getBuildType())); - - // first check if the file is missing. - File buildConfigFile = generator.getBuildConfigFile(); - boolean missingFile = buildConfigFile.exists() == false; - - if (missingFile || hasBuildTypeChanged()) { - if (isNewBuild()) { - System.out.println("Generating BuildConfig class."); - } else if (missingFile) { - System.out.println("BuildConfig class missing: Generating new BuildConfig class."); - } else { - System.out.println("Build type changed: Generating new BuildConfig class."); - } - - try { - generator.generate(); - } catch (IOException e) { - throw new BuildException("Failed to create BuildConfig class", e); - } - } else { - System.out.println("No need to generate new BuildConfig."); - } - } -} diff --git a/anttasks/src/com/android/ant/BuildTypedTask.java b/anttasks/src/com/android/ant/BuildTypedTask.java deleted file mode 100644 index 3f4b64a..0000000 --- a/anttasks/src/com/android/ant/BuildTypedTask.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2011 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 org.apache.tools.ant.Task; - -/** - * Base class for tasks that should exec when the build type change. - */ -public abstract class BuildTypedTask extends Task { - - private String mPreviousBuildType; - private String mBuildType; - - /** Sets the current build type */ - public void setBuildType(String buildType) { - mBuildType = buildType; - } - - /** Sets the previous build type */ - public void setPreviousBuildType(String previousBuildType) { - mPreviousBuildType = previousBuildType; - } - - protected String getBuildType() { - return mBuildType; - } - - /** - * Returns if it is a new build. If the build type is not input - * from the XML, this always returns true. - * A build type is defined by having an empty previousBuildType. - */ - protected boolean isNewBuild() { - return mBuildType == null || mPreviousBuildType.length() == 0; - } - - /** - * Returns true if the build type changed. - */ - protected boolean hasBuildTypeChanged() { - // no build type? return false as the feature is simply not used - if (mBuildType == null && mPreviousBuildType == null) { - return false; - } - - return mBuildType.equals(mPreviousBuildType) == false; - } -} diff --git a/anttasks/src/com/android/ant/CheckEnvTask.java b/anttasks/src/com/android/ant/CheckEnvTask.java deleted file mode 100644 index 98312f9..0000000 --- a/anttasks/src/com/android/ant/CheckEnvTask.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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.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 = getAntVersion(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 - DeweyDecimal toolsRevison = TaskHelper.getToolsRevision(sdkDir); - if (toolsRevison != null) { - 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 getAntVersion(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()); - } - -} diff --git a/anttasks/src/com/android/ant/ComputeDependencyTask.java b/anttasks/src/com/android/ant/ComputeDependencyTask.java deleted file mode 100644 index 7d96c70..0000000 --- a/anttasks/src/com/android/ant/ComputeDependencyTask.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * 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.SdkConstants; -import com.android.ant.DependencyHelper.JarProcessor; -import com.android.io.FileWrapper; -import com.android.sdklib.internal.project.IPropertySource; -import com.android.xml.AndroidManifest; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Path.PathElement; - -import java.io.File; -import java.util.List; - -/** - * Computes the dependency of the current project. - * - * Out params: - * <code>libraryResFolderPathOut</code>: the Path object containing the res folder for all the - * library projects in the order needed by aapt. - * - * <code>libraryPackagesOut</code>: a simple property containing ;-separated package name from - * the library projects. - * - * <code>jarLibraryPathOut</code>: the Path object containing all the 3rd party jar files. - * - * <code>libraryNativeFolderPathOut</code>: the Path with all the native folder for the library - * projects. - * - * - * In params: - * <code>targetApi</code>: the compilation target api. - * <code>verbose</code>: whether the build is verbose. - * - */ -public class ComputeDependencyTask extends GetLibraryPathTask { - - private String mLibraryManifestFilePathOut; - private String mLibraryResFolderPathOut; - private String mLibraryPackagesOut; - private String mJarLibraryPathOut; - private String mLibraryNativeFolderPathOut; - private String mLibraryBinAidlFolderPathOut; - private String mLibraryRFilePathOut; - private int mTargetApi = -1; - private boolean mVerbose = false; - - public void setLibraryManifestFilePathOut(String libraryManifestFilePathOut) { - mLibraryManifestFilePathOut = libraryManifestFilePathOut; - } - - public void setLibraryResFolderPathOut(String libraryResFolderPathOut) { - mLibraryResFolderPathOut = libraryResFolderPathOut; - } - - public void setLibraryPackagesOut(String libraryPackagesOut) { - mLibraryPackagesOut = libraryPackagesOut; - } - - public void setJarLibraryPathOut(String jarLibraryPathOut) { - mJarLibraryPathOut = jarLibraryPathOut; - } - - public void setLibraryBinAidlFolderPathOut(String libraryBinAidlFolderPathOut) { - mLibraryBinAidlFolderPathOut = libraryBinAidlFolderPathOut; - } - - public void setLibraryRFilePathOut(String libraryRFilePathOut) { - mLibraryRFilePathOut = libraryRFilePathOut; - } - - public void setLibraryNativeFolderPathOut(String libraryNativeFolderPathOut) { - mLibraryNativeFolderPathOut = libraryNativeFolderPathOut; - } - - public void setTargetApi(int targetApi) { - mTargetApi = targetApi; - } - - @Override - public void execute() throws BuildException { - if (mLibraryManifestFilePathOut == null) { - throw new BuildException("Missing attribute libraryManifestFilePathOut"); - } - if (mLibraryResFolderPathOut == null) { - throw new BuildException("Missing attribute libraryResFolderPathOut"); - } - if (mLibraryPackagesOut == null) { - throw new BuildException("Missing attribute libraryPackagesOut"); - } - if (mJarLibraryPathOut == null) { - throw new BuildException("Missing attribute jarLibraryPathOut"); - } - if (mLibraryNativeFolderPathOut == null) { - throw new BuildException("Missing attribute libraryNativeFolderPathOut"); - } - if (mLibraryBinAidlFolderPathOut == null) { - throw new BuildException("Missing attribute libraryBinFolderPathOut"); - } - if (mLibraryRFilePathOut == null) { - throw new BuildException("Missing attribute libraryRFilePathOut"); - } - if (mTargetApi == -1) { - throw new BuildException("Missing attribute targetApi"); - } - - final Project antProject = getProject(); - - // get the SDK location - File sdkDir = TaskHelper.getSdkLocation(antProject); - - // prepare several paths for future tasks - final Path manifestFilePath = new Path(antProject); - final Path resFolderPath = new Path(antProject); - final Path nativeFolderPath = new Path(antProject); - final Path binAidlFolderPath = new Path(antProject); - final Path rFilePath = new Path(antProject); - final StringBuilder packageStrBuilder = new StringBuilder(); - - // custom jar processor doing a bit more than just collecting the jar files - JarProcessor processor = new JarProcessor() { - @Override - public void processLibrary(String libRootPath, IPropertySource properties) { - // let the super class handle the jar files - super.processLibrary(libRootPath, properties); - - // get the AndroidManifest.xml path. - // FIXME: support renamed location. - PathElement element = manifestFilePath.createPathElement(); - element.setPath(libRootPath + '/' + SdkConstants.FN_ANDROID_MANIFEST_XML); - - // get the res path. $PROJECT/res as well as the crunch cache. - // FIXME: support renamed folders. - element = resFolderPath.createPathElement(); - element.setPath(libRootPath + '/' + SdkConstants.FD_OUTPUT + - '/' + SdkConstants.FD_RES); - element = resFolderPath.createPathElement(); - element.setPath(libRootPath + '/' + SdkConstants.FD_RESOURCES); - - // get the folder for the native libraries. Always $PROJECT/libs - // FIXME: support renamed folder and/or move libs to bin/libs/ - element = nativeFolderPath.createPathElement(); - element.setPath(libRootPath + '/' + SdkConstants.FD_NATIVE_LIBS); - - // get the bin/aidl folder. $PROJECT/bin/aidl for now - // FIXME: support renamed folder. - element = binAidlFolderPath.createPathElement(); - element.setPath(libRootPath + '/' + SdkConstants.FD_OUTPUT + - '/' + SdkConstants.FD_AIDL); - - // get the package from the manifest. - FileWrapper manifest = new FileWrapper(libRootPath, - SdkConstants.FN_ANDROID_MANIFEST_XML); - - try { - String value = AndroidManifest.getPackage(manifest); - if (value != null) { // aapt will complain if it's missing. - packageStrBuilder.append(';'); - packageStrBuilder.append(value); - - // get the text R file. $PROJECT/bin/R.txt for now - // This must be in sync with the package list. - // FIXME: support renamed folder. - element = rFilePath.createPathElement(); - element.setPath(libRootPath + "/" + SdkConstants.FD_OUTPUT + - "/" + "R.txt"); - - } - } catch (Exception e) { - throw new BuildException(e); - } - } - }; - - // list of all the jars that are on the classpath. This will receive the - // project's libs/*.jar files, the Library Projects output and their own libs/*.jar - List<File> jars = processor.getJars(); - - - // in case clean has been called before a build type target, the list of - // libraries has already been computed so we don't need to compute it again. - Path libraryFolderPath = (Path) antProject.getReference(getLibraryFolderPathOut()); - if (libraryFolderPath == null) { - execute(processor); - } else { - // this contains the list of library folder in reverse order (compilation order). - // We need to process it in the normal order (res order). - System.out.println("Ordered libraries:"); - - String[] libraries = libraryFolderPath.list(); - for (int i = libraries.length - 1 ; i >= 0 ; i--) { - String libRootPath = libraries[i]; - System.out.println(libRootPath); - - processor.processLibrary(libRootPath); - } - } - - boolean hasLibraries = jars.size() > 0; - - if (mTargetApi <= 15) { - System.out.println("\n------------------"); - System.out.println("API<=15: Adding annotations.jar to the classpath."); - - jars.add(new File(sdkDir, SdkConstants.FD_TOOLS + - '/' + SdkConstants.FD_SUPPORT + - '/' + SdkConstants.FN_ANNOTATIONS_JAR)); - - } - - // even with no libraries, always setup these so that various tasks in Ant don't complain - // (the task themselves can handle a ref to an empty Path) - antProject.addReference(mLibraryNativeFolderPathOut, nativeFolderPath); - antProject.addReference(mLibraryManifestFilePathOut, manifestFilePath); - antProject.addReference(mLibraryBinAidlFolderPathOut, binAidlFolderPath); - - // the rest is done only if there's a library. - if (hasLibraries) { - antProject.addReference(mLibraryResFolderPathOut, resFolderPath); - antProject.setProperty(mLibraryPackagesOut, packageStrBuilder.toString()); - antProject.addReference(mLibraryRFilePathOut, rFilePath); - } - - File projectFolder = antProject.getBaseDir(); - - // add the project's own content of libs/*.jar - File libsFolder = new File(projectFolder, SdkConstants.FD_NATIVE_LIBS); - File[] jarFiles = libsFolder.listFiles(processor.getFilter()); - if (jarFiles != null) { - for (File jarFile : jarFiles) { - jars.add(jarFile); - } - } - - // now sanitize the path to remove dups - jars = DependencyHelper.sanitizePaths(projectFolder, new IPropertySource() { - @Override - public String getProperty(String name) { - return antProject.getProperty(name); - } - - @Override - public void debugPrint() { - } - }, jars); - - // and create a Path object for them - Path jarsPath = new Path(antProject); - if (mVerbose) { - System.out.println("\n------------------\nSanitized jar list:"); - } - for (File f : jars) { - if (mVerbose) { - System.out.println("- " + f.getAbsolutePath()); - } - PathElement element = jarsPath.createPathElement(); - element.setPath(f.getAbsolutePath()); - } - antProject.addReference(mJarLibraryPathOut, jarsPath); - - if (mVerbose) { - System.out.println(); - } - } -} diff --git a/anttasks/src/com/android/ant/ComputeProjectClasspathTask.java b/anttasks/src/com/android/ant/ComputeProjectClasspathTask.java deleted file mode 100644 index ac793f3..0000000 --- a/anttasks/src/com/android/ant/ComputeProjectClasspathTask.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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.SdkConstants; -import com.android.ant.DependencyHelper.JarProcessor; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Path.PathElement; - -import java.io.File; -import java.util.List; - -public class ComputeProjectClasspathTask extends Task { - - private String mProjectLocation; - private String mProjectClassPathOut; - - public void setProjectLocation(String projectLocation) { - mProjectLocation = projectLocation; - } - - public void setProjectClassPathOut(String projectClassPathOut) { - mProjectClassPathOut = projectClassPathOut; - } - - @Override - public void execute() throws BuildException { - if (mProjectLocation == null) { - throw new BuildException("Missing attribute projectLocation"); - } - if (mProjectClassPathOut == null) { - throw new BuildException("Missing attribute projectClassPathOut"); - } - - DependencyHelper helper = new DependencyHelper(new File(mProjectLocation), - false /*verbose*/); - - JarProcessor processor = new JarProcessor(); - - helper.processLibraries(processor); - List<File> jars = processor.getJars(); - - // add the project's own content of libs/*.jar - File libsFolder = new File(mProjectLocation, SdkConstants.FD_NATIVE_LIBS); - File[] jarFiles = libsFolder.listFiles(processor.getFilter()); - if (jarFiles != null) { - for (File jarFile : jarFiles) { - jars.add(jarFile); - } - } - - jars = helper.sanitizePaths(jars); - - Project antProject = getProject(); - - System.out.println("Resolved classpath:"); - - // create a path with all the jars and the project's output as well. - Path path = new Path(antProject); - for (File jar : jars) { - PathElement element = path.createPathElement(); - String p = jar.getAbsolutePath(); - element.setPath(p); - System.out.println(p); - } - - File bin = new File(mProjectLocation, - helper.getOutDir() + File.separator + "classes"); - PathElement element = path.createPathElement(); - String p = bin.getAbsolutePath(); - element.setPath(p); - System.out.println(p); - - antProject.addReference(mProjectClassPathOut, path); - } -} diff --git a/anttasks/src/com/android/ant/DependencyGraph.java b/anttasks/src/com/android/ant/DependencyGraph.java deleted file mode 100644 index 7cb13a0..0000000 --- a/anttasks/src/com/android/ant/DependencyGraph.java +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Copyright (C) 2011 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.google.common.base.Charsets; -import com.google.common.io.Files; - -import org.apache.tools.ant.BuildException; - -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * This class takes care of dependency tracking for all targets and prerequisites listed in - * a single dependency file. A dependency graph always has a dependency file associated with it - * for the duration of its lifetime - */ -public class DependencyGraph { - - private final static boolean DEBUG = false; - - private static enum DependencyStatus { - NONE, NEW_FILE, UPDATED_FILE, MISSING_FILE, ERROR; - } - - // Files that we know about from the dependency file - private Set<File> mTargets = Collections.emptySet(); - private Set<File> mPrereqs = mTargets; - private File mFirstPrereq = null; - private boolean mMissingDepFile = false; - private long mDepFileLastModified; - private final List<InputPath> mNewInputs; - - public DependencyGraph(String dependencyFilePath, List<InputPath> newInputPaths) { - mNewInputs = newInputPaths; - parseDependencyFile(dependencyFilePath); - } - - /** - * Check all the dependencies to see if anything has changed. - * - * @param printStatus will print to {@link System#out} the dependencies status. - * @return true if new prerequisites have appeared, target files are missing or if - * prerequisite files have been modified since the last target generation. - */ - public boolean dependenciesHaveChanged(boolean printStatus) { - // If no dependency file has been set up, then we'll just return true - // if we have a dependency file, we'll check to see what's been changed - if (mMissingDepFile) { - System.out.println("No Dependency File Found"); - return true; - } - - // check for missing output first - if (missingTargetFile()) { - if (printStatus) { - System.out.println("Found Deleted Target File"); - } - return true; - } - - // get the time stamp of the oldest target. - long oldestTarget = getOutputLastModified(); - - // first look through the input folders and look for new files or modified files. - DependencyStatus status = checkInputs(oldestTarget); - - // this can't find missing files. This is done later. - switch (status) { - case ERROR: - throw new BuildException(); - case NEW_FILE: - if (printStatus) { - System.out.println("Found new input file"); - } - return true; - case UPDATED_FILE: - if (printStatus) { - System.out.println("Found modified input file"); - } - return true; - } - - // now do a full check on the remaining files. - status = checkPrereqFiles(oldestTarget); - // this can't find new input files. This is done above. - switch (status) { - case ERROR: - throw new BuildException(); - case MISSING_FILE: - if (printStatus) { - System.out.println("Found deleted input file"); - } - return true; - case UPDATED_FILE: - if (printStatus) { - System.out.println("Found modified input file"); - } - return true; - } - - return false; - } - - public Set<File> getTargets() { - return Collections.unmodifiableSet(mTargets); - } - - public File getFirstPrereq() { - return mFirstPrereq; - } - - /** - * Parses the given dependency file and stores the file paths - * - * @param dependencyFilePath the dependency file - */ - private void parseDependencyFile(String dependencyFilePath) { - // first check if the dependency file is here. - File depFile = new File(dependencyFilePath); - if (depFile.isFile() == false) { - mMissingDepFile = true; - return; - } - - // get the modification time of the dep file as we may need it later - mDepFileLastModified = depFile.lastModified(); - - // Read in our dependency file - List<String> content = readFile(depFile); - if (content == null) { - System.err.println("ERROR: Couldn't read " + dependencyFilePath); - return; - } - - // The format is something like: - // output1 output2 [...]: dep1 dep2 [...] - // expect it's likely split on several lines. So let's move it back on a single line - // first - StringBuilder sb = new StringBuilder(); - for (String line : content) { - line = line.trim(); - if (line.endsWith("\\")) { - line = line.substring(0, line.length() - 1); - } - sb.append(line); - } - - // split the left and right part - String[] files = sb.toString().split(":"); - - // get the target files: - String[] targets = files[0].trim().split(" "); - - String[] prereqs = {}; - // Check to make sure our dependency file is okay - if (files.length < 1) { - System.err.println( - "Warning! Dependency file does not list any prerequisites after ':' "); - } else { - // and the prerequisite files: - prereqs = files[1].trim().split(" "); - } - - mTargets = new HashSet<File>(targets.length); - for (String path : targets) { - if (path.length() > 0) { - mTargets.add(new File(path)); - } - } - - mPrereqs = new HashSet<File>(prereqs.length); - for (String path : prereqs) { - if (path.length() > 0) { - if (DEBUG) { - System.out.println("PREREQ: " + path); - } - File f = new File(path); - if (mFirstPrereq == null) { - mFirstPrereq = f; - } - mPrereqs.add(f); - } - } - } - - /** - * Check all the input files and folders to see if there have been new - * files added to them or if any of the existing files have been modified. - * - * This looks at the input paths, not at the list of known prereq. Therefore this - * will not find missing files. It will however remove processed files from the - * prereq file list so that we can process those in a 2nd step. - * - * This should be followed by a call to {@link #checkPrereqFiles(long)} which - * will process the remaining files in the prereq list. - * - * If a change is found, this will return immediately with either - * {@link DependencyStatus#NEW_FILE} or {@link DependencyStatus#UPDATED_FILE}. - * - * @param oldestTarget the timestamp of the oldest output file to compare against. - * - * @return the status of the file in the watched folders. - * - */ - private DependencyStatus checkInputs(long oldestTarget) { - if (mNewInputs != null) { - for (InputPath input : mNewInputs) { - File file = input.getFile(); - if (file.isDirectory()) { - DependencyStatus status = checkInputFolder(file, input, oldestTarget); - if (status != DependencyStatus.NONE) { - return status; - } - } else if (file.isFile()) { - DependencyStatus status = checkInputFile(file, input, oldestTarget); - if (status != DependencyStatus.NONE) { - return status; - } - } - } - } - - // If we make it all the way through our directories we're good. - return DependencyStatus.NONE; - } - - /** - * Check all the files in the tree under root and check to see if the files are - * listed under the dependencies, or if they have been modified. Recurses into subdirs. - * - * @param folder the folder to search through. - * @param inputFolder the root level inputFolder - * @param oldestTarget the time stamp of the oldest output file to compare against. - * - * @return the status of the file in the folder. - */ - private DependencyStatus checkInputFolder(File folder, InputPath inputFolder, - long oldestTarget) { - if (inputFolder.ignores(folder)) { - return DependencyStatus.NONE; - } - - File[] files = folder.listFiles(); - if (files == null) { - System.err.println("ERROR " + folder.toString() + " is not a dir or can't be read"); - return DependencyStatus.ERROR; - } - // Loop through files in this folder - for (File file : files) { - // If this is a directory, recurse into it - if (file.isDirectory()) { - DependencyStatus status = checkInputFolder(file, inputFolder, oldestTarget); - if (status != DependencyStatus.NONE) { - return status; - } - } else if (file.isFile()) { - DependencyStatus status = checkInputFile(file, inputFolder, oldestTarget); - if (status != DependencyStatus.NONE) { - return status; - } - } - } - // If we got to here then we didn't find anything interesting - return DependencyStatus.NONE; - } - - private DependencyStatus checkInputFile(File file, InputPath inputFolder, - long oldestTarget) { - if (inputFolder.ignores(file)) { - return DependencyStatus.NONE; - } - - // if it's a file, remove it from the list of prereqs. - // This way if files in this folder don't trigger a build we'll have less - // files to go through manually - if (mPrereqs.remove(file) == false) { - // turns out this is a new file! - - if (DEBUG) { - System.out.println("NEW FILE: " + file.getAbsolutePath()); - } - return DependencyStatus.NEW_FILE; - } else { - // check the time stamp on this file if it's a file we care about based what the - // input folder decides. - if (inputFolder.checksForModification(file)) { - if (file.lastModified() > oldestTarget) { - if (DEBUG) { - System.out.println("UPDATED FILE: " + file.getAbsolutePath()); - } - return DependencyStatus.UPDATED_FILE; - } - } - } - - return DependencyStatus.NONE; - } - - /** - * Check all the prereq files we know about to make sure they're still there, or that they - * haven't been modified since the last build. - * - * @param oldestTarget the time stamp of the oldest output file to compare against. - * - * @return the status of the files - */ - private DependencyStatus checkPrereqFiles(long oldestTarget) { - // TODO: Optimize for the case of a specific file as inputPath. - // We should have a map of filepath to inputpath to quickly search through them? - - // Loop through our prereq files and make sure they still exist - for (File prereq : mPrereqs) { - if (prereq.exists() == false) { - if (DEBUG) { - System.out.println("MISSING FILE: " + prereq.getAbsolutePath()); - } - return DependencyStatus.MISSING_FILE; - } - - // check the time stamp on this file if it's a file we care about. - // To know if we care about the file we have to find the matching input. - if (mNewInputs != null) { - String filePath = prereq.getAbsolutePath(); - for (InputPath input : mNewInputs) { - File inputFile = input.getFile(); - // if the input path is a directory, check if the prereq file is in it, - // otherwise check if the prereq file match exactly the input path. - if (inputFile.isDirectory()) { - if (filePath.startsWith(inputFile.getAbsolutePath())) { - // ok file is inside a directory type input folder. - // check if we need to check this type of file, and if yes, check it. - if (input.checksForModification(prereq)) { - if (prereq.lastModified() > oldestTarget) { - if (DEBUG) { - System.out.println( - "UPDATED FILE: " + prereq.getAbsolutePath()); - } - return DependencyStatus.UPDATED_FILE; - } - } - } - } else { - // this is a file input path, we must check if the match is exact. - if (prereq.equals(inputFile)) { - if (input.checksForModification(prereq)) { - if (prereq.lastModified() > oldestTarget) { - if (DEBUG) { - System.out.println( - "UPDATED FILE: " + prereq.getAbsolutePath()); - } - return DependencyStatus.UPDATED_FILE; - } - } - } - } - } - } else { - // no input? we consider all files. - if (prereq.lastModified() > oldestTarget) { - if (DEBUG) { - System.out.println("UPDATED FILE: " + prereq.getAbsolutePath()); - } - return DependencyStatus.UPDATED_FILE; - } - } - } - - // If we get this far, then all our prereq are okay - return DependencyStatus.NONE; - } - - /** - * Check all the target files we know about to make sure they're still there - * @return true if any of the target files are missing. - */ - private boolean missingTargetFile() { - // Loop through our target files and make sure they still exist - for (File target : mTargets) { - if (target.exists() == false) { - return true; - } - } - // If we get this far, then all our targets are okay - return false; - } - - /** - * Returns the earliest modification time stamp from all the output targets. If there - * are no known target, the dependency file time stamp is returned. - */ - private long getOutputLastModified() { - // Find the oldest target - long oldestTarget = Long.MAX_VALUE; - // if there's no output, then compare to the time of the dependency file. - if (mTargets.size() == 0) { - oldestTarget = mDepFileLastModified; - } else { - for (File target : mTargets) { - if (target.lastModified() < oldestTarget) { - oldestTarget = target.lastModified(); - } - } - } - - return oldestTarget; - } - - /** - * Reads and returns the content of a text file. - * @param file the file to read - * @return null if the file could not be read - */ - private static List<String> readFile(File file) { - try { - return Files.readLines(file, Charsets.UTF_8); - } catch (IOException e) { - // return null below - } - - return null; - } -} diff --git a/anttasks/src/com/android/ant/DependencyHelper.java b/anttasks/src/com/android/ant/DependencyHelper.java deleted file mode 100644 index b1797ad..0000000 --- a/anttasks/src/com/android/ant/DependencyHelper.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * 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.SdkConstants; -import com.android.annotations.Nullable; -import com.android.io.FolderWrapper; -import com.android.sdklib.build.JarListSanitizer; -import com.android.sdklib.build.JarListSanitizer.DifferentLibException; -import com.android.sdklib.build.JarListSanitizer.Sha1Exception; -import com.android.sdklib.internal.project.IPropertySource; -import com.android.sdklib.internal.project.ProjectProperties; -import com.android.sdklib.internal.project.ProjectProperties.PropertyType; - -import org.apache.tools.ant.BuildException; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -/** - * Helper class to manage dependency for projects. - * - */ -public class DependencyHelper { - - private final boolean mVerbose; - private final File mProjectFolder; - private final IPropertySource mProperties; - private final List<File> mLibraries = new ArrayList<File>(); - - /** - * A Library Processor. Used in {@link DependencyHelper#processLibraries(LibraryProcessor)} - * - */ - protected interface LibraryProcessor { - void processLibrary(String libRootPath); - } - - /** - * Advanced version of the {@link LibraryProcessor} that provides the library properties - * to the processor. - */ - public static abstract class AdvancedLibraryProcessor implements LibraryProcessor { - - public abstract void processLibrary(String libRootPath, IPropertySource properties); - - @Override - public final void processLibrary(String libRootPath) { - ProjectProperties properties = TaskHelper.getProperties(libRootPath); - - processLibrary(libRootPath, properties); - } - } - - /** - * Implementation of {@link AdvancedLibraryProcessor} that builds a list of sanitized list - * of 3rd party jar files from all the Library Projects. - */ - public static class JarProcessor extends AdvancedLibraryProcessor { - - private final List<File> mJars = new ArrayList<File>(); - - private final FilenameFilter mFilter = new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.toLowerCase(Locale.US).endsWith(".jar"); - } - }; - - public List<File> getJars() { - return mJars; - } - - public FilenameFilter getFilter() { - return mFilter; - } - - @Override - public void processLibrary(String libRootPath, IPropertySource properties) { - // get the library output - // FIXME: support renamed folder. - mJars.add(new File(libRootPath + "/" + SdkConstants.FD_OUTPUT + - "/" + SdkConstants.FN_CLASSES_JAR)); - - // Get the 3rd party jar files. - // FIXME: support renamed folder. - File libsFolder = new File(libRootPath, SdkConstants.FD_NATIVE_LIBS); - File[] jarFiles = libsFolder.listFiles(mFilter); - if (jarFiles != null) { - for (File jarFile : jarFiles) { - mJars.add(jarFile); - } - } - } - } - - - public static List<File> sanitizePaths(File projectFolder, IPropertySource properties, - List<File> paths) { - // first get the non-files. - List<File> results = new ArrayList<File>(); - for (int i = 0 ; i < paths.size() ;) { - File f = paths.get(i); - // TEMP WORKAROUND: ignore classes.jar as all the output of libraries are - // called the same (in Ant) but are not actually the same jar file. - // TODO: Be aware of library output vs. regular jar dependency. - if (f.isFile() && f.getName().equals(SdkConstants.FN_CLASSES_JAR) == false) { - i++; - } else { - results.add(f); - paths.remove(i); - } - } - - - File outputFile = new File(projectFolder, getOutDir(properties)); - JarListSanitizer sanitizer = new JarListSanitizer(outputFile); - - try { - results.addAll(sanitizer.sanitize(paths)); - } catch (DifferentLibException e) { - String[] details = e.getDetails(); - for (String s : details) { - System.err.println(s); - } - throw new BuildException(e.getMessage(), e); - } catch (Sha1Exception e) { - throw new BuildException( - "Failed to compute sha1 for " + e.getJarFile().getAbsolutePath(), e); - } - - return results; - } - - /** - * - * @param projectFolder the project root folder. - */ - public DependencyHelper(File projectFolder, boolean verbose) { - mProjectFolder = projectFolder; - mVerbose = verbose; - - mProperties = TaskHelper.getProperties(projectFolder.getAbsolutePath()); - - init(projectFolder); - } - - /** - * - * @param projectFolder the project root folder. - * @param source an {@link IPropertySource} that can provide the project properties values. - */ - public DependencyHelper(File projectFolder, IPropertySource properties, boolean verbose) { - mProjectFolder = projectFolder; - mProperties = properties; - mVerbose = verbose; - - init(projectFolder); - } - - private void init(File projectFolder) { - // get the top level list of library dependencies. - List<File> topLevelLibraries = getDirectDependencies(projectFolder, mProperties); - - // process the libraries in case they depend on other libraries. - resolveFullLibraryDependencies(topLevelLibraries, mLibraries); - } - - public List<File> getLibraries() { - return mLibraries; - } - - public int getLibraryCount() { - return mLibraries.size(); - } - - public String getProperty(String name) { - return mProperties.getProperty(name); - } - - public void processLibraries(@Nullable LibraryProcessor processor) { - // use that same order to process the libraries. - for (File library : mLibraries) { - // get the root path. - String libRootPath = library.getAbsolutePath(); - if (mVerbose) { - System.out.println(libRootPath); - } - - if (processor != null) { - processor.processLibrary(libRootPath); - } - } - } - - public List<File> sanitizePaths(List<File> paths) { - return sanitizePaths(mProjectFolder, mProperties, paths); - } - - public String getOutDir() { - return getOutDir(mProperties); - } - - - /** - * Returns the top level library dependencies of a given <var>source</var> representing a - * project properties. - * @param baseFolder the base folder of the project (to resolve relative paths) - * @param properties a source of project properties. - */ - private List<File> getDirectDependencies(File baseFolder, IPropertySource properties) { - ArrayList<File> libraries = new ArrayList<File>(); - - // first build the list. they are ordered highest priority first. - int index = 1; - while (true) { - String propName = ProjectProperties.PROPERTY_LIB_REF + Integer.toString(index++); - String rootPath = properties.getProperty(propName); - - if (rootPath == null) { - break; - } - - try { - File library = new File(baseFolder, rootPath).getCanonicalFile(); - - // check for validity - File projectProp = new File(library, PropertyType.PROJECT.getFilename()); - if (projectProp.isFile() == false) { - // error! - throw new BuildException(String.format( - "%1$s resolve to a path with no %2$s file for project %3$s", rootPath, - PropertyType.PROJECT.getFilename(), baseFolder.getAbsolutePath())); - } - - if (libraries.contains(library) == false) { - if (mVerbose) { - System.out.println(String.format("%1$s: %2$s => %3$s", - baseFolder.getAbsolutePath(), rootPath, library.getAbsolutePath())); - } - - libraries.add(library); - } - } catch (IOException e) { - throw new BuildException("Failed to resolve library path: " + rootPath, e); - } - } - - return libraries; - } - - /** - * Resolves a given list of libraries, finds out if they depend on other libraries, and - * returns a full list of all the direct and indirect dependencies in the proper order (first - * is higher priority when calling aapt). - * @param inLibraries the libraries to resolve - * @param outLibraries where to store all the libraries. - */ - private void resolveFullLibraryDependencies(List<File> inLibraries, List<File> outLibraries) { - // loop in the inverse order to resolve dependencies on the libraries, so that if a library - // is required by two higher level libraries it can be inserted in the correct place - for (int i = inLibraries.size() - 1 ; i >= 0 ; i--) { - File library = inLibraries.get(i); - - // get the default.property file for it - final ProjectProperties projectProp = ProjectProperties.load( - new FolderWrapper(library), PropertyType.PROJECT); - - // get its libraries - List<File> dependencies = getDirectDependencies(library, projectProp); - - // resolve the dependencies for those libraries - resolveFullLibraryDependencies(dependencies, outLibraries); - - // and add the current one (if needed) in front (higher priority) - if (outLibraries.contains(library) == false) { - outLibraries.add(0, library); - } - } - } - - private static String getOutDir(IPropertySource properties) { - String bin = properties.getProperty("out.dir"); - if (bin == null) { - return SdkConstants.FD_OUTPUT; - } - - return bin; - } - -} diff --git a/anttasks/src/com/android/ant/DexExecTask.java b/anttasks/src/com/android/ant/DexExecTask.java deleted file mode 100644 index e33da32..0000000 --- a/anttasks/src/com/android/ant/DexExecTask.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (C) 2011 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.google.common.hash.HashCode; -import com.google.common.hash.HashFunction; -import com.google.common.hash.Hashing; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.ExecTask; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.resources.FileResource; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -/** - * Custom task to execute dx while handling dependencies. - */ -public class DexExecTask extends SingleDependencyTask { - - private String mExecutable; - private String mOutput; - private String mDexedLibs; - private boolean mVerbose = false; - private boolean mNoLocals = false; - private boolean mForceJumbo = false; - private boolean mDisableDexMerger = false; - private List<Path> mPathInputs; - private List<FileSet> mFileSetInputs; - - - /** - * Sets the value of the "executable" attribute. - * @param executable the value. - */ - public void setExecutable(Path executable) { - mExecutable = TaskHelper.checkSinglePath("executable", executable); - } - - /** - * Sets the value of the "verbose" attribute. - * @param verbose the value. - */ - public void setVerbose(boolean verbose) { - mVerbose = verbose; - } - - /** - * Sets the value of the "output" attribute. - * @param output the value. - */ - public void setOutput(Path output) { - mOutput = TaskHelper.checkSinglePath("output", output); - } - - public void setDexedLibs(Path dexedLibs) { - mDexedLibs = TaskHelper.checkSinglePath("dexedLibs", dexedLibs); - } - - /** - * Sets the value of the "nolocals" attribute. - * @param verbose the value. - */ - public void setNoLocals(boolean nolocals) { - mNoLocals = nolocals; - } - - public void setForceJumbo(boolean forceJumbo) { - mForceJumbo = forceJumbo; - } - - public void setDisableDexMerger(boolean disableMerger) { - mDisableDexMerger = disableMerger; - } - - /** - * Returns an object representing a nested <var>path</var> element. - */ - public Object createPath() { - if (mPathInputs == null) { - mPathInputs = new ArrayList<Path>(); - } - - Path path = new Path(getProject()); - mPathInputs.add(path); - - return path; - } - - /** - * Returns an object representing a nested <var>path</var> element. - */ - public Object createFileSet() { - if (mFileSetInputs == null) { - mFileSetInputs = new ArrayList<FileSet>(); - } - - FileSet fs = new FileSet(); - fs.setProject(getProject()); - mFileSetInputs.add(fs); - - return fs; - } - - - private void preDexLibraries(List<File> inputs) { - if (mDisableDexMerger || inputs.size() == 1) { - // only one input, no need to put a pre-dexed version, even if this path is - // just a jar file (case for proguard'ed builds) - return; - } - - final int count = inputs.size(); - for (int i = 0 ; i < count; i++) { - File input = inputs.get(i); - if (input.isFile()) { - // check if this libs needs to be pre-dexed - String fileName = getDexFileName(input); - File dexedLib = new File(mDexedLibs, fileName); - String dexedLibPath = dexedLib.getAbsolutePath(); - - if (dexedLib.isFile() == false || - dexedLib.lastModified() < input.lastModified()) { - - System.out.println( - String.format("Pre-Dexing %1$s -> %2$s", - input.getAbsolutePath(), fileName)); - - if (dexedLib.isFile()) { - dexedLib.delete(); - } - - runDx(input, dexedLibPath, false /*showInput*/); - } else { - System.out.println( - String.format("Using Pre-Dexed %1$s <- %2$s", - fileName, input.getAbsolutePath())); - } - - // replace the input with the pre-dex libs. - inputs.set(i, dexedLib); - } - } - } - - private String getDexFileName(File inputFile) { - // get the filename - String name = inputFile.getName(); - // remove the extension - int pos = name.lastIndexOf('.'); - if (pos != -1) { - name = name.substring(0, pos); - } - - // add a hash of the original file path - HashFunction hashFunction = Hashing.md5(); - HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath()); - - return name + "-" + hashCode.toString() + ".jar"; - } - - - @Override - public void execute() throws BuildException { - - // get all input paths - List<File> paths = new ArrayList<File>(); - if (mPathInputs != null) { - for (Path pathList : mPathInputs) { - for (String path : pathList.list()) { - System.out.println("input: " + path); - paths.add(new File(path)); - } - } - } - - if (mFileSetInputs != null) { - for (FileSet fs : mFileSetInputs) { - Iterator<?> iter = fs.iterator(); - while (iter.hasNext()) { - FileResource fr = (FileResource) iter.next(); - System.out.println("input: " + fr.getFile().toString()); - paths.add(fr.getFile()); - } - } - } - - // pre dex libraries if needed - preDexLibraries(paths); - - // figure out the path to the dependency file. - String depFile = mOutput + ".d"; - - // get InputPath with no extension restrictions - List<InputPath> inputPaths = getInputPaths(paths, null /*extensionsToCheck*/, - null /*factory*/); - - if (initDependencies(depFile, inputPaths) && dependenciesHaveChanged() == false) { - System.out.println( - "No new compiled code. No need to convert bytecode to dalvik format."); - return; - } - - System.out.println(String.format( - "Converting compiled files and external libraries into %1$s...", mOutput)); - - runDx(paths, mOutput, mVerbose /*showInputs*/); - - // generate the dependency file. - generateDependencyFile(depFile, inputPaths, mOutput); - } - - private void runDx(File input, String output, boolean showInputs) { - runDx(Collections.singleton(input), output, showInputs); - } - - private void runDx(Collection<File> inputs, String output, boolean showInputs) { - ExecTask task = new ExecTask(); - task.setProject(getProject()); - task.setOwningTarget(getOwningTarget()); - task.setExecutable(mExecutable); - task.setTaskName(getExecTaskName()); - task.setFailonerror(true); - - task.createArg().setValue("--dex"); - - if (mNoLocals) { - task.createArg().setValue("--no-locals"); - } - - if (mVerbose) { - task.createArg().setValue("--verbose"); - } - - if (mForceJumbo) { - task.createArg().setValue("--force-jumbo"); - } - - task.createArg().setValue("--output"); - task.createArg().setValue(output); - - for (File input : inputs) { - String absPath = input.getAbsolutePath(); - if (showInputs) { - System.out.println("Input: " + absPath); - } - task.createArg().setValue(absPath); - } - - // execute it. - task.execute(); - } - - @Override - protected String getExecTaskName() { - return "dx"; - } -} diff --git a/anttasks/src/com/android/ant/GetEmmaFilterTask.java b/anttasks/src/com/android/ant/GetEmmaFilterTask.java deleted file mode 100644 index f449f8d..0000000 --- a/anttasks/src/com/android/ant/GetEmmaFilterTask.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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 org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; - -/** - * Task building an emma filter to remove all build-only classes. - * - * Currently ignore: - * app.package.R - * app.package.R$* - * app.package.Manifest - * app.package.BuildConfig - * - */ -public class GetEmmaFilterTask extends Task { - - private static final String[] FILTER_CLASSES = new String[] { - "R", "R$*", "Manifest", "BuildConfig" - }; - - private String mAppPackage; - private String mLibraryPackagesRefId; - private String mFilterOut; - - - public void setAppPackage(String appPackage) { - mAppPackage = appPackage; - } - - public void setLibraryPackagesRefId(String libraryPackagesRefId) { - mLibraryPackagesRefId = libraryPackagesRefId; - } - - public void setFilterOut(String filterOut) { - mFilterOut = filterOut; - } - - @Override - public void execute() throws BuildException { - if (mAppPackage == null) { - throw new BuildException("Missing attribute appPackage"); - } - if (mLibraryPackagesRefId == null) { - throw new BuildException("Missing attribute libraryPackagesRefId"); - } - if (mFilterOut == null) { - throw new BuildException("Missing attribute filterOut"); - } - - StringBuilder sb = new StringBuilder(); - - String libraryPackagesValue = getProject().getProperty(mLibraryPackagesRefId); - - if (libraryPackagesValue != null && libraryPackagesValue.length() > 0) { - // split the app packages. - String[] libPackages = libraryPackagesValue.split(";"); - - for (String libPackage : libPackages) { - if (libPackage.length() > 0) { - for (String filterClass : FILTER_CLASSES) { - sb.append(libPackage).append('.').append(filterClass).append(','); - } - } - } - } - - // add the app package: - final int count = FILTER_CLASSES.length; - for (int i = 0 ; i < count ; i++) { - sb.append(mAppPackage).append('.').append(FILTER_CLASSES[i]); - if (i < count - 1) { - sb.append(','); - } - } - - getProject().setProperty(mFilterOut, sb.toString()); - } -} diff --git a/anttasks/src/com/android/ant/GetLibraryPathTask.java b/anttasks/src/com/android/ant/GetLibraryPathTask.java deleted file mode 100644 index 813574e..0000000 --- a/anttasks/src/com/android/ant/GetLibraryPathTask.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * 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.annotations.NonNull; -import com.android.annotations.Nullable; -import com.android.ant.DependencyHelper.AdvancedLibraryProcessor; -import com.android.ant.DependencyHelper.LibraryProcessor; -import com.android.sdklib.internal.project.IPropertySource; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Path.PathElement; - -import java.io.File; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Task to get the list of Library Project paths for either the current project or any given - * project. - * - */ -public class GetLibraryPathTask extends Task { - - private String mProjectPath; - private String mLibraryFolderPathOut; - private String mLeaf; - private boolean mVerbose = false; - - private static class LeafProcessor extends AdvancedLibraryProcessor { - private final static Pattern PH = Pattern.compile("^\\@\\{(.*)\\}$"); - - private Path mPath; - private final String[] mLeafSegments; - - LeafProcessor(Project antProject, String leaf) { - mPath = new Path(antProject); - mLeafSegments = leaf.split("/"); - } - - @Override - public void processLibrary(String libRootPath, IPropertySource properties) { - StringBuilder sb = new StringBuilder(libRootPath); - for (String segment : mLeafSegments) { - sb.append('/'); - - Matcher m = PH.matcher(segment); - if (m.matches()) { - String value = properties.getProperty(m.group(1)); - if (value == null) { - value = TaskHelper.getDefault(m.group(1)); - } - if (value == null) { - throw new BuildException( - "Failed to resolve '" + m.group(1) + "' for project " - + libRootPath); - } - sb.append(value); - } else { - sb.append(segment); - } - } - - PathElement element = mPath.createPathElement(); - element.setPath(sb.toString()); - } - - @NonNull public Path getPath() { - return mPath; - } - } - - public void setProjectPath(String projectPath) { - mProjectPath = projectPath; - } - - public void setLibraryFolderPathOut(String libraryFolderPathOut) { - mLibraryFolderPathOut = libraryFolderPathOut; - } - - protected String getLibraryFolderPathOut() { - return mLibraryFolderPathOut; - } - - public void setLeaf(String leaf) { - mLeaf = leaf; - } - - /** - * Sets the value of the "verbose" attribute. - * @param verbose the value. - */ - public void setVerbose(boolean verbose) { - mVerbose = verbose; - } - - protected boolean getVerbose() { - return mVerbose; - } - - @Override - public void execute() throws BuildException { - if (mLibraryFolderPathOut == null) { - throw new BuildException("Missing attribute libraryFolderPathOut"); - } - - LibraryProcessor processor = null; - - if (mLeaf != null) { - // we need a custom processor - processor = new LeafProcessor(getProject(), mLeaf); - } - - if (mProjectPath == null) { - execute(processor); - } else { - DependencyHelper helper = new DependencyHelper(new File(mProjectPath), mVerbose); - - execute(helper, processor); - } - } - - /** - * Executes the processor on the current project. - * @param processor - * @throws BuildException - */ - protected void execute(@Nullable LibraryProcessor processor) throws BuildException { - final Project antProject = getProject(); - - DependencyHelper helper = new DependencyHelper(antProject.getBaseDir(), - new IPropertySource() { - @Override - public String getProperty(String name) { - return antProject.getProperty(name); - } - - @Override - public void debugPrint() { - } - }, - mVerbose); - - execute(helper, processor); - } - - /** - * Executes the processor using a given DependencyHelper. - * @param helper - * @param processor - * @throws BuildException - */ - private void execute(@NonNull DependencyHelper helper, @Nullable LibraryProcessor processor) - throws BuildException { - - final Project antProject = getProject(); - - System.out.println("Library dependencies:"); - - Path path = new Path(antProject); - - if (helper.getLibraryCount() > 0) { - System.out.println("\n------------------\nOrdered libraries:"); - - helper.processLibraries(processor); - - if (mLibraryFolderPathOut != null) { - if (mLeaf == null) { - // Fill a Path object with all the libraries in reverse order. - // This is important so that compilation of libraries happens - // in the reverse order. - List<File> libraries = helper.getLibraries(); - - for (int i = libraries.size() - 1 ; i >= 0; i--) { - File library = libraries.get(i); - PathElement element = path.createPathElement(); - element.setPath(library.getAbsolutePath()); - } - - } else { - path = ((LeafProcessor) processor).getPath(); - } - } - } else { - System.out.println("No Libraries"); - } - - antProject.addReference(mLibraryFolderPathOut, path); - } -} diff --git a/anttasks/src/com/android/ant/GetProjectPathsTask.java b/anttasks/src/com/android/ant/GetProjectPathsTask.java deleted file mode 100644 index 42494ab..0000000 --- a/anttasks/src/com/android/ant/GetProjectPathsTask.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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.internal.project.ProjectProperties; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; - -import java.io.File; - -public class GetProjectPathsTask extends Task { - - private String mProjectPath; - private String mBinName; - private String mSrcName; - - public void setProjectPath(String projectPath) { - mProjectPath = projectPath; - } - - public void setBinOut(String binName) { - mBinName = binName; - } - - public void setSrcOut(String srcName) { - mSrcName = srcName; - } - - @Override - public void execute() throws BuildException { - if (mProjectPath == null) { - throw new BuildException("Missing attribute projectPath"); - } - - ProjectProperties props = TaskHelper.getProperties(mProjectPath); - - if (mBinName != null) { - handleProp(props, "out.dir", mBinName); - } - - if (mSrcName != null) { - handleProp(props, "source.dir", mSrcName); - } - - } - - private void handleProp(ProjectProperties props, String inName, String outName) { - String value = props.getProperty(inName); - if (value == null) { - value = TaskHelper.getDefault(inName); - } - getProject().setProperty(outName, new File(mProjectPath, value).getAbsolutePath()); - - } -} diff --git a/anttasks/src/com/android/ant/GetTargetTask.java b/anttasks/src/com/android/ant/GetTargetTask.java deleted file mode 100644 index d79ffee..0000000 --- a/anttasks/src/com/android/ant/GetTargetTask.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * 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.SdkConstants; -import com.android.annotations.NonNull; -import com.android.sdklib.AndroidVersion; -import com.android.sdklib.IAndroidTarget; -import com.android.sdklib.IAndroidTarget.IOptionalLibrary; -import com.android.sdklib.SdkManager; -import com.android.sdklib.internal.project.ProjectProperties; -import com.android.utils.ILogger; -import com.android.xml.AndroidManifest; -import com.android.xml.AndroidXPathFactory; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.Path.PathElement; -import org.xml.sax.InputSource; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.HashSet; - -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; - -/** - * Task to resolve the target of the current Android project. - * - * Out params: - * <code>bootClassPathOut</code>: The boot class path of the project. - * - * <code>androidJarFileOut</code>: the android.jar used by the project. - * - * <code>androidAidlFileOut</code>: the framework.aidl used by the project. - * - * <code>targetApiOut</code>: the build API level. - * - * <code>minSdkVersionOut</code>: the app's minSdkVersion. - * - */ -public class GetTargetTask extends Task { - - private String mBootClassPathOut; - private String mAndroidJarFileOut; - private String mAndroidAidlFileOut; - private String mTargetApiOut; - private String mMinSdkVersionOut; - - public void setBootClassPathOut(String bootClassPathOut) { - mBootClassPathOut = bootClassPathOut; - } - - public void setAndroidJarFileOut(String androidJarFileOut) { - mAndroidJarFileOut = androidJarFileOut; - } - - public void setAndroidAidlFileOut(String androidAidlFileOut) { - mAndroidAidlFileOut = androidAidlFileOut; - } - - public void setTargetApiOut(String targetApiOut) { - mTargetApiOut = targetApiOut; - } - - public void setMinSdkVersionOut(String minSdkVersionOut) { - mMinSdkVersionOut = minSdkVersionOut; - } - - @Override - public void execute() throws BuildException { - if (mBootClassPathOut == null) { - throw new BuildException("Missing attribute bootClassPathOut"); - } - if (mAndroidJarFileOut == null) { - throw new BuildException("Missing attribute androidJarFileOut"); - } - if (mAndroidAidlFileOut == null) { - throw new BuildException("Missing attribute androidAidlFileOut"); - } - if (mTargetApiOut == null) { - throw new BuildException("Missing attribute targetApiOut"); - } - if (mMinSdkVersionOut == null) { - throw new BuildException("Missing attribute mMinSdkVersionOut"); - } - - Project antProject = getProject(); - - // get the SDK location - File sdkDir = TaskHelper.getSdkLocation(antProject); - - // 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(sdkDir.getPath(), new ILogger() { - @Override - 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()); - } - } - - @Override - public void info(@NonNull String msgFormat, Object... args) { - messages.add(String.format(msgFormat, args)); - } - - @Override - public void verbose(@NonNull String msgFormat, Object... args) { - info(msgFormat, args); - } - - @Override - public void warning(@NonNull 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 project target '%s'", targetHashString)); - } - - // display the project info - System.out.println( "Project Target: " + androidTarget.getName()); - if (androidTarget.isPlatform() == false) { - System.out.println("Vendor: " + androidTarget.getVendor()); - System.out.println("Platform Version: " + androidTarget.getVersionName()); - } - System.out.println( "API level: " + androidTarget.getVersion().getApiString()); - - antProject.setProperty(mTargetApiOut, - Integer.toString(androidTarget.getVersion().getApiLevel())); - - // always check the manifest minSdkVersion. - checkManifest(antProject, androidTarget.getVersion()); - - // sets up the properties to find android.jar/framework.aidl/target tools - String androidJar = androidTarget.getPath(IAndroidTarget.ANDROID_JAR); - antProject.setProperty(mAndroidJarFileOut, androidJar); - - String androidAidl = androidTarget.getPath(IAndroidTarget.ANDROID_AIDL); - antProject.setProperty(mAndroidAidlFileOut, 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(jarPath); - } - } - } - - // sets the path in the project with a reference - antProject.addReference(mBootClassPathOut, bootclasspath); - } - - /** - * Checks the manifest <code>minSdkVersion</code> attribute. - * @param antProject the ant project - * @param androidVersion the version of the platform the project is compiling against. - */ - private void checkManifest(Project antProject, AndroidVersion androidVersion) { - try { - File manifest = new File(antProject.getBaseDir(), SdkConstants.FN_ANDROID_MANIFEST_XML); - - XPath xPath = AndroidXPathFactory.newXPath(); - - // check the package name. - String value = xPath.evaluate( - "/" + AndroidManifest.NODE_MANIFEST + - "/@" + AndroidManifest.ATTRIBUTE_PACKAGE, - new InputSource(new FileInputStream(manifest))); - if (value != null) { // aapt will complain if it's missing. - // only need to check that the package has 2 segments - if (value.indexOf('.') == -1) { - throw new BuildException(String.format( - "Application package '%1$s' must have a minimum of 2 segments.", - value)); - } - } - - // check the minSdkVersion value - value = xPath.evaluate( - "/" + AndroidManifest.NODE_MANIFEST + - "/" + AndroidManifest.NODE_USES_SDK + - "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX + ":" + - AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION, - new InputSource(new FileInputStream(manifest))); - - if (androidVersion.isPreview()) { - // in preview mode, the content of the minSdkVersion must match exactly the - // platform codename. - String codeName = androidVersion.getCodename(); - if (codeName.equals(value) == false) { - throw new BuildException(String.format( - "For '%1$s' SDK Preview, attribute minSdkVersion in AndroidManifest.xml must be '%1$s' (current: %2$s)", - codeName, value)); - } - - // set the minSdkVersion to the previous API level (which is actually the value in - // androidVersion.) - antProject.setProperty(mMinSdkVersionOut, - Integer.toString(androidVersion.getApiLevel())); - - } else if (value.length() > 0) { - // for normal platform, we'll only display warnings if the value is lower or higher - // than the target api level. - // First convert to an int. - int minSdkValue = -1; - try { - minSdkValue = Integer.parseInt(value); - } catch (NumberFormatException e) { - // looks like it's not a number: error! - throw new BuildException(String.format( - "Attribute %1$s in AndroidManifest.xml must be an Integer!", - AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION)); - } - - // set the minSdkVersion to the value - antProject.setProperty(mMinSdkVersionOut, value); - - int projectApiLevel = androidVersion.getApiLevel(); - if (minSdkValue > androidVersion.getApiLevel()) { - System.out.println(String.format( - "WARNING: Attribute %1$s in AndroidManifest.xml (%2$d) is higher than the project target API level (%3$d)", - AndroidManifest.ATTRIBUTE_MIN_SDK_VERSION, - minSdkValue, projectApiLevel)); - } - } else { - // no minSdkVersion? display a warning - System.out.println( - "WARNING: No minSdkVersion value set. Application will install on all Android versions."); - - // set the target api to 1 - antProject.setProperty(mMinSdkVersionOut, "1"); - } - - } catch (XPathExpressionException e) { - throw new BuildException(e); - } catch (FileNotFoundException e) { - throw new BuildException(e); - } - } -} diff --git a/anttasks/src/com/android/ant/GetTypeTask.java b/anttasks/src/com/android/ant/GetTypeTask.java deleted file mode 100644 index 143bc35..0000000 --- a/anttasks/src/com/android/ant/GetTypeTask.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * 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.SdkConstants; -import com.android.sdklib.internal.project.ProjectProperties; -import com.android.xml.AndroidManifest; -import com.android.xml.AndroidXPathFactory; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -import org.xml.sax.InputSource; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; - -/** - * Task to query the type of the current project. - * - * Out params: - * - * <code>projectTypeOut</code>: String value containing the type of the project. Possible values - * are 'app', 'library', 'test', 'test-app' - * - */ -public class GetTypeTask extends Task { - - private String mProjectTypeOut; - - public void setProjectTypeOut(String projectTypeOut) { - mProjectTypeOut = projectTypeOut; - } - - @Override - public void execute() throws BuildException { - if (mProjectTypeOut == null) { - throw new BuildException("Missing attribute projectTypeOut"); - } - - Project antProject = getProject(); - - String libraryProp = antProject.getProperty(ProjectProperties.PROPERTY_LIBRARY); - if (libraryProp != null) { - if (Boolean.valueOf(libraryProp).booleanValue()) { - System.out.println("Project Type: Android Library"); - - antProject.setProperty(mProjectTypeOut, "library"); - return; - } - } - - if (antProject.getProperty(ProjectProperties.PROPERTY_TESTED_PROJECT) != null) { - System.out.println("Project Type: Test Application"); - - antProject.setProperty(mProjectTypeOut, "test"); - return; - } - - // we also need to check if the Manifest doesn't have some instrumentation which - // means the app is a self-contained test project. - try { - File manifest = new File(antProject.getBaseDir(), SdkConstants.FN_ANDROID_MANIFEST_XML); - XPath xPath = AndroidXPathFactory.newXPath(); - - // check the present of /manifest/instrumentation/ - String value = xPath.evaluate( - "/" + AndroidManifest.NODE_MANIFEST + - "/" + AndroidManifest.NODE_INSTRUMENTATION + - "/@" + AndroidXPathFactory.DEFAULT_NS_PREFIX + - ":" + AndroidManifest.ATTRIBUTE_TARGET_PACKAGE, - new InputSource(new FileInputStream(manifest))); - - if (value != null && value.length() > 0) { - System.out.println("Project Type: Self-Tested Application"); - - antProject.setProperty(mProjectTypeOut, "test-app"); - return; - } - } catch (XPathExpressionException e) { - throw new BuildException(e); - } catch (FileNotFoundException e) { - throw new BuildException(e); - } - - // default case - System.out.println("Project Type: Application"); - - antProject.setProperty(mProjectTypeOut, "app"); - } -} diff --git a/anttasks/src/com/android/ant/GetUiTargetTask.java b/anttasks/src/com/android/ant/GetUiTargetTask.java deleted file mode 100644 index e45d2bc..0000000 --- a/anttasks/src/com/android/ant/GetUiTargetTask.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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.annotations.NonNull; -import com.android.sdklib.IAndroidTarget; -import com.android.sdklib.IAndroidTarget.IOptionalLibrary; -import com.android.sdklib.SdkManager; -import com.android.sdklib.internal.project.ProjectProperties; -import com.android.utils.ILogger; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.Task; -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; - -/** - * Task to resolve the target of the current Android uiautomator project. - * - * Out params: - * <code>compileClassPathOut</code>: The compile class path for the project. - */ -public class GetUiTargetTask extends Task { - - private String mCompileClassPathOut; - - public void setCompileClassPathOut(String compileClassPathOut) { - mCompileClassPathOut = compileClassPathOut; - } - - @Override - public void execute() throws BuildException { - if (mCompileClassPathOut == null) { - throw new BuildException("Missing attribute compileClassPathOut"); - } - - Project antProject = getProject(); - - // get the SDK location - File sdkDir = TaskHelper.getSdkLocation(antProject); - - // 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(sdkDir.getPath(), new ILogger() { - @Override - 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()); - } - } - - @Override - public void info(@NonNull String msgFormat, Object... args) { - messages.add(String.format(msgFormat, args)); - } - - @Override - public void verbose(@NonNull String msgFormat, Object... args) { - info(msgFormat, args); - } - - @Override - public void warning(@NonNull 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 project target '%s'", targetHashString)); - } - - // display the project info - System.out.println( "Project Target: " + androidTarget.getName()); - if (androidTarget.isPlatform() == false) { - System.out.println("Vendor: " + androidTarget.getVendor()); - System.out.println("Platform Version: " + androidTarget.getVersionName()); - } - System.out.println( "API level: " + androidTarget.getVersion().getApiString()); - - if (androidTarget.getVersion().getApiLevel() < 16) { - throw new BuildException("UI Automator requires API 16"); - } - - // sets up the properties to find android.jar/framework.aidl/target tools - String androidJar = androidTarget.getPath(IAndroidTarget.ANDROID_JAR); - String uiAutomatorJar = androidTarget.getPath(IAndroidTarget.UI_AUTOMATOR_JAR); - - // sets up the boot classpath - - // create the Path object - Path compileclasspath = new Path(antProject); - - // create a PathElement for the framework jars - PathElement element = compileclasspath.createPathElement(); - element.setPath(androidJar); - - element = compileclasspath.createPathElement(); - element.setPath(uiAutomatorJar); - - // 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 = compileclasspath.createPathElement(); - element.setPath(jarPath); - } - } - } - - // sets the path in the project with a reference - antProject.addReference(mCompileClassPathOut, compileclasspath); - } -} diff --git a/anttasks/src/com/android/ant/IfElseTask.java b/anttasks/src/com/android/ant/IfElseTask.java deleted file mode 100644 index f34e486..0000000 --- a/anttasks/src/com/android/ant/IfElseTask.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2010 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 org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.taskdefs.Sequential; -import org.apache.tools.ant.taskdefs.condition.And; - -/** - * If (condition) then: {@link Sequential} else: {@link Sequential}. - * - * In XML: - * <if condition="${prop with a boolean value}"> - * <then> - * </then> - * <else> - * </else> - * </if> - * - * or - * - * <if> - * <condition> - * ... - * </condition> - * <then> - * </then> - * <else> - * </else> - * </if> - * - * both <then> and <else> behave like <sequential>. - * <condition> behaves like an <and> condition. - * - * The presence of both <then> and <else> is not required, but one of them must be present. - * <if condition="${some.condition}"> - * <else> - * </else> - * </if> - * is perfectly valid. - * - */ -public class IfElseTask extends Task { - - private boolean mCondition; - private boolean mConditionIsSet = false; - private And mAnd; - private Sequential mThen; - private Sequential mElse; - - /** - * Sets the condition value - */ - public void setCondition(boolean condition) { - mCondition = condition; - mConditionIsSet = true; - } - - /** - * Creates and returns the <condition> node which is basically a <and>. - */ - public Object createCondition() { - if (mConditionIsSet) { - throw new BuildException("Cannot use both condition attribute and <condition> element"); - } - - mAnd = new And(); - mAnd.setProject(getProject()); - return mAnd; - } - - /** - * Creates and returns the <then> {@link Sequential} - */ - public Object createThen() { - mThen = new Sequential(); - return mThen; - } - - /** - * Creates and returns the <else> {@link Sequential} - */ - public Object createElse() { - mElse = new Sequential(); - return mElse; - } - - @Override - public void execute() throws BuildException { - if (mConditionIsSet == false && mAnd == null) { - throw new BuildException("condition attribute or element must be set."); - } - - if (mAnd != null) { - mCondition = mAnd.eval(); - } - - // need at least one. - if (mThen == null && mElse == null) { - throw new BuildException("Need at least <then> or <else>"); - } - - if (mCondition) { - if (mThen != null) { - mThen.execute(); - } - } else { - if (mElse != null) { - mElse.execute(); - } - } - } -} diff --git a/anttasks/src/com/android/ant/InputPath.java b/anttasks/src/com/android/ant/InputPath.java deleted file mode 100644 index 2299f07..0000000 --- a/anttasks/src/com/android/ant/InputPath.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (C) 2011 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 java.io.File; -import java.util.Set; - -public class InputPath { - - private final File mFile; - /** - * A set of extensions. Only files with an extension in this set will - * be considered for a modification check. All deleted/created files will still be - * checked. - */ - private final Set<String> mTouchedExtensions; - - public InputPath(File file) { - this(file, null); - } - - public InputPath(File file, Set<String> extensionsToCheck) { - if (file == null) { - throw new RuntimeException("File in InputPath(File) can't be null"); - } - mFile = file; - mTouchedExtensions = extensionsToCheck; - } - - public File getFile() { - return mFile; - } - - /** - * Returns whether this input path (likely actually a folder) must check this files for - * modification (all files are checked for add/delete). - * - * This is configured by constructing the {@link InputPath} with additional restriction - * parameters such as specific extensions. - * @param file the file to check - * @return true if the file must be checked for modification. - */ - public boolean checksForModification(File file) { - if (ignores(file)) { - return false; - } - - if (mTouchedExtensions != null && - mTouchedExtensions.contains(getExtension(file)) == false) { - return false; - } - - return true; - } - - /** - * Returns whether the InputPath ignores a given file or folder. If it is ignored then - * the file (or folder) is not checked for any event (modification/add/delete). - * If it's a folder, then it and its content are completely ignored. - * @param file the file or folder to check - * @return true if the file or folder are ignored. - */ - public boolean ignores(File file) { - // always ignore hidden files/folders. - return file.getName().startsWith("."); - } - - /** - * Gets the extension (if present) on a file by looking at the filename - * @param file the file to get the extension from - * @return the extension if present, or the empty string if the filename doesn't have - * and extension. - */ - protected static String getExtension(File file) { - return getExtension(file.getName()); - } - - /** - * Gets the extension (if present) on a file by looking at the filename - * @param fileName the filename to get the extension from - * @return the extension if present, or the empty string if the filename doesn't have - * and extension. - */ - protected static String getExtension(String fileName) { - int index = fileName.lastIndexOf('.'); - if (index == -1) { - return ""; - } - // Don't include the leading '.' in the extension - return fileName.substring(index + 1); - } - -} diff --git a/anttasks/src/com/android/ant/LintExecTask.java b/anttasks/src/com/android/ant/LintExecTask.java deleted file mode 100644 index 3d687cb..0000000 --- a/anttasks/src/com/android/ant/LintExecTask.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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 org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.ExecTask; -import org.apache.tools.ant.types.Path; - -/** - * Custom task to execute lint - */ -public class LintExecTask extends ExecTask { - - private String mExecutable; - private String mHtml; - private String mXml; - private Path mSourcePath; - private Path mClassPath; - - /** - * Sets the value of the "executable" attribute. - * @param executable the value. - */ - public void setExecutable(Path executable) { - mExecutable = TaskHelper.checkSinglePath("executable", executable); - } - - /** Sets the path where Java source code should be found */ - public void setSrc(Path path) { - mSourcePath = path; - } - - /** Sets the path where class files should be found */ - public void setClasspath(Path path) { - mClassPath = path; - } - - /** - * Sets the value of the "html" attribute: a path to a file or directory name - * where the HTML report should be written. - * - * @param html path to the html report - */ - public void setHtml(Path html) { - mHtml = TaskHelper.checkSinglePath("html", html); - } - - /** - * Sets the value of the "xml" attribute: a path to a file or directory name - * where the XML report should be written. - * - * @param xml path to the xml report - */ - public void setXml(Path xml) { - mXml = TaskHelper.checkSinglePath("xml", xml); - } - - @Override - public void execute() throws BuildException { - - ExecTask task = new ExecTask(); - task.setProject(getProject()); - task.setOwningTarget(getOwningTarget()); - task.setExecutable(mExecutable); - task.setTaskName("lint"); - task.setFailonerror(true); - - task.createArg().setValue("--text"); - task.createArg().setValue("stdout"); - - if (mHtml != null) { - task.createArg().setValue("--html"); - task.createArg().setValue(mHtml); - } - - if (mXml != null) { - task.createArg().setValue("--xml"); - task.createArg().setValue(mXml); - } - - if (mSourcePath != null) { - task.createArg().setValue("--sources"); - task.createArg().setValue(mSourcePath.toString()); - } - - if (mClassPath != null) { - task.createArg().setValue("--classpath"); - task.createArg().setValue(mClassPath.toString()); - } - - task.createArg().setValue(getProject().getBaseDir().getAbsolutePath()); - task.execute(); - } -} diff --git a/anttasks/src/com/android/ant/ManifestMergerTask.java b/anttasks/src/com/android/ant/ManifestMergerTask.java deleted file mode 100644 index 6c53069..0000000 --- a/anttasks/src/com/android/ant/ManifestMergerTask.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * 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.annotations.NonNull; -import com.android.manifmerger.ICallback; -import com.android.manifmerger.ManifestMerger; -import com.android.manifmerger.MergerLog; -import com.android.sdklib.IAndroidTarget; -import com.android.sdklib.SdkManager; -import com.android.sdklib.io.FileOp; -import com.android.utils.StdLogger; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Path; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class ManifestMergerTask extends SingleDependencyTask { - - private String mAppManifest; - private String mOutManifest; - - private ArrayList<Path> mLibraryPaths; - private boolean mEnabled = false; - - public void setAppManifest(Path appManifest) { - mAppManifest = TaskHelper.checkSinglePath("appManifest", appManifest); - } - - public void setOutManifest(Path outManifest) { - mOutManifest = TaskHelper.checkSinglePath("outManifest", outManifest); - } - - public void setEnabled(boolean enabled) { - mEnabled = enabled; - } - - /** - * Returns an object representing a nested <var>library</var> element. - */ - public Object createLibrary() { - if (mLibraryPaths == null) { - mLibraryPaths = new ArrayList<Path>(); - } - - Path path = new Path(getProject()); - mLibraryPaths.add(path); - - return path; - } - - @Override - public void execute() throws BuildException { - if (mAppManifest == null) { - throw new BuildException("Missing attribute appManifest"); - } - if (mOutManifest == null) { - throw new BuildException("Missing attribute outManifest"); - } - - // if we merge, then get the rest of the input paths. - List<File> libraries = new ArrayList<File>(); - if (mLibraryPaths != null) { - for (Path pathList : mLibraryPaths) { - for (String path : pathList.list()) { - libraries.add(new File(path)); - } - } - } - - // prepare input files - ArrayList<File> allInputs = new ArrayList<File>(libraries.size() + 1); - - // always: the input manifest. - File appManifestFile = new File(mAppManifest); - allInputs.add(appManifestFile); - - // if enabled: add the libraries - if (mEnabled) { - allInputs.addAll(libraries); - } - - // figure out the path to the dependency file. - String depFile = mOutManifest + ".d"; - - // get InputPath with no extension restrictions - List<InputPath> inputPaths = getInputPaths(allInputs, null /*extensionsToCheck*/, - null /*factory*/); - - if (initDependencies(depFile, inputPaths) && dependenciesHaveChanged() == false) { - System.out.println( - "No changes in the AndroidManifest files."); - return; - } - - System.out.println("Merging AndroidManifest files into one."); - - if (mEnabled == false || libraries.size() == 0) { - if (mEnabled == false) { - System.out.println("Manifest merger disabled. Using project manifest only."); - } else { - System.out.println("No libraries. Using project manifest only."); - } - // no merge (disabled or nothing to merge)? do a simple copy. - try { - new FileOp().copyFile(appManifestFile, new File(mOutManifest)); - } catch (IOException e) { - throw new BuildException(e); - } - } else { - System.out.println(String.format("Merging manifests from project and %d libraries.", - libraries.size())); - ManifestMerger merger = new ManifestMerger( - MergerLog.wrapSdkLog(new StdLogger(StdLogger.Level.VERBOSE)), - new ICallback() { - SdkManager mManager; - @Override - public int queryCodenameApiLevel(@NonNull String codename) { - if (mManager == null) { - File sdkDir = TaskHelper.getSdkLocation(getProject()); - mManager = SdkManager.createManager(sdkDir.getPath(), - new StdLogger(StdLogger.Level.VERBOSE)); - } - if (mManager != null) { - IAndroidTarget t = mManager.getTargetFromHashString( - IAndroidTarget.PLATFORM_HASH_PREFIX + codename); - if (t != null) { - return t.getVersion().getApiLevel(); - } - } - return ICallback.UNKNOWN_CODENAME; - } - }); - if (merger.process( - new File(mOutManifest), - appManifestFile, - libraries.toArray(new File[libraries.size()]), - null /*injectAttributes*/) == false) { - throw new BuildException(); - } - } - - // generate the dependency file. - generateDependencyFile(depFile, inputPaths, mOutManifest); - } - - @Override - protected String getExecTaskName() { - return "ManifestMerger"; - } -} diff --git a/anttasks/src/com/android/ant/MultiFilesTask.java b/anttasks/src/com/android/ant/MultiFilesTask.java deleted file mode 100644 index 4f1ae40..0000000 --- a/anttasks/src/com/android/ant/MultiFilesTask.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2011 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 org.apache.tools.ant.Project; -import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.types.PatternSet.NameEntry; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -class MultiFilesTask extends BuildTypedTask { - - static enum DisplayType { - FOUND, COMPILING, REMOVE_OUTPUT, REMOVE_DEP; - } - - interface SourceProcessor { - Set<String> getSourceFileExtensions(); - void process(String filePath, String sourceFolder, - List<String> sourceFolders, Project taskProject); - void displayMessage(DisplayType type, int count); - } - - protected void processFiles(SourceProcessor processor, List<Path> paths, String genFolder) { - - Project taskProject = getProject(); - - Set<String> extensions = processor.getSourceFileExtensions(); - - // build a list of all the source folders - ArrayList<String> sourceFolders = new ArrayList<String>(); - for (Path p : paths) { - String[] values = p.list(); - if (values != null) { - sourceFolders.addAll(Arrays.asList(values)); - } - } - - ArrayList<String> includePatterns = new ArrayList<String>(extensions.size()); - for (String extension : extensions) { - includePatterns.add("**/*." + extension); - } - - // gather all the source files from all the source folders. - Map<String, String> sourceFiles = getFilesByNameEntryFilter(sourceFolders, - includePatterns.toArray(new String[includePatterns.size()])); - if (sourceFiles.size() > 0) { - processor.displayMessage(DisplayType.FOUND, sourceFiles.size()); - } - - // go look for all dependency files in the gen folder. This will have all dependency - // files but we can filter them based on the first pre-req file. - Iterator<?> depFiles = getFilesByNameEntryFilter(genFolder, "**/*.d"); - - // parse all the dep files and keep the ones that are of the proper type and check if - // they require compilation again. - Map<String, String> toCompile = new HashMap<String, String>(); - ArrayList<File> toRemove = new ArrayList<File>(); - ArrayList<String> depsToRemove = new ArrayList<String>(); - while (depFiles.hasNext()) { - String depFile = depFiles.next().toString(); - DependencyGraph graph = new DependencyGraph(depFile, null /*watchPaths*/); - - // get the source file. it's the first item in the pre-reqs - File sourceFile = graph.getFirstPrereq(); - String sourceFilePath = sourceFile.getAbsolutePath(); - - // The gen folder may contain other dependency files not generated by this particular - // processor. - // We only care if the first pre-rep is of the right extension. - String fileExtension = sourceFilePath.substring(sourceFilePath.lastIndexOf('.') + 1); - if (extensions.contains(fileExtension.toLowerCase(Locale.US))) { - // remove from the list of sourceFiles to mark as "processed" (but not compiled - // yet, that'll be done by adding it to toCompile) - String sourceFolder = sourceFiles.get(sourceFilePath); - if (sourceFolder == null) { - // looks like the source file does not exist anymore! - // we'll have to remove the output! - Set<File> outputFiles = graph.getTargets(); - toRemove.addAll(outputFiles); - - // also need to remove the dep file. - depsToRemove.add(depFile); - } else { - // Source file is present. remove it from the list as being processed. - sourceFiles.remove(sourceFilePath); - - // check if it needs to be recompiled. - if (hasBuildTypeChanged() || - graph.dependenciesHaveChanged(false /*printStatus*/)) { - toCompile.put(sourceFilePath, sourceFolder); - } - } - } - } - - // add to the list of files to compile, whatever is left in sourceFiles. Those are - // new files that have never been compiled. - toCompile.putAll(sourceFiles); - - processor.displayMessage(DisplayType.COMPILING, toCompile.size()); - if (toCompile.size() > 0) { - for (Entry<String, String> toCompilePath : toCompile.entrySet()) { - processor.process(toCompilePath.getKey(), toCompilePath.getValue(), - sourceFolders, taskProject); - } - } - - if (toRemove.size() > 0) { - processor.displayMessage(DisplayType.REMOVE_OUTPUT, toRemove.size()); - - for (File toRemoveFile : toRemove) { - if (toRemoveFile.delete() == false) { - System.err.println("Failed to remove " + toRemoveFile.getAbsolutePath()); - } - } - } - - // remove the dependency files that are obsolete - if (depsToRemove.size() > 0) { - processor.displayMessage(DisplayType.REMOVE_DEP, toRemove.size()); - - for (String path : depsToRemove) { - if (new File(path).delete() == false) { - System.err.println("Failed to remove " + path); - } - } - } - } - - /** - * Returns a list of files found in given folders, all matching a given filter. - * The result is a map of (file, folder). - * @param folders the folders to search - * @param filter the filter for the files. Typically a glob. - * @return a map of (file, folder) - */ - private Map<String, String> getFilesByNameEntryFilter(List<String> folders, String[] filters) { - Map<String, String> sourceFiles = new HashMap<String, String>(); - - for (String folder : folders) { - Iterator<?> iterator = getFilesByNameEntryFilter(folder, filters); - - while (iterator.hasNext()) { - sourceFiles.put(iterator.next().toString(), folder); - } - } - - return sourceFiles; - } - - /** - * Returns a list of files found in a given folder, matching a given filter. - * @param folder the folder to search - * @param filter the filter for the files. Typically a glob. - * @return an iterator. - */ - private Iterator<?> getFilesByNameEntryFilter(String folder, String... filters) { - Project taskProject = getProject(); - - // create a fileset to find all the files in the folder - FileSet fs = new FileSet(); - fs.setProject(taskProject); - fs.setDir(new File(folder)); - for (String filter : filters) { - NameEntry include = fs.createInclude(); - include.setName(filter); - } - - // loop through the results of the file set - return fs.iterator(); - } -} diff --git a/anttasks/src/com/android/ant/PropertyByReplaceTask.java b/anttasks/src/com/android/ant/PropertyByReplaceTask.java deleted file mode 100644 index a0707de..0000000 --- a/anttasks/src/com/android/ant/PropertyByReplaceTask.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.Property; - -/** - * Task to do simple char to char replacement on strings. - */ -public class PropertyByReplaceTask extends Property { - - private String mInput; - private char mInputChar; - private char mWithChar; - - public void setInput(String input) { - mInput = input; - } - - public void setReplace(char inputChar) { - mInputChar = inputChar; - } - - public void setWith(char withChar) { - mWithChar = withChar; - } - - @Override - public void execute() throws BuildException { - setValue(mInput.replace(mInputChar, mWithChar)); - super.execute(); - } -} diff --git a/anttasks/src/com/android/ant/RenderScriptTask.java b/anttasks/src/com/android/ant/RenderScriptTask.java deleted file mode 100644 index 5f743bb8..0000000 --- a/anttasks/src/com/android/ant/RenderScriptTask.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) 2010, 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.SdkConstants; -import com.google.common.collect.Sets; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.ExecTask; -import org.apache.tools.ant.types.Path; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * Task to execute renderscript. - * <p> - * It expects 7 attributes:<br> - * 'executable' ({@link Path} with a single path) for the location of the llvm executable<br> - * 'framework' ({@link Path} with 1 or more paths) for the include paths.<br> - * 'genFolder' ({@link Path} with a single path) for the location of the gen folder.<br> - * 'resFolder' ({@link Path} with a single path) for the location of the res folder.<br> - * 'targetApi' for the -target-api value.<br> - * 'optLevel' for the -O optimization level.<br> - * 'debug' for -g renderscript debugging.<br> - * <p> - * It also expects one or more inner elements called "source" which are identical to {@link Path} - * elements for where to find .rs files. - */ -public class RenderScriptTask extends MultiFilesTask { - - private final static Set<String> EXTENSIONS = Sets.newHashSetWithExpectedSize(2); - static { - EXTENSIONS.add(SdkConstants.EXT_RS); - EXTENSIONS.add(SdkConstants.EXT_FS); - } - - private String mExecutable; - private Path mIncludePath; - private String mGenFolder; - private String mResFolder; - private final List<Path> mPaths = new ArrayList<Path>(); - private int mTargetApi = 0; - public enum OptLevel { O0, O1, O2, O3 }; - private OptLevel mOptLevel; - private boolean mDebug = false; - - private class RenderScriptProcessor implements SourceProcessor { - - private final String mTargetApiStr; - - public RenderScriptProcessor(int targetApi) { - // get the target api value. Must be 11+ or llvm-rs-cc complains. - mTargetApiStr = Integer.toString(mTargetApi < 11 ? 11 : mTargetApi); - } - - @Override - public Set<String> getSourceFileExtensions() { - return EXTENSIONS; - } - - @Override - public void process(String filePath, String sourceFolder, List<String> sourceFolders, - Project taskProject) { - File exe = new File(mExecutable); - String execTaskName = exe.getName(); - - ExecTask task = new ExecTask(); - task.setTaskName(execTaskName); - task.setProject(taskProject); - task.setOwningTarget(getOwningTarget()); - task.setExecutable(mExecutable); - task.setFailonerror(true); - - for (String path : mIncludePath.list()) { - File res = new File(path); - if (res.isDirectory()) { - task.createArg().setValue("-I"); - task.createArg().setValue(path); - } else { - System.out.println(String.format( - "WARNING: RenderScript include directory '%s' does not exist!", - res.getAbsolutePath())); - } - - } - - if (mDebug) { - task.createArg().setValue("-g"); - } - - task.createArg().setValue("-O"); - task.createArg().setValue(Integer.toString(mOptLevel.ordinal())); - - task.createArg().setValue("-target-api"); - task.createArg().setValue(mTargetApiStr); - - task.createArg().setValue("-d"); - task.createArg().setValue(getDependencyFolder(filePath, sourceFolder)); - task.createArg().setValue("-MD"); - - task.createArg().setValue("-p"); - task.createArg().setValue(mGenFolder); - task.createArg().setValue("-o"); - task.createArg().setValue(mResFolder); - task.createArg().setValue(filePath); - - // execute it. - task.execute(); - } - - @Override - public void displayMessage(DisplayType type, int count) { - switch (type) { - case FOUND: - System.out.println(String.format("Found %1$d RenderScript files.", count)); - break; - case COMPILING: - if (count > 0) { - System.out.println(String.format( - "Compiling %1$d RenderScript files with -target-api %2$d", - count, mTargetApi)); - System.out.println(String.format("Optimization Level: %1$d", mOptLevel.ordinal())); - } else { - System.out.println("No RenderScript files to compile."); - } - break; - case REMOVE_OUTPUT: - System.out.println(String.format("Found %1$d obsolete output files to remove.", - count)); - break; - case REMOVE_DEP: - System.out.println( - String.format("Found %1$d obsolete dependency files to remove.", - count)); - break; - } - } - - private String getDependencyFolder(String filePath, String sourceFolder) { - String relative = filePath.substring(sourceFolder.length()); - if (relative.charAt(0) == '/') { - relative = relative.substring(1); - } - - return new File(mGenFolder, relative).getParent(); - } - } - - - /** - * Sets the value of the "executable" attribute. - * @param executable the value. - */ - public void setExecutable(Path executable) { - mExecutable = TaskHelper.checkSinglePath("executable", executable); - } - - public void setIncludePathRefId(String refId) { - Object path = getProject().getReference(refId); - if (path instanceof Path) { - mIncludePath = (Path) path; - } else if (path != null) { - throw new BuildException(refId + " is expected to reference a Path object."); - } - } - - public void setGenFolder(Path value) { - mGenFolder = TaskHelper.checkSinglePath("genFolder", value); - } - - public void setResFolder(Path value) { - mResFolder = TaskHelper.checkSinglePath("resFolder", value); - } - - public void setTargetApi(String targetApi) { - try { - mTargetApi = Integer.parseInt(targetApi); - if (mTargetApi <= 0) { - throw new BuildException("targetApi attribute value must be >= 1"); - } - } catch (NumberFormatException e) { - throw new BuildException("targetApi attribute value must be an integer", e); - } - } - - public void setOptLevel(OptLevel optLevel) { - mOptLevel = optLevel; - } - - /** Sets the current build type. value is a boolean, true for debug build, false for release */ - @Override - public void setBuildType(String buildType) { - super.setBuildType(buildType); - mDebug = Boolean.valueOf(buildType); - } - - public Path createSource() { - Path p = new Path(getProject()); - mPaths.add(p); - return p; - } - - @Override - public void execute() throws BuildException { - if (mExecutable == null) { - throw new BuildException("RenderScriptTask's 'executable' is required."); - } - if (mIncludePath == null) { - throw new BuildException("RenderScriptTask's 'includePath' is required."); - } - if (mGenFolder == null) { - throw new BuildException("RenderScriptTask's 'genFolder' is required."); - } - if (mResFolder == null) { - throw new BuildException("RenderScriptTask's 'resFolder' is required."); - } - if (mTargetApi == 0) { - throw new BuildException("RenderScriptTask's 'targetApi' is required."); - } - - processFiles(new RenderScriptProcessor(mTargetApi), mPaths, mGenFolder); - } -} diff --git a/anttasks/src/com/android/ant/SignApkTask.java b/anttasks/src/com/android/ant/SignApkTask.java deleted file mode 100644 index 6c29d68..0000000 --- a/anttasks/src/com/android/ant/SignApkTask.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.internal.build.SignedJarBuilder; -import com.android.sdklib.internal.build.SignedJarBuilder.IZipEntryFilter; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.types.Path; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.security.KeyStore; -import java.security.KeyStore.PrivateKeyEntry; -import java.security.cert.X509Certificate; - -/** - * Simple Task to sign an apk. - * - */ -public class SignApkTask extends SingleInputOutputTask { - - private String mKeystore; - private String mStorepass; - private String mAlias; - private String mKeypass; - - public void setKeystore(Path keystore) { - mKeystore = TaskHelper.checkSinglePath("keystore", keystore); - } - - public void setStorepass(String storepass) { - mStorepass = storepass; - } - - public void setAlias(String alias) { - mAlias = alias; - } - - public void setKeypass(String keypass) { - mKeypass = keypass; - } - - @Override - protected void createOutput() throws BuildException { - PrivateKeyEntry key = loadKeyEntry( - mKeystore, null, mStorepass.toCharArray(), - mAlias, mKeypass.toCharArray()); - - if (key == null) { - throw new BuildException(String.format("Signing key %s not found", mAlias)); - } - - SignedJarBuilder mBuilder = null; - try { - mBuilder = new SignedJarBuilder( - new FileOutputStream(getOutput(), false /* append */), - key.getPrivateKey(), (X509Certificate) key.getCertificate()); - - mBuilder.writeZip(new FileInputStream(getInput()), new NullZipFilter()); - - mBuilder.close(); - } catch (FileNotFoundException e) { - throw new BuildException(String.format("Keystore '%s' is not found!", mKeystore)); - } catch (Exception e) { - throw new BuildException(e.getMessage()); - } finally { - if (mBuilder != null) { - mBuilder.cleanUp(); - } - } - } - - /** - * Loads the debug key from the keystore. - * @param osKeyStorePath the OS path to the keystore. - * @param storeType an optional keystore type, or <code>null</code> if the default is to - * be used. - * @return <code>true</code> if success, <code>false</code> if the keystore does not exist. - */ - private PrivateKeyEntry loadKeyEntry(String osKeyStorePath, String storeType, - char[] storePassword, String alias, char[] aliasPassword) { - FileInputStream fis = null; - try { - KeyStore keyStore = KeyStore.getInstance( - storeType != null ? storeType : KeyStore.getDefaultType()); - fis = new FileInputStream(osKeyStorePath); - keyStore.load(fis, storePassword); - return (KeyStore.PrivateKeyEntry)keyStore.getEntry( - alias, new KeyStore.PasswordProtection(aliasPassword)); - } catch (Exception e) { - String msg = e.getMessage(); - String causeMsg = null; - - Throwable cause = e.getCause(); - if (cause != null) { - causeMsg = cause.getMessage(); - } - - if (msg != null) { - if (causeMsg == null) { - throw new BuildException(msg); - } else { - throw new BuildException(msg + ": " + causeMsg); - } - } else { - if (causeMsg == null) { - throw new BuildException(e); - } else { - throw new BuildException(causeMsg); - } - } - } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - // pass - } - } - } - } - - private final static class NullZipFilter implements IZipEntryFilter { - - @Override - public boolean checkEntry(String archivePath) throws ZipAbortException { - return true; - } - } -} diff --git a/anttasks/src/com/android/ant/SingleDependencyTask.java b/anttasks/src/com/android/ant/SingleDependencyTask.java deleted file mode 100644 index 4cc8f3e..0000000 --- a/anttasks/src/com/android/ant/SingleDependencyTask.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2011 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 org.apache.tools.ant.BuildException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * A base class for ant tasks that use a single dependency file to control (re)execution. - */ -public abstract class SingleDependencyTask extends BuildTypedTask { - - private DependencyGraph mDependencies; - - protected abstract String getExecTaskName(); - - protected interface InputPathFactory { - InputPath createPath(File file, Set<String> extensionsToCheck); - } - - private final static InputPathFactory sDefaultFactory = new InputPathFactory() { - @Override - public InputPath createPath(File file, Set<String> extensionsToCheck) { - return new InputPath(file, extensionsToCheck); - } - }; - - /** - * Creates a list of {@link InputPath} from a list of {@link File} and an optional list of - * extensions. All the {@link InputPath} will share the same extension restrictions. - * @param paths the list of path - * @param extensionsToCheck A set of extensions. Only files with an extension in this set will - * be considered for a modification check. All deleted/created files will still be - * checked. If this is null, all files will be checked for modification date - * @return a list of {@link InputPath} - */ - protected static List<InputPath> getInputPaths(List<File> paths, - Set<String> extensionsToCheck, InputPathFactory factory) { - List<InputPath> result = new ArrayList<InputPath>(paths.size()); - - if (factory == null ) { - factory = sDefaultFactory; - } - - for (File f : paths) { - result.add(factory.createPath(f, extensionsToCheck)); - } - - return result; - } - - /** - * Set up the dependency graph by passing it the location of the ".d" file, and the new input - * paths. - * @param dependencyFile path to the dependency file to use - * @param the new input paths for this new compilation. - * @return true if the dependency graph was successfully initialized - */ - protected boolean initDependencies(String dependencyFile, List<InputPath> inputPaths) { - if (hasBuildTypeChanged()) { - // we don't care about deps, we need to execute the task no matter what. - return true; - } - - File depFile = new File(dependencyFile); - if (depFile.exists()) { - mDependencies = new DependencyGraph(dependencyFile, inputPaths); - return true; - } else { - return false; - } - } - - /** - * Wrapper check to see if we need to execute this task at all - * @return true if the DependencyGraph reports that our prereqs or targets - * have changed since the last run - */ - protected boolean dependenciesHaveChanged() { - if (hasBuildTypeChanged()) { - // if this is not a new build, display that build type change is forcing running - // the task. - if (isNewBuild() == false) { - String execName = getExecTaskName(); - if (execName == null) { - System.out.println( - "Current build type is different than previous build: forced task run."); - } else { - System.out.println( - "Current build type is different than previous build: forced " + - execName + " run."); - } - } - return true; - } - - assert mDependencies != null : "Dependencies have not been initialized"; - return mDependencies.dependenciesHaveChanged(true /*printStatus*/); - } - - protected void generateDependencyFile(String depFilePath, - List<InputPath> inputs, String outputFile) { - File depFile = new File(depFilePath); - - try { - PrintStream ps = new PrintStream(depFile); - - // write the output file. - ps.print(outputFile); - ps.println(" : \\"); - - //write the input files - int count = inputs.size(); - for (int i = 0 ; i < count ; i++) { - InputPath input = inputs.get(i); - File file = input.getFile(); - if (file.isDirectory()) { - writeContent(ps, file, input); - } else { - ps.print(file.getAbsolutePath()); - ps.println(" \\"); - } - } - - ps.close(); - } catch (FileNotFoundException e) { - new BuildException(e); - } - } - - private void writeContent(PrintStream ps, File file, InputPath input) { - if (input.ignores(file)) { - return; - } - - File[] files = file.listFiles(); - if (files != null) { - for (File f : files) { - if (f.isDirectory()) { - writeContent(ps, f, input); - } else if (input.ignores(f) == false) { - ps.print(f.getAbsolutePath()); - ps.println(" \\"); - } - } - } - } -} diff --git a/anttasks/src/com/android/ant/SingleInputOutputTask.java b/anttasks/src/com/android/ant/SingleInputOutputTask.java deleted file mode 100644 index a559673..0000000 --- a/anttasks/src/com/android/ant/SingleInputOutputTask.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; - -import java.io.File; - -/** - * Single input single output class. Execution is controlled - * by modification timestamp of the input and output files. - * - * Implementation classes must implement {@link #createOutput()} - * - */ -public abstract class SingleInputOutputTask extends Task { - - private String mInput; - private String mOutput; - - public void setInput(Path inputPath) { - mInput = TaskHelper.checkSinglePath("input", inputPath); - } - - public void setOutput(Path outputPath) { - mOutput = TaskHelper.checkSinglePath("output", outputPath); - } - - @Override - public final void execute() throws BuildException { - if (mInput == null) { - throw new BuildException("Missing attribute input"); - } - if (mOutput == null) { - throw new BuildException("Missing attribute output"); - } - - // check if there's a need for the task to run. - File outputFile = new File(mOutput); - if (outputFile.isFile()) { - File inputFile = new File(mInput); - if (outputFile.lastModified() >= inputFile.lastModified()) { - System.out.println(String.format( - "Run cancelled: no changes to input file %1$s", - inputFile.getAbsolutePath())); - return; - } - } - - createOutput(); - } - - protected abstract void createOutput() throws BuildException; - - protected String getInput() { - return mInput; - } - - protected String getOutput() { - return mOutput; - } -} diff --git a/anttasks/src/com/android/ant/TaskHelper.java b/anttasks/src/com/android/ant/TaskHelper.java deleted file mode 100644 index c93b193..0000000 --- a/anttasks/src/com/android/ant/TaskHelper.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2010 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.SdkConstants; -import com.android.annotations.NonNull; -import com.android.annotations.Nullable; -import com.android.sdklib.internal.project.ProjectProperties; -import com.android.sdklib.internal.project.ProjectProperties.PropertyType; -import com.android.sdklib.internal.project.ProjectPropertiesWorkingCopy; -import com.android.sdklib.repository.FullRevision; -import com.android.sdklib.repository.PkgProps; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.util.DeweyDecimal; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -final class TaskHelper { - - private static Map<String, String> DEFAULT_ATTR_VALUES = new HashMap<String, String>(); - static { - DEFAULT_ATTR_VALUES.put("source.dir", SdkConstants.FD_SOURCES); - DEFAULT_ATTR_VALUES.put("out.dir", SdkConstants.FD_OUTPUT); - } - - static String getDefault(String name) { - return DEFAULT_ATTR_VALUES.get(name); - } - - static File getSdkLocation(Project antProject) { - // get the SDK location - String sdkOsPath = antProject.getProperty(ProjectProperties.PROPERTY_SDK); - - // check if it's valid and exists - if (sdkOsPath == null || sdkOsPath.length() == 0) { - throw new BuildException("SDK Location is not set."); - } - - File sdk = new File(sdkOsPath); - if (sdk.isDirectory() == false) { - throw new BuildException(String.format("SDK Location '%s' is not valid.", sdkOsPath)); - } - - return sdk; - } - - /** - * Returns the revision of the tools for a given SDK. - * @param sdkFile the {@link File} for the root folder of the SDK - * @return the tools revision or -1 if not found. - */ - @Nullable - static DeweyDecimal getToolsRevision(File sdkFile) { - Properties p = new Properties(); - try{ - // tools folder must exist, or this custom task wouldn't run! - File toolsFolder= new File(sdkFile, SdkConstants.FD_TOOLS); - File sourceProp = new File(toolsFolder, SdkConstants.FN_SOURCE_PROP); - - FileInputStream fis = null; - try { - fis = new FileInputStream(sourceProp); - p.load(fis); - } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException ignore) { - } - } - } - - String value = p.getProperty(PkgProps.PKG_REVISION); - if (value != null) { - FullRevision rev = FullRevision.parseRevision(value); - return new DeweyDecimal(rev.toIntArray(false /*includePreview*/)); - } - } catch (NumberFormatException e) { - // couldn't parse the version number. - } catch (FileNotFoundException e) { - // couldn't find the file. - } catch (IOException e) { - // couldn't find the file. - } - - return null; - } - - static String checkSinglePath(String attribute, Path path) { - String[] paths = path.list(); - if (paths.length != 1) { - throw new BuildException(String.format( - "Value for '%1$s' is not valid. It must resolve to a single path", attribute)); - } - - return paths[0]; - } - - /** - * Returns the ProjectProperties for a given project path. - * This loads and merges all the .properties files in the same way that Ant does it. - * - * Note that this does not return all the Ant properties but only the one customized by the - * project's own build.xml file. - * - * If the project has no .properties files, this returns an empty {@link ProjectProperties} - * with type {@link PropertyType#PROJECT}. - * - * @param projectPath the path to the project root folder. - * @return a ProjectProperties. - */ - @NonNull - static ProjectProperties getProperties(@NonNull String projectPath) { - // the import order is local, ant, project so we need to respect this. - PropertyType[] types = PropertyType.getOrderedTypes(); - - // make a working copy of the first non null props and then merge the rest into it. - ProjectProperties properties = null; - for (int i = 0 ; i < types.length ; i++) { - properties = ProjectProperties.load(projectPath, types[i]); - - if (properties != null) { - ProjectPropertiesWorkingCopy workingCopy = properties.makeWorkingCopy(); - for (int k = i + 1 ; k < types.length ; k++) { - workingCopy.merge(types[k]); - } - - // revert back to a read-only version - properties = workingCopy.makeReadOnlyCopy(); - - return properties; - } - } - - // return an empty object with type PropertyType.PROJECT (doesn't actually matter). - return ProjectProperties.createEmpty(projectPath, PropertyType.PROJECT); - } -} diff --git a/anttasks/src/com/android/ant/XPathTask.java b/anttasks/src/com/android/ant/XPathTask.java deleted file mode 100644 index b6de469..0000000 --- a/anttasks/src/com/android/ant/XPathTask.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2009 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.xml.AndroidXPathFactory; - -import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.Task; -import org.apache.tools.ant.types.Path; -import org.xml.sax.InputSource; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; - -/** - * Android specific XPath task. - * The goal is to get the result of an XPath expression on Android XML files. The android namespace - * (http://schemas.android.com/apk/res/android) must be associated to the "android" prefix. - */ -public class XPathTask extends Task { - - private Path mManifestFile; - private String mProperty; - private String mExpression; - private String mDefault; - - public void setInput(Path manifestFile) { - mManifestFile = manifestFile; - } - - public void setOutput(String property) { - mProperty = property; - } - - public void setExpression(String expression) { - mExpression = expression; - } - - public void setDefault(String defaultValue) { - mDefault = defaultValue; - } - - @Override - public void execute() throws BuildException { - try { - if (mManifestFile == null || mManifestFile.list().length == 0) { - throw new BuildException("input attribute is missing!"); - } - - if (mProperty == null) { - throw new BuildException("output attribute is missing!"); - } - - if (mExpression == null) { - throw new BuildException("expression attribute is missing!"); - } - - XPath xpath = AndroidXPathFactory.newXPath(); - - String file = mManifestFile.list()[0]; - String result = xpath.evaluate(mExpression, new InputSource(new FileInputStream(file))); - if (result.length() == 0 && mDefault != null) { - result = mDefault; - } - - getProject().setProperty(mProperty, result); - } catch (XPathExpressionException e) { - throw new BuildException(e); - } catch (FileNotFoundException e) { - throw new BuildException(e); - } - } -} diff --git a/anttasks/src/com/android/ant/ZipAlignTask.java b/anttasks/src/com/android/ant/ZipAlignTask.java deleted file mode 100644 index 840bee1..0000000 --- a/anttasks/src/com/android/ant/ZipAlignTask.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2011 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 org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.ExecTask; -import org.apache.tools.ant.types.Path; - -public class ZipAlignTask extends SingleInputOutputTask { - - private String mExecutable; - private int mAlign = 4; - private boolean mVerbose = false; - - /** - * Sets the value of the "executable" attribute. - * @param executable the value. - */ - public void setExecutable(Path executable) { - mExecutable = TaskHelper.checkSinglePath("executable", executable); - } - - public void setAlign(int align) { - mAlign = align; - } - - public void setVerbose(boolean verbose) { - mVerbose = verbose; - } - - @Override - public void createOutput() throws BuildException { - if (mExecutable == null) { - throw new BuildException("Missing attribute executable"); - } - - System.out.println("Running zip align on final apk..."); - doZipAlign(); - } - - private void doZipAlign() { - ExecTask task = new ExecTask(); - task.setExecutable(mExecutable); - task.setFailonerror(true); - task.setProject(getProject()); - task.setOwningTarget(getOwningTarget()); - - task.setTaskName("zip-align"); - - // force overwrite of existing output file - task.createArg().setValue("-f"); - - // verbose flag - if (mVerbose) { - task.createArg().setValue("-v"); - } - - // align value - task.createArg().setValue(Integer.toString(mAlign)); - - // input - task.createArg().setValue(getInput()); - - // output - task.createArg().setValue(getOutput()); - - // execute - task.execute(); - } -} |