I’m currently writing up a build file which is a step in our overall continuous delivery pipeline, in a nutshell some tar files will get thrown into a directory and from there we need to trigger a job to make a bunch of directory structure changes and edit some of the files.
My problem is that while I can get the reorganising of files to work fine using something like the following:
if (!project.hasProperty("environmentkey")) {
ext.environmentkey = "NONE"
}
task fileTree(dir: 'input').include('*.tar').each { tarFile ->
def name = tarFile.name - '.tar'
copy {
from tarTree("input/${tarFile.name}")
into "build/${name}"
}
copy {
from "build/$name/shared"
into "build/workspace/$name/$environmentkey/import/definition"
include '**/*.objc'
}
copy {
from "build/$name/createComms"
into "build/package/$name/$environmentkey/import/creation"
include '**/*.cmd'
}
copy {
from "build/$name/disk"
into "build/workspace/$name/$environmentkey/import/files"
}
...
etc.
I know that using methods for the copying isn’t ideal but it fits out needs almost perfectly.
That is, until the need to make some changes to the files, which I think might be a little harder. The end goal should be a package directory sitting in build which contains all of the properly structured appropriately formatted files.
The “workspace” directory I’ve defined above is just an interim measure, but preferably I wouldn’t need to be creating copies of the files all over the place to get something relatively simple done.
Rather than then having another job where I perform changes on the files, then copy them again into the package directory, is there any way to apply changes to the files while they are in motion?
To give an actual example, all of the files that are going into the “build/workspace/$name/$environmentkey/import/files” directory need to:
- be base64 encoded so they are consumable by another system
- Have a header attached which contains a @PATH@ token which needs to be replaced with the original relative file path
- End up in that same package directory so we can throw it into our maven repo.
Currently, looking at all the options I can find it looks like I would need to write a class which accepts two files (one of which would be my static header), base64 encodes the non-header file, appends the encoded data to the header file, replaces the @PATH@ token in the header file with the actual file path relative to the project directory, then outputs that file to the place where I was going to be copying it to. But that seems a little complicated for my current familiarity with gradle so I’m wondering if there is something more simple that I’ve missed.