2015-07-02 34 views
1

我使用Ant 1.8.4和xmltask 1.16。我試圖修改Maven pom.xml文件來檢查是否有/ project/properties元素,如果沒有(創建一個)以便我可以添加一個子元素。 xmltask documentation表示我必須使用副本任務來檢查,然後使用如果屬性上的插入任務。但是,當有一個現有的/項目/屬性節點xmltask測試是否存在沒有文本或屬性的節點

Can only copy/cut text() nodes and attribute values to properties (found com.sun.org.apache.xerces.internal.dom.DeferredElementNSImpl) 

,並將其插入第二個屬性點使用此代碼

<xmltask source="${pomdir}/pom.xml" dest=""${pomdir}/pom.xml"> 
    <copy path="/:project/:properties" property="hasProperties"/> 
    <insert path="/:project/:packaging" position="after" if="hasProperties" 
    xml="&lt;properties&gt;"/> 
</xmltask> 

生成此警告。在複製任務中將「/ text()」添加到xpath的末尾可以擺​​脫警告,但不會修復輸出中的重複屬性節點。

回答

1

我找到了解決方案。我必須有條件地選擇項目節點,該節點沒有屬性子節點。

<insert path="/:project[not(:properties)]/:packaging" 
    position="after"> 
    <![CDATA[ 
    <properties> 
     <customProperty>blah</customProperty> 
    </properties> 
    ]]> 
</insert> 
<insert path="/:project/:properties" 
    xml="&lt;customProperty&gt;blah&lt;/customProperty&gt;"/> 

第一次插入覆蓋了沒有屬性的輸入文件,第二次插入覆蓋了已經具有屬性的輸入文件。

相關問題