ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Noel Sebastien (BIL)" <Sebastien.N...@dexia-bil.com>
Subject RE: Multiple directory existence checking
Date Wed, 12 May 2004 09:49:37 GMT
Maybe my question is stupid, but I need to understand and make the example work here...

In the first example below, my ant command failed on the namespace ac... :

 <ac:for li...

I just installed Ant 1.6.1 (supporting namespace). But how to declare your ac namespace and
where ? Is it antcontrib ? and is there something (a additional jar)
to install on 1.6.1 ?

Thank you.

-----Original Message-----
From: Peter Reilly [mailto:peter.reilly@corvil.com]
Sent: mardi 11 mai 2004 19:23
To: Ant Users List
Subject: Re: Multiple directory existence checking


Dominique Devienne wrote:

>>From: Matt Benson [mailto:gudnabrsam@yahoo.com]
>>
>>Okay, gotta get my $0.02 in...
>>
>>Using pure Ant, since you have said that all
>>directories share a parent, you should be able to do
>>what you want using:
>>
>>a list of the subdirectories
>>one or more <dirset>s
>>one or more <pathconvert> invocations
>>the <equals> condition, possibly
>>    
>>
>
>Sounds like everyone's enjoying that one ;-)
>
>Game to try it without <script> ;-)))
>
>I actually think it's not doable with pure Ant (no <script>),
>but I could be wrong....
>
>I think Peter's solution is hard to top, and the easiest. --DD
>  
>
One could put it in an macrodef:
    <macrodef name="checknotallpresent">
      <attribute name="property"/>
      <attribute name="subdirs"/>
      <attribute name="root"/>
      <attribute name="delimiter" default=":"/>
      <sequential>
        <ac:for list="@{subdirs}" delimiter="@{delimiter}" param="dir">
          <ac:sequential>
            <condition property="@{property}">
              <not>
                <available file="@{root}/@{dir}" type="dir"/>
              </not>
            </condition>
          </ac:sequential>
        </ac:for>
      </sequential>
    </macrodef>
    <checknotallpresent property="notall.present"
                        root="." subdirs="a:b:c"/>
    <echo>notall.present : ${notall.present}</echo>
    <checknotallpresent property="upper.notall.present"
                        root=".." subdirs="for"/>
    <echo>upper.notall.present : ${upper.notall.present}</echo>

or use scripttypedef:

    <ae:scripttypedef name="allpresent" language="groovy">
      import org.apache.tools.ant.taskdefs.condition.Condition
      import java.io.File
      public class NotAllPresent implements Condition {
         File root
         String subdirs
         public boolean eval() {
            for (file in subdirs.split(":")) {
                if (!(new File(root, file).exists())) {
                    return false;
                }
            }
            return true;
         }
      }
      NotAllPresent
    </ae:scripttypedef>

    <condition property="all.dirs.present">
      <allpresent root="." subdirs="a:b:c"/>
    </condition>
    <echo>all.dirs.present : ${all.dirs.present}</echo>

    <condition property="upper.dirs.present">
      <allpresent root=".." subdirs="for"/>
    </condition>
    <echo>upper.dirs.present : ${upper.dirs.present}</echo>

Peter

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


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



---------------------
An electronic message is not binding on its sender.  
Any message referring to a binding engagement must be confirmed in writing and duly signed.
---------------------



---------------------
An electronic message is not binding on its sender.  
Any message referring to a binding engagement must be confirmed in writing and duly signed.
---------------------


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


Mime
View raw message