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

      http://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
     author: Conor MacNeill -->
<project name="manifest-test" basedir="." default="test1">

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

  <target name="test9">
    <jar file="mftest9.jar">
      <manifest>
        <attribute name="Class-Path" value="fubar"/>
        <section name="Test">
          <attribute name="Name" value="Test"/>
        </section>
      </manifest>
    </jar>
  </target>

  <target name="test10">
    <jar file="mftest10.jar">
      <manifest>
        <attribute value="fubar"/>
      </manifest>
    </jar>
  </target>

  <target name="test11">
    <jar file="mftest11.jar">
      <manifest>
        <attribute name="Test"/>
      </manifest>
    </jar>
  </target>

  <target name="test12">
    <jar file="mftest12.jar">
      <manifest>
        <section>
          <attribute name="TestAttr" value="Test"/>
        </section>
      </manifest>
    </jar>
  </target>

  <target name="test13">
    <jar file="mftest13.jar">
      <manifest>
        <attribute name="Test" value="Test1"/>
        <attribute name="Test" value="Test2"/>
      </manifest>
    </jar>
  </target>

  <target name="test14">
    <jar file="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="mftest14.jar" dest="manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>

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

  <target name="testLongLine">
    <jar file="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="mftestLongLine.jar" dest="manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>

  <target name="testOrder1">
    <jar file="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="mftestOrder1.jar" dest="manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>

  <target name="testOrder2">
    <jar file="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="mftestOrder2.jar" dest="manifests">
      <patternset>
        <include name="META-INF/MANIFEST.MF"/>
      </patternset>
    </unjar>
  </target>
  
  <target name="testReplace">
    <copy file="manifests/test2.mf" toFile="mftest.mf" />
    <manifest file="mftest.mf" />
  </target>

  <target name="testUpdate">
    <copy file="manifests/test2.mf" toFile="mftest.mf" />
    <manifest file="mftest.mf" mode="update">
      <attribute name="Foo" value="Bar" />
    </manifest>

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

  <target name="testFrom">
    <manifest file="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">
    <manifest file="mftestillegalname.mf">
      <attribute name="has blank" value="value"/>
    </manifest>
  </target>

  <target name="testIllegalNameInSection">
    <manifest file="mftestillegalnameinsection.mf">
      <section name="s1">
        <attribute name="has blank" value="value"/>
      </section>
    </manifest>
  </target>

  <target name="testIllegalNameBegin">
    <manifest file="mftestillegalnamebegin.mf">
      <attribute name="-name" value="value"/>
    </manifest>
  </target>

  <target name="testIllegalName2">
    <manifest file="mftestillegalnamebegin.mf">
      <attribute name="has.point" value="value"/>
    </manifest>
  </target>

  <target name="testIllegalName3">
    <manifest file="mftestillegalnamebegin.mf">
      <attribute name="has*star" value="value"/>
    </manifest>
  </target>

  <target name="clean">
    <delete>
      <fileset dir="." includes="mftest*"/>
    </delete>
    <delete dir="manifests/META-INF"/>
  </target>
</project>
