<?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.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="TMCSim" default="default" basedir=".">
    <description>Builds, tests, and runs the project TMCSim.</description>
    <import file="nbproject/build-impl.xml"/>
    <property name="workdir" value="../../.."/>
<!--        SYSTEM TEST SECTION      -->
    <target description="CAD Simulator" name="cadsimulator">
    <antcall target="run-single">
       <param name="javac.includes" value="tmcsim/cadsimulator/CADSimulator.java"/>
       <param name="run.class" value="tmcsim/cadsimulator/CADSimulator"/>
    </antcall>
    </target>
    <target description="Visible System Test of CADSimulator"  name="VisibleSystemTest">
    <antcall target="test-single">
       <param name="javac.includes" value="tmcsim/cadsimulator/VisibleSystemTest.java"/>
       <param name="test.includes" value="tmcsim/cadsimulator/VisibleSystemTest.java"/>
    </antcall>
    </target>
    <target description="CAD Simulator - console" name="cadconsole">
        <java jar="deploy/CADserver.jar"
           fork="true">
         <classpath>
           <pathelement location="deploy/CADserver.jar"/>
         </classpath>
       </java>
    </target>
    <target description="CAD Simulator - GUI" name="cadgui">
        <java jar="deploy/CADserver.jar"
           fork="true"><jvmarg value="-version"/>
         <classpath>
           <pathelement location="deploy/CADserver.jar"/>
         </classpath>
       </java>
    </target>
    <target description="Run Paramics Communicator" name="pcomm">
    <antcall target="run-single">
       <param name="javac.includes" value="tmcsim/paramicscommunicator/PComm.java"/>
       <param name="run.class" value="tmcsim/paramicscommunicator/PComm"/>
    </antcall>
    </target>
    <target description="Run Simulation Manager" name="simmgr">
    <antcall target="run-single">
       <param name="javac.includes" value="tmcsim/simulationmanager/SimulationManager.java"/>
       <param name="run.class" value="tmcsim/simulationmanager/SimulationManager"/>
    </antcall>
    </target>
    <target description="Emulate Paramics Modeler" name="emulate">
        <echo file="${workdir}/paramics_status.xml" append="false">
            &lt;Paramics&gt; &lt;Network_Status&gt;WARMING&lt;/Network_Status&gt; &lt;Network_ID&gt;1&lt;/Network_ID&gt; &lt;/Paramics&gt;
        </echo>
        <sleep seconds="5"/>
        <echo file="${workdir}/paramics_status.xml" append="false">
            &lt;Paramics&gt; &lt;Network_Status&gt;LOADED&lt;/Network_Status&gt; &lt;Network_ID&gt;1&lt;/Network_ID&gt; &lt;/Paramics&gt;
        </echo>
    </target>

<!--        STORE SUBVERSION BUILD STRING      -->
<target name="-post-init" description="Sets the buildversion for the current build">
    <exec outputproperty="svna.version" executable="svnversion">
        <arg value="-c" />
        <arg value="${workdir}" />
        <redirector>
            <outputfilterchain>
                <tokenfilter>
                    <replaceregex pattern="^[0-9]*:?" replace="" flags="g"/>
                    <replaceregex pattern="M" replace="" flags="g"/>
                </tokenfilter>
            </outputfilterchain>
        </redirector>
    </exec>
    <propertyfile file="${src.dir}/tmcsim/application.properties">
        <entry key="Application.revision" value="${svna.version}" type="int" operation="="/>
    </propertyfile>
    <echo>Setting SVN version: ${svna.version}</echo>
</target>
<target name="-post-jar" description="Sets the buildversion for the current build">
    <propertyfile file="${src.dir}/tmcsim/application.properties">
        <entry key="Application.buildnumber" value="1" type="int" operation="+"/>
    </propertyfile>
</target>
<!--
                =================
                LOC counter
                =================
-->
<target description="Count Lines of Code in src directory." name="loc">
        <java classname="textui.LOC"
	      classpath="${workdir}/lib/JavaLOC.jar">
               <arg line="-r -d ${workdir}/src"/>
	</java>
</target>
<!--
                =================
                CHECKSTYLE SECTION
                =================
     -->
<target description="Run checkstyle on src directory." name="checkstyle">
<taskdef resource="checkstyletask.properties"
         classpath="${workdir}/lib/customcheckstylechecks.jar;${workdir}/lib/checkstyle-all-4.4.jar"/>
<checkstyle config="${workdir}/lib/jdstyle.xml" failOnViolation="true">
            <!-- Specify includes and excludes -->
            <fileset dir="${workdir}/src/tmcsim" includes="**/*.java"
            />
</checkstyle>
</target>
<!--
                =================
                ZIP for Web-CAT SECTION for CPE 305 assignments
                =================
Create a zip file of source to CADSimulator for submission to Web-CAT grader.
-->
<target name="webcat-zip" depends="jar">

    <zip destfile="${workdir}/webcatsubmit.zip">
        <fileset dir="${workdir}/src/">
                 <include name="tmcsim/cadsimulator/viewer/**/*.java" />
                 <include name="tmcsim/cadsimulator/viewer/model/**/*.java" />
                 <include name="tmcsim/cadsimulator/viewer/actions/**/*.java" />
                 <include name="tmcsim/cadsimulator/videocontrol/**/*.java" />
                 <exclude name="tmcsim/paramics*/**"/>
                 <exclude name="tmcsim/simulationmanager/**"/>
                 <exclude name="tmcsim/cadsimulator/MP3Driver.java"/>
        </fileset>
        <!--
        <fileset dir="${workdir}"  includes="scripts/Cardfile.xml"/>
        -->
        <fileset dir="${workdir}/test/">
                 <include name="tmcsim/cadsimulator/viewer/CADSimulatorViewModelTest.java" />
        </fileset>
    </zip>
</target>
<!--
                =================
                PACKAGE JARS SECTION
                =================
-->
<target description="Build separate jar files for each component of the TMC system."
        name="package-jars" depends="jar">

    <!--         *** Build a jar with everything ***            -->
    <property name="deploy.jar.name" value="TMCSimAll"/>
    <property name="deploy.dir" value="${workdir}/deploy"/>
    <property name="deploy.jar" value="${deploy.dir}/${deploy.jar.name}.jar"/>

    <echo message="Packaging ${application.title} into a single JAR at ${deploy.jar}"/>

    <delete dir="${deploy.dir}"/>
    <mkdir dir="${deploy.dir}"/>
    <tstamp>
        <format property="TODAY" pattern="yyyy.MM.dd HH:mm" />
    </tstamp>
    <jar destfile="${deploy.dir}/temp_final.jar" filesetmanifest="skip">
        <zipgroupfileset dir="dist" includes="*.jar"/>
        <!-- zipgroupfileset dir="dist/lib" includes="*.jar"/ -->
        <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>

        <manifest>
            <attribute name="Main-Class" value="${main.class}"/>
        </manifest>
    </jar>

    <zip destfile="${deploy.jar}">
        <zipfileset src="${deploy.dir}/temp_final.jar"
        excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
    </zip>

    <delete file="${deploy.dir}/temp_final.jar"/>

    <!--                   *** Build CAD Server Only Jar ***         -->
      <jar destfile="${deploy.dir}/CADserver.jar"
       basedir="${build.dir}/classes"
       includes="tmcsim/cadsimulator/**, tmcsim/common/**, tmcsim/interfaces/**,
                 tmcsim/client/cadclientgui/**, tmcsim/cadmodels/**,
                 tmcsim/application.properties"
       excludes="**/Test.class">
        <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="tmcsim.cadsimulator.CADSimulator"/>
        </manifest>
      </jar>

      <!--                   *** Build Sim Manager Only Jar ***         -->
      <jar destfile="${deploy.dir}/SimManager.jar"
       basedir="${build.dir}/classes"
       includes="tmcsim/simulationmanager/**, tmcsim/common/**, tmcsim/cadmodels/**,
            tmcsim/client/cadclientgui/**, tmcsim/interfaces/**"
       excludes="**/Test.class">
        <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="tmcsim.simulationmanager.SimulationManager"/>
        </manifest>
      </jar>

      <!--                   *** Build CAD Client Only Jar ***         -->
      <jar destfile="${deploy.dir}/CADClient.jar"
       basedir="${build.dir}/classes"
       includes="tmcsim/client/**, tmcsim/common/**, tmcsim/interfaces/**,
            tmcsim/cadmodels/**, tmcsim/simulationmanager/model/LogEntryCellRenderer.class">
      <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="tmcsim.client.CADClient"/>
            <attribute name="Implementation-Version" value="${TODAY}"/>
        </manifest>
      </jar>
      <!-- Remove the following line when we get CADClient to run
      <delete file="${deploy.dir}/CADClient.jar"/>-->

      <!--                   *** Build Clock Client Only Jar ***         -->
      <jar destfile="${deploy.dir}/ClockClient.jar"
       basedir="${build.dir}/classes"
       includes="tmcsim/client/ClockClient*.class, tmcsim/client/ClockView.class,
        tmcsim/interfaces/**, tmcsim/cadmodels/**, tmcsim/common/**, tmcsim/client/**">
      <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="tmcsim.client.ClockClient"/>
            <attribute name="Implementation-Version" value="${TODAY}"/>
        </manifest>
      </jar>

      <!--                   *** Build Paramics Communicator Only Jar ***         -->
      <jar destfile="${deploy.dir}/ParamicsCommunicator.jar"
       basedir="${build.dir}/classes"
       includes="tmcsim/paramicscommunicator/**, tmcsim/common/**, tmcsim/interfaces/**,
                 tmcsim/client/cadclientgui/**, tmcsim/cadmodels/**, tmcsim/paramicslog/**"
       excludes="**/Test.class">
        <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="tmcsim.paramicscommunicator.ParamicsCommunicator"/>
        </manifest>
      </jar>
</target>

<target description="Build separate jar files for each component of the TMC system."
        name="ZipForInstall" depends="package-jars">
    <!-- Notes:    Create a zip file with jars and all external resources for distributing
    to other machines.
    Zip the Jar files.
    Zip folders for config, images, audio, scripts.
    Write .bat files and .bash files to launch each app.  Put these in root folder.
    Zip it all up!
    -->
</target>

    <!--

    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="TMCSim-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>
