You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2004/07/23 22:16:30 UTC

cvs commit: ant/src/etc/testcases/taskdefs ant.xml calltarget.xml

mbenson     2004/07/23 13:16:29

  Modified:    src/main/org/apache/tools/ant Project.java Target.java
               src/main/org/apache/tools/ant/taskdefs Ant.java
               src/testcases/org/apache/tools/ant/taskdefs AntTest.java
                        CallTargetTest.java
               src/etc/testcases/taskdefs ant.xml calltarget.xml
  Log:
  Try to get the dependency analysis right this time while preserving BC.
  PR: 29977
  
  Revision  Changes    Path
  1.172     +49 -18    ant/src/main/org/apache/tools/ant/Project.java
  
  Index: Project.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Project.java,v
  retrieving revision 1.171
  retrieving revision 1.172
  diff -u -r1.171 -r1.172
  --- Project.java	17 Jul 2004 16:31:40 -0000	1.171
  +++ Project.java	23 Jul 2004 20:16:29 -0000	1.172
  @@ -1181,14 +1181,11 @@
               throw new BuildException(msg);
           }
   
  -        // Sort the dependency tree, and run everything from the
  -        // beginning until we hit our targetName.
  +        // Sort and run the dependency tree.
           // Sorting checks if all the targets (and dependencies)
           // exist, and if there is any cycle in the dependency
           // graph.
  -        Vector sortedTargets = topoSort(targetName, targets);
  -        sortedTargets.setSize(sortedTargets.indexOf(targets.get(targetName)) + 1);
  -        executeSortedTargets(sortedTargets);
  +        executeSortedTargets(topoSort(targetName, targets, false));
       }
   
       /**
  @@ -1557,38 +1554,65 @@
       }
   
       /**
  -     * Topologically sorts a set of targets.
  +     * Topologically sorts a set of targets.  Equivalent to calling
  +     * <CODE>topoSort(new String[] {root}, targets, true)</CODE>.
        *
        * @param root The name of the root target. The sort is created in such
        *             a way that the sequence of Targets up to the root
        *             target is the minimum possible such sequence.
        *             Must not be <code>null</code>.
  -     * @param targets A map of names to targets (String to Target).
  +     * @param targets A Hashtable mapping names to Targets.
        *                Must not be <code>null</code>.
  -     * @return a vector of Target objects in sorted order.
  +     * @return a Vector of ALL Target objects in sorted order.
        * @exception BuildException if there is a cyclic dependency among the
        *                           targets, or if a named target does not exist.
        */
       public final Vector topoSort(String root, Hashtable targets)
           throws BuildException {
  -        return topoSort(new String[] {root}, targets);
  +        return topoSort(new String[] {root}, targets, true);
  +    }
  +
  +    /**
  +     * Topologically sorts a set of targets.  Equivalent to calling
  +     * <CODE>topoSort(new String[] {root}, targets, returnAll)</CODE>.
  +     *
  +     * @param root The name of the root target. The sort is created in such
  +     *             a way that the sequence of Targets up to the root
  +     *             target is the minimum possible such sequence.
  +     *             Must not be <code>null</code>.
  +     * @param targets A Hashtable mapping names to Targets.
  +     *                Must not be <code>null</code>.
  +     * @param returnAll <CODE>boolean</CODE> indicating whether to return all
  +     *                  targets, or the execution sequence only.
  +     * @return a Vector of Target objects in sorted order.
  +     * @exception BuildException if there is a cyclic dependency among the
  +     *                           targets, or if a named target does not exist.
  +     * @since Ant 1.6.3
  +     */
  +    public final Vector topoSort(String root, Hashtable targets,
  +                                 boolean returnAll) throws BuildException {
  +        return topoSort(new String[] {root}, targets, returnAll);
       }
   
       /**
        * Topologically sorts a set of targets.
        *
        * @param root <CODE>String[]</CODE> containing the names of the root targets.
  -     *             The sort is created in such a way that the sequence of Targets
  -     *             up to the root target is the minimum possible such sequence.
  +     *             The sort is created in such a way that the ordered sequence of
  +     *             Targets is the minimum possible such sequence to the specified
  +     *             root targets.
        *             Must not be <code>null</code>.
        * @param targets A map of names to targets (String to Target).
        *                Must not be <code>null</code>.
  -     * @return a vector of Target objects in sorted order.
  +     * @param returnAll <CODE>boolean</CODE> indicating whether to return all
  +     *                  targets, or the execution sequence only.
  +     * @return a Vector of Target objects in sorted order.
        * @exception BuildException if there is a cyclic dependency among the
        *                           targets, or if a named target does not exist.
  +     * @since Ant 1.6.3
        */
  -    public final Vector topoSort(String[] root, Hashtable targets)
  -        throws BuildException {
  +    public final Vector topoSort(String[] root, Hashtable targets,
  +                                 boolean returnAll) throws BuildException {
           Vector ret = new Vector();
           Hashtable state = new Hashtable();
           Stack visiting = new Stack();
  @@ -1602,7 +1626,13 @@
           // build Target.
   
           for (int i = 0; i < root.length; i++) {
  -            tsort(root[i], targets, state, visiting, ret);
  +            String st = (String)(state.get(root[i]));
  +            if (st == null) {
  +                tsort(root[i], targets, state, visiting, ret);
  +            } else if (st == VISITING) {
  +                throw new RuntimeException("Unexpected node in visiting state: "
  +                    + root[i]);
  +            }
           }
           StringBuffer buf = new StringBuffer("Build sequence for target(s)");
   
  @@ -1612,17 +1642,18 @@
           buf.append(" is " + ret);
           log(buf.toString(), MSG_VERBOSE);
   
  +        Vector complete = (returnAll) ? ret : new Vector(ret);
           for (Enumeration en = targets.keys(); en.hasMoreElements();) {
               String curTarget = (String) en.nextElement();
               String st = (String) state.get(curTarget);
               if (st == null) {
  -                tsort(curTarget, targets, state, visiting, ret);
  +                tsort(curTarget, targets, state, visiting, complete);
               } else if (st == VISITING) {
                   throw new RuntimeException("Unexpected node in visiting state: "
                       + curTarget);
               }
           }
  -        log("Complete build sequence is " + ret, MSG_VERBOSE);
  +        log("Complete build sequence is " + complete, MSG_VERBOSE);
           return ret;
       }
   
  
  
  
  1.55      +3 -8      ant/src/main/org/apache/tools/ant/Target.java
  
  Index: Target.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Target.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Target.java	10 Jun 2004 08:15:01 -0000	1.54
  +++ Target.java	23 Jul 2004 20:16:29 -0000	1.55
  @@ -219,14 +219,9 @@
        * @since Ant 1.6
        */
       public boolean dependsOn(String other) {
  -        if (getProject() != null) {
  -            List l = getProject().topoSort(getName(),
  -                                           getProject().getTargets());
  -            int myIdx = l.indexOf(this);
  -            int otherIdx = l.indexOf(getProject().getTargets().get(other));
  -            return myIdx >= otherIdx;
  -        }
  -        return false;
  +        Project p = getProject();
  +        Hashtable t = (p == null) ? null : p.getTargets();
  +        return (p != null && p.topoSort(getName(), t, false).contains(t.get(other)));
       }
   
       /**
  
  
  
  1.105     +2 -5      ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.104
  retrieving revision 1.105
  diff -u -r1.104 -r1.105
  --- Ant.java	24 Jun 2004 19:30:03 -0000	1.104
  +++ Ant.java	23 Jul 2004 20:16:29 -0000	1.105
  @@ -397,12 +397,9 @@
                       String[] nameArray =
                           (String[])(locals.toArray(new String[locals.size()]));
   
  -                    Hashtable targets = newProject.getTargets();
  -                    Vector sortedTargets = newProject.topoSort(nameArray, targets);
  +                    newProject.executeSortedTargets(newProject.topoSort(
  +                        nameArray, newProject.getTargets(), false));
   
  -                    sortedTargets.setSize(sortedTargets.indexOf(targets.get(
  -                        locals.lastElement())) + 1);
  -                    newProject.executeSortedTargets(sortedTargets);
                   } catch (BuildException ex) {
                       t = ProjectHelper
                           .addLocationToBuildException(ex, getLocation());
  
  
  
  1.27      +5 -1      ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java
  
  Index: AntTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/AntTest.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- AntTest.java	24 Jun 2004 19:30:03 -0000	1.26
  +++ AntTest.java	23 Jul 2004 20:16:29 -0000	1.27
  @@ -303,6 +303,10 @@
           expectLog("multiple-targets", "tadadctbdbtc");
       }
   
  +    public void testMultipleTargets2() {
  +        expectLog("multiple-targets-2", "dadctb");
  +    }
  +
       private class BasedirChecker implements BuildListener {
           private String[] expectedBasedirs;
           private int calls = 0;
  
  
  
  1.9       +4 -0      ant/src/testcases/org/apache/tools/ant/taskdefs/CallTargetTest.java
  
  Index: CallTargetTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/CallTargetTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CallTargetTest.java	24 Jun 2004 19:30:03 -0000	1.8
  +++ CallTargetTest.java	23 Jul 2004 20:16:29 -0000	1.9
  @@ -63,6 +63,10 @@
           expectLog("multiple-targets", "tadadctbdbtc");
       }
   
  +    public void testMultipleTargets2() {
  +        expectLog("multiple-targets-2", "dadctb");
  +    }
  +
       public void tearDown() {
           project.executeTarget("cleanup");
       }
  
  
  
  1.15      +7 -0      ant/src/etc/testcases/taskdefs/ant.xml
  
  Index: ant.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/ant.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ant.xml	24 Jun 2004 19:30:03 -0000	1.14
  +++ ant.xml	23 Jul 2004 20:16:29 -0000	1.15
  @@ -206,6 +206,13 @@
       </ant>
     </target>
   
  +  <target name="multiple-targets-2">
  +    <ant antfile="ant.xml">
  +      <target name="tb" />
  +      <target name="da" />
  +    </ant>
  +  </target>
  +
     <target name="ta"><echo>ta</echo></target>
     <target name="tb" depends="da,dc"><echo>tb</echo></target>
     <target name="tc" depends="db,dc"><echo>tc</echo></target>
  
  
  
  1.5       +7 -0      ant/src/etc/testcases/taskdefs/calltarget.xml
  
  Index: calltarget.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/calltarget.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- calltarget.xml	24 Jun 2004 19:30:03 -0000	1.4
  +++ calltarget.xml	23 Jul 2004 20:16:29 -0000	1.5
  @@ -65,6 +65,13 @@
           </antcall>
       </target>
   
  +    <target name="multiple-targets-2">
  +      <ant antfile="ant.xml">
  +        <target name="tb" />
  +        <target name="da" />
  +      </ant>
  +    </target>
  +
       <target name="ta"><echo>ta</echo></target>
       <target name="tb" depends="da,dc"><echo>tb</echo></target>
       <target name="tc" depends="db,dc"><echo>tc</echo></target>
  
  
  

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