<!--
  Copyright (c) 2009-2012  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">

  <!-- 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>

  <property name="name" value="spymemcached"/>
  <property name="copyright" value="2006-2011 Dustin Sallings, Matt Ingenthron" />
  <property name="group" value="net.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="build.javadoc.test" location="${build.dir}/testdocs/" />
  <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="" />
  <var name="version" value="no-version"/>

  <!-- ivy properties used -->
  <property name="ivy.settings.dir" value="${basedir}/ivy" />
  <property name="ivy.pom.url"
      value="http://www.couchbase.org/code/couchbase/java" />
  <property name="ivy.pom.groupId" value="net.spy" />
  <property name="ivy.pom.description"
   value = "A client library for memcached."/>
  <property name="ivy.pom.name" value="Spymemcached" />
  <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}" />

  <!-- 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.port_number" value="11211"/>
  <property name="test.type" value="unit"/>

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

  <!-- maven central repo urls -->
  <property name="maven-snapshots-repository-id" value="sonatype-nexus-snapshots" />
  <property name="maven-snapshots-repository-url" value="https://oss.sonatype.org/content/repositories/snapshots/" />
  <property name="maven-staging-repository-id" value="sonatype-nexus-staging" />
  <property name="maven-staging-repository-url" value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />

  <!-- 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>

  <!-- 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>IPV4 address ${server.address_v4}</echo>
    <echo>IPV6 address ${server.address_v6}</echo>
    <echo>Port Number ${server.port_number}</echo>
    <echo>Test Type(unit|ci) ${test.type}</echo>
    <delete dir="${junit.dir}"/>
    <mkdir  dir="${junit.dir}/data"/>
    <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.port_number" value="${server.port_number}"/>
      <sysproperty key="test.type" value="${test.type}"/>
      <formatter type="plain" usefile="false" />
      <classpath refid="test.classpath" />
    </junit>
    <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}"
        includeantruntime="false"
        target="1.6"
        source="1.6">
      <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>
      <srcfiles dir="${test.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" >
    <mkdir dir="${build.javadoc}" />
    <mkdir dir="${build.javadoc.test}" />
    <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 Dustin Sallings, 2009-2013 Couchbase, Inc.">
      <packageset dir="${src.dir}">
        <include name="**" />
      </packageset>
      <classpath>
        <path refid="${name}.common.classpath" />
      </classpath>
    </javadoc>
    <javadoc
      packagenames="src"
      sourcepath="${test.dir}"
      destdir="${build.javadoc.test}"
      author="true"
      version="true"
      use="true"
      windowtitle="${name}-test ${version} API"
      doctitle="${name}-test ${version} API"
      bottom="Copyright &amp;copy; 2006-2009 Dustin Sallings, 2009-2013 Couchbase, Inc.">
      <packageset dir="${test.dir}">
        <include name="**" />
      </packageset>
      <classpath refid="test.classpath" />
    </javadoc>
  </target>

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

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

  <target name="gen-version" depends="init">
    <exec executable="git" resultproperty="err" outputproperty="result">
      <arg value="describe" />
      <arg value="--abbrev=0" />
    </exec>
    <if>
      <equals arg1="${err}" arg2="0"/>
      <then>
        <var name="version" value="${result}"/>
      </then>
    </if>
    <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}"
        includeantruntime="false"
        target="1.6"
        source="1.6">
      <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}"
        includeantruntime="false"
        target="1.6"
        source="1.6">
      <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">
    <mkdir dir="${build.dir}/sources" />
    <jar jarfile="${build.dir}/sources/${name}-${version}.jar">
      <fileset dir="${src.dir}" />
      <fileset dir="${build.src.dir}" />
    </jar>
    <jar jarfile="${build.dir}/sources/${name}-test-${version}.jar">
      <fileset dir="${test.dir}" />
    </jar>
  </target>

  <target name="jar" depends="compile,compile-test" description="Creates a jar file for the library">
    <mkdir dir="${build.dir}/jars" />
    <jar jarfile="${build.dir}/jars/${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>
    <jar jarfile="${build.dir}/jars/${name}-test-${version}.jar" basedir="${build.test.classes}"/>
  </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-download" unless="offline">
    <mkdir dir="${build.dir}" />
    <get src="${mvn_repo_url}" dest="${mvn.jar}" usetimestamp="true" />
  </target>

  <target name="mvn-prep" depends="ivy-init, gen-version, mvn-download"
      description="Creates maven files">
    <!-- prepare for mvn tasks. -->
    <property name="spymemcached.pom" value="${mvn.build.dir}/poms/spymemcached-${version}.pom" />
    <property name="spymemcached-test.pom" value="${mvn.build.dir}/poms/spymemcached-test-${version}.pom" />

    <!-- 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}/poms" />
    <ivy:makepom ivyfile="ivy/spymemcached.xml"
        pomfile="${spymemcached.pom}"
        templatefile="ivy/pom.template.xml"
        settingsRef="${name}.ivy.settings">
      <mapping conf="default" scope="compile" />
      <mapping conf="runtime" scope="runtime" />
      <dependency group="log4j" artifact="log4j" version="${log4j.version}" optional="true" />
      <dependency group="org.slf4j" artifact="slf4j-api" version="${slf4j.version}" optional="true" />
      <dependency group="org.springframework" artifact="spring-beans" version="${spring-beans.version}" optional="true" />
      <dependency group="com.codahale.metrics" artifact="metrics-core" version="${codahale.metrics.version}" optional="true" />
    </ivy:makepom>

    <ivy:makepom ivyfile="ivy/spymemcached-test.xml"
        pomfile="${spymemcached-test.pom}"
        templatefile="ivy/pom.template.xml"
        settingsRef="${name}.ivy.settings">
      <mapping conf="default" scope="compile" />
      <mapping conf="runtime" scope="runtime" />
      <dependency group="log4j" artifact="log4j" version="${log4j.version}" optional="true" />
      <dependency group="org.slf4j" artifact="slf4j-api" version="${slf4j.version}" optional="true" />
      <dependency group="org.springframework" artifact="spring-beans" version="${spring-beans.version}" optional="true" />
      <dependency group="com.codahale.metrics" artifact="metrics-core" version="${codahale.metrics.version}" />
   </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}/poms">
        <include name="*.pom" />
      </fileset>
    </replaceregexp>
  </target>

  <target name="mvn-install" depends="jar,srcjar,package,mvn-prep"
      description="Install Spymemcached in local m2 repository">
    <!-- @todo: change to use ivy publish -->
    <artifact:pom id="spymemcached" file="${spymemcached.pom}" />
    <artifact:install file="${build.dir}/jars/${name}-${version}.jar">
      <pom refid="${name}" />
      <attach file="${build.dir}/sources/${name}-${version}.jar"
          classifier="sources" />
      <attach file="${build.dir}/javadocs/${name}-${version}.jar"
          classifier="javadoc" />
    </artifact:install>
    <artifact:pom id="spymemcached-test" file="${spymemcached-test.pom}" />
      <artifact:install file="${build.dir}/jars/${name}-test-${version}.jar">
        <pom refid="${name}-test" />
        <attach file="${build.dir}/sources/${name}-test-${version}.jar"
          classifier="sources" />
        <attach file="${build.dir}/javadocs/${name}-test-${version}.jar"
          classifier="javadoc" />
    </artifact:install>
  </target>

  <target name="mvn-deploy" depends="mvn-install" description="deploy snapshot version to maven snapshot repository">
    <artifact:mvn>
        <arg value="org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy-file" />
        <arg value="-Durl=${maven-snapshots-repository-url}" />
        <arg value="-DrepositoryId=${maven-snapshots-repository-id}" />
        <arg value="-DpomFile=${spymemcached.pom}" />
        <arg value="-Dfile=${build.dir}/jars/${name}-${version}.jar" />
    </artifact:mvn>
  </target>

  <target name="mvn-stage" depends="mvn-install" description="deploy release version to maven staging repository">
    <!-- sign and deploy the main artifact -->
    <artifact:mvn>
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=${spymemcached.pom}" />
            <arg value="-Dfile=${build.dir}/jars/${name}-${version}.jar" />
            <arg value="-Pgpg" />
    </artifact:mvn>

    <!-- sign and deploy the sources artifact -->
    <artifact:mvn>
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=${spymemcached.pom}" />
            <arg value="-Dfile=${build.dir}/sources/${name}-${version}.jar" />
            <arg value="-Dclassifier=sources" />
            <arg value="-Pgpg" />
    </artifact:mvn>

    <!-- sign and deploy the javadoc artifact -->
    <artifact:mvn>
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=${spymemcached.pom}" />
            <arg value="-Dfile=${build.dir}/javadocs/${name}-${version}.jar" />
            <arg value="-Dclassifier=javadoc" />
            <arg value="-Pgpg" />
    </artifact:mvn>

        <!-- sign and deploy the main artifact -->
    <artifact:mvn>
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=${spymemcached-test.pom}" />
            <arg value="-Dfile=${build.dir}/jars/${name}-test-${version}.jar" />
            <arg value="-Pgpg" />
    </artifact:mvn>

    <!-- sign and deploy the sources artifact -->
    <artifact:mvn>
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=${spymemcached-test.pom}" />
            <arg value="-Dfile=${build.dir}/sources/${name}-test-${version}.jar" />
            <arg value="-Dclassifier=sources" />
            <arg value="-Pgpg" />
    </artifact:mvn>

    <!-- sign and deploy the javadoc artifact -->
    <artifact:mvn>
            <arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
            <arg value="-Durl=${maven-staging-repository-url}" />
            <arg value="-DrepositoryId=${maven-staging-repository-id}" />
            <arg value="-DpomFile=${spymemcached-test.pom}" />
            <arg value="-Dfile=${build.dir}/javadocs/${name}-test-${version}.jar" />
            <arg value="-Dclassifier=javadoc" />
            <arg value="-Pgpg" />
    </artifact:mvn>
  </target>

  <!-- ======================================
        Section: Stage Maven locally
       ====================================== -->
  <target name="mvn-stage-local" depends="package,ivy-init,mvn-prep" description="publish jar/source to maven repo mounted at ~/mvn-stage">
    <ivy:publish resolver="share-m2" forcedeliver="true" overwrite="true" publishivy="false">
      <artifacts pattern="build/[type]s/[artifact]-[revision].[ext]" />
    </ivy:publish>
  </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" />
        <exclude name=".gitreview" />
	<exclude name=".git/**" />
	<exclude name=".idea/**" />
	<exclude name="pom.xml" />
      </fileset>
    </delete>
  </target>
</project>
