2009-10-01 5 views
6

मैं कुछ एसक्यूएल स्क्रिप्ट चलाने के लिए मूल रूप से निष्पादन कार्य का उपयोग कर डेटाबेस निर्माण करने के लिए चींटी का उपयोग कर रहा हूं।चींटी कैसे विफल हो सकती है अगर दो फाइलों में त्रुटियों का पता चला है?

हालांकि, स्क्रिप्ट निष्पादन के दौरान उत्पन्न त्रुटियां हो सकती हैं (उदा। एक कनेक्टेड उपयोगकर्ता को ठीक से नहीं छोड़ सका, आदि) इसलिए मैं दो आउटपुट लॉग फ़ाइलों को देखकर इसकी जांच करता हूं।

यहाँ प्रासंगिक लक्ष्य का एक टुकड़ा है:

<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> 

जब त्रुटियों का निर्माण विफल नहीं कर रहे हैं।

मुझे लगता है कि ऐसा इसलिए है क्योंकि एंटीकॉल लॉग की जांच करने के लिए कार्य संपत्ति त्रुटि वापस नहीं करता है।

बिल्ड लक्ष्य पर वापस मिला, इसलिए जब विफल-अगर-त्रुटि कहा जाता है, तो वह संपत्ति सेट नहीं होती है।

क्या यह सही है?

क्या इसे ठीक से विफल करने के लिए सेट अप करने का कोई तरीका है?

उत्तर

3

धन्यवाद: आप इस तरह macrodef कुछ निर्धारित करेंगे:

<macrodef name="check-log-file"> 
    <attribute name="fileToCheck"/> 

    <!--note attributes are referenced with an "@" rather than a "$" --> 
    <property name="file.errorcount" value="@{fileToCheck}.errorcount"/> 
    <copy file="@{fileToCheck}" tofile="${file.errorcount}"> 

    ... 

</macrodef> 

और इसे इस तरह कहते हैं। macrodef एक छोटे से सफाई की जरूरत (संपत्ति एक macrodef अंदर की अनुमति नहीं दी, कार्य की जरूरत है एक अनुक्रमिक टैग में लिपटे होने के लिए) तो मैं इसे यहाँ प्रदान कर रहा हूँ पूर्ण में: त्रुटि और चेतावनी के साथ जाँच

<macrodef name="check-log-file"> 
    <attribute name="file.to.check"/> 
    <attribute name="file.errorcount" default="@{file.to.check}.errorcount" description="The file to hold the error lines"/> 

    <sequential> 
     <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"> 
      <param name="file.to.check" value="@{file.to.check}"/> 
     </antcall> 
    </sequential> 
</macrodef> 
4

एंटीकॉल संपत्ति को उसके निष्पादन के दायरे में सेट करेगा, इसलिए जब आप अपनी जांच में आएं तो यह सेट नहीं है। इसके बजाय macrodef का उपयोग करने का प्रयास करें, यह वर्तमान दायरे में चलाएगा और त्रुटियों में पाए गए गुण को उस दायरे में सेट करेगा ताकि बाद में चेक इसे पढ़ सके। रिच विक्रेता, जो एक macrodef प्रयोग का विचार प्रदान की

<check-log-file fileToCheck="${output.log.1}"/> 
<check-log-file fileToCheck="${output.log.1}"/> 
0

जनरल लॉग फ़ाइल

यहां एक सामान्य मैक्रोडफ़ है जिसका उपयोग समस्याओं के लिए फ़ाइलों को स्कैन करने के लिए किया जा सकता है। जब तक आप इस मुद्दे के लिए regexp लिख सकते हैं, तो यह इसकी जांच कर सकता है ...

  • यह समस्या विफल हो सकती है या नहीं।
  • यह उन चीजों को सारांशित करता है जो उन्हें चींटी आउटपुट में लिखते हैं।
  • स्कैन करने के लिए फ़ाइलों को वाइल्डकार्ड के साथ इंगित किया जा सकता है।

    • विफल "SP2-" त्रुटियों
    • "ORA-" त्रुटियों
    • "त्रुटि पर चेतावनी दें पर चेतावनी दें पर:

    यहां उदाहरण के Oracle त्रुटियों के लिए लॉग फ़ाइलें जाँच करने के लिए कहता है कर रहे हैं: "पाठ।

    <check_for_errors file.to.check.dir="${buildlogs}" file.to.check.include="*.log" error.pattern="SP2-" /> 
    <check_for_errors file.to.check.dir="${buildlogs}" file.to.check.include="*.log" error.pattern="ORA-" error.action="warn" /> 
    <check_for_errors file.to.check.dir="${buildlogs}" file.to.check.include="*.log" error.pattern="ERROR:" error.action="warn" /> 
    

यहाँ, उदाहरण उत्पन्न एसक्यूएल फ़ाइलों में unreplaced टोकन के लिए जाँच करने के लिए कॉल कर रहे हैं निष्पादन से पहले:

<macrodef name="check_for_errors"> 
    <attribute name="file.to.check.dir" default="." /> 
    <attribute name="file.to.check.include" default="*.log" /> 
    <attribute name="file.to.check.exclude" default="" /> 
    <attribute name="error.pattern" default="ERROR" /> 
    <attribute name="error.name" default="ERROR" /> 
    <attribute name="error.action" default="fail" /> 
    <attribute name="error.display.find" default="(.+)" /> 
    <attribute name="error.display.show" default=" \1" /> 
    <sequential> 
     <echo message="Excluding file ${buildlogfile}" level="debug" /> 
     <for param="file.to.check.name"> 
      <fileset dir="@{file.to.check.dir}"> 
       <include name="@{file.to.check.include}"/> 
       <exclude name="@{file.to.check.exclude}"/> 
       <exclude name="${buildlogfile}"/> 
       <containsregexp expression="@{error.pattern}"/> 
      </fileset> 
      <sequential> 
       <echo message="ERROR: @{error.name} found in file '@{file.to.check.name}' :" level="warn" /> 
       <concat> 
        <fileset file="@{file.to.check.name}" /> 
        <filterchain> 
         <linecontainsregexp> 
          <regexp pattern="@{error.pattern}" /> 
         </linecontainsregexp> 
         <replaceregex pattern="@{error.display.find}" replace="@{error.display.show}" /> 
        </filterchain> 
       </concat> 
       <property name="error.check.foundvalues" value="true" /> 
      </sequential> 
     </for> 
     <condition property="error.check.fail"> 
      <and> 
       <matches string="@{error.action}" pattern="fail" /> 
       <isset property="error.check.foundvalues" /> 
      </and> 
     </condition> 
     <fail message="ERROR: Fix the above errors and try again. Exiting..." if="error.check.fail"/>  
    </sequential> 
</macrodef> 
:

<check_for_errors file.to.check.dir="${distdir}" file.to.check.include="**/\*.sql" 
     error.name="Token" error.pattern="^(?!--)[email protected][^@ ][email protected]" error.display.find=".*(@[^@ ][email protected]).*" error.display.show=" Token = '\1'"/> 
    <check_for_errors file.to.check.dir="${distdir}" file.to.check.include="**/*.sql" 
     error.name="Token" error.pattern="^(?!--)[email protected]\$\{[^ }]+\}" error.display.find=".*(\$\{[^ }]+\}).*" error.display.show=" Token = '\1'"/> 

यहाँ macrodef है

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