मैं कुछ एसक्यूएल स्क्रिप्ट चलाने के लिए मूल रूप से निष्पादन कार्य का उपयोग कर डेटाबेस निर्माण करने के लिए चींटी का उपयोग कर रहा हूं।चींटी कैसे विफल हो सकती है अगर दो फाइलों में त्रुटियों का पता चला है?
हालांकि, स्क्रिप्ट निष्पादन के दौरान उत्पन्न त्रुटियां हो सकती हैं (उदा। एक कनेक्टेड उपयोगकर्ता को ठीक से नहीं छोड़ सका, आदि) इसलिए मैं दो आउटपुट लॉग फ़ाइलों को देखकर इसकी जांच करता हूं।
यहाँ प्रासंगिक लक्ष्य का एक टुकड़ा है:
<target name="build">
<echo message="Add foo bar baz"/>
<exec executable="${db.sqlplus}">
</exec>
<echo message="Load x y z"/>
<exec executable="${db.sqlplus}" dir="foobar">
</exec>
<!--Check the log files here-->
<antcall target="check-log-file">
<param name="file.to.check" value="${output.log.1}"/>
</antcall>
<antcall target="check-log-file">
<param name="file.to.check" value="${output.log.2}"/>
</antcall>
<antcall target="fail-if-error"/>
</target>
<!--=============================================================================
Check the file named in the property file.to.check to see if there are errors.
The way this works is to find all lines containing the text "ERROR" and put
them into a separate file. Then it checks to see if this file has non-zero
length. If so, then there are errors, and it sets the property errors.found.
Then it calls the send-email target, which doesn't execute if the
errors.found property isn't set.
-->
<target name="check-log-file"
description="Checks the file (specified in ${file.to.check}) for errors">
<property name="file.errorcount" value="${file.to.check}.errorcount"
description="The file to hold the error lines"/>
<copy file="${file.to.check}" tofile="${file.errorcount}">
<filterchain>
<linecontains>
<contains value="ERROR"/>
</linecontains>
</filterchain>
</copy>
<condition property="errors.found" value="true">
<length file="${file.errorcount}" when="gt" length="0"/>
</condition>
<antcall target="check-log-file-send-email"/>
</target>
<!--=========================================================================
If there are any errors, send an email to let someone know
-->
<target name="check-log-file-send-email" if="errors.found"
description="Sends an email out if error detected">
<resourcecount property="error.count">
<tokens><!-- default tokenizer is a line tokenizer -->
<file file="${file.to.check}.errorcount"/>
</tokens>
</resourcecount>
<echo
message="Database build (${e1.codeline} - ${error.count} errors found..."/>
<antcall target="mail">
<param name="from-address" value="build"/>
<param name="to-list" value="myemail"/>
<param name="subject"
value="Automated database build error report for ${db.host}"/>
<param name="message"
value="See attached log file, ${error.count} error(s)found..."/>
<param name="attach" value="${file.to.check}"/>
</antcall>
</target>
<!--==========================================================================
Fails the database build if errors were detected.
-->
<target name="fail-if-error" if="errors.found">
<echo message="Errors found - setting database fail flag..."/>
<fail message="Errors detected during ${codeline} database build. Check logs."/>
</target>
जब त्रुटियों का निर्माण विफल नहीं कर रहे हैं।
मुझे लगता है कि ऐसा इसलिए है क्योंकि एंटीकॉल लॉग की जांच करने के लिए कार्य संपत्ति त्रुटि वापस नहीं करता है।
बिल्ड लक्ष्य पर वापस मिला, इसलिए जब विफल-अगर-त्रुटि कहा जाता है, तो वह संपत्ति सेट नहीं होती है।
क्या यह सही है?
क्या इसे ठीक से विफल करने के लिए सेट अप करने का कोई तरीका है?