<?xml version="1.0"?>

<project name="jar-test" basedir="." default="test1">

  <property name="tmp.jar" location="tmp.jar"/>
  <property name="tmp.dir" location="jartmp"/>
  <property name="tmp.zip" location="tmp.zip"/>
  <property name="tmp1.dir" location="jartmp1"/>
  <property name="tmp2.dir" location="jartmp2"/>

  <target name="test1">
    <jar/>
  </target>

  <target name="test2">
    <jar
    	jarfile="jar.tmp"
    	manifest="none"
    />
  </target>

  <target name="test3">
    <jar
    	destfile="jar.tmp"
	whenempty="format C: /y" 
    />
  </target>

  <target name="test4">
   <jar
    	destfile="${tmp.jar}"
	basedir="."
	includes="jar.xml"
    />
  </target>

  <target name="testNoRecreateWithUpdate">
    <jar
         destfile="${tmp.jar}"
         basedir="."
         includes="jar.xml"
         update="true"
    />
  </target>

  <target name="testRecreateNewerFileSetup" depends="test4">
    <touch file="jar.xml"/>
  </target>

  <target name="testRecreateWithoutUpdateAdditionalFiles">
    <jar
         destfile="${tmp.jar}"
         includes="*.xml"
         basedir="."
    />
  </target>

  <target name="testRecreateWithUpdateAdditionalFiles">
    <jar
         destfile="${tmp.jar}"
         basedir="."
         includes="*.xml"
         update="true"
    />
  </target>

  <target name="testRecreateWithoutUpdateNewerFile">
    <jar
         destfile="${tmp.jar}"
         basedir="."
         includes="jar.xml"
    />
  </target>

  <target name="testRecreateWithUpdateNewerFile">
    <jar
         destfile="${tmp.jar}"
         basedir="."
         includes="jar.xml"
         update="true"
    />
  </target>

  <target name="testManifestStaysIntact">
    <mkdir dir="${tmp.dir}"/>
    <manifest file="${tmp.dir}/manifest">
      <attribute name="Foo" value="bar"/>
    </manifest>
    <jar destfile="${tmp.jar}" basedir="." includes="jar.xml"
         manifest="${tmp.dir}/manifest"/>
    <sleep seconds="3"/>
    <touch file="jar.xml"/>
    <jar destfile="${tmp.jar}" basedir="." includes="jar.xml"
         update="true"/>
    <unjar src="${tmp.jar}" dest="${tmp.dir}"/>
  </target>    

  <target name="testNoRecreateBasedirExcludesWithUpdate">
    <jar
         destfile="${tmp.jar}"
         basedir="."
         includes="j*.xml"
         excludes="java.xml"
         update="true"
    />
  </target>

  <target name="testNoRecreateBasedirExcludesWithoutUpdate">
    <jar
         destfile="${tmp.jar}"
         basedir="."
         includes="j*.xml"
         excludes="java.xml"
    />
  </target>

  <target name="makezip">
    <zip destfile="${tmp.zip}"
         basedir="." includes="j*.xml"/>
  </target>

  <target name="testNoRecreateZipfilesetExcludesWithUpdate"
          depends="makezip">
    <jar destfile="${tmp.jar}"
         update="true">
      <zipfileset src="${tmp.zip}" excludes="java.xml"/>
    </jar>
  </target>

  <target name="testNoRecreateZipfilesetExcludesWithoutUpdate"
          depends="makezip">
    <jar destfile="${tmp.jar}">
      <zipfileset src="${tmp.zip}" excludes="java.xml"/>
    </jar>
  </target>

  <target name="testRecreateZipfilesetWithoutUpdateAdditionalFiles"
          depends="makezip">
    <jar destfile="${tmp.jar}">
      <zipfileset src="${tmp.zip}"/>
    </jar>
  </target>

  <target name="testRecreateZipfilesetWithUpdateAdditionalFiles"
          depends="makezip">
    <jar destfile="${tmp.jar}"
         update="true">
      <zipfileset src="${tmp.zip}"/>
    </jar>
  </target>

  <target name="testRecreateZipfilesetWithoutUpdateNewerFile"
          depends="makezip">
    <jar destfile="${tmp.jar}">
      <zipfileset src="${tmp.zip}" includes="jar.xml"/>
    </jar>
  </target>

  <target name="testRecreateZipfilesetWithUpdateNewerFile"
          depends="makezip">
    <jar destfile="${tmp.jar}"
         update="true">
      <zipfileset src="${tmp.zip}" includes="jar.xml"/>
    </jar>
  </target>

  <target name="cleanup">
    <delete file="${tmp.jar}" />
    <delete dir="${tmp.dir}"/>
    <delete file="${tmp.zip}" />
    <delete dir="${tmp1.dir}"/>
    <delete dir="${tmp2.dir}"/>
  </target>

  <target name="testCreateWithEmptyFilesetSetUp">
    <mkdir dir="${tmp1.dir}"/>
    <mkdir dir="${tmp2.dir}"/>
    <echo file="${tmp2.dir}/foo.txt" message="foo"/>
  </target>

  <target name="testCreateWithEmptyFileset">
    <jar destfile="${tmp.jar}">
      <fileset dir="${tmp1.dir}">
        <include name="**/*.doesNotExist"/>
      </fileset>
      <fileset dir="${tmp2.dir}">
        <include name="**/foo.txt"/>
      </fileset>
    </jar>
  </target>

  <!-- bug 17780 -->
  <target name="testUpdateIfOnlyManifestHasChanged"
          depends="test4">
    <jar destfile="${tmp.jar}" update="true">
      <manifest>
        <attribute name="Foo" value="bar"/>
      </manifest>
    </jar>
    <mkdir dir="${tmp.dir}"/>
    <unzip src="${tmp.jar}" dest="${tmp.dir}"/>
  </target>
</project>
