ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Diane Holt <hol...@yahoo.com>
Subject Re: [PATCH] Allow check for values on if/unless <target>
Date Tue, 10 Oct 2000 00:04:20 GMT
I'm all for it -- just not sure if other people will see it as having Ant
getting to "programming-y".  The only thing I'd rather see (but it's not a
big deal if you don't agree) is the equation symbol be == instead of =.

Diane

--- Jose  Alberto Fernandez <JFernandez@viquity.com> wrote:
> Hi,
>  
> This small patch makes possible to check for specific values of
> properties
> on if/unless attributes of <target>s. Hope you guys agree on incorporate
> it
> to 1.2.
>  
> <target name="a" if="myprop=${yourprop}" >
> ...
> </target>
> This helps a lot on builds that use properties to specify configuration
> options with different alternative tasks for different options.
>  
>  
> Jose Alberto
> 
>  
>  
> 

> ATTACHMENT part 2 application/octet-stream name=Jose Alberto
Fernandez.vcf
> Index: docs/index.html
> ===================================================================
> RCS file: /home/cvspublic/jakarta-ant/docs/index.html,v
> retrieving revision 1.120
> diff -u -r1.120 index.html
> --- docs/index.html	2000/09/29 15:40:29	1.120
> +++ docs/index.html	2000/10/09 22:32:04
> @@ -306,6 +306,11 @@
>    <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>You may also specify an expected value for the property, for
> example</p>
> +<blockquote>
> +  <pre>&lt;target name=&quot;build-module-A&quot;
> if=&quot;module-A-present=true&quot;/&gt;</pre>
> +  <pre>&lt;target name=&quot;build-own-fake-module-A&quot;
> unless=&quot;module-A-present=true&quot;/&gt;</pre>
> +</blockquote>
>  <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
> Index: src/main/org/apache/tools/ant/Target.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/Target.java,v
> retrieving revision 1.12
> diff -u -r1.12 Target.java
> --- src/main/org/apache/tools/ant/Target.java	2000/09/18 15:38:38	1.12
> +++ src/main/org/apache/tools/ant/Target.java	2000/10/09 22:32:05
> @@ -131,7 +131,8 @@
>      }
>  
>      public void execute() throws BuildException {
> -        if (testIfCondition() && testUnlessCondition()) {
> +        boolean ifTrue;
> +        if ((ifTrue = testIfCondition()) && testUnlessCondition()) {
>              Enumeration enum = tasks.elements();
>              while (enum.hasMoreElements()) {
>                  Task task = (Task) enum.nextElement();
> @@ -153,7 +154,7 @@
>                      throw exc;
>                  }
>              }
> -        } else if (!testIfCondition()) {
> +        } else if (!ifTrue) {
>              project.log(this, "Skipped because property '" +
> this.ifCondition + "' not set.", 
>                          Project.MSG_VERBOSE);
>          } else {
> @@ -171,11 +172,22 @@
>  
>      private boolean testIfCondition() {
>          return "".equals(ifCondition) 
> -            || project.getProperty(ifCondition) != null;
> +            || testProperty(ifCondition);
>      }
>  
>      private boolean testUnlessCondition() {
>          return "".equals(unlessCondition) 
> -            || project.getProperty(unlessCondition) == null;
> +            || !testProperty(unlessCondition);
> +    }
> +
> +    private boolean testProperty(String condition) {
> +        int pos = condition.indexOf('=');
> +        if (pos < 0)
> +            return project.getProperty(condition) != null;
> +
> +        String value = 
> +          ProjectHelper.replaceProperties(condition.substring(pos+1),
> +                                          project.getProperties());
> +        return
> value.equals(project.getProperty(condition.substring(0,pos)));
>      }
>  }
> 


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free!
http://photos.yahoo.com/

Mime
View raw message