ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject svn commit: r465065 - in /ant/core/trunk: ./ src/main/org/apache/tools/ant/ src/main/org/apache/tools/ant/helper/ src/main/org/apache/tools/ant/taskdefs/ src/tests/antunit/types/
Date Tue, 17 Oct 2006 21:33:43 GMT
Author: peterreilly
Date: Tue Oct 17 14:33:42 2006
New Revision: 465065

URL: http://svn.apache.org/viewvc?view=rev&rev=465065
Log:
add fall-back for undefined references that are parsed

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/Project.java
    ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java
    ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java
    ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java
    ant/core/trunk/src/tests/antunit/types/defer-reference-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=465065&r1=465064&r2=465065
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Oct 17 14:33:42 2006
@@ -16,6 +16,9 @@
   of Watchdog, ExecuteWatchdog and ExecuteJava, which could reduce the occurence
   of race conditions here, especially on Java1.5+.
 
+* Allow broken reference build files. The defer reference processing would
+  break too many files - so allow them with a warning.
+
 Changes from Ant 1.7.0Beta2 to Ant 1.7.0Beta3 
 =============================================
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/Project.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/Project.java?view=diff&rev=465065&r1=465064&r2=465065
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/Project.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/Project.java Tue Oct 17 14:33:42 2006
@@ -33,6 +33,7 @@
 import java.util.Vector;
 import java.util.Set;
 import java.util.HashSet;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.WeakHashMap;
 import org.apache.tools.ant.input.DefaultInputHandler;
@@ -61,6 +62,8 @@
  *
  */
 public class Project implements ResourceFactory {
+    private static final String LINE_SEP = System.getProperty("line.separator");
+
     /** Message priority of "error". */
     public static final int MSG_ERR = 0;
     /** Message priority of "warning". */
@@ -136,6 +139,12 @@
     /** Map of references within the project (paths etc) (String to Object). */
     private Hashtable references = new AntRefTable();
 
+    /** Map of id references - used for indicating broken build files */
+    private HashMap idReferences = new HashMap();
+
+    /** the parent project for old id resolution (if inheritreferences is set) */
+    private Project parentIdProject = null;
+
     /** Name of the project's default target. */
     private String defaultTarget;
 
@@ -1815,6 +1824,46 @@
     }
 
     /**
+     * Inherit the id references.
+     * @param parent the parent project of this project.
+     */
+    public void inheritIDReferences(Project parent) {
+        parentIdProject = parent;
+    }
+
+    /**
+     * Attempt to resolve an Unknown Reference using the
+     * parsed id's - for BC.
+     */
+    private Object resolveIdReference(String key, Project callerProject) {
+        UnknownElement origUE = (UnknownElement) idReferences.get(key);
+        if (origUE == null) {
+            return parentIdProject == null
+                ? null
+                : parentIdProject.resolveIdReference(key, callerProject);
+        }
+        callerProject.log(
+            "Warning: Reference " + key + " has not been set at runtime,"
+            + " but was found during" + LINE_SEP
+            + "build file parsing, attempting to resolve."
+            + " Future versions of Ant may support" + LINE_SEP
+            + " referencing ids defined in non-executed targets.", MSG_WARN);
+        UnknownElement copyUE = origUE.copy(callerProject);
+        copyUE.maybeConfigure();
+        return copyUE.getRealThing();
+    }
+
+    /**
+     * Add an id reference.
+     * Used for broken build files.
+     * @param id the id to set.
+     * @param value the value to set it to (Unknown element in this case.
+     */
+    public void addIdReference(String id, Object value) {
+        idReferences.put(id, value);
+    }
+
+    /**
      * Add a reference to the project.
      *
      * @param referenceName The name of the reference. Must not be <code>null</code>.
@@ -1856,7 +1905,12 @@
      *         there is no such reference in the project.
      */
     public Object getReference(String key) {
-        return references.get(key);
+        Object ret = references.get(key);
+        if (ret != null) {
+            return ret;
+        }
+        // Check for old id behaviour
+        return resolveIdReference(key, this);
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java?view=diff&rev=465065&r1=465064&r2=465065
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/UnknownElement.java Tue Oct 17 14:33:42 2006
@@ -19,8 +19,10 @@
 package org.apache.tools.ant;
 
 import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.io.IOException;
 import org.apache.tools.ant.taskdefs.PreSetDef;
 
@@ -620,5 +622,46 @@
 
     private static boolean equalsString(String a, String b) {
         return (a == null) ? (b == null) : a.equals(b);
+    }
+
+    /**
+     * Make a copy of the unknown element and set it in the new project.
+     * @param newProject the project to create the UE in.
+     * @return the copied UE.
+     */
+    public UnknownElement copy(Project newProject) {
+        UnknownElement ret = new UnknownElement(getTag());
+        ret.setNamespace(getNamespace());
+        ret.setProject(newProject);
+        ret.setQName(getQName());
+        ret.setTaskType(getTaskType());
+        ret.setTaskName(getTaskName());
+        ret.setLocation(getLocation());
+        if (getOwningTarget() == null) {
+            Target t = new Target();
+            t.setProject(getProject());
+            ret.setOwningTarget(t);
+        } else {
+            ret.setOwningTarget(getOwningTarget());
+        }
+        RuntimeConfigurable copyRC = new RuntimeConfigurable(
+            ret, getTaskName());
+        copyRC.setPolyType(getWrapper().getPolyType());
+        Map m = getWrapper().getAttributeMap();
+        for (Iterator i = m.entrySet().iterator(); i.hasNext();) {
+            Map.Entry entry = (Map.Entry) i.next();
+            copyRC.setAttribute(
+                (String) entry.getKey(), (String) entry.getValue());
+        }
+        copyRC.addText(getWrapper().getText().toString());
+
+        for (Enumeration e = getWrapper().getChildren(); e.hasMoreElements();) {
+            RuntimeConfigurable r = (RuntimeConfigurable) e.nextElement();
+            UnknownElement ueChild = (UnknownElement) r.getProxy();
+            UnknownElement copyChild = ueChild.copy(newProject);
+            copyRC.addChild(copyChild.getWrapper());
+            ret.addChild(copyChild);
+        }
+        return ret;
     }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java?view=diff&rev=465065&r1=465064&r2=465065
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/AntXMLContext.java Tue Oct 17 14:33:42
2006
@@ -268,7 +268,7 @@
     public void configureId(Object element, Attributes attr) {
         String id = attr.getValue("id");
         if (id != null) {
-            project.addReference(id, element);
+            project.addIdReference(id, element);
         }
     }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java?view=diff&rev=465065&r1=465064&r2=465065
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/helper/ProjectHelper2.java Tue Oct 17 14:33:42
2006
@@ -1015,6 +1015,8 @@
                 context.getCurrentTarget().addTask(task);
             }
 
+            context.configureId(task, attrs);
+
             // container.addTask(task);
             // This is a nop in UE: task.init();
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java?view=diff&rev=465065&r1=465064&r2=465065
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Ant.java Tue Oct 17 14:33:42 2006
@@ -491,6 +491,7 @@
                     continue;
                 }
                 copyReference(key, key);
+                newProject.inheritIDReferences(getProject());
             }
         }
     }

Modified: ant/core/trunk/src/tests/antunit/types/defer-reference-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/defer-reference-test.xml?view=diff&rev=465065&r1=465064&r2=465065
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/defer-reference-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/types/defer-reference-test.xml Tue Oct 17 14:33:42 2006
@@ -5,10 +5,10 @@
   
   <target name="test-notcalled">
     <!-- bug 36955 -->
-    <au:expectfailure>
-      <pathconvert property="_output2" refid="ref1"
-                   pathsep="${line.separator}" />
-    </au:expectfailure>
+    <pathconvert property="_output2" refid="ref1"
+                 pathsep="${line.separator}" />
+    <echo>${_output2}</echo>
+    <au:assertLogContains text="Future versions of Ant"/>
   </target>
 
   <target name="test-macrodef-embedded-ref">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message