Reputation: 1939
How do you write an ant target that takes a file as input and replaces all white space ' ' characters with '' (i.e. I need an ant target to "minify" the input text file and write it to disk)?
I know that in Java it's a simply doing something like this:
public void minify(String originalString){
String minifiedFile = originalString.replaceAll(" ", "");
}
But how do I get an ant target to invoke "minify()" function and how do I pass in a parameter "originalString" in Ant?
Would appreciate all / any advise.
Upvotes: 1
Views: 182
Reputation: 18459
Recent version of ant support regular expression based string replacement. Here is code example from ant site
<replaceregexp match="\s+" replace=" " flags="g" byline="true">
<fileset dir="${html.dir}" includes="**/*.html"/>
</replaceregexp>
For the original question - yes. You can extend ant by
Option 3 (calling programs like sed) will cause problems in the long term maintenance of build environment, though
Upvotes: 1
Reputation: 28029
Have you tried Ant-Contrib's PropertyRegex tag? That will perform a 'regex-replace' on a given string.
However, it sounds like you may be trying to do that to a whole file, in which case I would write an entire Java program (not just a single function) and invoke that program with ant's built-in Java
task.
Alternatively, as @jahroy suggested in the comments, you could use Ant's built-in exec
task to invoke sed
. That's actually probably the easiest solution.
Upvotes: 2