Multiple filters does not work as expected

We have are using a template syntax that isn’t XML friendly. I wanted to test xslt transformations. I created a filter that changes the variables to something that XML likes. A XSLT filter. Finally a filter that restored the variables to their original state.

filter 1
$<variable> -> $[variable]
filter 2
xslt
filter 3
$[variable] -> $<variable>

When I run the filters on a Copy only filter 1 and 3 is executed.
When I run 1 and 2 it executes both.
When I run 2 and 1 or 3 only 1 or 3 is executed.
If I use only 2 the transformation fails because XML is destroyed by the variables.

I have a github repo with the files. GitHub - mcNisse/gradleXsltFilter: A repo for testing/debugging xslt filter in gradle. The filters is in buildSrc.
the task transform runs the filters that I want it to work.

This is not actually a Gradle question.
From Gradle side everything is working as expected.
But your filters (or the BaseFilterReader) are buggy, you need to debug them.
Your restore filter has the xslt filter as in, your xslt filter has the xml file filter as in.
Your restore filter’s read calls readLine on its in which is the xslt filter.
The readLine on your xslt filter then uses read on its in to get characters, so reads it from the xml filter.
So the read from your xslt filter effectively is skipped.

1 Like