Phoenix
Phoenix

Reputation: 8923

Is there an alternative to duplicating the code below five times

         antBuilder.copy(file: lstFile, todir:srcDir)
         antBuilder.copy(file: lstGzippedFile, todir: srcDir)
         antBuilder.copy(file: tarFile1, todir:srcDir)
         antBuilder.copy(file: tarFile2, todir:srcDir)
         antBuilder.copy(file: tarFile3, todir:srcDir)

can i write the code above in 1 line by combining file parameters and todir parameters

Upvotes: 0

Views: 75

Answers (1)

Dave Newton
Dave Newton

Reputation: 160191

Why not just iterate over a collection of file: parameters?

def files = [ lst, gzipped, tar1, tar2, tar3 ]
files.each { antBuilder.copy(file: it, todir: srcDir) }

You could put it all on one line, but it's getting a bit long (TWSS):

[ lst, gzipped, tar1, tar2, tar3 ].each { antBuilder.copy(file: it, todir: srcDir) }

Upvotes: 6

Related Questions