在另一个问题中 - Getting directory listing from SVN for use in ANT dropdown
我询问如何将 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>
我所需要的只是名称节点,这样我就可以构建以下结构的形式 -
- 一些标题标签
- 标签|文本字段
- SVN 在下拉菜单中调用 1 个名称
- SVN 在下拉菜单中调用 2 个姓名
- SVN 在下拉菜单中调用 3 个名称
- 是/否<- 单选按钮 - 用于发布我们的应用程序框架的核心文件
- SVN 在下拉列表中调用 4 个名称 <- 哪个版本的核心
- 测试/生产/> <- 单选按钮 - 我们想要发布到的环境
- 密码文本字段
- 部署按钮
- 取消按钮
希望这是有道理的,但我需要做的是进行 x4 SVN 调用,每个存储库保存我们的项目文件(主项目文件、相关组件、插件和核心),并使用 ANTForm 的 SelectionProperty 填充这些下拉列表(http://antforms.sourceforge.net/usageaf.html)。
除此之外,我还需要做更多事情(例如将“Trunk”附加到每个下拉列表的开头),但一次一步到位。
最佳答案
我过去使用的一个策略是让 ANT 脚本生成另一个 ANT 构建文件,然后在运行中执行动态生成的 ANT 构建文件:
- 调用进程(获取 SVN 信息)
- 调用 XSLT 动态生成另一个 ANT 构建文件(使用动态构建的 ANTForm)
- 调用动态生成的 ANT 构建文件(使用 antcall、ant 等)
这样的样式表可以用作生成动态 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 表单会产生:
这应该足以让您开始。 ANTForm usage page告诉您每个 ANTForm 元素的每个属性是什么。您还可以进行更多自定义操作(使用您自己的 CSS、自定义图标、保存属性以在下次运行时预填充表单等)
如果您要将四个 SVN 调用的结果保存在单独的 XML 文件中,那么您可能需要考虑使用 XSLT document()
函数来在单个文件中完成您需要的操作XSLT。
关于xslt - ANT ANTForm XSL - 备忘单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3627983/