views:

133

answers:

2

Hi ANT experts :-)

I've done some Googling on this but I can't seem to find anything along the lines of what I'm needing.

I'm using ANTForms for the GUI on our deployment. Developers can choose the build from the dynamically populated dropdown, hit ok and away it goes.

The way the dropdown is dynamically populated at the moment is by ANT making an HTTP webservice call to our ColdFusion server giving it a list of needed SVN directories. CF then uses a bit of underlining Java to call SVNKit and return a query result for CF to process. It converts this to a comma-separated list, outputs it for ANT and it then builds these dropdowns options.

I'm using CF because that's our main language. I don't really know any Java but what's bugging me a bit here is if I did I know I could get ANT to talk to Java / SVNKit directly and therefore cut CF out the picture completely. It would probably also remove the need for the HTTP call as the SVN setup is local so a speed increase is there + it takes out the reliance on a external source.

Has anyone done this or do you know any working examples I could see that show ANT talking to SVNKit directly to do this kind of thing?

I had a look at the usual SVN ANT tasks over at Subclipse but they don't have any way of doing this.

Any help appreciated, James

+1  A: 

Rather than trying to build something in Java why not generate your ANTForm configuration file using XLST, based on the XML output produced by the standard subversion client:

svn list --xml http://svn.apache.org/repos/asf/ant/ivy/core/tags > releases.xml

Produces the following releases.xml file (I've edited it for clarity):

<?xml version="1.0"?>
<lists>
  <list path="http://svn.apache.org/repos/asf/ant/ivy/core/tags"&gt;
    <entry ..>
      <name>1.4.1</name>
      ..
    </entry>
    <entry ..>
      <name>2.0.0</name>
      ..
    </entry>
  </list>
</lists>

Example

Example is comprised of two files

  • genGUI.xml
  • genGUI.xsl

Run as follows:

ant -f genGUI.xml

genGUI.xml

<project name="genGUI" default="run">

    <property name="repo.url"  value="http://svn.apache.org/repos/asf/ant/ivy/core/tags"/&gt;
    <property name="build.dir" location="build"/>
    <property name="xsl.file"  location="genGUI.xsl"/>
    <property name="data.file" location="${build.dir}/data.xml"/>
    <property name="run.file"  location="${build.dir}/run.xml"/>

    <target name="init">
        <mkdir dir="${build.dir}"/>
    </target>

    <target name="get-data" depends="init">
        <exec executable="svn" failonerror="true" output="${data.file}">
            <arg line="list --xml ${repo.url}"/>
        </exec>
    </target>

    <target name="generate" depends="get-data">
        <xslt style="${xsl.file}" in="${data.file}" out="${run.file}"/>
    </target>

    <target name="run" depends="generate">
        <ant antfile="${run.file}"/>
    </target>

    <target name="clean">
        <delete dir="${build.dir}"/>
    </target>

</project>

genGUI.xsl

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

    <xsl:output method="xml" indent="yes"/>

    <xsl:variable name="antform-home">${env.ANTFORM_HOME}</xsl:variable>

    <xsl:template match="/">
        <project name="genForm" default="menu">

            <property environment="env"/>

            <path id="runtime.cp">
                <pathelement location="{$antform-home}/lib/antform.jar"/>
            </path>

            <target name="menu">
                <taskdef name="antmenu" classname="com.sardak.antform.AntMenu" classpathref="runtime.cp"/>

                <antmenu image="{$antform-home}/doc/images/logo-small.jpg" title="My simple form" stylesheet="{$antform-home}/style.test">
                    <label>Form is generated from subversion</label>
                    <xsl:apply-templates select="lists/list/entry"/>
                </antmenu>
            </target>

        </project>
    </xsl:template>

    <xsl:template match="entry">
        <button label="{name}" target="{name}"/>
    </xsl:template>

</xsl:stylesheet>
Mark O'Connor
A: 

Oh I like that solution :-), thanks a lot Mark.

I don't know anything about XSLT but now seems like a good a time as any to learn.

I'll give it a go.

Cheers, James

James Buckingham
Don't forget to accept the answer if you're happy with it :-)
Mark O'Connor