Is it possible to do in-place filtering?


(Cédric Champeau) #1

Hi guys,

I’m looking for a way to post-process generated documentation files (as a workaround for a missing asciidoctor feature). For that, I’m trying to use the Copy task to filter resources. Here’s what my task looks like:

task createJavadocLinks(type:Copy) {
    description = 'Filters generated documentation to generate links to javadoc'
    from asciidoctor.outputDir
    into asciidoctor.outputDir
    filter { line ->
        line.replaceAll(/gapi::([a-zA-Z0-9$.]+)/) { m->
            // ... snip ...
        }
    }
}
  asciidoctor.finalizedBy createJavadocLinks

The problem is that the source files are also the target files, so there’s a conflict and the resulting file is empty. I’d like to avoid having a separate output directory with the postprocessed files, so the question is simple: is there any way to do in-place filtering?

Thanks!


(Peter Niederwieser) #2

You may have to do the in-place filtering with plain Groovy. It should probably go into ‘asciidoctor.doLast {}’. Otherwise, the ‘asciidoctor’ task will always be out-of-date, because the subsequent in-place filtering task keeps changing its outputs.


(Cédric Champeau) #3

I see… Thanks for the answer!