<?xml version="1.0" encoding="UTF-8"?>

<project name="pant"  basedir="." default="pant">
    <description>
        PAnt examples
    </description>    
    
    <property name="lib.dir" value="${basedir}/../lib" />

    <property name="jython.version" value="2.5" />
    <property name="jython.home" value="${lib.dir}/jython-${jython.version}" />

    <path id="lib.classpath">
        <!-- next 2 lines are only needed for PAnt development -->
        <pathelement location="../classes"/>
        <pathelement path="../pant.jar"/>
        <!-- jython.jar could also be added to ANT_HOME/lib -->
        <pathelement path="${jython.home}/jython.jar"/>
    </path>

    <!-- Use loaderref to so that the classloader remains the same. 
    This will help avoid classcast exceptions -->
    <taskdef resource="com/myarch/antjython/jython-antlib.xml"
        loaderref="lib.classpath.loader" 
        classpathref="lib.classpath" />

    <!--
    PythonHome/Lib or pythonHome itself is automatically added to the classpath
    python.cache.dir is set to ${java.io.tmpdir}/jython
    -->
    <jythonInit pythonHome="${jython.home}" >
        <pythonPath >
            <pathelement location="${basedir}"/>
        </pythonPath>
    </jythonInit>

    <!-- Invoke Jython code to create targets programmatically.
    Note: this has to be done outside of any Ant target 
    This script creates several targets -->
    <jython import="from pant_examples import *" exec="create_targets()"  />
    
    <!-- With Jython 2.5 you can use 'pimport' task and decorators -->
    <pimport module="python_ant_project" />

    <target name="init" />

    <target name="pant.tasks" description="Exampes of running Ant tasks from python" >

        <!-- Properties are available to python-->
        <property name="prop1" value="val1" />
        <!-- Simple usage of PAnt -->
        <jython>
print "Simple Jython script" 
# echo property. "ant" variable is defined by jython task
ant.echo("Echo from python: ${prop1}")
# we can also use properties directly in python as variables
print "Property from ant: "+ prop1
# We can define a variable that we can use in other scripts
s="test"
        </jython>

        <jython>
print "Var created earlier: ",s
        </jython>

        <!-- for any more or less complex logic, python code should be in 
        its own module -->
        <jython import="from pant_examples import *" exec="pant_task_examples()"  />

        <!-- You can also run a file directly as a script -->
        <jython execfile="${basedir}/pant_examples.py" />
    </target>

    <!-- target1, target2, target3 are defined in python -->
    <target name="pant" depends="pant.tasks, target1, target2, target3" />

    <!-- Call targets defined using decorator in python_ant_project -->
    <target name="ant.project" depends="p.target3" />
        

</project>
