<project name="spreadsheet" default="build.spreadsheet" basedir=".">
  <!-- Path containing core.xml -->
  <dirname property="build_dir" file="${ant.file.spreadsheet}"/>
  <import file="${build_dir}/core.xml"/>

  <!--  ===================================================================== -->
  <!--                 Build GData Spreadsheet library.                       -->
  <!--  ===================================================================== -->

  <property name="gdata-spreadsheet.jar"
    value="${build.jars}/gdata-spreadsheet-${spreadsheet.spec.version}.jar"/>

  <!--  ===================================================================== -->
  <!--                 Build the GData Spreadsheet samples.                   -->
  <!--  ===================================================================== -->

  <!-- samples build Properties -->
  <property name="sample.spreadsheet.basedir"       value="${build}/sample/spreadsheet"/>
  <property name="sample.spreadsheet.src.home"      value="${sample.spreadsheet.basedir}"/>
  <property name="sample.spreadsheet.build.classes" value="${sample.spreadsheet.basedir}/classes"/>
  <property name="sample.spreadsheet.build.lib"     value="${sample.spreadsheet.basedir}/lib"/>
  <property name="sample.spreadsheet.celldemo.jar"
            value="${sample.spreadsheet.build.lib}/CellDemo.jar"/>
  <property name="sample.spreadsheet.celldemo.main"
            value="sample.spreadsheet.cell.CellDemo"/>
  <property name="sample.spreadsheet.listdemo.jar"
            value="${sample.spreadsheet.build.lib}/ListDemo.jar"/>
  <property name="sample.spreadsheet.listdemo.main"
            value="sample.spreadsheet.list.ListDemo"/>
  <property name="sample.spreadsheet.recorddemo.jar"
            value="${sample.spreadsheet.build.lib}/RecordDemo.jar"/>
  <property name="sample.spreadsheet.recorddemo.main"
            value="sample.spreadsheet.record.RecordDemo"/>
  <property name="sample.spreadsheet.worksheetdemo.jar"
            value="${sample.spreadsheet.build.lib}/WorksheetDemo.jar"/>
  <property name="sample.spreadsheet.worksheetdemo.main"
            value="sample.spreadsheet.worksheet.WorksheetDemo"/>
  <property name="sample.spreadsheet.tabledemo.jar"
            value="${sample.spreadsheet.build.lib}/TableDemo.jar"/>
  <property name="sample.spreadsheet.tabledemo.main"
            value="sample.spreadsheet.table.TableDemo"/>
  <property name="sample.spreadsheet.guidemo.jar"
            value="${sample.spreadsheet.build.lib}/GUIDemo.jar"/>
  <property name="sample.spreadsheet.guidemo.main"
            value="sample.spreadsheet.gui.SpreadsheetApiDemo"/>
  <property name="sample.spreadsheet.indexclient.jar"
            value="${sample.spreadsheet.build.lib}/IndexClient.jar"/>
  <property name="sample.spreadsheet.indexclient.main"
            value="sample.spreadsheet.IndexClient"/>
  <property name="sample.spreadsheet.importclient.jar"
            value="${sample.spreadsheet.build.lib}/ImportClient.jar"/>
  <property name="sample.spreadsheet.importclient.main"
            value="sample.spreadsheet.ImportClient"/>


  <!-- dependency check -->
  <target name="sample.spreadsheet.dependencies">
    <antcall target="template.require.service.jar">
      <param name="template.service.name" value="spreadsheet"/>
      <param name="template.service.version" value="${spreadsheet.spec.version}"/>
    </antcall>
  </target>

  <!-- samples dependencies -->
  <path id="sample.spreadsheet.compile.classpath">
    <path refid="build.service.core.classpath"/>
    <pathelement location="${gdata-spreadsheet.jar}"/>
    <pathelement location="${sample-util.jar}"/>
  </path>


  <!-- samples build -->
  <target name="sample.spreadsheet.build"
    depends="sample.spreadsheet.dependencies,core.sample.core.util.build"
    description="Create binary distribution">

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

    <!-- Create dist directory -->
    <mkdir   dir="${sample.spreadsheet.build.lib}"/>

    <!-- Create CellDemo JAR file -->
    <jar jarfile="${sample.spreadsheet.celldemo.jar}"
         basedir="${sample.spreadsheet.build.classes}">
      <manifest>
        <attribute name="Main-Class"
                   value="${sample.spreadsheet.celldemo.main}"/>
      </manifest>
    </jar>

    <!-- Create ListDemo JAR file -->
    <jar jarfile="${sample.spreadsheet.listdemo.jar}"
         basedir="${sample.spreadsheet.build.classes}">
      <manifest>
        <attribute name="Main-Class"
                   value="${sample.spreadsheet.listdemo.main}"/>
      </manifest>
    </jar>

    <!-- Create RecordDemo JAR file -->
    <jar jarfile="${sample.spreadsheet.recorddemo.jar}"
         basedir="${sample.spreadsheet.build.classes}">
      <manifest>
        <attribute name="Main-Class"
                   value="${sample.spreadsheet.recorddemo.main}"/>
      </manifest>
    </jar>

    <!-- Create WorksheetDemo JAR file -->
    <jar jarfile="${sample.spreadsheet.worksheetdemo.jar}"
         basedir="${sample.spreadsheet.build.classes}">
      <manifest>
        <attribute name="Main-Class"
                   value="${sample.spreadsheet.worksheetdemo.main}"/>
      </manifest>
    </jar>

    <!-- Create TableDemo JAR file -->
    <jar jarfile="${sample.spreadsheet.tabledemo.jar}"
         basedir="${sample.spreadsheet.build.classes}">
      <manifest>
        <attribute name="Main-Class"
                   value="${sample.spreadsheet.tabledemo.main}"/>
      </manifest>
    </jar>

    <!-- Create GUIDemo JAR file -->
    <jar jarfile="${sample.spreadsheet.guidemo.jar}"
         basedir="${sample.spreadsheet.build.classes}">
      <manifest>
        <attribute name="Main-Class"
                   value="${sample.spreadsheet.guidemo.main}"/>
      </manifest>
    </jar>

    <!-- Create IndexClient JAR file -->
    <jar jarfile="${sample.spreadsheet.indexclient.jar}"
         basedir="${sample.spreadsheet.build.classes}">
      <manifest>
        <attribute name="Main-Class"
                   value="${sample.spreadsheet.indexclient.main}"/>
      </manifest>
    </jar>

    <!-- Create ImportClient JAR file -->
    <jar jarfile="${sample.spreadsheet.importclient.jar}"
         basedir="${sample.spreadsheet.build.classes}">
      <manifest>
        <attribute name="Main-Class"
                   value="${sample.spreadsheet.importclient.main}"/>
      </manifest>
    </jar>

  </target>

  <target name="sample.spreadsheet.clean"
   description="Delete old build and dist directories">
    <delete dir="${sample.spreadsheet.build.classes}"/>
  </target>


  <!-- samples run -->
  <target name="sample.spreadsheet.celldemo.run"
          depends="sample.spreadsheet.build"
   description="Runs the Spreadsheet CellDemo sample">
    <java fork="true" classname="${sample.spreadsheet.celldemo.main}">
      <arg line="-u ${sample.credentials.username} -p ${sample.credentials.password}"/>
      <classpath>
        <path refid="sample.spreadsheet.compile.classpath"/>
        <path location="${sample.spreadsheet.celldemo.jar}"/>
      </classpath>
    </java>

  </target>

  <target name="sample.spreadsheet.listdemo.run"
          depends="sample.spreadsheet.build"
   description="Runs the Spreadsheet ListDemo sample">
    <java fork="true" classname="${sample.spreadsheet.listdemo.main}">
      <arg line="-u ${sample.credentials.username} -p ${sample.credentials.password}"/>
      <classpath>
        <path refid="sample.spreadsheet.compile.classpath"/>
        <path location="${sample.spreadsheet.listdemo.jar}"/>
      </classpath>
    </java>

  </target>

  <target name="sample.spreadsheet.recorddemo.run"
          depends="sample.spreadsheet.build"
   description="Runs the Spreadsheet Record Demo sample">
    <java fork="true" classname="${sample.spreadsheet.recorddemo.main}">
      <arg line="-u ${sample.credentials.username} -p ${sample.credentials.password}"/>
      <classpath>
        <path refid="sample.spreadsheet.compile.classpath"/>
        <path location="${sample.spreadsheet.recorddemo.jar}"/>
      </classpath>
    </java>

  </target>

  <target name="sample.spreadsheet.worksheetdemo.run"
          depends="sample.spreadsheet.build"
   description="Runs the Spreadsheet WorksheetDemo sample">
    <java fork="true" classname="${sample.spreadsheet.worksheetdemo.main}">
      <arg line="-u ${sample.credentials.username} -p ${sample.credentials.password}"/>
      <classpath>
        <path refid="sample.spreadsheet.compile.classpath"/>
        <path location="${sample.spreadsheet.worksheetdemo.jar}"/>
      </classpath>
    </java>

  </target>

  <target name="sample.spreadsheet.tabledemo.run"
          depends="sample.spreadsheet.build"
   description="Runs the Spreadsheet Table Demo sample">
    <java fork="true" classname="${sample.spreadsheet.tabledemo.main}">
      <arg line="-u ${sample.credentials.username} -p ${sample.credentials.password}"/>
      <classpath>
        <path refid="sample.spreadsheet.compile.classpath"/>
        <path location="${sample.spreadsheet.tabledemo.jar}"/>
      </classpath>
    </java>

  </target>

  <target name="sample.spreadsheet.guidemo.run"
          depends="sample.spreadsheet.build"
   description="Runs the Spreadsheet GUIDemo sample">
    <java fork="true" classname="${sample.spreadsheet.guidemo.main}">
      <classpath>
        <path refid="sample.spreadsheet.compile.classpath"/>
        <path location="${sample.spreadsheet.guidemo.jar}"/>
      </classpath>
    </java>

  </target>

  <target name="sample.spreadsheet.indexclient.run"
          depends="sample.spreadsheet.build"
   description="Runs the Spreadsheet IndexClient sample">
    <java fork="true" classname="${sample.spreadsheet.indexclient.main}">
      <arg line="-u ${sample.credentials.username} -p ${sample.credentials.password} --author --worksheets --headers"/>
      <classpath>
        <path refid="sample.spreadsheet.compile.classpath"/>
        <path location="${sample.spreadsheet.celldemo.jar}"/>
      </classpath>
    </java>

  </target>

  <target name="sample.spreadsheet.importclient.run"
          depends="sample.spreadsheet.build"
   description="Runs the Spreadsheet ImportClient sample">
    <java fork="true" classname="${sample.spreadsheet.importclient.main}">
      <arg line="-u ${sample.credentials.username} -p ${sample.credentials.password} --filename ${sample.spreadsheet.importclient.filename} --spreadsheet ${sample.spreadsheet.importclient.spreadsheet} --worksheet ${sample.spreadsheet.importclient.worksheet} --delimiter ,"/>
      <classpath>
        <path refid="sample.spreadsheet.compile.classpath"/>
        <path location="${sample.spreadsheet.celldemo.jar}"/>
      </classpath>
    </java>

  </target>


</project>
