<project name="core" default="build.core" basedir=".">

  <!-- Path containing core.xml -->
  <dirname property="build_dir" file="${ant.file.core}"/>

<!--  ===================================================================== -->
<!--                      Global targets                                    -->
<!--  ===================================================================== -->
  <!-- Root build path -->
  <property name="build" value="${build_dir}/../"/>

  <!-- Path for compiled files -->
  <property name="build.jars" value="${build}/lib"/>

  <!-- User properties -->
  <property name="version.properties" value="${build}/version.properties"/>
  <property name="build.properties" value="${build_dir}/build.properties"/>
  <property file="${version.properties}"/>
  <property file="${build.properties}"/>

  <property name="gdata-core.jar"
            value="${build.jars}/gdata-core-${client.spec.version}.jar"/>
  <property name="gdata-client-meta.jar"
            value="${build.jars}/gdata-client-meta-${client.spec.version}.jar"/>
  <property name="gdata-client.jar"
            value="${build.jars}/gdata-client-${client.spec.version}.jar"/>
  <property name="gdata-media.jar"
            value="${build.jars}/gdata-media-${media.spec.version}.jar"/>

  <!-- path for third_party google dependencies -->
  <path id="build.google-deps.classpath">
    <pathelement location="${google-jsr305.jar}"/>
    <pathelement location="${google-collect.jar}"/>
  </path>

  <!-- Dependency path for all services -->
  <path id="build.service.core.classpath">
    <path refid="build.google-deps.classpath"/>
    <pathelement location="${gdata-client.jar}"/>
  </path>

  <!-- Dependency path for all media enabled services -->
  <path id="build.service.media.classpath">
    <path refid="build.google-deps.classpath"/>
    <pathelement location="${mail.jar}"/>
    <pathelement location="${activation.jar}"/>
    <pathelement location="${gdata-media.jar}"/>
  </path>

  <!-- Template to check if Service libs are available
  Params:
    @param template.service.name  name of the service
    @param template.service.version specificaiton version for the service
  -->
  <target name="template.require.service.jar">
    <property name="template.service.jar"
      value="${build.jars}/gdata-${template.service.name}-${template.service.version}.jar"/>
    <available
      file="${template.service.jar}"
      property="has.service.jar"/>
    <fail unless="has.service.jar">
      Missing dependency jar: ${template.service.jar}
      Please run "ant ${template.service.name}.build.${template.service.name}".
    </fail>
  </target>


<!-- ==================== Build Core samples ============================= -->

<!--  ===================================================================== -->
<!--                      Util For Sample Targets                           -->
<!--  ===================================================================== -->
  <property name="sample.core.util.basedir"       value="${build}/sample/util"/>
  <property name="sample.core.util.build.classes" value="${sample.core.util.basedir}/classes"/>
  <property name="sample.core.util.build.lib"     value="${sample.core.util.basedir}/lib"/>
  <property name="sample-util.jar"           value="${sample.core.util.build.lib}/sample-util.jar"/>


  <target name="sample.core.dependencies">
    <available
      file="${gdata-client.jar}"
      property="has.client.jar"/>
    <fail unless="has.client.jar">
      Missing dependency jar: ${gdata-client.jar}
      Please run "ant core.build.core.client first".
    </fail>
  </target>


  <path id="sample.core.util.compile.classpath">
    <pathelement location="${gdata-core.jar}"/>
    <pathelement location="${gdata-client.jar}"/>
  </path>

  <target name="sample.core.util.build" depends="sample.core.dependencies">
    <mkdir dir="${sample.core.util.build.classes}"/>
    <javac srcdir="${sample.core.util.basedir}"
           destdir="${sample.core.util.build.classes}"
           debug="${javac.debug}" debuglevel="${javac.debuglevel}"
           deprecation="false"
           optimize="true">
        <classpath refid="sample.core.util.compile.classpath"/>
    </javac>
    <mkdir dir="${sample.core.util.build.lib}"/>
    <jar jarfile="${sample-util.jar}"
         basedir="${sample.core.util.build.classes}">
    </jar>
  </target>

  <target name="sample.core.util.clean">
    <delete dir="${sample.core.util.build.classes}"/>
  </target>


<!--  ===================================================================== -->
<!--                      Tester Sample Targets                             -->
<!--  ===================================================================== -->
  <property name="sample.core.tester.basedir"       value="${build}/sample/tester"/>
  <property name="sample.core.tester.src.home"      value="${sample.core.tester.basedir}"/>
  <property name="sample.core.tester.build.classes" value="${sample.core.tester.basedir}/classes"/>
  <property name="sample.core.tester.build.lib"     value="${sample.core.tester.basedir}/lib"/>
  <property name="sample.core.tester.jar"           value="${sample.core.tester.build.lib}/TesterClient.jar"/>
  <property name="sample.core.tester.main"          value="sample.tester.Tester"/>

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

  <path id="sample.core.tester.compile.classpath">
    <pathelement location="${gdata-client.jar}"/>
    <pathelement location="${sample-util.jar}"/>
  </path>


  <target name="sample.core.tester.build" depends="sample.core.dependencies">
    <mkdir dir="${sample.core.tester.build.classes}"/>
    <javac srcdir="${sample.core.tester.src.home}"
           destdir="${sample.core.tester.build.classes}"
           debug="false"
           deprecation="false"
           optimize="true">
        <classpath refid="sample.core.tester.compile.classpath"/>
    </javac>

    <mkdir   dir="${sample.core.tester.build.lib}"/>
    <jar jarfile="${sample.core.tester.jar}"
         basedir="${sample.core.tester.build.classes}">
      <manifest>
        <attribute name="Main-Class" value="${sample.core.tester.main}"/>
      </manifest>
    </jar>
  </target>

  <target name="sample.core.tester.run" depends="sample.core.tester.build">
    <java fork="true" classname="${sample.core.tester.main}">
      <arg line="-s ${sample.tester.serviceName} -a ${sample.tester.appName} -f ${sample.tester.feedUrl} -u ${sample.credentials.username} -p ${sample.credentials.password}"/>
      <classpath>
        <path refid="sample.core.tester.compile.classpath"/>
        <path location="${sample.core.tester.jar}"/>
      </classpath>
    </java>
  </target>

  <target name="sample.core.build">
    <antcall target="sample.core.util.build"/>
    <antcall target="sample.core.tester.build"/>
  </target>

  <target name="sample.core.clean">
    <antcall target="sample.core.util.clean"/>
    <antcall target="sample.core.tester.clean"/>
  </target>

  <target name="sample.core.run">
    <antcall target="sample.core.tester.run"/>
  </target>


<!--  ===================================================================== -->
<!--                      Third party dependency checks                     -->
<!--  ===================================================================== -->
  <!--  Dependencies for media extensions -->
  <target name="require.client.dependencies">
    <available file="${mail.jar}" property="has.sunmail"/>
    <available file="${activation.jar}" property="has.sunactivation"/>
    <fail unless="has.sunmail">missing jar file: ${mail.jar}
The GData client requires Sun's javamail API (version 1.4), which
is not included in this distribution.

You can download it from:
  http://java.sun.com/products/javamail/downloads/index.html

Then save it under:
  ${mail.jar}
    </fail>
    <fail unless="has.sunactivation">missing jar file: ${activation.jar}
The GData client requires Sun's Activation Framework 1.1, which
is not included in this distribution.

You can download it from:
 http://java.sun.com/products/javabeans/jaf/downloads/index.html

Then save it under:
  ${activation.jar}
    </fail>
  </target>


  <target name="require.servlet-api">
    <available file="${servlet.jar}" property="has.servlet-api"/>
    <fail unless="has.servlet-api">missing jar file: ${servlet.jar}
The recipe example requires Sun's Servlet API (version 2.3 or 2.4), which
is not included in this distribution.

You can download it from:
 http://java.sun.com/products/servlet/download.html
 Under SPECIFICATIONS/Java Servlet, download 'class files 2.3' from "2.3 - Final Release"

Then save it under:
  ${servlet.jar}
    </fail>
  </target>


</project>
