diff options
author | Xavier Ducrohet <xav@android.com> | 2010-09-16 18:53:44 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-09-24 16:33:38 -0700 |
commit | a66ca8ad997527af0e7a07ba851da0a6d379fad0 (patch) | |
tree | 0827f8d51c3d55ecf4abc0f2b824feafdf211a4f /anttasks | |
parent | 03dec99d1bc5fc418e58235c5e6dd0543b41413e (diff) | |
download | sdk-a66ca8ad997527af0e7a07ba851da0a6d379fad0.zip sdk-a66ca8ad997527af0e7a07ba851da0a6d379fad0.tar.gz sdk-a66ca8ad997527af0e7a07ba851da0a6d379fad0.tar.bz2 |
Use proguard for release builds through Ant.
This is only activated if default.properties contains
a property "proguard.config" with the name of a proguard
config file.
Some clean-up in the Ant tasks and in the name
of the properties used by the rules and the custom
tasks to make them clearer.
Added a new test app with a project using a jar file
as well as a library using a jar file.
Change-Id: Ia8f4d873025993d454c0a484e61d47ae679ea79c
Diffstat (limited to 'anttasks')
-rw-r--r-- | anttasks/src/com/android/ant/AaptExecLoopTask.java | 13 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/AntConstants.java | 58 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/IfElseTask.java | 35 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/MultiApkExportTask.java | 12 | ||||
-rw-r--r-- | anttasks/src/com/android/ant/SetupTask.java | 39 |
5 files changed, 116 insertions, 41 deletions
diff --git a/anttasks/src/com/android/ant/AaptExecLoopTask.java b/anttasks/src/com/android/ant/AaptExecLoopTask.java index 171e781..f3824ef 100644 --- a/anttasks/src/com/android/ant/AaptExecLoopTask.java +++ b/anttasks/src/com/android/ant/AaptExecLoopTask.java @@ -259,10 +259,10 @@ public final class AaptExecLoopTask extends Task { // if the parameters indicate generation of the R class, check if // more R classes need to be created for libraries. if (mRFolder != null && new File(mRFolder).isDirectory()) { - String libPkgProp = taskProject.getProperty("android.libraries.package"); + String libPkgProp = taskProject.getProperty(AntConstants.PROP_PROJECT_LIBS_PKG); if (libPkgProp != null) { // get the main package to compare in case the libraries use the same - String mainPackage = taskProject.getProperty("manifest.package"); + String mainPackage = taskProject.getProperty(AntConstants.PROP_MANIFEST_PACKAGE); String[] libPkgs = libPkgProp.split(";"); for (String libPkg : libPkgs) { @@ -354,8 +354,8 @@ public final class AaptExecLoopTask extends Task { } // if the project contains libraries, force auto-add-overlay - Object libSrc = taskProject.getReference("android.libraries.res"); - if (libSrc != null) { + Object libResRef = taskProject.getReference(AntConstants.PROP_PROJECT_LIBS_RES_REF); + if (libResRef != null) { task.createArg().setValue("--auto-add-overlay"); } @@ -385,9 +385,8 @@ public final class AaptExecLoopTask extends Task { } // add other resources coming from library project - Object libPath = taskProject.getReference("android.libraries.res"); - if (libPath instanceof Path) { - for (String path : ((Path)libPath).list()) { + 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()) { diff --git a/anttasks/src/com/android/ant/AntConstants.java b/anttasks/src/com/android/ant/AntConstants.java new file mode 100644 index 0000000..81c6682 --- /dev/null +++ b/anttasks/src/com/android/ant/AntConstants.java @@ -0,0 +1,58 @@ +/* + * 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; + +/** + * Constants used by custom tasks and the rules files. + */ +public interface AntConstants { + + /** ant property with the path to the android.jar */ + public final static String PROP_ANDROID_JAR = "android.jar"; + + /** ant property with the path to the framework.jar */ + public final static String PROP_ANDROID_AIDL = "android.aidl"; + + /** ant property with the path to the aapt tool */ + public final static String PROP_AAPT = "aapt"; + /** ant property with the path to the aidl tool */ + public final static String PROP_AIDL = "aidl"; + /** ant property with the path to the dx tool */ + public final static String PROP_DX = "dx"; + /** ref id to the <path> object containing all the boot classpaths. */ + public final static String PROP_CLASSPATH_REF = "android.target.classpath"; + + /** ant property ref to the list of source folder for the project libraries */ + public static final String PROP_PROJECT_LIBS_SRC_REF = "project.libraries.src"; + /** ant property ref to the list of jars for the project libraries */ + public static final String PROP_PROJECT_LIBS_JARS_REF = "project.libraries.jars"; + /** ant property ref to the list of libs folder for the project libraries */ + public static final String PROP_PROJECT_LIBS_LIBS_REF = "project.libraries.libs"; + /** ant property ref to the list of res folder for the project libraries */ + public static final String PROP_PROJECT_LIBS_RES_REF = "project.libraries.res"; + /** ant property for semi-colon separated packages for the project libraries */ + public static final String PROP_PROJECT_LIBS_PKG = "project.libraries.package"; + /** ant property for the test project directory */ + public static final String PROP_TESTED_PROJECT_DIR = "tested.project.dir"; + + public static final String PROP_MANIFEST_PACKAGE = "manifest.package"; + + public static final String PROP_OUT_ABS_DIR = "out.absolute.dir"; + + public static final String PROP_KEY_STORE_PASSWORD = "key.store.password"; + public static final String PROP_KEY_ALIAS_PASSWORD = "key.alias.password"; +} diff --git a/anttasks/src/com/android/ant/IfElseTask.java b/anttasks/src/com/android/ant/IfElseTask.java index fd4f9d0..0a59466 100644 --- a/anttasks/src/com/android/ant/IfElseTask.java +++ b/anttasks/src/com/android/ant/IfElseTask.java @@ -17,14 +17,25 @@ package com.android.ant; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.Sequential; +import org.apache.tools.ant.taskdefs.condition.IsSet; /** * If (condition) then: {@link Sequential} else: {@link Sequential}. * * In XML: - * <if condition="${some.condition}"> + * <if condition="${prop with a boolean value}"> + * <then> + * </then> + * <else> + * </else> + * </if> + * + * or + * + * <if isset="propertyname"> * <then> * </then> * <else> @@ -52,10 +63,30 @@ public class IfElseTask extends Task { * Sets the condition value */ public void setCondition(boolean condition) { + if (mConditionIsSet) { + throw new BuildException("Cannot use both condition and isset attribute"); + } + mCondition = condition; mConditionIsSet = true; } + public void setIsset(String name) { + if (mConditionIsSet) { + throw new BuildException("Cannot use both condition and isset attribute"); + } + + Project antProject = getProject(); + + // use Isset to ensure the implementation is correct + IsSet isSet = new IsSet(); + isSet.setProject(antProject); + isSet.setProperty(name); + + mCondition = isSet.eval(); + mConditionIsSet = true; + } + /** * Creates and returns the <then> {@link Sequential} */ @@ -75,7 +106,7 @@ public class IfElseTask extends Task { @Override public void execute() throws BuildException { if (mConditionIsSet == false) { - throw new BuildException("Condition has not been set."); + throw new BuildException("condition or isset attribute is missing"); } // need at least one. diff --git a/anttasks/src/com/android/ant/MultiApkExportTask.java b/anttasks/src/com/android/ant/MultiApkExportTask.java index 03e27e9..a21478e 100644 --- a/anttasks/src/com/android/ant/MultiApkExportTask.java +++ b/anttasks/src/com/android/ant/MultiApkExportTask.java @@ -117,7 +117,7 @@ public class MultiApkExportTask extends Task { mXPathFactory = XPathFactory.newInstance(); File exportProjectOutput = new File( - getValidatedProperty(antProject, "out.absolute.dir")); + getValidatedProperty(antProject, AntConstants.PROP_OUT_ABS_DIR)); // if there's no error, and we can sign, prompt for the passwords. String keyStorePassword = null; @@ -127,21 +127,23 @@ public class MultiApkExportTask extends Task { Input input = new Input(); input.setProject(antProject); - input.setAddproperty("key.store.password"); + input.setAddproperty(AntConstants.PROP_KEY_STORE_PASSWORD); input.setMessage(String.format("Please enter keystore password (store: %1$s):", keyStore)); input.execute(); input = new Input(); input.setProject(antProject); - input.setAddproperty("key.alias.password"); + input.setAddproperty(AntConstants.PROP_KEY_ALIAS_PASSWORD); input.setMessage(String.format("Please enter password for alias '%1$s':", keyAlias)); input.execute(); // and now read the property so that they can be set into the sub ant task. - keyStorePassword = getValidatedProperty(antProject, "key.store.password"); - keyAliasPassword = getValidatedProperty(antProject, "key.alias.password"); + keyStorePassword = getValidatedProperty(antProject, + AntConstants.PROP_KEY_STORE_PASSWORD); + keyAliasPassword = getValidatedProperty(antProject, + AntConstants.PROP_KEY_ALIAS_PASSWORD); } for (ApkData apk : apks) { diff --git a/anttasks/src/com/android/ant/SetupTask.java b/anttasks/src/com/android/ant/SetupTask.java index 966956f..ba62403 100644 --- a/anttasks/src/com/android/ant/SetupTask.java +++ b/anttasks/src/com/android/ant/SetupTask.java @@ -71,21 +71,6 @@ public final class SetupTask extends ImportTask { // library rules file. private final static String RULES_LIBRARY = "lib_rules.xml"; - // ant property with the path to the android.jar - private final static String PROPERTY_ANDROID_JAR = "android.jar"; - - // ant property with the path to the framework.jar - private final static String PROPERTY_ANDROID_AIDL = "android.aidl"; - - // ant property with the path to the aapt tool - private final static String PROPERTY_AAPT = "aapt"; - // ant property with the path to the aidl tool - private final static String PROPERTY_AIDL = "aidl"; - // ant property with the path to the dx tool - private final static String PROPERTY_DX = "dx"; - // ref id to the <path> object containing all the boot classpaths. - private final static String REF_CLASSPATH = "android.target.classpath"; - private boolean mDoImport = true; @Override @@ -112,7 +97,7 @@ public final class SetupTask extends ImportTask { boolean isTestProject = false; - if (antProject.getProperty("tested.project.dir") != null) { + if (antProject.getProperty(AntConstants.PROP_TESTED_PROJECT_DIR) != null) { isTestProject = true; } @@ -185,14 +170,14 @@ public final class SetupTask extends ImportTask { // sets up the properties to find android.jar/framework.aidl/target tools String androidJar = androidTarget.getPath(IAndroidTarget.ANDROID_JAR); - antProject.setProperty(PROPERTY_ANDROID_JAR, androidJar); + antProject.setProperty(AntConstants.PROP_ANDROID_JAR, androidJar); String androidAidl = androidTarget.getPath(IAndroidTarget.ANDROID_AIDL); - antProject.setProperty(PROPERTY_ANDROID_AIDL, androidAidl); + antProject.setProperty(AntConstants.PROP_ANDROID_AIDL, androidAidl); - antProject.setProperty(PROPERTY_AAPT, androidTarget.getPath(IAndroidTarget.AAPT)); - antProject.setProperty(PROPERTY_AIDL, androidTarget.getPath(IAndroidTarget.AIDL)); - antProject.setProperty(PROPERTY_DX, androidTarget.getPath(IAndroidTarget.DX)); + antProject.setProperty(AntConstants.PROP_AAPT, androidTarget.getPath(IAndroidTarget.AAPT)); + antProject.setProperty(AntConstants.PROP_AIDL, androidTarget.getPath(IAndroidTarget.AIDL)); + antProject.setProperty(AntConstants.PROP_DX, androidTarget.getPath(IAndroidTarget.DX)); // sets up the boot classpath @@ -219,7 +204,7 @@ public final class SetupTask extends ImportTask { } // finally sets the path in the project with a reference - antProject.addReference(REF_CLASSPATH, bootclasspath); + antProject.addReference(AntConstants.PROP_CLASSPATH_REF, bootclasspath); // Now the import section. This is only executed if the task actually has to import a file. if (mDoImport) { @@ -436,14 +421,14 @@ public final class SetupTask extends ImportTask { // 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("android.libraries.src", sourcePath); - antProject.addReference("android.libraries.jars", jarsPath); - antProject.addReference("android.libraries.libs", libsPath); + antProject.addReference(AntConstants.PROP_PROJECT_LIBS_SRC_REF, sourcePath); + antProject.addReference(AntConstants.PROP_PROJECT_LIBS_JARS_REF, jarsPath); + antProject.addReference(AntConstants.PROP_PROJECT_LIBS_LIBS_REF, libsPath); // the rest is done only if there's a library. if (sourcePath.list().length > 0) { - antProject.addReference("android.libraries.res", resPath); - antProject.setProperty("android.libraries.package", sb.toString()); + antProject.addReference(AntConstants.PROP_PROJECT_LIBS_RES_REF, resPath); + antProject.setProperty(AntConstants.PROP_PROJECT_LIBS_PKG, sb.toString()); } } |