OSDN Git Service

Fix external jar support when building with proguard.
authorXavier Ducrohet <xav@android.com>
Mon, 25 Oct 2010 21:24:09 +0000 (14:24 -0700)
committerXavier Ducrohet <xav@android.com>
Mon, 25 Oct 2010 21:55:32 +0000 (14:55 -0700)
Change-Id: I3dafb284770f475d70a212cbe22cdae6bff36ff7

anttasks/src/com/android/ant/IfElseTask.java
files/ant/main_rules.xml

index 0a59466..f34e486 100644 (file)
 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;
+import org.apache.tools.ant.taskdefs.condition.And;
 
 /**
  * If (condition) then: {@link Sequential} else: {@link Sequential}.
@@ -35,7 +34,10 @@ import org.apache.tools.ant.taskdefs.condition.IsSet;
  *
  * or
  *
- * <if isset="propertyname">
+ * <if>
+ *     <condition>
+ *         ...
+ *     </condition>
  *     <then>
  *     </then>
  *     <else>
@@ -43,6 +45,7 @@ import org.apache.tools.ant.taskdefs.condition.IsSet;
  * </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}">
@@ -56,6 +59,7 @@ public class IfElseTask extends Task {
 
     private boolean mCondition;
     private boolean mConditionIsSet = false;
+    private And mAnd;
     private Sequential mThen;
     private Sequential mElse;
 
@@ -63,28 +67,21 @@ 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) {
+    /**
+     * Creates and returns the <condition> node which is basically a <and>.
+     */
+    public Object createCondition() {
         if (mConditionIsSet) {
-            throw new BuildException("Cannot use both condition and isset attribute");
+            throw new BuildException("Cannot use both condition attribute and <condition> element");
         }
 
-        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;
+        mAnd = new And();
+        mAnd.setProject(getProject());
+        return mAnd;
     }
 
     /**
@@ -105,8 +102,12 @@ public class IfElseTask extends Task {
 
     @Override
     public void execute() throws BuildException {
-        if (mConditionIsSet == false) {
-            throw new BuildException("condition or isset attribute is missing");
+        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.
index 83f2a63..f573f48 100644 (file)
         <element name="external-libs" optional="yes" />
         <element name="extra-parameters" optional="yes" />
         <sequential>
-            <!-- sets the input for dex. If a pre-dex task sets it to something else
-                 this has no effect -->
+            <!-- sets the primary input for dex. If a pre-dex task sets it to
+                 something else this has no effect -->
             <property name="out.dex.input.absolute.dir" value="${out.classes.absolute.dir}" />
 
+            <!-- set the secondary dx input: the project (and library) jar files
+                 If a pre-dex task sets it to something else this has no effect -->
+            <if>
+                <condition>
+                    <isreference refid="out.dex.jar.input.ref" />
+                </condition>
+                <else>
+                    <path id="out.dex.jar.input.ref">
+                        <path refid="jar.libs.ref" />
+                    </path>
+                </else>
+            </if>
+
             <echo>Converting compiled files and external libraries into ${intermediate.dex.file}...</echo>
             <apply executable="${dx}" failonerror="true" parallel="true">
                 <arg value="--dex" />
                 <extra-parameters />
                 <arg line="${verbose.option}" />
                 <arg path="${out.dex.input.absolute.dir}" />
-                <path refid="jar.libs.ref" />
+                <path refid="out.dex.jar.input.ref" />
                 <external-libs />
             </apply>
         </sequential>
                 <isset property="proguard.config" />
             </and>
         </condition>
+        <if condition="${proguard.enabled}">
+            <then>
+                <!-- Secondary dx input (jar files) is empty since all the
+                     jar files will be in the obfuscated jar -->
+                <path id="out.dex.jar.input.ref" />
+            </then>
+        </if>
     </target>
 
     <target name="-set-release-mode">