There are a few methods of using Ant with Xindice;

XindiceDeploymentTask

by jim.fuller@ruminate.co.uk

Fortunately Xindice ships with its own Ant task called DeploymentTask. To use it in your ant build scripts you will first need to declare a TaskDef statement.

1) place the following before your target definitions

  <taskdef name="xindice" classname="org.apache.xindice.tools.DeploymentTask"/>

2) here are some examples of using the Ant task

export

<xindice home="E:\java\xindice" Collection="xmldb:xindice://127.0.0.1:8080/db/log/" 
Activity="export" Path="c:\test\"/>

import

<xindice home="E:\java\xindice" Collection="xmldb:xindice://127.0.0.1:8080/db/somecollection/" 
Activity="import" Path="c:\test\"/>

Check out the commands.xml file contained in /config directory, which lists all the available commands for this task.

Here is an example ant build.xml file which uses the useful Macrodef task to create xindice tasks.

<?xml version="1.0"?>
<project name="test xindice deployment task" default="test" basedir=".">
<description>
    Illustrate how to use xindice DeploymentTask.
</description>

<taskdef name="xindicedeploy" classname="org.apache.xindice.tools.DeploymentTask"/>

<!-- xindice properties //-->
<property name="xindice.collection" value="xmldb:xindice://127.0.0.1:8080/db"/>
<property name="xindice.home" location="E:\java\xindice"/>      
<property name="xindice.path" location="c:\test\log"/>  
<property name="xindice.document_dir" location="c:\\doctest\\"/>        
        
<macrodef name="xindice-add-collection">
<attribute name="name"/>
<sequential>
<xindicedeploy Home="${xindice.home}" Name="@{name}" Collection="${xindice.collection}" Activity="add_collection" Path="${xindice.path}"/>
</sequential>
</macrodef>

<macrodef name="xindice-remove-collection">
<attribute name="name"/>
<sequential>
<xindicedeploy Home="${xindice.home}" Name="@{name}" Collection="${xindice.collection}" Activity="delete_collection" Path="${xindice.path}"/>
</sequential>
</macrodef>

<macrodef name="xindice-add-document">
<attribute name="name"/>
<sequential>
<xindicedeploy Home="${xindice.home}" Name="@{name}" Collection="${xindice.collection}" Activity="add_document" Path="${xindice.document_dir}"/>
</sequential>
</macrodef>

<target name="test">

<xindice-add-collection name="test"/>

<xindice-add-document name="test.xml"/>

<xindice-remove-collection name="test"/>

</target>

</project>

Xindice Ant Task v.1alpha

jim.fuller@ruminate.co.uk

Add and remove Xindice documents and collections. This version is an alpha prototype written within an hour to get an understanding of Xindice, it works... but use at your own risk !

Download from http://www.ruminate.co.uk/samples/xindiceanttask.zip

usage:

1) add com.example.XindiceAntTask using taskdef to make it available to Ant

<taskdef classpath="${java.class.path}" name="xindice" classname="com.example.XindiceAntTask" />

There is no reason you need to keep the namespace, all classes are in com.example....possibly with a better version this Xindice Task may find itself within Xindice or Ant optional.

2) The following target is an example of the syntax used when adding and removing documents and collections

    <target name="test-xindice-ant-task" description="test XindiceAntTask">

            <taskdef classpath="${java.class.path}" name="xindice" classname="com.epinx.xindice.XindiceAntTask"/>

            <xindice action="add-collection" name="test collection" host="127.0.0.1" port="8080" url="/xindice/db" collection="/db/pims">
            <metadata>a</metadata>
            </xindice>
        
            <xindice action="add-document" name="test" host="127.0.0.1" port="8080" url="/xindice/db" collection="/db/pims">
            <metadata>b</metadata>
            </xindice>

            <xindice action="remove-document" name="test" host="127.0.0.1" port="8080" url="/xindice/db" collection="/db/pims">
            <metadata>c</metadata>
            </xindice>
                    
            <xindice action="remove-collection" name="test collection" host="127.0.0.1" port="8080" url="/xindice/db" collection="/db/pims">
            <metadata><a>asdfasdf</a></metadata>
            </xindice>

    </target>

Feel free to take this code and make better, but please post back to either here or the Xindice list.

todo:

* create commercial quality java code...at the moment its an alpha scratched up in an afternoon

* comment code

* add fileset capability when adding or removing documents from repository

* create meta data definition, as encapsulated within xindice element

* add retrieve-document function

* add BASIC/DIGEST authentication with username/password attributes

AntXindice (last edited 2009-09-20 23:23:41 by localhost)