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

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

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

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

  <!-- samples build Properties -->
  <property name="sample.codesearch.basedir"       value="${build}/sample/codesearch"/>
  <property name="sample.codesearch.src.home"      value="${sample.codesearch.basedir}"/>
  <property name="sample.codesearch.build.classes" value="${sample.codesearch.basedir}/classes"/>
  <property name="sample.codesearch.build.lib"     value="${sample.codesearch.basedir}/lib"/>
  <property name="sample.codesearch.jar"           value="${sample.codesearch.build.lib}/CodeSearchClient.jar"/>
  <property name="sample.codesearch.main"          value="sample.codesearch.CodeSearchClient"/>

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

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

  <!-- samples build -->
  <target name="sample.codesearch.build"
      depends="sample.codesearch.dependencies,core.sample.core.util.build"
      description="Create binary distribution">
    <mkdir   dir="${sample.codesearch.build.lib}"/>
    <mkdir    dir="${sample.codesearch.build.classes}"/>
    <javac srcdir="${sample.codesearch.src.home}"
           destdir="${sample.codesearch.build.classes}"
           debug="${javac.debug}" debuglevel="${javac.debuglevel}"
           deprecation="false"
           optimize="true">
        <classpath refid="sample.codesearch.compile.classpath"/>
    </javac>
    <jar jarfile="${sample.codesearch.jar}"
         basedir="${sample.codesearch.build.classes}">
      <manifest>
        <attribute name="Main-Class" value="${sample.codesearch.main}"/>
      </manifest>
    </jar>
  </target>

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

  <!-- samples run -->
  <target name="sample.codesearch.run" depends="sample.codesearch.build"
   description="Runs the CodeSearch sample">
    <java fork="true" classname="${sample.codesearch.main}">
      <arg line="--query ${sample.codesearch.querystring}"/>
      <classpath>
        <path refid="sample.codesearch.compile.classpath"/>
        <path location="${sample.codesearch.jar}"/>
      </classpath>
    </java>
  </target>


</project>
