2010-07-23 13 views
8

Bir makroyu Ant'deki hata ayıklamaya çalışıyorum. Bir öğe olarak gönderilen bir parametrenin içeriğini görüntülemek için bir yol bulamıyorum.Ant makrodef: Bir eleman parametresinin içeriğini almanın bir yolu var mı?

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

Yani ben bir şekilde (bazı genişletilmiş macrodef uygulaması buna sahip olabilir) bir mülkte <elem /> içeriğini almak için bir yol ya da ihtiyaç tahmin yoksa bir ihtiyaç:

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

Örnek çalıştırmak İçine koyduğunuz XML ağacını yazdırabilen <element-echo><elem /></element-echo> türünde. Bunlardan herhangi birinin uygulanmasını bilen var mı? Verileri elde etmenin üçüncü, beklenmedik bir yolu da elbette hoş karşılanır.

cevap

9

echoxml görevi nasıl yapılır? senin örneğin inşa dosyasında

Belki XML bildirimi olsa istenmediği

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

yılında

<echoxml><elem /></echoxml> 

sonuçlarla hattını

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

değiştirilmesi. Çıktıyı geçici bir dosyaya koymak için echoxml file özniteliğini kullanabilir, ardından bu dosyayı okuyabilir ve bildirimi kaldırabilir veya bilgileri uygun gördüğünüz şekilde yeniden biçimlendirebilirsiniz.

düzenlemek

Yansıması, muhtemelen yakın size macrodef örneğin, bu sıralı vücudu nitelendirdikleri alabilirsiniz

<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

verir Öğe tam olarak aradığım şeydi, teşekkür ederim! – clacke

+0

Bir bonus olarak, '', XML başlıklarını eklemek için ekstra işlem yapılmadan bile çalışır (karınca 1.8.4'te test edilmiştir). –

İlgili konular