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


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

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

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

  <!-- samples build Properties -->
  <property name="sample.youtube.basedir"
            value="${basedir}/sample/youtube"/>
  <property name="sample.youtube.src.home"
            value="${sample.youtube.basedir}"/>
  <property name="sample.youtube.build.classes"
            value="${sample.youtube.basedir}/classes"/>
  <property name="sample.youtube.build.lib"
            value="${sample.youtube.basedir}/lib"/>
  <property name="sample.youtube.read.jar"
            value="${sample.youtube.build.lib}/YouTubeReadonlyClient.jar"/>
  <property name="sample.youtube.write.jar"
            value="${sample.youtube.build.lib}/YouTubeWriteClient.jar"/>
  <property name="sample.youtube.upload.jar"
            value="${sample.youtube.build.lib}/YouTubeUploadClient.jar"/>
  <property name="sample.youtube.partial.jar"
            value="${sample.youtube.build.lib}/YouTubePartialDemo.jar"/>
  <property name="sample.youtube.read.main"
            value="sample.youtube.YouTubeReadonlyClient"/>
  <property name="sample.youtube.write.main"
            value="sample.youtube.YouTubeWriteClient"/>
  <property name="sample.youtube.partial.main"
            value="sample.youtube.YouTubePartialDemo"/>
  <property name="sample.youtube.upload.main"
            value="sample.youtube.YouTubeUploadClient"/>

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

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

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

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

    <mkdir   dir="${sample.youtube.build.lib}"/>
    <mkdir    dir="${sample.youtube.build.classes}"/>

    <javac srcdir="${sample.youtube.src.home}"
           destdir="${sample.youtube.build.classes}"
           debug="${javac.debug}" debuglevel="${javac.debuglevel}"
           deprecation="false"
           optimize="true">
        <classpath refid="sample.youtube.compile.classpath"/>
    </javac>

    <jar jarfile="${sample.youtube.read.jar}"
         basedir="${sample.youtube.build.classes}">
      <manifest>
        <attribute name="Main-Class" value="${sample.youtube.read.main}"/>
      </manifest>
    </jar>
    <jar jarfile="${sample.youtube.write.jar}"
         basedir="${sample.youtube.build.classes}">
      <manifest>
        <attribute name="Main-Class" value="${sample.youtube.write.main}"/>
      </manifest>
    </jar>
    <jar jarfile="${sample.youtube.partial.jar}"
         basedir="${sample.youtube.build.classes}">
      <manifest>
        <attribute name="Main-Class" value="${sample.youtube.partial.main}"/>
      </manifest>
    </jar>
    <jar jarfile="${sample.youtube.upload.jar}"
         basedir="${sample.youtube.build.classes}">
      <manifest>
        <attribute name="Main-Class" value="${sample.youtube.upload.main}"/>
      </manifest>
    </jar>
  </target>

  <!-- samples run -->
  <target name="sample.youtube.read.run"
          depends="sample.youtube.build"
          description="Runs the youtube read-only sample">
    <java fork="true" classname="${sample.youtube.read.main}">
      <classpath>
        <path refid="sample.youtube.compile.classpath"/>
        <path location="${sample.youtube.read.jar}"/>
      </classpath>
    </java>
  </target>

  <target name="sample.youtube.write.run"
          depends="sample.youtube.build"
          description="Runs the youtube read-write sample">
    <java fork="true" classname="${sample.youtube.write.main}">
      <arg line="-u ${sample.youtube.username} -p ${sample.youtube.password} -k ${sample.youtube.key}"/>
      <classpath>
        <path refid="sample.youtube.compile.classpath"/>
        <path location="${sample.youtube.write.jar}"/>
      </classpath>
    </java>
  </target>

  <target name="sample.youtube.partial.run"
          depends="sample.youtube.build"
          description="Runs the youtube Partial Query/Patch demo">
    <java fork="true" classname="${sample.youtube.partial.main}">
      <arg line="-u ${sample.youtube.username} -p ${sample.youtube.password} -k ${sample.youtube.key}"/>
      <classpath>
        <path refid="sample.youtube.compile.classpath"/>
        <path location="${sample.youtube.partial.jar}"/>
      </classpath>
    </java>
  </target>

  <target name="sample.youtube.upload.run"
          depends="sample.youtube.build"
          description="Runs the youtube resumable upload sample">
    <java fork="true" classname="${sample.youtube.upload.main}">
      <arg line="-u ${sample.youtube.username} -p ${sample.youtube.password} -k ${sample.youtube.key}"/>
      <classpath>
        <path refid="sample.youtube.compile.classpath"/>
        <path location="${sample.youtube.upload.jar}"/>
      </classpath>
    </java>
  </target>


</project>
