| <?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 default="cleanup" basedir="."> |
| |
| <target name="init"> |
| <mkdir dir="result" /> |
| </target> |
| |
| <target name="cleanup"> |
| <delete dir="result"/> |
| </target> |
| |
| <target name="tokenfilter"> |
| <copy file="input/linecontains.test" tofile="result/file1"> |
| <filterchain> |
| <tokenfilter/> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <target name="trimignore"> |
| <concat destfile="result/input"> |
| Hello |
| |
| World |
| </concat> |
| <copy file="result/input" tofile="result/output" overwrite="yes"> |
| <filterchain> |
| <tokenfilter delimoutput="-"> |
| <trim/> |
| <ignoreblank/> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| <concat> |
| <filelist dir="." files="result/output"/> |
| </concat> |
| </target> |
| |
| <target name="trimfile"> |
| <concat destfile="result/trimfile"> |
| This is the contents of the trimmed file. |
| This is the second line. |
| <filterchain> |
| <trim byline="no"/> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="trimfilebyline"> |
| <concat destfile="result/trimfilebyline"> |
| This is the contents of the trimmed file. |
| This is the second line. |
| <filterchain> |
| <trim/> |
| <tokenfilter delimoutput="\n"/> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="filterreplacestring"> |
| <concat destfile="result/filterreplacestring"> |
| This is foo bar |
| <filterchain> |
| <replacestring from="foo" to="the"/> |
| <replacestring from="bar" to="moon"/> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="filterreplacestrings"> |
| <concat> |
| foo foo foo |
| <filterchain> |
| <replacestring from="foo" to="bar"/> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="stringtokenizer"> |
| <concat destfile="result/input"> |
| This is a number |
| of words |
| </concat> |
| <copy file="result/input" tofile="result/output" overwrite="yes"> |
| <filterchain> |
| <tokenfilter delimoutput="#"> |
| <stringtokenizer/> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| <concat> |
| <filelist dir="." files="result/output"/> |
| </concat> |
| </target> |
| |
| <target name="unixlineoutput"> |
| <concat destfile="result/unixlineoutput"> |
| This is a number |
| of words |
| <filterchain> |
| <tokenfilter delimoutput="\n"> |
| <stringtokenizer/> |
| </tokenfilter> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="doslineoutput"> |
| <concat destfile="result/doslineoutput"> |
| This is a number |
| of words |
| <filterchain> |
| <tokenfilter delimoutput="\r\n"> |
| <stringtokenizer/> |
| </tokenfilter> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="filetokenizer"> |
| <concat destfile="result/input"> |
| This is a number |
| of words |
| </concat> |
| <copy file="result/input" tofile="result/filetokenizer"> |
| <filterchain> |
| <tokenfilter> |
| <filetokenizer/> |
| <trim/> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <target name="replacestring"> |
| <concat destfile="result/replacestring"> |
| this is the sun |
| <filterchain> |
| <tokenfilter> |
| <replacestring from="sun" to="moon"/> |
| </tokenfilter> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="replacestrings"> |
| <concat> |
| foo foo foo |
| <filterchain> |
| <tokenfilter> |
| <replacestring from="foo" to="bar"/> |
| </tokenfilter> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="containsstring"> |
| <concat destfile="result/input"> |
| this is a line contains foo |
| this line does not |
| </concat> |
| <copy file="result/input" tofile="result/containsstring"> |
| <filterchain> |
| <tokenfilter> |
| <containsstring contains="foo"/> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <!-- need to check for existance of regex --> |
| <target name="replaceregex"> |
| <concat destfile="result/input"> |
| hello Hello HELLO hello |
| cat Cat cat |
| Sun Sun Sun |
| WhiteSpace tab |
| This is a line with digits - 1234 -- there |
| </concat> |
| <copy file="result/input" tofile="result/replaceregex"> |
| <filterchain> |
| <tokenfilter> |
| <replaceregex pattern="hello" replace="world" flags="gi"/> |
| <replaceregex pattern="cat" replace="dog" flags="g"/> |
| <replaceregex pattern="sun" replace="moon" flags="i"/> |
| <replaceregex pattern="WhiteSpace[ \t]+tab" |
| replace="found WhiteSpace"/> |
| <replaceregex pattern="This is a line with dig.* ([0-9]+).*" |
| replace="Found digits [\1]"/> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <target name="filterreplaceregex"> |
| <concat destfile="result/filterreplaceregex"> |
| hello Hello HELLO hello |
| <filterchain> |
| <replaceregex pattern="hello" replace="world" flags="gi"/> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="dollermatch"> |
| <concat> |
| @hello@ |
| <filterchain> |
| <replaceregex pattern="@([^@]*)@" replace="${\1}"/> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <!-- need to check for existance of regex --> |
| <target name="containsregex"> |
| <concat destfile="result/input"> |
| hello world |
| this is the moon |
| World here |
| </concat> |
| <copy file="result/input" tofile="result/containsregex"> |
| <filterchain> |
| <tokenfilter> |
| <containsregex pattern="(hello|world)" flags="i"/> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <target name="filtercontainsregex"> |
| <concat destfile="result/filtercontainsregex"> |
| hello world |
| this is the moon |
| World here |
| <filterchain> |
| <tokenfilter> |
| <containsregex pattern="(hello|world)" flags="i"/> |
| </tokenfilter> |
| </filterchain> |
| </concat> |
| </target> |
| |
| |
| <!-- need to check for existance of regex --> |
| <target name="containsregex2"> |
| <concat destfile="result/input"> |
| SUITE(TestSuite, bits); |
| here |
| </concat> |
| <copy file="result/input" tofile="result/containsregex2"> |
| <filterchain> |
| <tokenfilter> |
| <containsregex |
| pattern="^ *SUITE\(.*,\s*(.*)\s*\).*" |
| replace="void register_\1();"/> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <target name="deletecharacters"> |
| <concat destfile="result/deletechars"> |
| This is some ### s |
| some **** |
| <filterchain> |
| <tokenfilter> |
| <deletecharacters chars="#"/> |
| </tokenfilter> |
| <deletecharacters chars="*"/> |
| </filterchain> |
| </concat> |
| </target> |
| |
| <target name="scriptfilter"> |
| <concat destfile="result/input"> |
| hello world |
| </concat> |
| <copy file="result/input" tofile="result/scriptfilter"> |
| <filterchain> |
| <tokenfilter> |
| <scriptfilter language="javascript"> |
| self.setToken(self.getToken().toUpperCase()); |
| </scriptfilter> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <target name="scriptfilter2"> |
| <concat destfile="result/input"> |
| hello moon |
| </concat> |
| <copy file="result/input" tofile="result/scriptfilter2"> |
| <filterchain> |
| <scriptfilter language="javascript"> |
| self.setToken(self.getToken().toUpperCase()); |
| </scriptfilter> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <target name="customtokenfilter"> |
| <path id="test-classes"> |
| <pathelement location="../../../../build/testcases" /> |
| <pathelement path="${java.class.path}" /> |
| </path> |
| |
| |
| <typedef |
| name="capitalize" |
| classname="org.apache.tools.ant.filters.TokenFilterTest$Capitalize"> |
| <classpath refid="test-classes"/> |
| </typedef> |
| |
| <concat destfile="result/input"> |
| hello world |
| </concat> |
| |
| <copy file="result/input" tofile="result/custom"> |
| <filterchain> |
| <tokenfilter> |
| <stringtokenizer/> |
| <capitalize/> |
| </tokenfilter> |
| </filterchain> |
| </copy> |
| </target> |
| |
| <target name="hasscript"> |
| <script language="javascript"> |
| i = 1; |
| </script> |
| </target> |
| |
| <target name="hasregex"> |
| <concat destfile="result/replaceregexp"> |
| hello world |
| </concat> |
| <replaceregexp file="result/replaceregexp" |
| match="hello( )world" |
| replace="bye\1world"/> |
| </target> |
| |
| </project> |