2010-09-02 13 views
2

在另一個問題 - Getting directory listing from SVN for use in ANT dropdownANT ANTForm XSL - 小抄

我問如何我可以直接連接多達SVN到我的Ant腳本。我得到的答案非常好,遵循從SVN導出目錄列表爲XML格式,然後使用XSL構建表單。

我對XSL沒有經驗,所以我想知道是否有人可能能夠給我任何指針?更具體地說,通過XSL在ANTForms中構建表單。他們的網站似乎沒有提及使用它的任何內容,我在Google上找不到任何東西。

附加資料...

下面是我碰到SVN回XML的一小部分。

<?xml version="1.0"?> 
<lists> 
<list path="https://example.com/svn/website/tags"> 
    <entry kind="dir"> 
     <name>archive</name> 
     <commit revision="1337"> 
      <author>itncj</author> 
      <date>2010-02-17T12:21:22.342500Z</date> 
     </commit> 
    </entry> 
    <entry kind="dir"> 
     <name>milestone 1-0-0</name> 
     <commit revision="1302"> 
      <author>jcb4337</author> 
      <date>2010-02-12T10:15:00.282625Z</date> 
     </commit> 
    </entry> 
    <entry kind="dir"> 
     <name>milestone 1-0-0b</name> 
     <commit revision="1329"> 
      <author>itncj</author> 
      <date>2010-02-17T12:08:56.248750Z</date> 
     </commit> 
    </entry> 
</list> 

所有我需要從這個名字的節點,所以我可以構建以下結構的一種形式 -

  • 部分目標LABEL
  • LABEL |文本框
  • SVN CALL1名稱在一個下拉
  • SVN CALL2名稱在一個下拉
  • SVN CALL3名稱在一個下拉
  • YES/NO < - 單選按鈕 - 爲了釋放我們的應用程序框架的核心文件
  • SVN CALL4名稱在一個下拉< - 哪個版本的核心
  • 測試/生產/> <的 - 單選按鈕 - 我們希望釋放到
  • PASSWORD環境文本框
  • 部署按鈕
  • 取消按鈕

希望是有道理的,但什麼,我需要做的就是X4 SVN電話,一個爲持有我們的項目文件(主項目文件每一個倉庫,相關組件,插件&核心)並使用ANTForm的selectionProperty(http://antforms.sourceforge.net/usageaf.html)填充這些下拉列表。

除此之外,我還需要做更多的事情(比如在每個下拉菜單的開頭添加「Trunk」),但是我只需要一步。我在過去使用

+0

XSLT是一種將任何XML文檔轉換爲另一種文檔的技術。我建議從這裏開始:http://www.w3schools.com/xsl/ – 2010-09-02 19:06:27

+0

我不是XML SVN和ANTForms專家,但如果您要提供減少輸入樣本和期望的輸出,有人會幫助你。 – 2010-09-02 19:26:50

+0

@Mark - 對不起,這可能只是我的術語,但這是上次回覆你有用的回覆:-)。你給我的示例代碼工作得非常好,但我想看看我可以採取多大措施,例如使用選項填充下拉列表。 @Alejandro - 感謝您的建議。明天早上我會在這裏舉一個例子。 – 2010-09-02 22:43:20

回答

3

一種策略是有一個Ant腳本生成另一個Ant構建文件,然後在運行中執行動態生成的Ant生成文件:

  1. 調用過程(獲取SVN信息)
  2. 調用XSLT動態地產生另一個ANT構建文件(帶有動態構造ANTForm)
  3. 調用動態生成ANT構建文件(使用antcall,螞蟻等)

像這樣的樣式表可以作爲一個起點,生成調用動態生成的ANT形成動態Ant構建文件:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output indent="yes"/> 

    <xsl:template match="/"> 
     <project name="enhancedRSS" default="form" basedir="."> 
      <taskdef name="antform" classname="com.sardak.antform.AntForm" 
       classpath="${antform.home}/lib/antform.jar"/> 
      <target name="form"> 
       <xsl:call-template name="ANTFORM" /> 
      </target> 
     </project> 
    </xsl:template> 

    <xsl:template name="ANTFORM"> 
     <antform title="Example ANTForm generated from XSLT"> 

      <label>Some title label</label> 
      <textProperty label="LABEL" property="label1" required="true" focus="true" 
       tooltip="This is the first label, which will assign the value entered to the ANT property label1" /> 

      <selectionProperty label="Values from SVN-CALL1:" property="svn-call1" separator=";"> 
       <xsl:attribute name="values"> 
        <xsl:call-template name="SVN-CALL1" /> 
       </xsl:attribute> 
      </selectionProperty> 

      <selectionProperty label="Values from SVN-CALL2:" property="svn-call2" separator=";"> 
       <xsl:attribute name="values"> 
        <xsl:call-template name="SVN-CALL2" /> 
       </xsl:attribute> 
      </selectionProperty> 

      <selectionProperty label="Values from SVN-CALL3:" property="svn-call3" separator=";"> 
       <xsl:attribute name="values"> 
        <xsl:call-template name="SVN-CALL3" /> 
       </xsl:attribute> 
      </selectionProperty> 

      <radioSelectionProperty label="Release core files: " property="release" values="Yes;No" separator=";" /> 

      <selectionProperty label="Which verion of the core:"> 
       <xsl:attribute name="values"> 
        <xsl:call-template name="SVN-CALL4" /> 
       </xsl:attribute> 
      </selectionProperty> 

      <radioSelectionProperty label="Environment: " property="environment" values="Test;Production" separator=";" /> 

      <textProperty label="Password" property="svn.password" required="true" password="true" /> 

      <controlbar> 
       <button label="Cancel" type="cancel" /> 
       <button label="Deploy" target="deploy" /> 
      </controlbar> 
     </antform> 
    </xsl:template> 

    <xsl:template name="SVN-CALL1"> 
     <xsl:text>Trunk</xsl:text> 
     <xsl:for-each select="/lists/list/entry/name"> 
      <xsl:text>;</xsl:text> 
      <xsl:value-of select="."/> 
     </xsl:for-each> 
    </xsl:template> 

    <xsl:template name="SVN-CALL2"> 
     <!--Similar logic as SVN-CALL1--> 
    </xsl:template> 
    <xsl:template name="SVN-CALL3"> 
     <!--Similar logic as SVN-CALL1--> 
    </xsl:template> 
    <xsl:template name="SVN-CALL4"> 
     <!--Similar logic as SVN-CALL1--> 
    </xsl:template> 
</xsl:stylesheet> 

它創建了一個Ant構建文件與廣大的ANT形式的你描述(應該足以讓你開始):

<?xml version="1.0" encoding="UTF-8"?> 
<project name="enhancedRSS" default="form" basedir="."> 
    <taskdef name="antform" classname="com.sardak.antform.AntForm" 
      classpath="$/lib/antform.jar"/> 
    <target name="form"> 
     <antform title="Example ANTForm generated from XSLT"> 
     <label>Some title label</label> 
     <textProperty label="LABEL" property="label1" required="true" focus="true" 
         tooltip="This is the first label, which will assign the value entered to the ANT property label1"/> 
     <selectionProperty label="Values from SVN-CALL1:" property="svn-call1" separator=";" 
          values="Trunk;archive;milestone 1-0-0;milestone 1-0-0b"/> 
     <selectionProperty label="Values from SVN-CALL2:" property="svn-call2" separator=";" values=""/> 
     <selectionProperty label="Values from SVN-CALL3:" property="svn-call3" separator=";" values=""/> 
     <radioSelectionProperty label="Release core files: " property="release" values="Yes;No" separator=";"/> 
     <selectionProperty label="Which verion of the core:" property="svn-call4" values=""/> 
     <radioSelectionProperty label="Environment: " property="environment" values="Test;Production" 
           separator=";"/> 
     <textProperty label="Password" property="svn.password" required="true" password="true"/> 
     <controlbar> 
      <button label="Cancel" type="cancel"/> 
      <button label="Deploy" target="deploy"/> 
     </controlbar> 
     </antform> 
    </target> 
</project> 

執行時,生成的Ant生成文件和ANT形式產生:

ANT Form

這應該足以讓你開始。 ANTForm usage page告訴你每個ANTForm元素的每個屬性。你還可以做更多的事情來定製(使用你自己的CSS進行皮膚定製,自定義圖標,保存屬性以預先填充下一次運行的表單等)

如果您打算獲得您的四個SVN調用分開的XML文件,那麼您可能需要考慮使用XSLT document()函數來完成您在單個XSLT中需要的功能。