I'm using Ant to create a zip file. I want to also replace a token in the zipped files with the line number where the token is. I have tried to use a FilterChain, but I don't know how to engage with the zipfileset. Any suggestions?
I'm adding an example here. Let's say I have a file test.js like this:
function start(){
console.debug("Start");
}
function end(){
console.debug("End");
}
function processLine(line){
console.debug("processLine"/*--location--*/);
}
I want to replace /*--location-- */ with ,"test.js:10". I've managed to create a FilterReader that writes the line number
@Override
public int read() throws IOException {
if (!getInitialized()) {
initialize();
setInitialized(true);
}
int ch = -1;
if (line != null) {
ch = line.charAt(0);
if (line.length() == 1) {
line = null;
} else {
line = line.substring(1);
}
} else {
lineNumber++;
line = readLine();
System.out.println("line " + line);
if (line != null) {
line = line.replace("/*--location--*/", ",\"pagina:"+lineNumber+"\"");
return read();
}
}
return ch;
}
And I can invoke it using a copy with a filterchain
<copy file="${src}/ant-util/test/resources/box.js" tofile="${installation}/box.js">
<filterchain>
<filterreader classname="com.xxx.util.ant.AddLineNumberReaderFilter"/>
</filterchain>
</copy>
But I don't know how to get the file name. And then I would like to use this filter when zipping files, instead of doing a copy.