2011-03-12 13 views
14

चींटी में, मैं कैसे जांच सकता हूं कि फ़ाइलों का एक सेट (पथों की अल्पविराम से अलग सूची) मौजूद है या नहीं? path1path2path3 के सभी उदाहरण मेंफ़ाइलों के एक सेट के लिए चींटी जांच अस्तित्व

<property name="myprop" value="path1,path2,path3"/> 

तो करने के लिए pathExist स्थापित करने के लिए मौजूद होना चाहिए:

उदाहरण के लिए मैं अगर myprop में सूचीबद्ध सभी रास्तों मौजूद हैं और यदि ऐसा है तो मैं एक संपत्ति pathExist सेट करना चाहते हैं जांच करने की आवश्यकता true, अन्यथा false

मुझे पता चला कि एक संसाधन के लिए मैं resourceexist कार्य का उपयोग कर सकता हूं, लेकिन मैं यह समझ नहीं सकता कि पथों की अल्पविराम से अलग सूची के साथ इसका उपयोग कैसे किया जाए।

मैं पथ के सेट के लिए अस्तित्व की जांच कैसे कर सकता हूं? धन्यवाद!

<condition property="pathExist"> 
<and> 
    <available file="/foo/bar" type="dir"/> 
    <available file="/foo/baz" type="dir"/> 
    <available file="path/to/foobar.txt"/> 
    ... 
</and> 
</condition> 

पथ के एक commaseparated सूची की जांच करने के का उपयोग चींटी ऐड-ऑन Flaka, उदा:

+0

यह भी देखें [एंटी के उपलब्ध कमांड में वाइल्डकार्ड का उपयोग कैसे करें] (http://stackoverflow.com/questions/1073077/how-to-use-wildcard-in-ants-available-command/) – Vadzim

उत्तर

12

आप इस के लिए एक filelist, restrict और condition कार्य के संयोजन का उपयोग कर सकते हैं की तरह एक JVM स्क्रिप्टिंग भाषा के साथ scriptcondition कार्य का उपयोग है।

नीचे दिए गए उदाहरण में फ़ाइल से अल्पविराम से अलग सूची वाली संपत्ति से फ़ाइललिस्ट बनाई गई है। restrict का उपयोग उन फ़ाइलों की एक सूची है जो मौजूद नहीं हैं। यह ऐसी संपत्ति में रखा गया है जो सभी फाइलें पाई जाने पर खाली हो जाएंगी।

<property name="myprop" value="path1,path2,path3"/> 
<filelist id="my.files" dir="." files="${myprop}" /> 

<restrict id="missing.files"> 
    <filelist refid="my.files"/> 
    <not> 
    <exists/> 
    </not> 
</restrict> 

<property name="missing.files" refid="missing.files" /> 
<condition property="pathExist" value="true" else="false"> 
    <length string="${missing.files}" length="0" /> 
</condition> 
<echo message="Files all found: ${pathExist}" /> 

आप एक विफलता गुम फ़ाइलें लिस्टिंग संदेश उत्पन्न करने के लिए कुछ इस तरह इस्तेमाल कर सकते हैं:

<fail message="Missing files: ${missing.files}"> 
    <condition> 
     <length string="${missing.files}" when="greater" length="0" /> 
    </condition> 
</fail> 
+2

समाधान हो सकता है संसाधन गणना स्थिति से छोटा: http://stackoverflow.com/a/19219702/603516 – Vadzim

+3

चींटी 1.7.1 के साथ इस समाधान का उपयोग करते समय, 'xmlns: rsel = "antlib: org.apache.tools.ant.types.resources जोड़ें। चयनकर्ता "' 'तत्व पर। फिर '' ' 'और' '' ' में बदलें। –

2

बंडल की स्थिति कई dirs या फ़ाइलों के होने की जाँच करने के लिए कम से कम समाधान कर रहे हैं :

<project xmlns:fl="antlib:it.haefelinger.flaka"> 

<!-- when you have a cvs property use split function 
     to get your list to iterate over --> 
<property name="checkpath" value="/foo/bar,/foo/baz,/foo/bazz"/> 
    <fl:for var="file" in="split('${checkpath}', ',')"> 
    <fl:fail message="#{file} does not exist !!" test="!file.tofile.exists"/> 
    </fl:for>    
</project> 

एक और संभावना ग्रूवी, BeanShell .. आदि

1

यह Ant's resource collections के सेट के संचालन के साथ हल किया जा सकता है। यदि आप मौजूदा फ़ाइलों की सूची के साथ आवश्यक फ़ाइलों की सूची के चौराहे की गणना करते हैं तो यह आवश्यक फ़ाइलों की सूची से अलग नहीं होना चाहिए। इससे पता चलता है कि यह कैसे करना है:

<property name="files" value="a.jar,b.jar,c.jar"/> 

<target name="missing"> 
    <condition property="missing"> 
    <resourcecount when="ne" count="0"> 
     <difference id="missing"> 
     <intersect> 
      <filelist id="required" dir="." files="${files}"/> 
      <fileset id="existing" dir="." includes="*.jar"/> 
     </intersect> 
     <filelist refid="required"/> 
     </difference> 
    </resourcecount> 
    </condition> 
</target> 

<target name="check" depends="missing" if="missing"> 
    <echo message="missing: ${toString:missing}"/> 
</target> 

check लक्ष्य लापता फाइलों की सूची में केवल तभी एक फाइल गायब है रिपोर्ट।

संबंधित मुद्दे