<?xml version="1.0" encoding="utf-8"?>
<!-- you may freely edit this file. see commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (if you delete it and reopen the project it will be recreated.) -->

<project name="jprt" default="default" basedir=".">
    <description>Builds, tests, and runs the project jprt.</description>
    
    <import file="nbproject/build-impl.xml"/>
    
    <import file="nbproject/profiler-build-impl.xml"/>    
    
    <!--

    There exist several targets which are by default empty and which can be 
    used for execution of your tasks. These targets are usually executed 
    before and after some main targets. They are: 

      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-single:       called before javac compilation of single file
      -post-compile-single:      called after javac compilation of single file
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-compile-test-single:  called before javac compilation of single JUnit test
      -post-compile-test-single: called after javac compilation of single JUunit test
      -pre-jar:                  called before JAR building
      -post-jar:                 called after JAR building
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting an obfuscator after compilation could look like this:

        <target name="-post-compile">
            <obfuscate>
                <fileset dir="${build.classes.dir}"/>
            </obfuscate>
        </target>

    For list of available properties check the imported 
    nbproject/build-impl.xml file. 


    Another way to customize the build is by overriding existing main targets.
    The targets of interest are: 

      -init-macrodef-javac:     defines macro for javac compilation
      -init-macrodef-junit:     defines macro for junit execution
      -init-macrodef-debug:     defines macro for class debugging
      -init-macrodef-java:      defines macro for class execution
      -do-jar-with-manifest:    JAR building (if you are using a manifest)
      -do-jar-without-manifest: JAR building (if you are not using a manifest)
      run:                      execution of project 
      -javadoc-build:           Javadoc generation
      test-report:              JUnit report generation

    An example of overriding the target for project execution could look like this:

        <target name="run" depends="jprt-impl.jar">
            <exec dir="bin" executable="launcher.exe">
                <arg file="${dist.jar}"/>
            </exec>
        </target>

    Notice that the overridden target depends on the jar target and not only on 
    the compile target as the regular run target does. Again, for a list of available 
    properties which you can use, check the target you are overriding in the
    nbproject/build-impl.xml file. 

    -->
   
    <!-- project name (determines jar and script name) -->
    <property name="project.name"           value="jprt"/>
    
    <!-- top level package name -->
    <property name="package.name"           value="jprt"/>
    
    <!-- top level paths -->
    <property name="src.dir"                value="src"/>
    <property name="test.src.dir"           value="test"/>
    <property name="lib.dir"                value="lib"/>
    
    <!-- source paths -->
    <property name="bin.src"                value="${src.dir}/bin"/>
    <property name="sbin.src"               value="${src.dir}/sbin"/>
    <property name="doc.files.src"          value="${src.dir}/${package.name}/doc-files"/>
    
    <!-- build paths -->
    <property name="build.dir"              value="build"/>
    <property name="manifest.file"          value="${build.dir}/mainfest.mf"/>
    <property name="build.classes.dir"      value="${build.dir}/classes"/>
    <property name="build.test.classes.dir" value="${build.dir}/test/classes"/>
    
    <!-- dist paths -->
    <property name="dist.dir"               value="dist"/>
    <property name="bin.dir"                value="${dist.dir}/bin"/>
    <property name="sbin.dir"               value="${dist.dir}/sbin"/>
    <property name="dist.jar"               value="${dist.dir}/${project.name}.jar"/>
    
    <!-- path to test scripts  -->
    <property name="test.script"            value="${test.src.dir}/test.sh"/>
    <property name="test.system.script"     value="${test.src.dir}/test_system.sh"/>
    
    <!-- javadoc paths -->
    <property name="dist.javadoc.dir"       value="${dist.dir}/javadoc"/>
    <property name="doc.files"              value="${dist.javadoc.dir}/${package.name}/doc-files"/>
    
    <!-- classpath settings -->
    <property name="javac.classpath"        value=""/>
    <property name="run.classpath"          value="${build.classes.dir}"/>
    <property name="javac.test.classpath"   value="${build.classes.dir}:${lib.dir}/junit.jar"/>
    <property name="run.test.classpath"     value="${build.test.classes.dir}:${javac.test.classpath}"/>
    
    <!-- default system options -->
    <condition property="system.instance" value="testsystem-ant">
        <not> <isset property="system.instance"/> </not>
    </condition>
    
    <!-- always provide debugging information -->
    <property name="javac.debug"            value="true"/>
    
    <!-- the main class for the project -->
    <property name="main.class"             value="${package.name}.tools.Main"/>
    
    <!-- make sure netbeans knows we have a manifest file -->
    <property name="manifest.available"     value="true"/>
    
    <!-- hooks into netbeans ant files -->
    <target name="-pre-compile"             depends="mycompilestart"/>
    <target name="-post-compile"            depends="mycompileend"/>
    <target name="-do-jar-with-manifest"    depends="mymanifest"/>
    <target name="-pre-jar"                 depends="myjarstart,mymanifest"/>
    <target name="-post-jar"                depends="myjarend,mybinfiles,mysbinfiles,mypropfiles,myjartests"/>
    <target name="javadoc"                  depends="myjavadoc"/>
    
    <!-- just used to add messages at certain points -->
    <target name="mycompilestart"> <echo message="COMPILING"/>           </target>
    <target name="mycompileend">   <echo message="COMPILING COMPLETED"/> </target>
    <target name="myjarstart">     <echo message="BUILDING JAR"/>        </target>
    <target name="myjarend">       <echo message="JAR COMPLETED"/>       </target>
    
    <!-- create my own manifest file -->
    <target name="mymanifest" description="Create manifest file">
        <echo message="Creating manifest file: ${manifest.file}"/>
        <manifest file="${manifest.file}">
            <attribute name="Built-By"   value="${user.name}"/>
            <attribute name="Main-Class" value="${main.class}"/>
        </manifest>
    </target>
    
    <!-- copy the bin files -->
    <target name="mybinfiles" description="Create bin files">
        <echo message="Populating bin files"/>
        <mkdir dir="${bin.dir}"/>
        <copy todir="${bin.dir}">
            <fileset dir="${bin.src}" casesensitive="yes">
                <include name="*"/>
            </fileset>
        </copy>
        <chmod dir="${bin.dir}" perm="ugo+rx" includes="*"/>
    </target>
    
    <!-- copy the sbin files -->
    <target name="mysbinfiles" description="Create sbin files">
        <echo message="Populating sbin files"/>
        <mkdir dir="${sbin.dir}"/>
        <copy todir="${sbin.dir}">
            <fileset dir="${sbin.src}" casesensitive="yes">
                <include name="*"/>
            </fileset>
        </copy>
        <chmod dir="${sbin.dir}" perm="ugo+rx" includes="*"/>
    </target>
    
    <!-- copy the property files into the sbin directory -->
    <target name="mypropfiles" description="Create sbin property files">
        <echo message="Populating ${dist.dir} with prop files"/>
        <mkdir dir="${dist.dir}"/>
        <copy todir="${dist.dir}">
            <fileset dir="${src.dir}" casesensitive="yes">
                <include name="*.properties"/>
            </fileset>
        </copy>
        <echo message="System instance: ${system.instance}"/>
        <!-- Ant echo is Broken: <echo file="${dist.dir}/config-default.properties"
              message="jprt.system.instance=${system.instance}"/> -->
        <exec executable="echo" failonerror="true"
              output="${dist.dir}/config-default.properties">
            <arg value="jprt.system.instance=${system.instance}"/>
        </exec>
    </target>
    
    <!-- test the jar file -->
    <target name="myjartests" description="Test jar.">
        <echo message="Testing: java -jar ${dist.jar} "/>
        <java jar="${dist.jar}" fork="true" failonerror="true">
            <assertions> <enable/> </assertions>
        </java>
        <echo message="Testing: java -jar ${dist.jar} help"/>
        <java jar="${dist.jar}" fork="true" failonerror="true">
            <arg value="help"/>
            <assertions> <enable/> </assertions>
        </java>
        <echo message="Testing: java -jar ${dist.jar} usage"/>
        <java jar="${dist.jar}" fork="true" failonerror="true">
            <arg value="usage"/>
            <assertions> <enable/> </assertions>
        </java>
        <echo message="Testing: java -jar ${dist.jar} version"/>
        <java jar="${dist.jar}" fork="true" failonerror="true">
            <arg value="version"/>
            <assertions> <enable/> </assertions>
        </java>
        <echo message="TESTING JAR COMPLETED."/>
    </target>
    
    <!-- test the bin script -->
    <target name="mybintests" description="Test bin.">
        <chmod file="${test.script}" perm="ugo+rx"/>
        <echo message="Testing: sh -c ${test.script} ${dist.dir}"/>
        <exec executable="sh" failonerror="true">
            <arg value="-c"/>
            <arg value="${test.script} ${dist.dir}"/>
        </exec>
        <echo message="TESTING BIN SCRIPT COMPLETED."/>
    </target>
    
    <!-- test the system script -->
    <target name="mysystemtest" description="Test system.">
        <chmod file="${test.system.script}" perm="ugo+rx"/>
        <echo message="Testing: sh -c ${test.system.script} ${dist.dir} ."/>
        <exec executable="sh" failonerror="true">
            <arg value="-c"/>
            <arg value="${test.system.script} ${dist.dir} ."/>
        </exec>
        <echo message="TESTING SYSTEM SCRIPT COMPLETED."/>
    </target>
    
    <!-- findbugs target -->
    <target name="findbugs" depends="myfindbugs"
            description="Run findbugs in batch mode"/>
    
    <!-- my target that runs findbugs directly (in separate VM with 512M heap) -->
    <target name="myfindbugs" description="Run findbugs in batch mode">
        <echo message="findbugs -version"/>
        <exec executable="findbugs" failonerror="true">
            <arg value="-version"/>
        </exec>
        <echo message="findbugs -maxHeap 512 -textui -effort:max -low -exitcode ${dist.jar}"/>
        <exec executable="findbugs" failonerror="true">
            <arg value="-maxHeap"/>
            <arg value="512"/>
            <arg value="-textui"/>
            <arg value="-effort:max"/>
            <arg value="-low"/>
            <arg value="-exitcode"/>
            <arg path="${dist.jar}"/>
        </exec>
        <echo message="FINDBUGS COMPLETED."/>
    </target>
    
    <!-- my own javadoc target because doc-files don't seem to get copied over -->
    <target name="myjavadoc" depends="init,-javadoc-build,-javadoc-browse" 
            description="Build Javadoc.">
        <mkdir dir="${doc.files}"/>
        <echo message="Populating doc-files directory: ${doc.files}"/>
        <copy todir="${doc.files}">
            <fileset dir="${doc.files.src}" casesensitive="yes">
                <include name="*"/>
            </fileset>
        </copy>
        <echo message="JAVADOC COMPLETED."/>
    </target>
    
    <!-- all target -->
    <target name="all" depends="jar,test,mybintests,javadoc,findbugs"
            description="Do everything"/>
    
</project>
