ANT ANTForm XSL - 备忘单

时间:2010-09-02 14:16:16

标签: xslt ant

在另一个问题 - Getting directory listing from SVN for use in ANT dropdown

我问过如何直接将SVN连接到我的ANT脚本。我得到的答案非常好,并遵循从SVN导出目录列表作为XML,然后使用XSL构建表单的行。

我没有使用XSL的经验,所以我想知道是否有人可以给我任何指针?更具体地说,通过XSL在ANTForms中构建表单。他们的网站似乎没有提及使用它的任何内容,我在谷歌上找不到任何东西。

其他信息......

以下是我从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 |文本框
  • SVN CALL1在DROPDOWN中的名字
  • SVN CALL2在DROPDOWN中的名字
  • SVN CALL3在DROPDOWN中的名字
  • YES / NO&lt; - 单选按钮 - 用于发布应用程序框架的核心文件
  • SVN CALL4在DROPDOWN中的名字&lt; - 核心的哪个版本
  • 测试/生产/&gt; &lt; - 单选按钮 - 我们想要发布的环境
  • PASSWORD TEXTFIELD
  • DEPLOY BUTTON
  • CANCEL BUTTON

希望这有意义,但我需要做的是进行x4 SVN调用,每个存储库保存一个项目文件(主项目文件,相关组件,插件和核心),并使用ANTForm填充这些下拉列表selectionProperty(http://antforms.sourceforge.net/usageaf.html)。

除此之外我还需要做更多的工作(比如在每个下拉列表的开头添加“Trunk”),但是我一次只需要一步。

1 个答案:

答案 0 :(得分:3)

我过去使用的一个策略是让ANT脚本生成另一个ANT构建文件,然后在运行中执行该动态生成的ANT构建文件:

  1. 调用进程(以获取SVN信息)
  2. 调用XSLT动态生成另一个ANT构建文件(使用动态构造的ANTForm)
  3. 调用动态生成的ANT构建文件(使用antcall,ant等)
  4. 这样的样式表可以用作生成动态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中所需的内容。