// Ġtag :: filter - files [] Ċ import Ġorg . apache . tools . ant . filters . Fix Cr Lf Filter Ċ import Ġorg . apache . tools . ant . filters . Replace Tokens Ċ // Ġend :: filter - files [] Ċ Ċ version Ġ= Ġ" 1 . 1 " Ċ Ċ // Ġtag :: copy - single - file - example [] Ċ tasks . register < Copy >(" copy Report ") Ġ{ ĊĠĠĠ Ġfrom ( layout . build Directory . file (" reports / my - report . pdf ")) ĊĠĠĠ Ġinto ( layout . build Directory . dir (" to Archive ")) Ċ } Ċ // Ġend :: copy - single - file - example [] Ċ Ċ // Ġtag :: copy - single - file - example - without - file - method [] Ċ tasks . register < Copy >(" copy Report 2 ") Ġ{ ĊĠĠĠ Ġfrom ("$ build Dir / reports / my - report . pdf ") ĊĠĠĠ Ġinto ("$ build Dir / to Archive ") Ċ } Ċ // Ġend :: copy - single - file - example - without - file - method [] Ċ Ċ val Ġmy Report Task Ġby Ġtasks . register ing Ġ{ ĊĠĠĠ Ġval ĠoutputFile Ġby Ġextra Ġ{ Ġfile ("$ build Dir / reports / my - report . pdf ") Ġ} ĊĊĠĠĠ Ġoutputs . files ( outputFile ) ĊĠĠĠ Ġdo Last Ġ{ ĊĠĠĠĠĠĠĠ ĠoutputFile . set LastModified ( System . currentTimeMillis ()) ĊĠĠĠ Ġ} Ċ } Ċ Ċ val Ġarchive Reports Task Ġby Ġtasks . register ing Ġ{ ĊĠĠĠ Ġval Ġdir To Archive Ġby Ġextra Ġ{ Ġfile ("$ build Dir / to Archive ") Ġ} ĊĠĠĠ Ġinputs . dir ( dir To Archive ) Ċ } Ċ Ċ // Ġtag :: copy - single - file - example - with - task - properties [] Ċ tasks . register < Copy >(" copy Report 3 ") Ġ{ ĊĠĠĠ Ġval ĠoutputFile : ĠFile Ġby Ġmy Report Task . get (). extra ĊĠĠĠ Ġval Ġdir To Archive : ĠFile Ġby Ġarchive Reports Task . get (). extra ĊĠĠĠ Ġfrom ( outputFile ) ĊĠĠĠ Ġinto ( dir To Archive ) Ċ } Ċ // Ġend :: copy - single - file - example - with - task - properties [] Ċ Ċ // Ġtag :: copy - multiple - files - example [] Ċ tasks . register < Copy >(" copy Reports For Arch iving ") Ġ{ ĊĠĠĠ Ġfrom ( layout . build Directory . file (" reports / my - report . pdf "), Ġlayout . project Directory . file (" src / docs / manual . pdf ")) ĊĠĠĠ Ġinto ( layout . build Directory . dir (" to Archive ")) Ċ } Ċ // Ġend :: copy - multiple - files - example [] Ċ Ċ // Ġtag :: copy - multiple - files - with - flat - filter - example [] Ċ tasks . register < Copy >(" copy Pdf Reports For Arch iving ") Ġ{ ĊĠĠĠ Ġfrom ( layout . build Directory . dir (" reports ")) ĊĠĠĠ Ġinclude (" *. pdf ") ĊĠĠĠ Ġinto ( layout . build Directory . dir (" to Archive ")) Ċ } Ċ // Ġend :: copy - multiple - files - with - flat - filter - example [] Ċ Ċ // Ġtag :: copy - multiple - files - with - deep - filter - example [] Ċ tasks . register < Copy >(" copy All Pdf Reports For Arch iving ") Ġ{ ĊĠĠĠ Ġfrom ( layout . build Directory . dir (" reports ")) ĊĠĠĠ Ġinclude (" ** /*. pdf ") ĊĠĠĠ Ġinto ( layout . build Directory . dir (" to Archive ")) Ċ } Ċ // Ġend :: copy - multiple - files - with - deep - filter - example [] ĊĊ Ċ // Ġtag :: copy - directory - example [] Ċ tasks . register < Copy >(" copy Reports Dir For Arch iving ") Ġ{ ĊĠĠĠ Ġfrom ( layout . build Directory . dir (" reports ")) ĊĠĠĠ Ġinto ( layout . build Directory . dir (" to Archive ")) Ċ } Ċ // Ġend :: copy - directory - example [] Ċ Ċ // Ġtag :: copy - directory - including - it self - example [] Ċ tasks . register < Copy >(" copy Reports Dir For Arch iving 2 ") Ġ{ ĊĠĠĠ Ġfrom ( layout . build Directory ) Ġ{ ĊĠĠĠĠĠĠĠ Ġinclude (" reports /** ") ĊĠĠĠ Ġ} ĊĠĠĠ Ġinto ( layout . build Directory . dir (" to Archive ")) Ċ } Ċ // Ġend :: copy - directory - including - it self - example [] Ċ Ċ // Ġtag :: create - archive - example [] Ċ tasks . register < Zip >(" package Distribution ") Ġ{ ĊĠĠĠ Ġarchive FileName . set (" my - distribution . zip ") ĊĠĠĠ Ġdestination Directory . set ( layout . build Directory . dir (" dist ")) ĊĊĠĠĠ Ġfrom ( layout . build Directory . dir (" to Archive ")) Ċ } Ċ // Ġend :: create - archive - example [] Ċ Ċ // Ġtag :: rename - on - copy - example [] Ċ tasks . register < Copy >(" copyFrom Staging ") Ġ{ ĊĠĠĠ Ġfrom (" src / main / webapp ") ĊĠĠĠ Ġinto ( layout . build Directory . dir (" explo ded War ")) ĊĊĠĠĠ Ġrename (" (. + )- staging (. + )", Ġ"$ 1 $ 2 ") Ċ } Ċ // Ġend :: rename - on - copy - example [] Ċ Ċ // Ġtag :: truncate - names - example [] Ċ tasks . register < Copy >(" copy With Truncate ") Ġ{ ĊĠĠĠ Ġfrom ( layout . build Directory . dir (" reports ")) ĊĠĠĠ Ġrename Ġ{ Ġfilename : ĠString Ġ-> ĊĠĠĠĠĠĠĠ Ġif Ġ( filename . length Ġ> Ġ 1 0 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfilename . slice ( 0 .. 7 ) Ġ+ Ġ"~ " Ġ+ Ġfilename . length ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġelse Ġfilename ĊĠĠĠ Ġ} ĊĠĠĠ Ġinto ( layout . build Directory . dir (" to Archive ")) Ċ } Ċ // Ġend :: truncate - names - example [] ĊĊĊĊĊĊĊ Ċ val Ġcopy Task Ġby Ġtasks . register ing ( Copy :: class ) Ġ{ ĊĠĠĠ Ġfrom (" src / main / webapp ") ĊĠĠĠ Ġinto ( layout . build Directory . dir (" explo ded War ")) Ċ } Ċ Ċ // Ġtag :: copy - task - with - patterns [] Ċ tasks . register < Copy >(" copy Task With Patterns ") Ġ{ ĊĠĠĠ Ġfrom (" src / main / webapp ") ĊĠĠĠ Ġinto ( layout . build Directory . dir (" explo ded War ")) ĊĠĠĠ Ġinclude (" ** /*. html ") ĊĠĠĠ Ġinclude (" ** /*. jsp ") ĊĠĠĠ Ġexclude Ġ{ Ġdetails : ĠFile Tree Element Ġ-> ĊĠĠĠĠĠĠĠ Ġdetails . file . name . endsWith (". html ") Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdetails . file . read Text (). contains (" DR AFT ") ĊĠĠĠ Ġ} Ċ } Ċ // Ġend :: copy - task - with - patterns [] Ċ Ċ // Ġtag :: copy - task - 2 [] Ċ tasks . register < Copy >(" another Copy Task ") Ġ{ ĊĠĠĠ Ġ// ĠCopy Ġeverything Ġunder Ġsrc / main / webapp ĊĠĠĠ Ġfrom (" src / main / webapp ") ĊĠĠĠ Ġ// ĠCopy Ġa Ġsingle Ġfile ĊĠĠĠ Ġfrom (" src / staging / index . html ") ĊĠĠĠ Ġ// ĠCopy Ġthe Ġoutput Ġof Ġa Ġtask ĊĠĠĠ Ġfrom ( copy Task ) ĊĠĠĠ Ġ// ĠCopy Ġthe Ġoutput Ġof Ġa Ġtask Ġusing ĠTask Ġoutputs Ġexplicitly . ĊĠĠĠ Ġfrom ( tasks [" copy Task With Patterns "]. outputs ) ĊĠĠĠ Ġ// ĠCopy Ġthe Ġcontents Ġof Ġa ĠZip Ġfile ĊĠĠĠ Ġfrom ( zip Tree (" src / main / assets . zip ")) ĊĠĠĠ Ġ// ĠDetermine Ġthe Ġdestination Ġdirectory Ġlater ĊĠĠĠ Ġinto ({ Ġget Dest Dir () Ġ}) Ċ } Ċ // Ġend :: copy - task - 2 [] Ċ Ċ fun Ġget Dest Dir () Ġ= Ġfile (" some - dir ") Ċ Ċ // Ġtag :: copy - method [] Ċ tasks . register (" copy Method ") Ġ{ ĊĠĠĠ Ġdo Last Ġ{ ĊĠĠĠĠĠĠĠ Ġcopy Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfrom (" src / main / webapp ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinto ( layout . build Directory . dir (" explo ded War ")) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude (" ** /*. html ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinclude (" ** /*. jsp ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ // Ġend :: copy - method [] Ċ Ċ // Ġtag :: copy - method - with - dependency [] Ċ tasks . register (" copy Method With Explicit Dependencies ") Ġ{ ĊĠĠĠ Ġ// Ġup - to - date Ġcheck Ġfor Ġinputs , Ġplus Ġadd Ġcopy Task Ġas Ġdependency ĊĠĠĠ Ġinputs . files ( copy Task ) ĊĠĠĠĠĠĠĠ Ġ. with PropertyName (" inputs ") ĊĠĠĠĠĠĠĠ Ġ. with Path Sensitivity ( Path Sensitivity . REL ATIVE ) ĊĠĠĠ Ġoutputs . dir (" some - dir ") Ġ// Ġup - to - date Ġcheck Ġfor Ġoutputs ĊĠĠĠĠĠĠĠ Ġ. with PropertyName (" output Dir ") ĊĠĠĠ Ġdo Last Ġ{ ĊĠĠĠĠĠĠĠ Ġcopy Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠCopy Ġthe Ġoutput Ġof Ġcopy Task ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfrom ( copy Task ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinto (" some - dir ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ // Ġend :: copy - method - with - dependency [] Ċ Ċ configurations Ġ{ Ġ" runtime " Ġ} Ċ Ċ // Ġtag :: rename - files [] Ċ tasks . register < Copy >(" rename ") Ġ{ ĊĠĠĠ Ġfrom (" src / main / webapp ") ĊĠĠĠ Ġinto ( layout . build Directory . dir (" explo ded War ")) ĊĠĠĠ Ġ// ĠUse Ġa Ġclosure Ġto Ġconvert Ġall Ġfile Ġnames Ġto Ġupper Ġcase ĊĠĠĠ Ġrename Ġ{ ĠfileName : ĠString Ġ-> ĊĠĠĠĠĠĠĠ ĠfileName . toUpperCase () ĊĠĠĠ Ġ} ĊĠĠĠ Ġ// ĠUse Ġa Ġregular Ġexpression Ġto Ġmap Ġthe Ġfile Ġname ĊĠĠĠ Ġrename (" (. + )- staging -( .+ )", Ġ"$ 1 $ 2 ") ĊĠĠĠ Ġrename (" (. + )- staging -( . +) ". to Regex (). pattern , Ġ"$ 1 $ 2 ") Ċ } Ċ // Ġend :: rename - files [] Ċ Ċ // Ġtag :: filter - files [] Ċ tasks . register < Copy >(" filter ") Ġ{ ĊĠĠĠ Ġfrom (" src / main / webapp ") ĊĠĠĠ Ġinto ( layout . build Directory . dir (" explo ded War ")) ĊĠĠĠ Ġ// ĠSubstitute Ġproperty Ġtokens Ġin Ġfiles ĊĠĠĠ Ġexpand (" copyright " Ġto Ġ" 2 0 0 9 ", Ġ" version " Ġto Ġ" 2 . 3 . 1 ") ĊĠĠĠ Ġexpand ( project . properties ) ĊĠĠĠ Ġ// ĠUse Ġsome Ġof Ġthe Ġfilters Ġprovided Ġby ĠAnt ĊĠĠĠ Ġfilter ( Fix Cr Lf Filter :: class ) ĊĠĠĠ Ġfilter ( Replace Tokens :: class , Ġ" tokens " Ġto Ġmap Of (" copyright " Ġto Ġ" 2 0 0 9 ", Ġ" version " Ġto Ġ" 2 . 3 . 1 ")) ĊĠĠĠ Ġ// ĠUse Ġa Ġclosure Ġto Ġfilter Ġeach Ġline ĊĠĠĠ Ġfilter Ġ{ Ġline : ĠString Ġ-> ĊĠĠĠĠĠĠĠ Ġ" [$ line ]" ĊĠĠĠ Ġ} ĊĠĠĠ Ġ// ĠUse Ġa Ġclosure Ġto Ġremove Ġlines ĊĠĠĠ Ġfilter Ġ{ Ġline : ĠString Ġ-> ĊĠĠĠĠĠĠĠ Ġif Ġ( line . startsWith ('- ')) Ġnull Ġelse Ġline ĊĠĠĠ Ġ} ĊĠĠĠ Ġfiltering Charset Ġ= Ġ" UTF - 8 " Ċ } Ċ // Ġend :: filter - files [] Ċ Ċ tasks . register (" test ") Ġ{ ĊĠĠĠ Ġdepends On ( tasks . with Type < Copy >()) ĊĠĠĠ Ġdepends On ( tasks [" copy Method "]) ĊĠĠĠ Ġdepends On ( tasks [" copy Method With Explicit Dependencies "]) Ċ } Ċ Ċ val Ġapp Classes Ġ= Ġlayout . build Directory . dir (" classes ") Ċ Ċ // Ġtag :: standalone - copy spec [] Ċ val Ġweb Assets Spec : ĠCopy Spec Ġ= Ġcopy Spec Ġ{ ĊĠĠĠ Ġfrom (" src / main / webapp ") ĊĠĠĠ Ġinclude (" ** /*. html ", Ġ"** /*. png ", Ġ"** /*. jpg ") ĊĠĠĠ Ġrename (" (. + )- staging (. + )", Ġ"$ 1 $ 2 ") Ċ } Ċ Ċ tasks . register < Copy >(" copy Assets ") Ġ{ ĊĠĠĠ Ġinto ( layout . build Directory . dir (" in Place App ")) ĊĠĠĠ Ġwith ( web Assets Spec ) Ċ } Ċ Ċ tasks . register < Zip >(" dist App ") Ġ{ ĊĠĠĠ Ġarchive FileName . set (" my - app - dist . zip ") ĊĠĠĠ Ġdestination Directory . set ( layout . build Directory . dir (" dists ")) ĊĊĠĠĠ Ġfrom ( app Classes ) ĊĠĠĠ Ġwith ( web Assets Spec ) Ċ } Ċ // Ġend :: standalone - copy spec [] Ċ Ċ // Ġtag :: shared - copy - patterns [] Ċ val Ġweb Asset Patterns Ġ= ĠAction < Copy Spec > Ġ{ ĊĠĠĠ Ġinclude (" ** /*. html ", Ġ"** /*. png ", Ġ"** /*. jpg ") Ċ } Ċ Ċ tasks . register < Copy >(" copy App Assets ") Ġ{ ĊĠĠĠ Ġinto ( layout . build Directory . dir (" in Place App ")) ĊĠĠĠ Ġfrom (" src / main / webapp ", Ġweb Asset Patterns ) Ċ } Ċ Ċ tasks . register < Zip >(" archive Dist Assets ") Ġ{ ĊĠĠĠ Ġarchive FileName . set (" distribution - assets . zip ") ĊĠĠĠ Ġdestination Directory . set ( layout . build Directory . dir (" dists ")) ĊĊĠĠĠ Ġfrom (" dist Resources ", Ġweb Asset Patterns ) Ċ } Ċ // Ġend :: shared - copy - patterns [] Ċ