<commit_before><!--
  Copyright (c) 2009-2011  Couchbase, Inc.

  Permission is hereby granted, free of charge, to any person obtaining a copy of
  this software and associated documentation files (the "Software"), to deal in
  the Software without restriction, including without limitation the rights to
  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  of the Software, and to permit persons to whom the Software is furnished to do
  so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
-->

<project name="spymemcached" default="jar"
    xmlns:artifact="urn:maven-artifact-ant"
    xmlns:ivy="antlib:org.apache.ivy.ant">

  <property name="name" value="spymemcached"/>
  <property name="copyright" value="2006-2011 <NAME>, <NAME>" />
  <property name="group" value="spy" />

  <property name="base.src.dir" value="${basedir}/src" />
  <property name="build.dir" value="${basedir}/build" />
  <property name="build.src.dir" value="${build.dir}/src" />
  <property name="etc.dir" value="${basedir}/etc" />
  <property name="lib.dir" value="${basedir}/lib" />
  <property name="src.dir" value="${base.src.dir}/main/java" />
  <property name="test.dir" value="${base.src.dir}/test/java" />
  <property name="script.src.dir" value="${base.src.dir}/scripts" />
  <property name="build.javadoc" location="${build.dir}/docs/" />
  <property name="junit.dir" location="${build.dir}/junit" />

  <property name="dist.dir" value="${basedir}/target" />
  <property name="build.classes" location="${build.dir}/classes"/>

  <property name="git.hash" value="" />

  <!-- ivy properties used -->
  <property name="ivy.settings.dir" value="${basedir}/ivy" />

  <path id="test.classpath">
    <pathelement location="${build.classes}" />
    <fileset dir="${lib.dir}">
      <include name="**/*.jar"/>
    </fileset>
  </path>

  <!-- tests -->
  <property name="build.test" location="${build.dir}/test"/>
  <property name="test.log.dir" location="${build.dir}/test/logs"/>
  <property name="build.test.classes" location="${build.test}/classes" />

  <!-- maven -->
  <property name="mvn.build.dir" value="${build.dir}/m2" />
  <property name="spymemcached.pom" value="${mvn.build.dir}/spymemcached.pom" />

  <!-- compilation -->
  <property name="javac.deprecation" value="off"/>
  <property name="javac.debug" value="on"/>
  <property name="build.encoding" value="ISO-8859-1"/>

  <!-- Checking code style -->
  <property name="checkstyle.xml" value="${etc.dir}/checkstyle.xml" />
  <property name="checkstyle.format.xsl" value="${etc.dir}/checkstyle-noframes.xsl" />
  <property name="checkstyle.report.dir" value="${build.dir}/checkstyle" />

  <!-- static analysis -->
  <property name="findbugs.out.dir" value="${build.dir}/findbugs" />
  <property name="findbugs.output.xml.file"
      value="${findbugs.out.dir}/report.xml" />
  <property name="findbugs.output.html.file"
      value="${findbugs.out.dir}/report.html" />

  <!-- Ivy-based dependency resolution -->
  <property name="ivy.dir" location="${basedir}/ivy" />
  <property name="ivysettings.xml" location="${ivy.dir}/ivysettings.xml"/>
  <loadproperties srcfile="${ivy.dir}/libraries.properties"/>
  <property name="ivy.jar" location="${lib.dir}/ivy-${ivy.version}.jar"/>
  <property name="ivy_repo_url"
      value="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar" />
  <property name="mvn_repo_url"
      value="http://repo2.maven.org/maven2/org/apache/maven/maven-ant-tasks/${mvn.version}/maven-ant-tasks-${mvn.version}.jar"/>
  <property name="mvn.jar" location="${build.dir}/maven-ant-tasks-${mvn.version}.jar" />
  <property name="build.ivy.dir" location="${build.dir}/ivy" />
  <property name="build.ivy.lib.dir" location="${build.ivy.dir}/lib" />
  <property name="build.ivy.report.dir" location="${build.ivy.dir}/report" />
  <property name="redist.ivy.lib.dir" location="${build.ivy.lib.dir}/${name}/redist"/>

  <!--test related properties -->
  <property name="server.address_v4" value="127.0.0.1"/>
  <property name="server.address_v6" value="::1"/>
  <property name="server.type" value="memcached"/>

  <!--this is the naming policy for artifacts we want pulled down-->
  <property name="ivy.artifact.retrieve.pattern"
      value="${name}/[conf]/[artifact]-[revision](-[classifier]).[ext]"/>

  <!-- paths used for compilation and run  -->
  <path id="lib.path.id">
    <fileset dir="${lib.dir}" />
  </path>
  <path id="run.path.id">
    <path refid="lib.path.id" />
    <path location="${build.dir}" />
  </path>

  <!-- load ant-contrib tasks to get the "if" task. -->
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
      <pathelement location="${basedir}/lib/ant-contrib-1.0b3.jar"/>
    </classpath>
  </taskdef>

  <!-- The classpath for compiling and running Spymemcached -->

  <path id="compile.classpath">
    <pathelement location="${build.classes}"/>
    <path refid="lib.path"/>
    <path refid="${name}.common.classpath"/>
  </path>

  <!-- ======================================
        Section: Initializing
       ====================================== -->
  <target name="init">
  <!-- Path containing third-party libraries deployed directly with spymemcached.
       This does not include anything that Ivy can retrieve for us.
    -->
    <path id="lib.path">
      <fileset dir="${lib.dir}">
        <include name="*.jar" />
      </fileset>
    </path>

    <!-- Classpath for unit tests (superset of compile.classpath) -->
    <path id="test.classpath">
      <pathelement location="${build.test.classes}" />
      <path refid="compile.classpath" />
    </path>
  </target>

  <target name="ivy-probe-antlib" >
    <condition property="ivy.found">
      <typefound uri="antlib:org.apache.ivy.ant" name="cleancache"/>
    </condition>
  </target>

  <target name="ivy-download" unless="offline">
    <mkdir dir="${lib.dir}" />
    <get src="${ivy_repo_url}" dest="${ivy.jar}" usetimestamp="true"/>
  </target>

  <target name="ivy-init-antlib" depends="ivy-download,ivy-probe-antlib"
    unless="ivy.found">
    <typedef uri="antlib:org.apache.ivy.ant" onerror="fail"
      loaderRef="ivyLoader">
      <classpath>
        <pathelement location="${ivy.jar}"/>
      </classpath>
    </typedef>
    <fail >
      <condition >
        <not>
          <typefound uri="antlib:org.apache.ivy.ant" name="cleancache"/>
        </not>
      </condition>
        You need Apache Ivy 2.0 or later from http://ant.apache.org/
        It could not be loaded from ${ivy_repo_url}
    </fail>
  </target>

  <target name="ivy-init" depends="ivy-init-antlib" unless="ivy.configured">
    <ivy:configure settingsid="${name}.ivy.settings" file="${ivysettings.xml}"/>
    <property name="ivy.configured" value="true" />
  </target>

  <!-- ======================================
        Section: Resolving and Retrieving
       ====================================== -->
  <target name="ivy-resolve" depends="ivy-init">
    <ivy:resolve settingsRef="${name}.ivy.settings" conf="common" />
  </target>

  <target name="ivy-retrieve" depends="ivy-resolve">
    <ivy:retrieve settingsRef="${name}.ivy.settings" conf="common"
      pattern="${build.ivy.lib.dir}/${ivy.artifact.retrieve.pattern}" sync="true" />
    <ivy:cachepath pathid="${name}.common.classpath" conf="common" />
  </target>

  <!-- retrieve ivy-managed artifacts for checkstyle -->
  <target name="ivy-resolve-checkstyle" depends="ivy-init">
    <ivy:resolve settingsRef="${name}.ivy.settings" conf="checkstyle" />
  </target>

  <target name="ivy-retrieve-checkstyle" depends="ivy-resolve-checkstyle">
    <ivy:retrieve settingsRef="${name}.ivy.settings"
      pattern="${build.ivy.lib.dir}/${ivy.artifact.retrieve.pattern}" sync="true" />
    <ivy:cachepath pathid="${name}.checkstyle.classpath" conf="checkstyle" />
  </target>

  <!-- retrieve ivy-managed artifacts for checkstyle -->
  <target name="ivy-resolve-findbugs" depends="ivy-init">
    <ivy:resolve settingsRef="${name}.ivy.settings" conf="findbugs" />
  </target>

  <target name="ivy-retrieve-findbugs" depends="ivy-resolve-findbugs">
    <ivy:retrieve settingsRef="${name}.ivy.settings"
      pattern="${build.ivy.lib.dir}/${ivy.artifact.retrieve.pattern}" sync="true" />
    <ivy:cachepath pathid="${name}.findbugs.classpath" conf="findbugs" />
  </target>

  <!-- ======================================
        Section: Testing and Reporting
       ====================================== -->
  <target name="report" depends="ivy-retrieve"
      description="Generates a report of dependencies">
    <ivy:report todir="${build.dir}"/>
  </target>

  <target name="test" depends="compile, compile-test"
      description="Run Spymemcached unit tests">
    <echo>Testing against ${server.type}</echo>
    <echo>IPV4 address ${server.address_v4}</echo>
    <echo>IPV6 address ${server.address_v6}</echo>
    <delete dir="${junit.dir}"/>
    <mkdir  dir="${junit.dir}/data"/>
    <if>
      <equals arg1="${server.type}" arg2="memcached"/>
      <then>
        <junit fork="yes" timeout="60000" failureproperty="junit.failure">
          <batchtest todir="${junit.dir}/data" fork="yes">
            <fileset dir="${test.dir}">
              <include name="**/*Test.java"/>
              <exclude name="**/VBucketMemcachedClientTest.java"/>
              <exclude name="**/BucketMonitorTest.java"/>
              <exclude name="**/ConfigurationProviderHTTPTest.java"/>
              <exclude name="**/CouchbaseClientTest.java"/>
              <exclude name="**/MembaseClientTest.java"/>
            </fileset>
          <formatter type="xml"/>
          </batchtest>
          <jvmarg value="-ea" />
          <sysproperty key="server.address_v4" value="${server.address_v4}"/>
          <sysproperty key="server.address_v6" value="${server.address_v6}"/>
          <sysproperty key="server.type" value="${server.type}"/>
          <formatter type="plain" usefile="false" />
          <classpath refid="test.classpath" />
        </junit>
      </then>
    </if>
    <if>
      <equals arg1="${server.type}" arg2="membase"/>
        <then>
          <junit fork="yes" timeout="60000" failureproperty="junit.failure">
            <batchtest todir="${junit.dir}/data" fork="yes">
              <fileset dir="${test.dir}">
              <include name="**/*Test.java"/>
              <exclude name="**/CouchbaseClientTest.java"/>
            </fileset>
          <formatter type="xml"/>
          </batchtest>
          <jvmarg value="-ea" />
          <sysproperty key="server.address_v4" value="${server.address_v4}"/>
          <sysproperty key="server.address_v6" value="${server.address_v6}"/>
          <sysproperty key="server.type" value="${server.type}"/>
          <formatter type="plain" usefile="false" />
          <classpath refid="test.classpath" />
        </junit>
      </then>
    </if>
    <if>
      <equals arg1="${server.type}" arg2="couchbase"/>
        <then>
          <junit fork="yes" timeout="60000" failureproperty="junit.failure">
            <batchtest todir="${junit.dir}/data" fork="yes">
              <fileset dir="${test.dir}">
              <include name="**/*Test.java"/>
            </fileset>
          <formatter type="xml"/>
          </batchtest>
          <jvmarg value="-ea" />
          <sysproperty key="server.address_v4" value="${server.address_v4}"/>
          <sysproperty key="server.address_v6" value="${server.address_v6}"/>
          <sysproperty key="server.type" value="${server.type}"/>
          <formatter type="plain" usefile="false" />
          <classpath refid="test.classpath" />
        </junit>
      </then>
    </if>
    <mkdir  dir="${junit.dir}/tmp"/>
    <junitreport todir="${junit.dir}/tmp">
      <fileset dir="${junit.dir}/data"/>
      <report todir="${junit.dir}"/>
    </junitreport>
    <delete  dir="${junit.dir}/tmp"/>
    <fail if="junit.failure" message="Unit test(s) failed.  See reports!"/>
  </target>

    <target name="junitreport">
        <mkdir dir="${junit.out.dir.html}"/>
        <junitreport todir="${junit.out.dir.html}">
            <fileset dir="${junit.out.dir.xml}">
                <include name="*.xml"/>
            </fileset>
            <report format="frames" todir="${junit.out.dir.html}"/>
        </junitreport>
    </target>

  <target name="compile-test" depends="compile"
      description="Compile test classes">
    <mkdir dir="${build.test.classes}" />
    <javac
        encoding="${build.encoding}"
        srcdir="${test.dir}"
        includes="**/*.java"
        destdir="${build.test.classes}"
        debug="${javac.debug}">
      <classpath>
        <path refid="test.classpath"/>
      </classpath>
    </javac>
  </target>

  <!-- =======================================
        Section: Documentation Generation
       ======================================= -->

  <target name="javadoc-uptodate" depends="init">
    <uptodate property="javadoc.is.uptodate">
    <srcfiles dir="${src.dir}">
        <include name="**/*.java" />
        <include name="**/*.html" />
      </srcfiles>
      <mapper type="merge" to="${build.javadoc}/index.html" />
    </uptodate>
  </target>

  <target name="docs" description="Build javadoc"
      depends="init,javadoc-uptodate,compile" unless="javadoc.is.uptodate">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <mkdir dir="${build.javadoc}" />
    <exec executable="date" outputproperty="year">
      <arg value="+%Y" />
    </exec>
    <javadoc
      packagenames="src"
      sourcepath="${src.dir}"
      destdir="${build.javadoc}"
      author="true"
      version="true"
      use="true"
      windowtitle="${name} ${version} API"
      doctitle="${name} ${version} API"
      bottom="Copyright &amp;copy; 2006-2009 <NAME>, 2009-2011 Couchbase, Inc.">
      <packageset dir="${src.dir}">
        <include name="**" />
      </packageset>
      <classpath>
        <path refid="${name}.common.classpath" />
      </classpath>
    </javadoc>
  </target>

  <target name="docsjar" depends="docs"
      description="Create the documentation jar">
    <zip destfile="${build.dir}/${name}-${version}-javadoc.jar"
        basedir="${build.javadoc}" />
  </target>

  <!-- =======================================
        Section: Compiling and Packaging
       ======================================= -->

  <target name="gen-version" depends="init">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <exec executable="${script.src.dir}/write-version-info.sh"
        dir="${basedir}" failonerror="true">
      <arg value="${build.dir}" />
      <arg value="${version}" />
      <arg value="${git.hash}" />
    </exec>
  </target>

  <target name="compile" depends="ivy-init, gen-version, ivy-retrieve"
      description="Compile and run the project">
    <mkdir dir="${build.classes}" />
    <javac
        encoding="${build.encoding}"
        srcdir="${src.dir}"
        includes="**/*.java"
        destdir="${build.classes}"
        debug="${javac.debug}"
        deprecation="${javac.deprecation}">
      <classpath refid="${name}.common.classpath" />
    </javac>

    <javac
        encoding="${build.encoding}"
        srcdir="${build.src.dir}"
        includes="**/*.java"
        destdir="${build.classes}"
        debug="${javac.debug}"
        deprecation="${javac.deprecation}">
      <classpath refid="${name}.common.classpath"/>
    </javac>
    <move file="${build.src.dir}/net/spy/memcached/changelog.txt"
        tofile="${build.classes}/net/spy/memcached/changelog.txt" />
  </target>

  <target name="srcjars" depends="init,jar"
      description="Create source jars">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <mkdir dir="${build.dir}" />
    <jar jarfile="${build.dir}/${name}-${version}-sources.jar">
      <fileset dir="${src.dir}" />
      <fileset dir="${build.src.dir}" />
    </jar>
    <jar jarfile="${build.dir}/${name}-${version}-test-sources.jar">
      <fileset dir="${test.dir}" />
    </jar>
  </target>

  <target name="jar" depends="compile" description="Creates a jar file for the plugin">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <jar jarfile="${build.dir}/${name}-${version}.jar" basedir="${build.classes}">
      <manifest>
        <attribute name="Implementation-Title" value="java memcached client" />
        <attribute name="Implementation-Version" value="${version}" />
        <attribute name="Implementation-Vendor" value="${copyright}" />
        <attribute name="Copyright" value="${copyright}" />
        <attribute name="Main-Class" value="net.spy.memcached.BuildInfo" />
      </manifest>
    </jar>
  </target>

  <target name="package" depends="jar" description="Packages files for distribution">
    <mkdir dir="${dist.dir}" />
    <zip destfile="${name}-${version}.zip" basedir="${build.javadoc}" />
  </target>

  <!-- ======================================
        Section: Checkstyle Integration
       ====================================== -->
  <target name="checkstyle" depends="ivy-retrieve-checkstyle, compile"
      description="Check source code conventions">
    <taskdef resource="checkstyletask.properties">
      <classpath refid="${name}.checkstyle.classpath" />
    </taskdef>

    <mkdir dir="${checkstyle.report.dir}" />
    <checkstyle config="${checkstyle.xml}" failOnViolation="false">
      <fileset dir="${base.src.dir}" includes="**/*.java" />
      <classpath refid="test.classpath"/>
      <formatter type="xml"
        toFile="${checkstyle.report.dir}/checkstyle-errors.xml" />
    </checkstyle>

    <xslt style="${checkstyle.format.xsl}"
      in="${checkstyle.report.dir}/checkstyle-errors.xml"
      out="${checkstyle.report.dir}/checkstyle-errors.html" />
  </target>

  <!-- ======================================
        Section: Maven Support
       ====================================== -->

  <target name="mvn-prep" depends="init, ivy-init"
      description="Creates maven files">
    <!-- prepare for mvn tasks. -->
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>

    <!-- Download maven -->
    <mkdir dir="${build.dir}" />
    <get src="${mvn_repo_url}" dest="${mvn.jar}" usetimestamp="true" />

    <!-- Register mvn tasks -->
    <path id="mvn-ant-task.classpath" path="${mvn.jar}" />
    <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
        uri="urn:maven-artifact-ant"
        classpathref="mvn-ant-task.classpath"/>

    <!-- generate our poms from our ivy files. -->
    <mkdir dir="${mvn.build.dir}" />
    <ivy:makepom ivyfile="ivy/spymemcached.xml" pomfile="${spymemcached.pom}"
        settingsRef="${name}.ivy.settings">
      <mapping conf="default" scope="compile" />
      <mapping conf="runtime" scope="runtime" />
    </ivy:makepom>

    <!-- Change the version in the pom file to reflect our claimed version. -->
    <replaceregexp>
      <regexp pattern="&lt;version&gt;.*&lt;/version&gt;" />
      <substitution expression="&lt;version&gt;${version}&lt;/version&gt;" />
      <fileset dir="${mvn.build.dir}">
        <include name="*.pom" />
      </fileset>
    </replaceregexp>
  </target>

  <target name="mvn-install" depends="init,mvn-prep,jar,srcjars"
      description="Install Spymemcached in local m2 repository">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <artifact:pom id="spymemcached" file="${spymemcached.pom}" />
    <artifact:install file="${build.dir}/${name}-${version}.jar">
      <pom refid="spymemcached" />
      <attach file="${build.dir}/${name}-${version}-sources.jar"
          classifier="sources" />
    </artifact:install>
  </target>

  <!-- ======================================
        Section: Findbugs Integration
       ====================================== -->
  <target name="findbugs" depends="check-for-findbugs, jar"
      description="Run FindBugs">
    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
        classpath="${findbugs.home}/lib/findbugs-ant.jar" />
    <mkdir dir="${findbugs.out.dir}"/>
    <findbugs home="${findbugs.home}" output="xml:withMessages"
        outputFile="${findbugs.output.xml.file}" effort="max"
        jvmargs="-Xms512m -Xmx512m">
      <auxClasspath>
        <path refid="${name}.common.classpath"/>
      </auxClasspath>
      <sourcePath path="${src.dir}" />
      <sourcePath path="${test.dir}" />
      <class location="${build.dir}/${dest.jar}" />
    </findbugs>
    <xslt style="${findbugs.home}/src/xsl/default.xsl"
        in="${findbugs.output.xml.file}"
        out="${findbugs.output.html.file}" />
  </target>

  <target name="warn-findbugs-unset" unless="findbugs.home">
    <fail message="You need to set -Dfindbugs.home=/path/to/findbugs" />
  </target>

  <target name="check-for-findbugs" depends="warn-findbugs-unset">
    <available property="findbugs.present"
        file="${findbugs.home}/lib/findbugs.jar" />
  </target>
  <!-- ======================================
        Section: IDE Integration
       ====================================== -->
  <target name="eclipse" description="Generate Eclipse project"
      depends="init, ivy-retrieve">
    <taskdef name="eclipse" classname="prantl.ant.eclipse.EclipseTask"
        classpath="${lib.dir}/ant-eclipse-1.0-jvm1.2.jar" />
    <eclipse failonerror="true" updatealways="true">
      <project name="${name}" />
      <classpath>
        <source path="${src.dir}" />
        <source path="${test.dir}" />
        <output path="${build.dir}/eclipse-build" />
        <library pathref="${name}.common.classpath" />
      </classpath>
    </eclipse>
  </target>

  <!-- =================================
        Section: Cleaning
       ================================= -->
  <target name="clean" description="Clean the project">
    <delete includeemptydirs="true">
      <fileset dir="${basedir}">
        <exclude name="src/**" />
        <exclude name="ivy/**" />
        <exclude name="etc/**" />
        <exclude name="lib/ant*" />
        <exclude name="xdocs/**" />
        <exclude name="build.xml" />
        <exclude name="config.properties" />
        <exclude name="ivy.xml" />
        <exclude name="LICENSE.txt" />
        <exclude name="README.markdown" />
      </fileset>
    </delete>
  </target>
</project>
<commit_msg>Made package the default target and made it build all jars<commit_after><!--
  Copyright (c) 2009-2011  Couchbase, Inc.

  Permission is hereby granted, free of charge, to any person obtaining a copy of
  this software and associated documentation files (the "Software"), to deal in
  the Software without restriction, including without limitation the rights to
  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  of the Software, and to permit persons to whom the Software is furnished to do
  so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
-->

<project name="spymemcached" default="package"
    xmlns:artifact="urn:maven-artifact-ant"
    xmlns:ivy="antlib:org.apache.ivy.ant">

  <property name="name" value="spymemcached"/>
  <property name="copyright" value="2006-2011 <NAME>, <NAME>" />
  <property name="group" value="spy" />

  <property name="base.src.dir" value="${basedir}/src" />
  <property name="build.dir" value="${basedir}/build" />
  <property name="build.src.dir" value="${build.dir}/src" />
  <property name="etc.dir" value="${basedir}/etc" />
  <property name="lib.dir" value="${basedir}/lib" />
  <property name="src.dir" value="${base.src.dir}/main/java" />
  <property name="test.dir" value="${base.src.dir}/test/java" />
  <property name="script.src.dir" value="${base.src.dir}/scripts" />
  <property name="build.javadoc" location="${build.dir}/docs/" />
  <property name="junit.dir" location="${build.dir}/junit" />

  <property name="dist.dir" value="${basedir}/target" />
  <property name="build.classes" location="${build.dir}/classes"/>

  <property name="git.hash" value="" />

  <!-- ivy properties used -->
  <property name="ivy.settings.dir" value="${basedir}/ivy" />

  <path id="test.classpath">
    <pathelement location="${build.classes}" />
    <fileset dir="${lib.dir}">
      <include name="**/*.jar"/>
    </fileset>
  </path>

  <!-- tests -->
  <property name="build.test" location="${build.dir}/test"/>
  <property name="test.log.dir" location="${build.dir}/test/logs"/>
  <property name="build.test.classes" location="${build.test}/classes" />

  <!-- maven -->
  <property name="mvn.build.dir" value="${build.dir}/m2" />
  <property name="spymemcached.pom" value="${mvn.build.dir}/spymemcached.pom" />

  <!-- compilation -->
  <property name="javac.deprecation" value="off"/>
  <property name="javac.debug" value="on"/>
  <property name="build.encoding" value="ISO-8859-1"/>

  <!-- Checking code style -->
  <property name="checkstyle.xml" value="${etc.dir}/checkstyle.xml" />
  <property name="checkstyle.format.xsl" value="${etc.dir}/checkstyle-noframes.xsl" />
  <property name="checkstyle.report.dir" value="${build.dir}/checkstyle" />

  <!-- static analysis -->
  <property name="findbugs.out.dir" value="${build.dir}/findbugs" />
  <property name="findbugs.output.xml.file"
      value="${findbugs.out.dir}/report.xml" />
  <property name="findbugs.output.html.file"
      value="${findbugs.out.dir}/report.html" />

  <!-- Ivy-based dependency resolution -->
  <property name="ivy.dir" location="${basedir}/ivy" />
  <property name="ivysettings.xml" location="${ivy.dir}/ivysettings.xml"/>
  <loadproperties srcfile="${ivy.dir}/libraries.properties"/>
  <property name="ivy.jar" location="${lib.dir}/ivy-${ivy.version}.jar"/>
  <property name="ivy_repo_url"
      value="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar" />
  <property name="mvn_repo_url"
      value="http://repo2.maven.org/maven2/org/apache/maven/maven-ant-tasks/${mvn.version}/maven-ant-tasks-${mvn.version}.jar"/>
  <property name="mvn.jar" location="${build.dir}/maven-ant-tasks-${mvn.version}.jar" />
  <property name="build.ivy.dir" location="${build.dir}/ivy" />
  <property name="build.ivy.lib.dir" location="${build.ivy.dir}/lib" />
  <property name="build.ivy.report.dir" location="${build.ivy.dir}/report" />
  <property name="redist.ivy.lib.dir" location="${build.ivy.lib.dir}/${name}/redist"/>

  <!--test related properties -->
  <property name="server.address_v4" value="127.0.0.1"/>
  <property name="server.address_v6" value="::1"/>
  <property name="server.type" value="memcached"/>

  <!--this is the naming policy for artifacts we want pulled down-->
  <property name="ivy.artifact.retrieve.pattern"
      value="${name}/[conf]/[artifact]-[revision](-[classifier]).[ext]"/>

  <!-- paths used for compilation and run  -->
  <path id="lib.path.id">
    <fileset dir="${lib.dir}" />
  </path>
  <path id="run.path.id">
    <path refid="lib.path.id" />
    <path location="${build.dir}" />
  </path>

  <!-- load ant-contrib tasks to get the "if" task. -->
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
      <pathelement location="${basedir}/lib/ant-contrib-1.0b3.jar"/>
    </classpath>
  </taskdef>

  <!-- The classpath for compiling and running Spymemcached -->

  <path id="compile.classpath">
    <pathelement location="${build.classes}"/>
    <path refid="lib.path"/>
    <path refid="${name}.common.classpath"/>
  </path>

  <!-- ======================================
        Section: Initializing
       ====================================== -->
  <target name="init">
  <!-- Path containing third-party libraries deployed directly with spymemcached.
       This does not include anything that Ivy can retrieve for us.
    -->
    <path id="lib.path">
      <fileset dir="${lib.dir}">
        <include name="*.jar" />
      </fileset>
    </path>

    <!-- Classpath for unit tests (superset of compile.classpath) -->
    <path id="test.classpath">
      <pathelement location="${build.test.classes}" />
      <path refid="compile.classpath" />
    </path>
  </target>

  <target name="ivy-probe-antlib" >
    <condition property="ivy.found">
      <typefound uri="antlib:org.apache.ivy.ant" name="cleancache"/>
    </condition>
  </target>

  <target name="ivy-download" unless="offline">
    <mkdir dir="${lib.dir}" />
    <get src="${ivy_repo_url}" dest="${ivy.jar}" usetimestamp="true"/>
  </target>

  <target name="ivy-init-antlib" depends="ivy-download,ivy-probe-antlib"
    unless="ivy.found">
    <typedef uri="antlib:org.apache.ivy.ant" onerror="fail"
      loaderRef="ivyLoader">
      <classpath>
        <pathelement location="${ivy.jar}"/>
      </classpath>
    </typedef>
    <fail >
      <condition >
        <not>
          <typefound uri="antlib:org.apache.ivy.ant" name="cleancache"/>
        </not>
      </condition>
        You need Apache Ivy 2.0 or later from http://ant.apache.org/
        It could not be loaded from ${ivy_repo_url}
    </fail>
  </target>

  <target name="ivy-init" depends="ivy-init-antlib" unless="ivy.configured">
    <ivy:configure settingsid="${name}.ivy.settings" file="${ivysettings.xml}"/>
    <property name="ivy.configured" value="true" />
  </target>

  <!-- ======================================
        Section: Resolving and Retrieving
       ====================================== -->
  <target name="ivy-resolve" depends="ivy-init">
    <ivy:resolve settingsRef="${name}.ivy.settings" conf="common" />
  </target>

  <target name="ivy-retrieve" depends="ivy-resolve">
    <ivy:retrieve settingsRef="${name}.ivy.settings" conf="common"
      pattern="${build.ivy.lib.dir}/${ivy.artifact.retrieve.pattern}" sync="true" />
    <ivy:cachepath pathid="${name}.common.classpath" conf="common" />
  </target>

  <!-- retrieve ivy-managed artifacts for checkstyle -->
  <target name="ivy-resolve-checkstyle" depends="ivy-init">
    <ivy:resolve settingsRef="${name}.ivy.settings" conf="checkstyle" />
  </target>

  <target name="ivy-retrieve-checkstyle" depends="ivy-resolve-checkstyle">
    <ivy:retrieve settingsRef="${name}.ivy.settings"
      pattern="${build.ivy.lib.dir}/${ivy.artifact.retrieve.pattern}" sync="true" />
    <ivy:cachepath pathid="${name}.checkstyle.classpath" conf="checkstyle" />
  </target>

  <!-- retrieve ivy-managed artifacts for checkstyle -->
  <target name="ivy-resolve-findbugs" depends="ivy-init">
    <ivy:resolve settingsRef="${name}.ivy.settings" conf="findbugs" />
  </target>

  <target name="ivy-retrieve-findbugs" depends="ivy-resolve-findbugs">
    <ivy:retrieve settingsRef="${name}.ivy.settings"
      pattern="${build.ivy.lib.dir}/${ivy.artifact.retrieve.pattern}" sync="true" />
    <ivy:cachepath pathid="${name}.findbugs.classpath" conf="findbugs" />
  </target>

  <!-- ======================================
        Section: Testing and Reporting
       ====================================== -->
  <target name="report" depends="ivy-retrieve"
      description="Generates a report of dependencies">
    <ivy:report todir="${build.dir}"/>
  </target>

  <target name="test" depends="compile, compile-test"
      description="Run Spymemcached unit tests">
    <echo>Testing against ${server.type}</echo>
    <echo>IPV4 address ${server.address_v4}</echo>
    <echo>IPV6 address ${server.address_v6}</echo>
    <delete dir="${junit.dir}"/>
    <mkdir  dir="${junit.dir}/data"/>
    <if>
      <equals arg1="${server.type}" arg2="memcached"/>
      <then>
        <junit fork="yes" timeout="60000" failureproperty="junit.failure">
          <batchtest todir="${junit.dir}/data" fork="yes">
            <fileset dir="${test.dir}">
              <include name="**/*Test.java"/>
              <exclude name="**/VBucketMemcachedClientTest.java"/>
              <exclude name="**/BucketMonitorTest.java"/>
              <exclude name="**/ConfigurationProviderHTTPTest.java"/>
              <exclude name="**/CouchbaseClientTest.java"/>
              <exclude name="**/MembaseClientTest.java"/>
            </fileset>
          <formatter type="xml"/>
          </batchtest>
          <jvmarg value="-ea" />
          <sysproperty key="server.address_v4" value="${server.address_v4}"/>
          <sysproperty key="server.address_v6" value="${server.address_v6}"/>
          <sysproperty key="server.type" value="${server.type}"/>
          <formatter type="plain" usefile="false" />
          <classpath refid="test.classpath" />
        </junit>
      </then>
    </if>
    <if>
      <equals arg1="${server.type}" arg2="membase"/>
        <then>
          <junit fork="yes" timeout="60000" failureproperty="junit.failure">
            <batchtest todir="${junit.dir}/data" fork="yes">
              <fileset dir="${test.dir}">
              <include name="**/*Test.java"/>
              <exclude name="**/CouchbaseClientTest.java"/>
            </fileset>
          <formatter type="xml"/>
          </batchtest>
          <jvmarg value="-ea" />
          <sysproperty key="server.address_v4" value="${server.address_v4}"/>
          <sysproperty key="server.address_v6" value="${server.address_v6}"/>
          <sysproperty key="server.type" value="${server.type}"/>
          <formatter type="plain" usefile="false" />
          <classpath refid="test.classpath" />
        </junit>
      </then>
    </if>
    <if>
      <equals arg1="${server.type}" arg2="couchbase"/>
        <then>
          <junit fork="yes" timeout="60000" failureproperty="junit.failure">
            <batchtest todir="${junit.dir}/data" fork="yes">
              <fileset dir="${test.dir}">
              <include name="**/*Test.java"/>
            </fileset>
          <formatter type="xml"/>
          </batchtest>
          <jvmarg value="-ea" />
          <sysproperty key="server.address_v4" value="${server.address_v4}"/>
          <sysproperty key="server.address_v6" value="${server.address_v6}"/>
          <sysproperty key="server.type" value="${server.type}"/>
          <formatter type="plain" usefile="false" />
          <classpath refid="test.classpath" />
        </junit>
      </then>
    </if>
    <mkdir  dir="${junit.dir}/tmp"/>
    <junitreport todir="${junit.dir}/tmp">
      <fileset dir="${junit.dir}/data"/>
      <report todir="${junit.dir}"/>
    </junitreport>
    <delete  dir="${junit.dir}/tmp"/>
    <fail if="junit.failure" message="Unit test(s) failed.  See reports!"/>
  </target>

    <target name="junitreport">
        <mkdir dir="${junit.out.dir.html}"/>
        <junitreport todir="${junit.out.dir.html}">
            <fileset dir="${junit.out.dir.xml}">
                <include name="*.xml"/>
            </fileset>
            <report format="frames" todir="${junit.out.dir.html}"/>
        </junitreport>
    </target>

  <target name="compile-test" depends="compile"
      description="Compile test classes">
    <mkdir dir="${build.test.classes}" />
    <javac
        encoding="${build.encoding}"
        srcdir="${test.dir}"
        includes="**/*.java"
        destdir="${build.test.classes}"
        debug="${javac.debug}">
      <classpath>
        <path refid="test.classpath"/>
      </classpath>
    </javac>
  </target>

  <!-- =======================================
        Section: Documentation Generation
       ======================================= -->

  <target name="javadoc-uptodate" depends="init">
    <uptodate property="javadoc.is.uptodate">
    <srcfiles dir="${src.dir}">
        <include name="**/*.java" />
        <include name="**/*.html" />
      </srcfiles>
      <mapper type="merge" to="${build.javadoc}/index.html" />
    </uptodate>
  </target>

  <target name="docs" description="Build javadoc"
      depends="init,javadoc-uptodate,compile" unless="javadoc.is.uptodate">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <mkdir dir="${build.javadoc}" />
    <exec executable="date" outputproperty="year">
      <arg value="+%Y" />
    </exec>
    <javadoc
      packagenames="src"
      sourcepath="${src.dir}"
      destdir="${build.javadoc}"
      author="true"
      version="true"
      use="true"
      windowtitle="${name} ${version} API"
      doctitle="${name} ${version} API"
      bottom="Copyright &amp;copy; 2006-2009 <NAME>, 2009-2011 Couchbase, Inc.">
      <packageset dir="${src.dir}">
        <include name="**" />
      </packageset>
      <classpath>
        <path refid="${name}.common.classpath" />
      </classpath>
    </javadoc>
  </target>

  <target name="docsjar" depends="docs"
      description="Create the documentation jar">
    <zip destfile="${build.dir}/${name}-${version}-javadoc.jar"
        basedir="${build.javadoc}" />
  </target>

  <!-- =======================================
        Section: Compiling and Packaging
       ======================================= -->

  <target name="gen-version" depends="init">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <exec executable="${script.src.dir}/write-version-info.sh"
        dir="${basedir}" failonerror="true">
      <arg value="${build.dir}" />
      <arg value="${version}" />
      <arg value="${git.hash}" />
    </exec>
  </target>

  <target name="compile" depends="ivy-init, gen-version, ivy-retrieve"
      description="Compile and run the project">
    <mkdir dir="${build.classes}" />
    <javac
        encoding="${build.encoding}"
        srcdir="${src.dir}"
        includes="**/*.java"
        destdir="${build.classes}"
        debug="${javac.debug}"
        deprecation="${javac.deprecation}">
      <classpath refid="${name}.common.classpath" />
    </javac>

    <javac
        encoding="${build.encoding}"
        srcdir="${build.src.dir}"
        includes="**/*.java"
        destdir="${build.classes}"
        debug="${javac.debug}"
        deprecation="${javac.deprecation}">
      <classpath refid="${name}.common.classpath"/>
    </javac>
    <move file="${build.src.dir}/net/spy/memcached/changelog.txt"
        tofile="${build.classes}/net/spy/memcached/changelog.txt" />
  </target>

  <target name="srcjar" depends="init,jar"
      description="Create source jars">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <mkdir dir="${build.dir}" />
    <jar jarfile="${build.dir}/${name}-${version}-sources.jar">
      <fileset dir="${src.dir}" />
      <fileset dir="${build.src.dir}" />
    </jar>
    <jar jarfile="${build.dir}/${name}-${version}-test-sources.jar">
      <fileset dir="${test.dir}" />
    </jar>
  </target>

  <target name="jar" depends="compile" description="Creates a jar file for the plugin">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <jar jarfile="${build.dir}/${name}-${version}.jar" basedir="${build.classes}">
      <manifest>
        <attribute name="Implementation-Title" value="java memcached client" />
        <attribute name="Implementation-Version" value="${version}" />
        <attribute name="Implementation-Vendor" value="${copyright}" />
        <attribute name="Copyright" value="${copyright}" />
        <attribute name="Main-Class" value="net.spy.memcached.BuildInfo" />
      </manifest>
    </jar>
  </target>

  <target name="package" depends="jar,srcjar,docsjar"
      description="Packages files for distribution"/>

  <!-- ======================================
        Section: Checkstyle Integration
       ====================================== -->
  <target name="checkstyle" depends="ivy-retrieve-checkstyle, compile"
      description="Check source code conventions">
    <taskdef resource="checkstyletask.properties">
      <classpath refid="${name}.checkstyle.classpath" />
    </taskdef>

    <mkdir dir="${checkstyle.report.dir}" />
    <checkstyle config="${checkstyle.xml}" failOnViolation="false">
      <fileset dir="${base.src.dir}" includes="**/*.java" />
      <classpath refid="test.classpath"/>
      <formatter type="xml"
        toFile="${checkstyle.report.dir}/checkstyle-errors.xml" />
    </checkstyle>

    <xslt style="${checkstyle.format.xsl}"
      in="${checkstyle.report.dir}/checkstyle-errors.xml"
      out="${checkstyle.report.dir}/checkstyle-errors.html" />
  </target>

  <!-- ======================================
        Section: Maven Support
       ====================================== -->

  <target name="mvn-prep" depends="init, ivy-init"
      description="Creates maven files">
    <!-- prepare for mvn tasks. -->
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>

    <!-- Download maven -->
    <mkdir dir="${build.dir}" />
    <get src="${mvn_repo_url}" dest="${mvn.jar}" usetimestamp="true" />

    <!-- Register mvn tasks -->
    <path id="mvn-ant-task.classpath" path="${mvn.jar}" />
    <typedef resource="org/apache/maven/artifact/ant/antlib.xml"
        uri="urn:maven-artifact-ant"
        classpathref="mvn-ant-task.classpath"/>

    <!-- generate our poms from our ivy files. -->
    <mkdir dir="${mvn.build.dir}" />
    <ivy:makepom ivyfile="ivy/spymemcached.xml" pomfile="${spymemcached.pom}"
        settingsRef="${name}.ivy.settings">
      <mapping conf="default" scope="compile" />
      <mapping conf="runtime" scope="runtime" />
    </ivy:makepom>

    <!-- Change the version in the pom file to reflect our claimed version. -->
    <replaceregexp>
      <regexp pattern="&lt;version&gt;.*&lt;/version&gt;" />
      <substitution expression="&lt;version&gt;${version}&lt;/version&gt;" />
      <fileset dir="${mvn.build.dir}">
        <include name="*.pom" />
      </fileset>
    </replaceregexp>
  </target>

  <target name="mvn-install" depends="jar,srcjar,mvn-prep"
      description="Install Spymemcached in local m2 repository">
    <exec executable="git" outputproperty="version">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <artifact:pom id="spymemcached" file="${spymemcached.pom}" />
    <artifact:install file="${build.dir}/${name}-${version}.jar">
      <pom refid="spymemcached" />
      <attach file="${build.dir}/${name}-${version}-sources.jar"
          classifier="sources" />
    </artifact:install>
  </target>

  <!-- ======================================
        Section: Findbugs Integration
       ====================================== -->
  <target name="findbugs" depends="check-for-findbugs, jar"
      description="Run FindBugs">
    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"
        classpath="${findbugs.home}/lib/findbugs-ant.jar" />
    <mkdir dir="${findbugs.out.dir}"/>
    <findbugs home="${findbugs.home}" output="xml:withMessages"
        outputFile="${findbugs.output.xml.file}" effort="max"
        jvmargs="-Xms512m -Xmx512m">
      <auxClasspath>
        <path refid="${name}.common.classpath"/>
      </auxClasspath>
      <sourcePath path="${src.dir}" />
      <sourcePath path="${test.dir}" />
      <class location="${build.dir}/${dest.jar}" />
    </findbugs>
    <xslt style="${findbugs.home}/src/xsl/default.xsl"
        in="${findbugs.output.xml.file}"
        out="${findbugs.output.html.file}" />
  </target>

  <target name="warn-findbugs-unset" unless="findbugs.home">
    <fail message="You need to set -Dfindbugs.home=/path/to/findbugs" />
  </target>

  <target name="check-for-findbugs" depends="warn-findbugs-unset">
    <available property="findbugs.present"
        file="${findbugs.home}/lib/findbugs.jar" />
  </target>
  <!-- ======================================
        Section: IDE Integration
       ====================================== -->
  <target name="eclipse" description="Generate Eclipse project"
      depends="init, ivy-retrieve">
    <taskdef name="eclipse" classname="prantl.ant.eclipse.EclipseTask"
        classpath="${lib.dir}/ant-eclipse-1.0-jvm1.2.jar" />
    <eclipse failonerror="true" updatealways="true">
      <project name="${name}" />
      <classpath>
        <source path="${src.dir}" />
        <source path="${test.dir}" />
        <output path="${build.dir}/eclipse-build" />
        <library pathref="${name}.common.classpath" />
      </classpath>
    </eclipse>
  </target>

  <!-- =================================
        Section: Cleaning
       ================================= -->
  <target name="clean" description="Clean the project">
    <delete includeemptydirs="true">
      <fileset dir="${basedir}">
        <exclude name="src/**" />
        <exclude name="ivy/**" />
        <exclude name="etc/**" />
        <exclude name="lib/ant*" />
        <exclude name="xdocs/**" />
        <exclude name="build.xml" />
        <exclude name="config.properties" />
        <exclude name="ivy.xml" />
        <exclude name="LICENSE.txt" />
        <exclude name="README.markdown" />
      </fileset>
    </delete>
  </target>
</project>

{'fraction_non_alphanumeric': 0.21936313927307816, 'fraction_numerical': 0.004717486866087702, 'mean_word_length': 3.2200705818477964, 'pattern_counts': {'":': 2, '<': 882, '<?xml version=': 0, '>': 882, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 50}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1000452', 'n_tokens_mistral': 14774, 'n_tokens_neox': 14119, 'n_words': 2610}