<?xml version="1.0" encoding="UTF-8"?>
<project name="template" default="none">
    <!--
         WARNING!!!

         This file is maintained automatically by Bndtools! You should not edit it directly.
         Instead, insert overrides into build.xml as follows:

         <target name="compile" depends="template.init">
            <echo message="This task executed before compilation..."/>
            <antcall target="template.compile"/>
            <echo message="This task executed after compilation."/>
         </target>
    -->


    <!--
         Default Target
    -->
    <target name="none">
        <fail message="This ant script should never be called directly." />
    </target>


    <!--
         INIT

         All other targets depend on init.
         It's purpose is to set up the environment only once and avoid it being repeated for each antcall.
    -->
    <target name="init" unless="initialized">
        <!-- Initialise some basic properties -->
        <tstamp>
            <format property="NOW" pattern="yyyyMMdd-HHmmss" timezone="UTC"/>
        </tstamp>
        <dirname property="projectdir" file="${ant.file}" />
        <dirname property="workspacedir" file="${projectdir}" />

        <!-- Define the classpath of bnd (location is defined in build.ant.properties) -->
        <property file="${workspacedir}/cnf/build.ant.properties"/>
        <path id="bnd-classpath" location="${workspacedir}/${bnd.location}" />

        <!-- Load bnd and prepare the workspace -->
        <taskdef resource="aQute/bnd/ant/taskdef.properties" classpathref="bnd-classpath" />
        <bndprepare basedir="${projectdir}" print="false" top="${release.dir}" />

        <fileset dir="${project}" id="srcjavafiles">
            <include name="${src}/**/*.java"/>
        </fileset>
        <pathconvert refid="srcjavafiles" property="srcjavafiles.present" setonempty="false"/>

        <fileset dir="${project}" id="testjavafiles">
            <include name="${testsrc}/**/*.java"/>
        </fileset>
        <pathconvert refid="testjavafiles" property="testjavafiles.present" setonempty="false"/>

        <!-- Create a marker property to indicate that initialisation has been completed -->
        <property name="initialized" value="set" />
        <echo message="Enter project ${project.name}"/>
    </target>


    <!--
        DEPENDENCIES

        Build project dependencies.
    -->
    <target name="dependencies" depends="init" if="project.dependson" unless="donotrecurse">
        <subant target="build" inheritAll="false" buildpath="${project.dependson}">
            <property name="donotrecurse" value="true" />
        </subant>
    </target>


    <!--
         COMPILE

         Compile the sources.
    -->
    <target name="compile" depends="dependencies" if="srcjavafiles.present">
        <mkdir dir="${bin}"/>
        <javac fork="yes" executable="${javac}" srcdir="${src}" destdir="${bin}" classpath="${project.buildpath}" bootclasspath="${project.bootclasspath}" deprecation="true" listfiles="true" target="${javac.target}" source="${javac.source}" debug="${javac.debug}" includeAntRuntime="no" verbose="${verbose}" />
        <!--
          The eclipse compiler copies resources but the Javac compiler does not
          If ${src} == ${bin} then this is not necessary, but unfortunately, now
          it is.
        -->
        <copy todir="${bin}" verbose="${verbose}" preservelastmodified="true">
            <fileset dir="${src}">
                <exclude name="**/*.java" />
                <exclude name="**/*.class" />
            </fileset>
        </copy>
    </target>


    <!--
        BUILD

        Build the project after building its dependencies.
    -->
    <target name="build" depends="compile">
        <mkdir dir="${target}"/>
        <bnd command="build" exceptions="true" basedir="${project}" />
    </target>


    <!--
        JUNIT

        Run the junit test if present and no disabled by the no.junit property.
    -->
    <target name="compileTests" depends="init,build" if="testjavafiles.present" unless="no.junit">
        <mkdir dir="${testbin}"/>
        <javac fork="yes" executable="${javac}" srcdir="${testsrc}" destdir="${testbin}" classpath="${project.buildpath}:${project.testpath}" bootclasspath="${project.bootclasspath}" deprecation="true" listfiles="true" target="${javac.target}" source="${javac.source}" debug="${javac.debug}" includeAntRuntime="no" verbose="${verbose}" />
        <!--
          The eclipse compiler copies resources but the Javac compiler does not
          If ${src} == ${bin} then this is not necessary, but unfortunately, now
          it is.
        -->
        <copy todir="${testbin}" verbose="${verbose}" preservelastmodified="true">
            <fileset dir="${testsrc}">
                <exclude name="**/*.java" />
                <exclude name="**/*.class" />
            </fileset>
        </copy>
    </target>

    <target name="junit" depends="init,compileTests" if="testjavafiles.present" unless="no.junit">
        <junit showoutput="false" printsummary="true" failureproperty='stop' errorproperty='stop' fork="true" dir="${basedir}">
            <assertions>
                <enable />
            </assertions>
            <classpath path="${project.buildpath}:${testbin}/" />
            <formatter type="xml"/>
            <batchtest todir="${target}">
                <fileset dir="${testsrc}">
                    <include name="**/*.java"/>
                </fileset>
            </batchtest>
        </junit>
    </target>


    <!--
         TEST
    -->
    <target name="test" depends="compile">
        <bndtest/>
    </target>


    <!--
        RELEASE

        Run the bnd release task on the project and its dependencies.
    -->
    <target name="_release" depends="init">
        <bndrelease/>
    </target>

    <target name="release" depends="build">
        <subant target="_release" inheritAll="false" buildpath="${project.dependson}">
            <property name="donotrecurse" value="true" />
        </subant>
    </target>


    <!--
         CLEAN

         Clean up the project.
    -->
    <target name="clean" depends="init">
        <bnd command="clean" exceptions="true" basedir="${project}" />
    </target>

    <target name="deepclean" depends="init,clean" if="project.dependson">
        <subant target="clean" inheritAll="false" buildpath="${project.dependson}" />
    </target>


    <!--
         JAVADOC

         Generate javadoc
    -->
    <target name="javadoc" depends="init,build" if="srcjavafiles.present">
        <javadoc
            sourcepath="${src}"
            destdir="${target}/javadoc"
            maxmemory="256M"
            classpath="${project.buildpath}"
            bootclasspath="${project.bootclasspath}"
            access="private"
            version="true"
            use="true"
            author="true"
            splitindex="true"
            windowtitle="${project.name}"
            doctitle="${project.name}"
            nodeprecated="false"
            nodeprecatedlist="false"
            notree="false"
            noindex="false"
            nohelp="false"
            nonavbar="false"
            source="${javac.source}"
        />
    </target>


    <!--
         ECHO

         Print some settings
    -->
    <target name="echo" depends="init">
        <echo>verbose:                ${verbose}</echo>
        <echo>project.name:           ${project.name}</echo>
        <echo>Bundle-Version:         ${Bundle-Version}</echo>
        <echo>src:                    ${src}</echo>
        <echo>bin:                    ${bin}</echo>
        <echo>testsrc:                ${testsrc}</echo>
        <echo>testbin:                ${testbin}</echo>
        <echo>project.output:         ${project.output}</echo>
        <echo>project.sourcepath:     ${project.sourcepath}</echo>
        <echo>project.allsourcepath:  ${project.allsourcepath}</echo>
        <echo>project.buildpath:      ${project.buildpath}</echo>
        <echo>project.testpath:       ${project.testpath}</echo>
        <echo>project.dependson:      ${project.dependson}</echo>
        <echo>project.bootclasspath:  ${project.bootclasspath}</echo>
        <echo>javac:                  ${javac}</echo>
        <echo>javac.debug:            ${javac.debug}</echo>
        <echo>javac.source:           ${javac.source}</echo>
        <echo>javac.target:           ${javac.target}</echo>
        <echo>p:                      ${p}</echo>
        <echo>btool.manifestVersion:  ${btool.manifestVersion}</echo>
        <echo>btool.analyse:          ${btool.analyse}</echo>
        <echo>btool.showmanifest:     ${btool.showmanifest}</echo>
        <echo>btool.noversion:        ${btool.noversion}</echo>
        <echo>btool.sources:          ${btool.sources}</echo>
        <echo>btool.noextraheaders:   ${btool.noextraheaders}</echo>
        <echo>jars.compile.order:     ${jars.compile.order}</echo>
        <echo>bin.includes:           ${bin.includes}</echo>
        <echo>base.modfied:           ${base.modified} (${base.modified.readable})</echo>
        <echo>build:                  ${build}</echo>
        <echo>target:                 ${target}</echo>
        <echo>release.target:         ${release.target}</echo>
        <echo>releaserepo:            ${releaserepo}</echo>
        <echo>licensed repo:          ${licensed-repo}</echo>
        <echo>repo:                   ${repo}</echo>
        <echo>use.bnd:                ${use.bnd}</echo>
        <echo>nodeploy:               ${nodeploy}</echo>
        <echo>-dependson:             ${-dependson}</echo>
    </target>
</project>
