ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: Multiple directory existence checking
Date Tue, 11 May 2004 17:23:23 GMT
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


Mime
View raw message