2009-06-19 14 views
12

मान लीजिए कि मेरे पास कुछ चींटी कार्य है - जैवैक या जुनीट कहें - यदि कोई कार्य विफल रहता है, तो मैं एक कार्य निष्पादित करना चाहता हूं, लेकिन यदि वे सफल होते हैं तो मैं नहीं करता हूं।कोई कार्य विफल होने पर मैं एंट कमांड कैसे निष्पादित करूं?

कोई विचार यह कैसे करना है?

उत्तर

14

अपने junit लक्ष्य में, उदाहरण के लिए, आप failureProperty सेट कर सकते हैं

<target name="otherStuff" if="test.failed"> 
    <echo message="I'm here. Now what?"/> 
    <fail message="JUnit test or tests failed."/> 
</target> 

अंत में, उन्हें एक साथ टाई:

<target name="test" depends="junit,otherStuff"/> 

फिर अपने JUnit परीक्षण चलाने के लिए test लक्ष्य को कॉल करें। junit लक्ष्य चलाएगा। यदि यह विफल रहता है (विफलता या त्रुटि) test.failed संपत्ति सेट की जाएगी, और otherStuff लक्ष्य का कार्य निष्पादित होगा।

javac कार्य failonerror और errorProperty विशेषताएँ का समर्थन करता है, जिसका उपयोग समान व्यवहार प्राप्त करने के लिए किया जा सकता है।

1

ant-contrib में एक trycatch कार्य है।

+0

अफसोस की बात है कि काम नहीं करेगा, क्योंकि मैं अभी भी निर्माण विफल होना चाहता हूं। – tomjen

0

उस कार्य में एक संपत्ति सेट करें जिसके लिए आप विफलता की जांच करना चाहते हैं, और फिर दूसरा कार्य लिखें ताकि यह निष्पादित हो सके कि संपत्ति सेट नहीं है। मुझे build.xml के लिए सटीक वाक्यविन्यास याद नहीं हैं, या मैं उदाहरण दूंगा।

<target name="junit" depends="compile-tests" description="Runs JUnit tests"> 
    <mkdir dir="${junit.report}"/> 
    <junit printsummary="true" failureProperty="test.failed"> 
     <classpath refid="test.classpath"/> 
     <formatter type="xml"/> 
     <test name="${test.class}" todir="${junit.report}" if="test.class"/> 
     <batchtest fork="true" todir="${junit.report}" unless="test.class"> 
      <fileset dir="${test.src.dir}"> 
       <include name="**/*Test.java"/> 
       <exclude name="**/AllTests.java"/> 
      </fileset> 
     </batchtest> 
    </junit> 
</target> 

फिर, एक लक्ष्य है कि केवल अगर test.failed संपत्ति सेट कर दिया जाता चलाता है बनाते हैं, लेकिन अंत में विफल रहता है:

6

काई से उल्लेख किया:

ant-contrib एक trycatch कार्य है।

लेकिन आपको हालिया संस्करण 1.0b3 की आवश्यकता है। और फिर

<trycatch> 
    <try> 
     ... <!-- your executions which may fail --> 
    </try> 
    <catch> 
     ... <!-- execute on failure --> 
     <throw message="xy failed" /> 
    </catch> 
</trycatch> 

चाल टूटा हुआ निर्माण इंगित करने के लिए एक त्रुटि फिर से फेंकना है।

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