<!-- Ant build script for yFiles applet deployment.    -->
<!-- The Java based Ant tool is available from         -->
<!-- http://ant.apache.org/                            -->

<project name="yFiles Applet" default="all" basedir=".">

  <target name="help">
    <echo>
This Ant script can be used to perform deployment of this sample applet.
Deployment is composed of two steps:
First the applet's application classes are compiled and jarred into
"application.jar" together with all application resources.
Next the application jar and the yFiles library jar "y.jar" are signed
and moved to the build's base directory.
Once both jar files are signed and located in the build's base directory,
the applet is ready to be displayed on a web page.
To try out the applet open the HTML page "applet.html" in the build's base
directory with your web browser.
    </echo>
  </target>

  <!-- Define some properties that are used throughout the tasks. -->
  <target name="init">
    <!-- the base directory of the yFiles installation -->
    <property name="yBase"          location="../../../.."/>
    <!-- the path to the demo sources -->
    <property name="src"            location="${yBase}/src"/>
    <!-- the path to the demo classes -->
    <property name="classes"        location="${yBase}/classes"/>
    <!-- the yFiles jar file -->
    <property name="yJar"           location="${yBase}/lib/y.jar"/>
    <!-- the application jar file -->
    <property name="appJar"         value="application.jar"/>
  </target>

  <!-- Compiles the application's classes. -->
  <target name="compile" depends="init">
    <mkdir dir="${classes}"/>
    <javac includeantruntime="false" srcdir="${src}" destdir="${classes}">
      <include name="demo/view/applet/*.java"/>
      <classpath>
        <pathelement location="${yJar}"/>
      </classpath>
    </javac>
  </target>

  <!-- Puts the application's classes into "application.jar." -->
  <target name="jar" depends="compile">
    <delete file="${appJar}"/>
    <jar jarfile="${appJar}">
      <manifest>
        <!-- required as of Java 7u25 -->
        <attribute name="Permissions" value="all-permissions"/>
      </manifest>
      <!-- other possibly required security attributes are -->
      <!--   "Codebase"           (as of Java 7u25) and    -->
      <!--   "Application-Name"   (as of Java 7u45)        -->
      <!-- for additional information see                  -->
      <!-- http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/security/manifest.html -->
      <fileset dir="${src}">
        <include name="demo/view/applet/resource/*.gif"/>
        <include name="demo/view/applet/resource/*.png"/>
      </fileset>
      <fileset dir="${classes}">
        <include name="demo/view/applet/*.class"/>
      </fileset>
    </jar>
  </target>

  <!-- Signs the application jar and the yFiles library jar for -->
  <!-- Java 7u25 security compliancy                            -->
  <target name="sign" depends="jar" unless="unsigned">
    <property file="${basedir}/keystore.properties"/>
    <!-- check if the required keystore access data is available -->
    <condition property="keystore.available">
      <and>
        <isset property="keystore.file"/>
        <not>
          <equals arg1="${keystore.file}" arg2="" trim="true"/>
        </not>
        <isset property="keystore.pass"/>
        <not>
          <equals arg1="${keystore.pass}" arg2="" trim="true"/>
        </not>
        <isset property="keystore.type"/>
        <not>
          <equals arg1="${keystore.type}" arg2="" trim="true"/>
        </not>
        <isset property="keystore.alias"/>
        <not>
          <equals arg1="${keystore.alias}" arg2="" trim="true"/>
        </not>
      </and>
    </condition>
    <fail unless="keystore.available">
  As of Java 7u25 applets have to be signed by default.


  To sign the application jar and the yFiles library jar, create a keystore
  suitable for Oracle's jarsigner tool. See
    http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/jarsigner.html
  or
    http://docs.oracle.com/javase/6/docs/technotes/tools/windows/jarsigner.html
  for documentation on Oracle's jarsigner tool.

  Additionally, specify the access data required by ANT's signjar task in the
  keystore.properties file located in the build's base directory. See
    http://ant.apache.org/manual/Tasks/signjar.html
  for documentation on ANT's signjar task.


  If you want to create an unsigned applet (which may be executed by reducing
  Java's default security settings), run the build process with property
  "unsigned" set to "true".
</fail>


    <property name="bin" value="${yBase}/bin"/>
    <mkdir dir="${bin}"/>

    <signjar
     destdir="${bin}"
     keystore="${keystore.file}"
     storepass="${keystore.pass}"
     storetype="${keystore.type}"
     alias="${keystore.alias}">
      <path>
        <pathelement location="${appJar}"/>
        <pathelement location="${yJar}"/>
      </path>
    </signjar>

    <move todir="${basedir}">
      <fileset dir="${bin}">
        <include name="*.jar"/>
      </fileset>
    </move> 

    <delete dir="${bin}"/>
  </target>

  <target name="all" depends="sign" if="unsigned">
    <copy file="${yJar}" tofile="${basedir}/y.jar"/>
  </target>
  
  <!-- Removes all that has been built. -->
  <target name="clean" depends="init">
    <delete file="${appJar}"/>
    <delete file="${basedir}/y.jar"/>
    <delete includeemptydirs="true" dir="${classes}"/>
  </target>

</project>
