ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant Target.java ProjectHelper.java
Date Wed, 12 Jul 2000 12:40:29 GMT
bodewig     00/07/12 05:40:29

  Modified:    docs     index.html
               src/main/org/apache/tools/ant Target.java ProjectHelper.java
  Log:
  Added unless attribute to target.
  
  Revision  Changes    Path
  1.44      +17 -7     jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- index.html	2000/07/12 11:51:29	1.43
  +++ index.html	2000/07/12 12:40:28	1.44
  @@ -274,16 +274,20 @@
   on B, and B depends on A, so first A is executed, then B, then C, and finally D.</p>
   <p>A target gets executed only once. Even when more targets depend on it (see
   the previous example).</p>
  -<p>A target has also the ability to perform its execution if a property has been
  -set. This allows, for example, better control on the building process depending
  -on the state of the system (java version, OS, command line properties, etc...).
  -To make target <i>sense</i> this property you should add the <i>if</i>
attribute
  -with the name of the property that the target should react to, for example</p>
  +<p>A target has also the ability to perform its execution if (or
  +unless) a property has been set. This allows, for example, better
  +control on the building process depending on the state of the system
  +(java version, OS, command line properties, etc...).  To make target
  +<i>sense</i> this property you should add the <i>if</i> (or
  +<i>unless</i>) attribute with the name of the property that the target
  +should react to, for example</p>
   <blockquote>
     <pre>&lt;target name=&quot;build-module-A&quot; if=&quot;module-A-present&quot;/&gt;</pre>
  +  <pre>&lt;target name=&quot;build-own-fake-module-A&quot; unless=&quot;module-A-present&quot;/&gt;</pre>
   </blockquote>
  -<p>If no <i>if</i> attribute is present, the target will always be executed.</p>
  -<p>It is a good practice to place your <a href="#property">property</a>
and <a
  +<p>If no <i>if</i> and no <i>unless</i> attribute is present,
the target will 
  +always be executed.</p>
  +<p>It is a good practice to place your <a
   href="#tstamp">tstamp</a> tasks in a so called initialization target, on which
   all other targets depend. Make sure that that target is always the first one in
   the depends list of the other targets. In this manual, most initialization targets
  @@ -310,6 +314,12 @@
       <td valign="top">if</td>
       <td valign="top">the name of the property that must be set in order for this
         target to execute.</td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">unless</td>
  +    <td valign="top">the name of the property that must not be set in order 
  +      for this target to execute.</td>
       <td align="center" valign="top">No</td>
     </tr>
   </table>
  
  
  
  1.8       +24 -5     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Target.java	2000/07/06 16:48:09	1.7
  +++ Target.java	2000/07/12 12:40:28	1.8
  @@ -65,7 +65,8 @@
   public class Target {
   
       private String name;
  -    private String condition = "";
  +    private String ifCondition = "";
  +    private String unlessCondition = "";
       private Vector dependencies = new Vector(2);
       private Vector tasks = new Vector(5);
       private Project project;
  @@ -108,16 +109,20 @@
           return dependencies.elements();
       }
   
  -    public void setCondition(String property) {
  -        this.condition = (property == null) ? "" : property;
  +    public void setIf(String property) {
  +        this.ifCondition = (property == null) ? "" : property;
       }
  + 
  +    public void setUnless(String property) {
  +        this.unlessCondition = (property == null) ? "" : property;
  +    }
   
       public String toString() {
           return name;
       }
   
       public void execute() throws BuildException {
  -        if (("".equals(this.condition)) || (project.getProperty(this.condition) != null))
{
  +        if (testIfCondition() && testUnlessCondition()) {
               Enumeration enum = tasks.elements();
               while (enum.hasMoreElements()) {
                   Task task = (Task) enum.nextElement();
  @@ -135,8 +140,22 @@
                       throw exc;
                   }
               }
  +        } else if (!testIfCondition()) {
  +            project.log(this, "Skipped because property '" + this.ifCondition + "' not
set.", 
  +                        Project.MSG_VERBOSE);
           } else {
  -            project.log(this, "Skipped because property '" + this.condition + "' not set.",
Project.MSG_VERBOSE);
  +            project.log(this, "Skipped because property '" + this.unlessCondition + "'
set.",
  +                        Project.MSG_VERBOSE);
           }
  +    }
  +
  +    private boolean testIfCondition() {
  +        return "".equals(ifCondition) 
  +            || project.getProperty(ifCondition) != null;
  +    }
  +
  +    private boolean testUnlessCondition() {
  +        return "".equals(unlessCondition) 
  +            || project.getProperty(unlessCondition) == null;
       }
   }
  
  
  
  1.19      +7 -3      jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ProjectHelper.java	2000/07/11 11:14:46	1.18
  +++ ProjectHelper.java	2000/07/12 12:40:28	1.19
  @@ -276,7 +276,8 @@
           public void init(String tag, AttributeList attrs) throws SAXParseException {
               String name = null;
               String depends = "";
  -            String cond = null;
  +            String ifCond = null;
  +            String unlessCond = null;
               String id = null;
   
               for (int i = 0; i < attrs.getLength(); i++) {
  @@ -288,7 +289,9 @@
                   } else if (key.equals("depends")) {
                       depends = value;
                   } else if (key.equals("if")) {
  -                    cond = value;
  +                    ifCond = value;
  +                } else if (key.equals("unless")) {
  +                    unlessCond = value;
                   } else if (key.equals("id")) {
                       id = value;
                   } else {
  @@ -302,7 +305,8 @@
   
               target = new Target();
               target.setName(name);
  -            target.setCondition(cond);
  +            target.setIf(ifCond);
  +            target.setUnless(unlessCond);
               project.addTarget(name, target);
   
               if (id != null && !id.equals(""))
  
  
  

Mime
View raw message