2010-07-23 10 views
8

मैं चींटी में एक macrodef डीबग करने की कोशिश कर रहा हूँ। मुझे तत्व के रूप में भेजे गए पैरामीटर की सामग्री को प्रदर्शित करने का कोई तरीका नहीं दिख रहा है।चींटी मैक्रोडेफ़: क्या तत्व पैरामीटर की सामग्री प्राप्त करने का कोई तरीका है?

<project name='debug.macrodef'> 
    <macrodef name='def.to.debug'> 
    <attribute name='attr' /> 
    <element name='elem' /> 
    <sequential> 
     <echo>Sure, the attribute is easy to debug: @{attr}</echo> 
     <echo>The element works only in restricted cases: <elem /> </echo> 
     <!-- This works only if <elem /> doesn't contain anything but a 
      textnode, if there were any elements in there echo would 
      complain it doesn't understand them. --> 
    </sequential> 
    </macrodef> 

    <target name='works'> 
    <def.to.debug attr='contents of attribute'> 
     <elem>contents of elem</elem> 
    </def.to.debug> 
    </target> 

    <target name='does.not.work'> 
    <def.to.debug attr='contents of attribute'> 
     <elem><sub.elem>contents of sub.elem</sub.elem></elem> 
    </def.to.debug> 
    </target> 
</project> 

उदाहरण चलाएँ:

$ ant works 
... 
works: 
[echo] Sure, the attribute is easy to debug: contents of attribute 
[echo] The element works only in restricted cases: contents of elem 
... 

$ ant does.not.work 
... 
does.not.work: 
[echo] Sure, the attribute is easy to debug: contents of attribute 

BUILD FAILED 
.../build.xml:21: The following error occurred while executing this line: 
.../build.xml:7: echo doesn't support the nested "sub.elem" element. 
... 

तो मुझे लगता है मैं एक संपत्ति में <elem /> की सामग्री को प्राप्त करने के लिए या तो एक तरह से की जरूरत है किसी भी तरह (कुछ विस्तारित macrodef कार्यान्वयन हो सकता है), या मैं एक की जरूरत है <element-echo><elem /></element-echo> का प्रकार जो आपके द्वारा डाले गए एक्सएमएल पेड़ को प्रिंट कर सकता है। क्या इनमें से किसी के कार्यान्वयन के बारे में कोई जानकारी है? डेटा प्राप्त करने का कोई भी तीसरा, अप्रत्याशित तरीका निश्चित रूप से भी स्वागत है।

उत्तर

9

echoxml कार्य के बारे में कैसे?

अपने उदाहरण का निर्माण फ़ाइल में

$ ant does.not.work 
... 
does.not.work: 
    [echo] Sure, the attribute is easy to debug: contents of attribute 
<?xml version="1.0" encoding="UTF-8"?> 
<sub.elem>contents of sub.elem</sub.elem> 

शायद XML घोषणा हालांकि चाहता था नहीं है के साथ

<echoxml><elem /></echoxml> 

परिणाम लाइन

<echo>The element works only in restricted cases: <elem /> </echo> 

की जगह। आउटपुट को अस्थायी फ़ाइल में रखने के लिए आप echoxml file विशेषता का उपयोग कर सकते हैं, फिर उस फ़ाइल को पढ़ें और घोषणा को हटा दें, या जब आप फिट देखते हैं तो जानकारी को दोबारा सुधारें।

संपादित

प्रतिबिंब पर, संभव है कि आप अपने macrodef का वर्णन है, उदाहरण के लिए इस अनुक्रमिक शरीर के पास प्राप्त कर सकते हैं

<sequential> 
    <echo>Sure, the attribute is easy to debug: @{attr}</echo> 
    <echoxml file="macro_elem.xml"><elem /></echoxml> 
    <loadfile property="elem" srcFile="macro_elem.xml"> 
    <filterchain> 
     <LineContainsRegexp negate="yes"> 
     <regexp pattern=".xml version=.1.0. encoding=.UTF-8..." /> 
     </LineContainsRegexp> 
    </filterchain> 
    </loadfile> 
    <echo message="${elem}" /> 
</sequential> 

$ ant does.not.work 
... 
does.not.work: 
    [echo] Sure, the attribute is easy to debug: contents of attribute 
    [echo] <sub.elem>contents of sub.elem</sub.elem> 
+0

' देता है' तत्व वही था जो मैं खोज रहा था, धन्यवाद! – clacke

+0

बोनस के रूप में, '' एक्सएमएल हेडर जोड़ने के लिए अतिरिक्त प्रसंस्करण के बिना भी काम करता है (चींटी 1.8.4 पर परीक्षण)। –

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

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