You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/12/12 09:48:42 UTC

cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs FailTest.java

bodewig     01/12/12 00:48:42

  Modified:    .        WHATSNEW
               docs/manual/CoreTasks fail.html
               src/etc/testcases/taskdefs fail.xml
               src/main/org/apache/tools/ant Target.java
               src/main/org/apache/tools/ant/taskdefs Exit.java
               src/testcases/org/apache/tools/ant/taskdefs FailTest.java
  Log:
  Add if/unless attributes to <fail>.
  
  PR: 1380
  
  This is the first step to remove the fail functionality from input and
  waitfor.
  
  Revision  Changes    Path
  1.189     +3 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.188
  retrieving revision 1.189
  diff -u -r1.188 -r1.189
  --- WHATSNEW	2001/12/10 10:10:35	1.188
  +++ WHATSNEW	2001/12/12 08:48:42	1.189
  @@ -121,6 +121,9 @@
     <antcall> unless a reference of the same name already exists in the
     subbuild or inheritall has been set to false.
   
  +* <fail> no supports builds to fail based on conditions via if and
  +  unless attributes.
  +
   Changes from Ant 1.4 to Ant 1.4.1
   ===========================================
   
  
  
  
  1.5       +12 -0     jakarta-ant/docs/manual/CoreTasks/fail.html
  
  Index: fail.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/fail.html,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- fail.html	2001/10/30 10:05:34	1.4
  +++ fail.html	2001/12/12 08:48:42	1.5
  @@ -24,6 +24,18 @@
       <td valign="top">A message giving further information on why the build exited</td>
       <td align="center" valign="top">No</td>
     </tr>
  +  <tr>
  +    <td valign="top">if</td>
  +    <td valign="top">Only fail if a property of the given name exists
  +      in the current project</td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">unless</td>
  +    <td valign="top">Only fail if a property of the given name doesn't
  +      exist in the current project</td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
   </table>
   <h3>Examples</h3>
   <pre>  &lt;fail/&gt;</pre>
  
  
  
  1.3       +8 -0      jakarta-ant/src/etc/testcases/taskdefs/fail.xml
  
  Index: fail.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/fail.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- fail.xml	2000/12/18 15:43:54	1.2
  +++ fail.xml	2001/12/12 08:48:42	1.3
  @@ -10,4 +10,12 @@
       <fail message="test"/>
     </target>
   
  +  <target name="testIf">
  +    <fail if="foo" />
  +  </target>
  +
  +  <target name="testUnless">
  +    <fail unless="foo" />
  +  </target>
  +
   </project>
  
  
  
  1.28      +1 -0      jakarta-ant/src/main/org/apache/tools/ant/Target.java
  
  Index: Target.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Target.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- Target.java	2001/12/01 03:34:35	1.27
  +++ Target.java	2001/12/12 08:48:42	1.28
  @@ -233,4 +233,5 @@
           String test = ProjectHelper.replaceProperties(getProject(), unlessCondition);
           return project.getProperty(test) == null;
       }
  +
   }
  
  
  
  1.7       +30 -4     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Exit.java
  
  Index: Exit.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Exit.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Exit.java	2001/12/01 03:34:35	1.6
  +++ Exit.java	2001/12/12 08:48:42	1.7
  @@ -66,16 +66,27 @@
    */
   public class Exit extends Task { 
       private String message;
  +    private String ifCondition, unlessCondition;
       
       public void setMessage(String value) { 
           this.message = value;
       }
       
  +    public void setIf(String c) {
  +        ifCondition = c;
  +    }
  +
  +    public void setUnless(String c) {
  +        unlessCondition = c;
  +    }
  +
       public void execute() throws BuildException {
  -        if (message != null && message.length() > 0) { 
  -            throw new BuildException(message);
  -        } else {
  -            throw new BuildException("No message");
  +        if (testIfCondition() && testUnlessCondition()) {
  +            if (message != null && message.length() > 0) { 
  +                throw new BuildException(message);
  +            } else {
  +                throw new BuildException("No message");
  +            }
           }
       }
   
  @@ -85,6 +96,21 @@
       public void addText(String msg) {
           message += 
               ProjectHelper.replaceProperties(project, msg);
  +    }
  +
  +    private boolean testIfCondition() {
  +        if (ifCondition == null || "".equals(ifCondition)) {
  +            return true;
  +        }
  +        
  +        return project.getProperty(ifCondition) != null;
  +    }
  +
  +    private boolean testUnlessCondition() {
  +        if (unlessCondition == null || "".equals(unlessCondition)) {
  +            return true;
  +        }
  +        return project.getProperty(unlessCondition) == null;
       }
   
   }
  
  
  
  1.4       +23 -0     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/FailTest.java
  
  Index: FailTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/FailTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FailTest.java	2001/11/14 12:25:30	1.3
  +++ FailTest.java	2001/12/12 08:48:42	1.4
  @@ -54,10 +54,12 @@
   
   package org.apache.tools.ant.taskdefs;
   
  +import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.BuildFileTest;
   
   /**
    * @author Nico Seessle <ni...@seessle.de> 
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
    */
   public class FailTest extends BuildFileTest { 
       
  @@ -75,5 +77,26 @@
   
       public void test2() { 
           expectBuildException("test2", "it is required to fail :-)");
  +    }
  +
  +    public void testIf() {
  +        try {
  +            executeTarget("testIf");
  +        } catch (BuildException be) {
  +            fail("foo has not been defined, testIf must not fail");
  +        }
  +        project.setProperty("foo", "");
  +        expectBuildException("testIf", "testIf must fail if foo has been set");
  +    }
  +
  +    public void testUnless() {
  +        expectBuildException("testUnless", 
  +                             "testUnless must fail unless foo has been set");
  +        project.setProperty("foo", "");
  +        try {
  +            executeTarget("testUnless");
  +        } catch (BuildException be) {
  +            fail("foo has been defined, testUnless must not fail");
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs FailTest.java

Posted by Stefan Bodewig <bo...@apache.org>.
On 12 Dec 2001, <bo...@apache.org> wrote:

>                src/main/org/apache/tools/ant Target.java
>                src/main/org/apache/tools/ant/taskdefs Exit.java

Instead of duplicating the code, I would have preferred to put it into
a central place, but couldn't make up my mind, where this should be.
Project?  Other ideas?

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>