Iterative Exec

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 ->
  if(file.name.endsWith(".fmb")){
   println file
   commandLine 'cmd', '/c', 'frmf2xml.bat', file, 'OVERWRITE=YES'
  }
 }
}

Thank you kindly in advance.

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é

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'
 }
}

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

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.

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”.