Filter with TokenFilter.DeleteCharacters produces Invalid filter specification

Let’s imagine we have properties file with jdbc.url=${jdbc.url} As far as ReplaceTokens can’t operate on any tokens longer than 1 char ( {jdb.url} will work. Same with ${…} will not) we have to strip ‘$’ somehow. DeleteCharacters looks suitable but then I do

filter(TokenFilter.DeleteCharacters, chars: '\$')

it leads to

Caused by: org.gradle.api.InvalidUserDataException: Error - Invalid filter specification for org.apache.tools.ant.filters.TokenFilter$DeleteCharacters

Any ideas what is going on? Thanks

Ofc, I can replace this call by filter {line -> line.replace ‘abc’, ‘’} but looking for explanation.

TokenFilter.DeleteCharacters implements TokenFilter.Filter and gradle does not support this kind of filter. I think the expand() method can solve your problem. here’s an example:

task myCopy(type:Copy){
 from("test.properties")
 into("build")
 expand(jdbcUrl: "http://myCompany:8081/...")
}

regards, René

Thanks for answer, your approach works fine, just like mine.

maybe I phrased it badly. The problem is not that TokenFilter.DeleteCharacters implements TokenFilter.Filter, but that it does not extend from java.io.FilterReader. Have a look at the javadoc of the filter method for the details:

http://gradle.org/docs/current/javadoc/org/gradle/api/tasks/AbstractCopyTask.html#filter(java.lang.Class)

regards, René

Most stupid question ever. I read that FilterReader about 5 times, I knew that DeleteCharacter doesn’t inherit it and checked hierachy about 7 times but I was looking for interfaces only. It even didn’t came into my head that someone can use particular classes and not the interface to distinct the classes…

Thanks for explanation.

Can the TokenFilter class be used as wrapper???

Can someone help with the syntax? filter(TokenFilter (TokenFilter.ReplaceRegex , pattern: ~/lib/store/store/, replace: ‘lib/store/store.min’))