tags:

views:

106

answers:

1

Hi folks,

In another question - http://stackoverflow.com/questions/3530181/getting-directory-listing-from-svn-for-use-in-ant-dropdown/3546043#3546043

I asked about how I can connect SVN up to my ANT scripts directly. The answer I got was really good and follows the lines of exporting a directory listing from SVN as XML and then using XSL to build the form.

I've no experience with XSL so I was wondering if anyone who has might be able to give me any pointers? More specifically with building forms in ANTForms through XSL. Their website doesn't seem to mention anything about using it and I can't find anything on Google.

Any help is appreciated.

Cheers, James

Additional Info...

Here's a small sample of the XML I'm getting back from SVN.

<?xml version="1.0"?>
<lists>
<list path="https://mydomain.com/svn/website/tags"&gt;
    <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>

All I'm needing from this is the name nodes so I can build a form of the following structure -

  • SOME TITLE LABEL
  • LABEL | TEXTFIELD
  • SVN CALL1 NAMES IN A DROPDOWN
  • SVN CALL2 NAMES IN A DROPDOWN
  • SVN CALL3 NAMES IN A DROPDOWN
  • YES / NO <- Radio button - For releasing the core files of our applications framework
  • SVN CALL4 NAMES IN A DROPDOWN <- Which version of the core
  • Test / Production /> <- Radio Button - the environment we're wanting to release to
  • PASSWORD TEXTFIELD
  • DEPLOY BUTTON
  • CANCEL BUTTON

Hope that makes sense but what I'm needing to do is make x4 SVN calls, one for each repository which holds our projects files ( the main project files, associated components, plugins & core ) and populate these dropdowns using ANTForm's selectionProperty (http://antforms.sourceforge.net/usageaf.html).

There is more I need to do beyond that (like append "Trunk" to the start of each dropdown) but one step at a I time.

Thanks again, James

A: 

One strategy that I have used in the past is to have an ANT script generate another ANT build file and then execute that dynamically generated ANT build file in the run:

  1. invoke a process(to fetch SVN info)
  2. invoke an XSLT to dynamically produce another ANT build file(with a dynamically constructed ANTForm)
  3. invoke the dynamically generated ANT build file (using antcall, ant, etc)

A stylesheet like this could be used as a starting point to generate the dynamic ANT build file that invokes the dynamically generated ANT Form:

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

It creates this ANT build file with the majority of the ANT Form that you described (should be enough to get you started):

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

When executed, the generated ANT build file and ANT Form produce:

ANT Form

This should be enough to get you started. The ANTForm usage page tells you what each of the attributes are for each of the ANTForm elements. There is also a lot more that you can do to customize(skin it with your own CSS, custom icons, save properties to pre-populate the form on next run, etc)

If you are going to have the results of your four SVN calls in separate XML files, then you may need to look into using the XSLT document() function to accomplish what you need in a single XSLT.

Mads Hansen