<?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="../../.."/>
    <property name="config.dir" value="../../../config"/>
<!--        SYSTEM TEST SECTION      -->
    <target description="CAD Server" name="cadserver">
    <antcall target="run-single">
       <param name="javac.includes" value="tmcsim/cadsimulator/CADServer.java"/>
       <param name="run.class" value="tmcsim/cadsimulator/CADServer"/>
    </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 Server - console" name="cadconsole">
        <java jar="deploy/CADserver.jar"
           fork="true">
         <classpath>
           <pathelement location="deploy/CADserver.jar"/>
         </classpath>
       </java>
    </target>
    <target description="CAD Server - 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 file="${config.dir}/application_properties.cfg" append="false">
[Versions]
revision_number = ${svna.version}
    </echo>
    <!-- Write the version number to a javascript file -->
    <echo file="${work.dir}/webapps/common/js/revision_number.dat" append="false">
    var revisionNumber = "${svna.version}";
    </echo>
    <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} components into Jar files in deploy folder."/>

    <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_r${svna.version}.jar"
       basedir="${build.dir}/classes"
       includes="tmcsim/cadsimulator/**, tmcsim/common/**, tmcsim/interfaces/**,
                 tmcsim/client/cadclientgui/**, tmcsim/cadmodels/**, atmsdriver/model/**,
                 tmcsim/highwaymodel/**, tmcsim/application.properties"
       excludes="**/Test.class">
        <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar,jaco-mp3-player-0.9.3.jar"/>
        <manifest>
            <attribute name="Main-Class" value="tmcsim.cadsimulator.CADServer"/>
        </manifest>
      </jar>

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

      <!--                   *** Build CAD Client Only Jar ***         -->
      <jar destfile="${deploy.dir}/CADclient_r${svna.version}.jar"
       basedir="${build.dir}/classes"
       includes="tmcsim/client/**, tmcsim/common/**, tmcsim/interfaces/**,
            tmcsim/cadmodels/**, tmcsim/simulationmanager/model/LogEntryCellRenderer.class,
            tmcsim/application.properties">
      <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="tmcsim.client.CADClient"/>
            <attribute name="Implementation-Version" value="${TODAY}"/>
        </manifest>
      </jar>

      <!--                   *** Build Clock Client Only Jar ***         -->
      <jar destfile="${deploy.dir}/ClockClient_r${svna.version}.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>
      
      <!--                   *** Traffic Events Animator Only Jar ***         -->
      <jar destfile="${deploy.dir}/TrafficEventsAnimator.jar"
       basedir="${build.dir}/classes"
       includes="atmsdriver/**, atmsdriver/model/**, tmcsim/common/**,
            tmcsim/cadsimulator/managers/**"
       excludes="**/Test.class">
        <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="atmsdriver/TrafficEventsAnimator"/>
        </manifest>
      </jar>
      
      <!--                   *** Spike Only Jar ***         -->
      <jar destfile="${deploy.dir}/ShowUserDir.jar"
       basedir="${build.dir}/classes"
       includes="spikes/**"
       excludes="**/Test.class">
        <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="spikes/ShowUserDir"/>
        </manifest>
      </jar>
      
      <!--                   *** Build CAD Data Table Test Only Jar ***         -->
      <jar destfile="${deploy.dir}/CADDataTableTest_r${svna.version}.jar"
       basedir="${build.dir}/classes"
       includes="tmcsim/client/CadDataTableTest*.class, 
        tmcsim/interfaces/**, tmcsim/cadmodels/**, tmcsim/common/**, tmcsim/client/**">
      <zipgroupfileset dir="dist/lib" includes="xercesImpl.jar"/>
        <manifest>
            <attribute name="Main-Class" value="tmcsim.client.CadDataTableTest"/>
            <attribute name="Implementation-Version" value="${TODAY}"/>
        </manifest>
      </jar>
      
      <!--                ** Unified Logger Zip file **                      -->
      <zip destfile="${deploy.dir}/unifiedlogger.zip"
        basedir="${src.dir}/python/unifiedlogger"
        excludes="**/pyc, **/package.sh, wing_project.wpr"/>
            
      <!--  Set Executable --> 
      <chmod file="${deploy.dir}/CADserver_r${svna.version}.jar" perm="a+x"/>
      <chmod file="${deploy.dir}/SimManager_r${svna.version}.jar" perm="a+x"/>
      <chmod file="${deploy.dir}/CADclient_r${svna.version}.jar" perm="a+x"/>
      <chmod file="${deploy.dir}/ClockClient_r${svna.version}.jar" perm="a+x"/>
      <chmod file="${deploy.dir}/TrafficEventsAnimator.jar" perm="a+x"/>
      <chmod file="${deploy.dir}/ShowUserDir.jar" perm="a+x"/>
      <chmod file="${deploy.dir}/unifiedlogger.zip" perm="a+x"/>
</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>

</project>
