<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<!-- Manifest tests build file -->
<project name="manifest-test" basedir="." default="test1">
  <import file="../buildfiletest-base.xml"/>

  <target name="setUp">
    <mkdir dir="${output}/manifests"/>
  </target>

  <target name="test1" depends="setUp">
    <jar file="${output}/mftest1.jar" manifest="manifests/test1.mf"/>
    <unjar src="${output}/mftest1.jar" dest="${output}/manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>
  
  <target name="test2" depends="setUp">
    <jar file="${output}/mftest2.jar" manifest="manifests/test2.mf"/>
    <unjar src="${output}/mftest2.jar" dest="${output}/manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>
  
  <target name="test3" depends="setUp">
    <jar file="${output}/mftest3.jar" manifest="manifests/test3.mf"/>
  </target>
  
  <target name="test4" depends="setUp">
    <jar file="${output}/mftest4.jar" manifest="manifests/test4.mf"/>
  </target>
  
  <target name="test5" depends="setUp">
    <jar file="${output}/mftest5.jar" manifest="manifests/test5.mf"/>
  </target>
  
  <target name="test6" depends="setUp">
    <jar file="${output}/mftest6.jar" manifest="manifests/test6.mf"/>
  </target>
  
  <target name="test7" depends="setUp">
    <jar file="${output}/mftest7.jar" manifest="manifests/test7.mf"/>
  </target>
  
  <target name="test8" depends="setUp">
    <jar file="${output}/mftest8.jar">
      <manifest>
        <attribute name="Class-Path" value="fubar"/>
        <section name="Test">
          <attribute name="TestAttr" value="Test"/>
        </section>
      </manifest>
    </jar>
    <unjar src="${output}/mftest8.jar" dest="${output}/manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>

  <target name="test9" depends="setUp">
    <jar file="${output}/mftest9.jar">
      <manifest>
        <attribute name="Class-Path" value="fubar"/>
        <section name="Test">
          <attribute name="Name" value="Test"/>
        </section>
      </manifest>
    </jar>
  </target>

  <target name="test10" depends="setUp">
    <jar file="${output}/mftest10.jar">
      <manifest>
        <attribute value="fubar"/>
      </manifest>
    </jar>
  </target>

  <target name="test11" depends="setUp">
    <jar file="${output}/mftest11.jar">
      <manifest>
        <attribute name="Test"/>
      </manifest>
    </jar>
  </target>

  <target name="test12" depends="setUp">
    <jar file="${output}/mftest12.jar">
      <manifest>
        <section>
          <attribute name="TestAttr" value="Test"/>
        </section>
      </manifest>
    </jar>
  </target>

  <target name="test13" depends="setUp">
    <jar file="${output}/mftest13.jar">
      <manifest>
        <attribute name="Test" value="Test1"/>
        <attribute name="Test" value="Test2"/>
      </manifest>
    </jar>
  </target>

  <target name="test14" depends="setUp">
    <jar file="${output}/mftest14.jar">
      <manifest>
        <attribute name="Class-path" value="Test1"/>
        <attribute name="Class-path" value="Test2"/>
        <attribute name="Class-Path" value="Test3"/>
        <attribute name="class-Path" value="Test4"/>
      </manifest>
    </jar>
    <unjar src="${output}/mftest14.jar" dest="${output}/manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>

  <target name="testNoFile">
    <manifest />
  </target>

  <target name="testLongLine" depends="setUp">
    <jar file="${output}/mftestLongLine.jar">
      <manifest>
        <attribute name="Class-path" 
                   value="${test.longline}"/>
        <attribute name="${test.long68name}" value="${test.value}" />
        <attribute name="${test.long70name}" value="${test.value}" />
        <attribute name="${test.notlongname}" value="${test.value}" />
      </manifest>
    </jar>
    <unjar src="${output}/mftestLongLine.jar" dest="${output}/manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>

  <target name="testOrder1" depends="setUp">
    <jar file="${output}/mftestOrder1.jar">
      <manifest>
        <section name="Test1">
          <attribute name="TestAttr1" value="Test1"/>
          <attribute name="TestAttr2" value="Test2"/>
        </section>
        <section name="Test2">
          <attribute name="TestAttrx" value="Testx"/>
        </section>
      </manifest>
    </jar>
    <unjar src="${output}/mftestOrder1.jar" dest="${output}/manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>

  <target name="testOrder2" depends="setUp">
    <jar file="${output}/mftestOrder2.jar">
      <manifest>
        <section name="Test2">
          <attribute name="TestAttrx" value="Testx"/>
        </section>
        <section name="Test1">
          <attribute name="TestAttr2" value="Test2"/>
          <attribute name="TestAttr1" value="Test1"/>
        </section>
      </manifest>
    </jar>
    <unjar src="${output}/mftestOrder2.jar" dest="${output}/manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>
  
  <target name="testReplace" depends="setUp">
    <copy file="manifests/test2.mf" toFile="${output}/mftest.mf" />
    <manifest file="${output}/mftest.mf" />
  </target>

  <target name="testUpdate" depends="setUp">
    <copy file="manifests/test2.mf" toFile="${output}/mftest.mf" />
    <manifest file="${output}/mftest.mf" mode="update">
      <attribute name="Foo" value="Bar" />
    </manifest>

    <copy file="manifests/test2.mf" toFile="${output}/mftest2.mf" />
    <manifest file="${output}/mftest2.mf" mode="update">
      <section name="Test">
        <attribute name="Foo" value="Bar" />
      </section>
    </manifest>
    <manifest file="${output}/mftest2.mf" mode="update">
      <section name="Test">
        <attribute name="Foo" value="Baz" />
      </section>
    </manifest>
  </target>

  <target name="testFrom" depends="setUp">
    <manifest file="${output}/mftestfrom.mf" >
      <section name="Test">
        <attribute name="before" value="before" />
        <attribute name="From" value="illegal"/>
        <attribute name="after" value="after" />
      </section>
    </manifest>
  </target>
  
  <target name="testIllegalName" depends="setUp">
    <manifest file="${output}/mftestillegalname.mf">
      <attribute name="has blank" value="value"/>
    </manifest>
  </target>

  <target name="testIllegalNameInSection" depends="setUp">
    <manifest file="${output}/mftestillegalnameinsection.mf">
      <section name="s1">
        <attribute name="has blank" value="value"/>
      </section>
    </manifest>
  </target>

  <target name="testIllegalNameBegin" depends="setUp">
    <manifest file="${output}/mftestillegalnamebegin.mf">
      <attribute name="-name" value="value"/>
    </manifest>
  </target>

  <target name="testIllegalName2" depends="setUp">
    <manifest file="${output}/mftestillegalnamebegin.mf">
      <attribute name="has.point" value="value"/>
    </manifest>
  </target>

  <target name="testIllegalName3" depends="setUp">
    <manifest file="${output}/mftestillegalnamebegin.mf">
      <attribute name="has*star" value="value"/>
    </manifest>
  </target>
</project>
