OSDN Git Service

New If/Then/Else custom Ant rules to simplify some Ant rules logic.
authorXavier Ducrohet <xav@android.com>
Wed, 5 May 2010 00:46:54 +0000 (17:46 -0700)
committerXavier Ducrohet <xav@android.com>
Wed, 5 May 2010 00:49:39 +0000 (17:49 -0700)
Also cleaned up some attribute of our other custom tasks to conform
to the standard convention (all lower case, all those were new in r3)

Change-Id: If328a8eb2448d95bee1f1b70928d72fde5014eeb

anttasks/src/com/android/ant/AaptExecLoopTask.java
anttasks/src/com/android/ant/ApkBuilderTask.java
anttasks/src/com/android/ant/IfElseTask.java [new file with mode: 0644]
anttasks/src/com/android/ant/MultiApkExportTask.java
apkbuilder/src/com/android/apkbuilder/ApkBuilder.java
files/ant_rules_r3.xml

index d9ec6bc..f93a208 100644 (file)
@@ -197,7 +197,7 @@ public final class AaptExecLoopTask extends Task {
     @Deprecated
     public void setBasename(String baseName) {
         System.out.println("WARNNG: Using deprecated 'basename' attribute in AaptExecLoopTask." +
-                "Use 'resourceFilename' (string) instead.");
+                "Use 'resourcefilename' (string) instead.");
         mApkBaseName = baseName;
     }
 
@@ -207,15 +207,15 @@ public final class AaptExecLoopTask extends Task {
      */
     public void setApkbasename(String apkbaseName) {
         System.out.println("WARNNG: Using deprecated 'apkbasename' attribute in AaptExecLoopTask." +
-                "Use 'resourceFilename' (string) instead.");
+                "Use 'resourcefilename' (string) instead.");
         mApkBaseName = apkbaseName;
     }
 
     /**
-     * Sets the value of the apkname attribute
+     * Sets the value of the resourcefilename attribute
      * @param apkName the value
      */
-    public void setResourceFilename(String apkName) {
+    public void setResourcefilename(String apkName) {
         mApkName = apkName;
     }
 
@@ -227,7 +227,7 @@ public final class AaptExecLoopTask extends Task {
         mRFolder = TaskHelper.checkSinglePath("rfolder", rFolder);
     }
 
-    public void setresourceFilter(String filter) {
+    public void setresourcefilter(String filter) {
         if (filter != null && filter.length() > 0) {
             mResourceFilter = filter;
         }
index e34eb6e..a49c2c5 100644 (file)
@@ -69,7 +69,7 @@ public class ApkBuilderTask extends Task {
      */
     public void setBasename(String baseName) {
         System.out.println("WARNNG: Using deprecated 'basename' attribute in ApkBuilderTask." +
-                "Use 'apkFilename' (path) instead.");
+                "Use 'apkfilepath' (path) instead.");
         mBaseName = baseName;
     }
 
@@ -77,15 +77,15 @@ public class ApkBuilderTask extends Task {
      * Sets the full filepath to the apk to generate.
      * @param filepath
      */
-    public void setApkFilepath(String filepath) {
+    public void setApkfilepath(String filepath) {
         mApkFilepath = filepath;
     }
 
     /**
-     * Sets the
+     * Sets the resourcefile attribute
      * @param resourceFile
      */
-    public void setResourceFile(String resourceFile) {
+    public void setResourcefile(String resourceFile) {
         mResourceFile = resourceFile;
     }
 
diff --git a/anttasks/src/com/android/ant/IfElseTask.java b/anttasks/src/com/android/ant/IfElseTask.java
new file mode 100644 (file)
index 0000000..fd4f9d0
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * 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;
+
+/**
+ * If (condition) then: {@link Sequential} else: {@link Sequential}.
+ *
+ * In XML:
+ * <if condition="${some.condition}">
+ *     <then>
+ *     </then>
+ *     <else>
+ *     </else>
+ * </if>
+ *
+ * both <then> and <else> behave like <sequential>.
+ *
+ * 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 Sequential mThen;
+    private Sequential mElse;
+
+    /**
+     * Sets the condition value
+     */
+    public void setCondition(boolean condition) {
+        mCondition = condition;
+        mConditionIsSet = true;
+    }
+
+    /**
+     * 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) {
+            throw new BuildException("Condition has not been set.");
+        }
+
+        // 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();
+            }
+        }
+    }
+}
index 1babcf7..89123d8 100644 (file)
@@ -53,6 +53,13 @@ import javax.xml.xpath.XPathFactory;
  */
 public class MultiApkExportTask extends Task {
 
+    /**
+     * Class representing one apk that needs to be generated. This contains
+     * which project it must be created from, and which filters should be used.
+     *
+     * This class is meant to be sortable in a way that allows generation of the buildInfo
+     * value that goes in the composite versionCode.
+     */
     private static class ExportData implements Comparable<ExportData> {
 
         String relativePath;
@@ -169,6 +176,10 @@ public class MultiApkExportTask extends Task {
         }
         System.out.println("versionCode: " + version);
 
+        // checks whether the projects can be signed.
+        boolean canSign = true;
+
+
         ExportData[] projects = getProjects(antProject, appPackage);
         HashSet<String> compiledProject = new HashSet<String>();
 
@@ -223,7 +234,6 @@ public class MultiApkExportTask extends Task {
                 // set the output file names/paths. Keep all the temporary files in the project
                 // folder, and only put the final file (which is different depending on whether
                 // the file can be signed) locally.
-                boolean canSign = false;
 
                 // read the base name from the build.xml file.
                 String name = null;
index 236ebbb..dd6da8d 100644 (file)
@@ -44,7 +44,6 @@ public final class ApkBuilder {
         public ApkCreationException(Throwable throwable) {
             super(throwable);
         }
-
     }
 
     /**
index 50b2f3a..d6e8ab9 100644 (file)
         classname="com.android.ant.XPathTask"
         classpathref="android.antlibs" />
 
+    <taskdef name="if"
+        classname="com.android.ant.IfElseTask"
+        classpathref="android.antlibs" />
+
     <!-- Properties -->
 
     <!-- Tells adb which device to target. You can change this from the command line
         <sequential>
             <apkbuilder
                     outfolder="${out.absolute.dir}"
-                    resourceFile="${resource.package.file.name}"
-                    apkFilepath="@{output.filepath}"
+                    resourcefile="${resource.package.file.name}"
+                    apkfilepath="@{output.filepath}"
                     signed="@{sign.package}"
                     debug="${manifest.debuggable}"
                     abifilter="${filter.abi}"
                 assets="${asset.absolute.dir}"
                 androidjar="${android.jar}"
                 apkfolder="${out.absolute.dir}"
-                resourceFilename="${resource.package.file.name}"
-                resourceFilter="${aapt.resource.filter}">
+                resourcefilename="${resource.package.file.name}"
+                resourcefilter="${aapt.resource.filter}">
             <res path="${resource.absolute.dir}" />
             <!-- <nocompress /> forces no compression on any files in assets or res/raw -->
             <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets and res/raw -->
         </condition>
     </target>
 
+    <!-- Runs -release-check first, which sets release.sign, and then runs
+         only if release.sign is false. -->
     <target name="-release-nosign" depends="-release-check" unless="release.sign">
         <echo>No key.store and key.alias properties found in build.properties.</echo>
         <echo>Please sign ${out.unsigned.file} manually</echo>
         <echo>and run zipalign from the Android SDK tools.</echo>
     </target>
 
+    <!-- This runs -package-release and -release-nosign first and then runs
+         only if release-sign is true (set in -release-check,
+         called by -release-no-sign)-->
     <target name="release" depends="-package-release, -release-nosign" if="release.sign"
                 description="Builds the application. The generated apk file must be signed before
                             it is published.">