Iterative Exec

(Sion Williams) #1

I suspect this is a Groovy quirk as opposed to Gradle. In the code provided below I can print each of the file names in the directory, but when it reaches the Exec command it only performs an Exec on the last file.

I would like it to run the tool on every file, just as the println does.

task frmf2xml(type:Exec)
 new File('src/orca/').eachFile {file ->
   println file
   commandLine 'cmd', '/c', 'frmf2xml.bat', file, 'OVERWRITE=YES'

Thank you kindly in advance.

(René Groeschke) #2

Hello Sion, The problem with your code is, that you reconfigure commandLine property of the Exec tasks multiple times and overwrite the value each time. To have an task of type Exec for each matching file, you have to move the definition of the task into the eachFile closure.

cheers, René

(Sion Williams) #3

Is the following the best way to handle this:

new File('src/orca/').eachFileMatch(~/np.*\.fmb/){file ->
         def output = exec{
  commandLine 'cmd', '/c', 'frmf2xml.bat', file, 'OVERWRITE=YES'

(Sion Williams) #4

new File(‘src/orca/’).eachFileMatch(~/np.*.fmb/){file ->

def output = exec{

commandLine ‘cmd’, ‘/c’, ‘frmf2xml.bat’, file, ‘OVERWRITE=YES’



Code tags not working so good for some reason

(René Groeschke) #5

It depends on what you try to achieve. With your last snippet you run multiple exec calls with different arguments.

It depends on your usecase if it makes sense to wrap this logic into a task action or use one task of type Exec for each File.

(Sion Williams) #6

Sorry, i’m new to Gradle and Groovy, but ultimately I would like to make use of Gradle’s excellent incremental build feature - that is convert the file to xml each time it changes.

Just for your information the task I am executing is part of the Oracle Forms toolsuite, it converts a binary to xml for merging. I would like to also use a similar approach to compile Oracle Forms using “frmcmp.bat”.