<?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.
-->
<project name="test" default="new" basedir=".">
  <filterset id="testset.one">
    <filter token="aaaa" value="1111"/>
    <filter token="bbbb" value="2222"/>
  </filterset>
  
  <filterset id="testset.two" beginToken="%" endToken="^">
    <filter token="cccc" value="3333"/>
    <filter token="dddd" value="4444"/>
  </filterset>
  
  <target name="test1">
    <delete file="dest1.txt"/>
    <copy file="filterseta.txt" tofile="dest1.txt">
        <filterset refid="testset.one"/> 
    </copy>
  </target>

  <target name="test2">
    <delete file="dest2.txt"/>
    <copy file="filtersetb.txt" tofile="dest2.txt">
        <filterset refid="testset.two"/> 
    </copy>
  </target>

  <target name="test3">
    <delete file="dest3.txt"/>
    <copy file="filtersetc.txt" tofile="dest3.txt">
        <filterset refid="testset.one"/> 
        <filterset refid="testset.two"/> 
    </copy>
  </target>
  
  <target name="test-nested-filtersets">
    <filterset id="1">
      <filter token="token1" value="value1"/>
    </filterset>
    <filterset id="2">
      <filterset refid="testset.one"/>
    </filterset>
    <filterset id="3">
      <filterset id="4">
        <filter token="token4" value="value4"/>
      </filterset>
    </filterset>
    <filterset id="5">
      <filterset refid="1"/>
    </filterset>
  </target>

  <target name="testFiltersFileElement">
    <copy file="filtersetd.txt" tofile="dest4.txt">
      <filterset>
        <filtersfile file="filtersfile1" />
      </filterset>
    </copy>
    <fail>
      <condition>
        <not>
          <resourcesmatch asText="true">
            <file file="dest4.txt" />
            <string value="FOO BAR @baz@ @blah@" />
          </resourcesmatch>
        </not>
      </condition>
    </fail>
  </target>

  <target name="testFiltersFileAttribute">
    <copy file="filtersetd.txt" tofile="dest5.txt">
      <filterset filtersfile="filtersfile1" />
    </copy>
    <fail>
      <condition>
        <not>
          <resourcesmatch asText="true">
            <file file="dest5.txt" />
            <string value="FOO BAR @baz@ @blah@" />
          </resourcesmatch>
        </not>
      </condition>
    </fail>
  </target>

  <target name="testMultipleFiltersFiles">
    <copy file="filtersetd.txt" tofile="dest6.txt">
      <filterset filtersfile="filtersfile1">
        <filtersfile file="filtersfile2" />
      </filterset>
    </copy>
    <fail>
      <condition>
        <not>
          <resourcesmatch asText="true">
            <file file="dest6.txt" />
            <string value="FOO BAR BAZ @blah@" />
          </resourcesmatch>
        </not>
      </condition>
    </fail>
  </target>

  <target name="testMissingFiltersFile">
    <copy file="filtersetd.txt" tofile="dest7.txt">
      <filterset filtersfile="nonexistentfiltersfile" />
    </copy>
  </target>

  <target name="testAllowMissingFiltersFile">
    <copy file="filtersetd.txt" tofile="dest8.txt">
      <filterset filtersfile="nonexistentfiltersfile"
                 onmissingfiltersfile="ignore" />
    </copy>
    <fail>
      <condition>
        <not>
          <filesmatch file1="filtersetd.txt" file2="dest8.txt" />
        </not>
      </condition>
    </fail>
  </target>

  <target name="cleanup">
    <delete quiet="true">
      <fileset dir="." includes="dest?.txt" />
    </delete>
  </target>

</project>
