<project name="benow-util" default="compile" basedir=".">


  <property name="app.name"      value="benow-util"/>
  <property name="app.version"   value="1.0"/>
  <property name="src.home"      value="src/java"/>

  <!-- deploy should be the webapps directory for the servlet container -->
  <property file="/etc/benow/build.properties"/>
  <property file="etc/build.properties"/>

  <path id="compile.classpath">

    <!-- Include all JAR files that will be included in /WEB-INF/lib -->
    <!-- *** CUSTOMIZE HERE AS REQUIRED BY YOUR APPLICATION *** -->

    <!-- Include all needed jars -->
    <fileset dir="${lib.home}">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${lib.home}/linux">
      <include name="*.jar"/>
    </fileset>
    <fileset dir="${lib.home}/linux/amd64">
      <include name="*.jar"/>
    </fileset>
    <pathelement path="${build.home}"/>
  </path>

  <target name="all" depends="clean,jar"
   description="Clean build and dist, then compile"/>

  <target name="clean"
   description="Delete old build directories">
    <delete dir="${build.home}" quiet="yes"/>
    <delete quiet="yes">
      <fileset dir="." includes="**/*~" defaultexcludes="no"/>
    </delete>

   <delete dir="${dist.home}"/>
  </target>

  <target name="compile" depends="clean"
   description="Compile Java sources">

    <!-- Compile Java classes as necessary -->
    <mkdir dir="${build.home}"/>
    <javac srcdir="${src.home}"
          destdir="${build.home}"
           debug="true"
        deprecation="${compile.deprecation}"
        optimize="${compile.optimize}">
        <classpath refid="compile.classpath"/>
    </javac>

  </target>

  <target name="rmi_deploy" depends="compile"
   description="Compile Java sources">

    <rmic classname="test.org.benow.util.RemoteEchoerImpl" base="build">
      <classpath refid="compile.classpath"/>
    </rmic>

	<mkdir  dir="rmi_deploy/test/org/benow/util/"/>
    <copy todir="rmi_deploy/test/org/benow/util/">
    	<fileset dir="build/test/org/benow/util/" includes="*_*.class"/>
    </copy>

    <rmic classname="org.benow.util.net.rmi.RMIManagerImpl" base="build">
      <classpath refid="compile.classpath"/>
    </rmic>

<!--
    <rmic classname="org.benow.util.net.rmi.ServiceApplication" base="build">
      <classpath refid="compile.classpath"/>
    </rmic>
-->

    <copy todir="rmi_deploy/org/benow/util/net/rmi">
    	<fileset dir="build/org/benow/util/net/rmi/" includes="*_*.class"/>
    </copy>

    <copy todir="rmi_deploy/org/benow/util/net/rmi/" file="${build.home}/org/benow/util/net/rmi/RMIManager.class"/>
    <copy todir="rmi_deploy/org/benow/util/net/rmi/" file="${build.home}/org/benow/util/net/rmi/Service.class"/>
    <copy todir="rmi_deploy/org/benow/util/" file="${build.home}/org/benow/util/Named.class"/>

  </target>


  <target name="deploy" depends="rmi_deploy,dist"
   description="Deploy application to servlet container">
  </target>


  <target name="dist" depends="jar"
   description="Create binary distribution">

    <mkdir dir="${dist.home}/docs"/>
    <!-- Copy documentation subdirectory -->
    <copy    todir="${dist.home}/docs">
      <fileset dir="docs"/>
    </copy>
  </target>

  <target name="jar" depends="compile"
   description="Create binary distribution">

    <mkdir dir="${lib.home}"/>

    <java classname="org.benow.java.scanner.ClassScanner" failonerror="true" fork="false">
      <classpath refid="compile.classpath"/>
    </java>
   <mkdir dir="${lib.home}/t"/>
  	
  	<unjar src="${lib.home}/benow-launch.jar" dest="${lib.home}/t">
      <patternset>
        <include name="**/SimpleSwitcher*"/>
        <include name="**/SimpleSwitcher*"/>
      </patternset>
  	</unjar>
  	
    <copy todir="${lib.home}/t">
      <fileset dir="${build.home}"/>
    </copy>
  	
    <java classname="org.benow.SimpleSwitcher" fork="no">
      <classpath refid="compile.classpath"/>
      <arg value="--package"/>
	    <arg value="${lib.home}/t"/>
	    <arg value="org.benow.util.Copy"/>
    	<arg value="org.benow.burninate.Burninator"/>
    	<arg value="org.benow.hotmount.HotMount"/>
    </java>

    <jar jarfile="${app.name}.jar" basedir="${lib.home}/t">
			  	<manifest>
  					<attribute name="Built-By" value="${user.name}" />
  					<attribute name="Main-Class" value="org.benow.SimpleSwitcher"/>
  					<attribute name="Switcher-Default" value="Copy"/>
  				</manifest>
    </jar>
    
   <delete dir="${lib.home}/t"/>
  <mkdir dir="${lib.home}/t"/>
    <copy todir="${lib.home}/t/org/benow/burninate">
      <fileset dir="${build.home}/org/benow/burninate"/>
    </copy>
    <copy todir="${lib.home}/t/org/benow/burninate">
      <fileset dir="src/java/org/benow/burninate"/>
    </copy>
    <copy todir="${lib.home}/t/" file="README.burninate"/>
    <jar jarfile="benow-burninate.jar" basedir="${lib.home}/t">
    <manifest>
      <attribute name="Main-Class" value="org.benow.burninate.Burninator"/>
    </manifest>
    </jar>
   <delete dir="${lib.home}/t"/>

	 <mkdir dir="${lib.home}/t"/>
   <copy todir="${lib.home}/t/org/benow/hotmount">
     <fileset dir="${build.home}/org/benow/hotmount"/>
   </copy>
   <copy todir="${lib.home}/t/org/benow/hotmount">
     <fileset dir="src/java/org/benow/hotmount"/>
   </copy>
   <copy todir="${lib.home}/t/" file="README.hotmount"/>
   <jar jarfile="benow-hotmount.jar" basedir="${lib.home}/t">
		 <manifest>
		   <attribute name="Main-Class" value="org.benow.hotmount.HotMount"/>
		 </manifest>
   </jar>
   <delete dir="${lib.home}/t"/>

  </target>


<!-- ==================== Javadoc Target ================================== -->

<!--

  The "javadoc" target creates Javadoc API documentation for the Java
  classes included in your application.  Normally, this is only required
  when preparing a distribution release, but is available as a separate
  target in case the developer wants to create Javadocs independently.

-->

  <target name="javadoc" depends="compile"
   description="Create Javadoc API documentation">

    <delete dir="docs/api"/>
    <mkdir          dir="docs/api"/>
    <javadoc sourcepath="${src.home}"
                destdir="docs/api"
            windowtitle="BeNOW Documentation"
               doctitle="BeNOW Documentation"
           packagenames="org.*,test.*">
      <link href="http://java.sun.com/javase/6/docs/api/"/>
      <classpath refid="compile.classpath"/>
    </javadoc> 

  </target>


  <target name="native" depends="compile"
   description="Compile native code">

	<javah classpath="build" destdir="native/linux" verbose="yes">
	  <class name="org.benow.util.io.ConsoleReader"/>
  	</javah>

	<exec dir="native/linux" executable="make" os="Linux">
	 <env key="java.home" value="${java.home}"/>
	 <env key="os.name" value="linux"/>
	</exec>

<!--
	<exec dir="native" executable="gmake" os="FreeBSD">
	 <env key="java.home" value="${java.home}"/>
	 <env key="os.name" value="freebsd"/>
	</exec>
-->
  </target>


<!-- ==================== Prepare Target ================================== -->

<!--

  The "prepare" target is used to create the "build" destination directory,
  and copy the static contents of your web application to it.  If you need
  to copy static files from external dependencies, you can customize the
  contents of this task.

  Normally, this task is executed indirectly when needed.

-->

  <target name="prepare">

    <!-- Create build directory and copy static content -->
    <mkdir  dir="${build.home}"/>

    <!-- Copy static files from external dependencies as needed -->

  </target>


</project>

