so fine that little ANT holds up the burden.I was thinking how about giving another trouble to it. Debugging with ant ! would some one there thinks it is good enough to include this concept in ant's later versions. consider this: in a typical program say HelloWorld public class HelloWorld{ public static void main(String arg[]){ //@debug start System.out.println("debug:let say this is a debug code or logging"); //@debug end System.out.println("HELLO WORLD"); } } I was thinking that what about a plugin or task or what ever in ANT in ant to elliminate those codes enclosed between two //@debug comments at time of building or deployment.
For simple logging use a logging framework, e.g. Log4J. The code remains in production code but logging is switched of by configuration file. More complex things should be done with XDoclet or an preprocessor. See the external page [1] for resources (search for "preprocessor"). I won´t close this, because there could be other opinions, but I think that should not be done by a build tool... [1] http://ant.apache.org/external.html
Also it may be possible to use a <replaceregex> tokenfilter to achieve the original desired result... it would take someone far more skilled with REs than I, however...
Nice idea. I played a little bit: build.xml --------- <?xml version="1.0" encoding="ISO-8859-1"?> <project> <echo> ************* Debug Mode ************* </echo> <delete dir="classes"/> <mkdir dir="classes"/> <javac srcdir="src" destdir="classes"/> <java classname="HelloWorld" classpath="classes"/> <echo> ************* LIVE Mode ************* </echo> <delete dir="classes"/> <delete dir="src-live"/> <mkdir dir="classes"/> <copy todir="src-live"> <fileset dir="src"/> </copy> <!-- important is the .*? because .* matches too much --> <replaceregexp match="//@debug start.*?//@debug end" replace="" flags="gs"> <fileset dir="src-live"/> </replaceregexp> <javac srcdir="src-live" destdir="classes"/> <java classname="HelloWorld" classpath="classes"/> </project> src/HelloWorld.java ------------------- // see http://issues.apache.org/bugzilla/show_bug.cgi?id=28738 public class HelloWorld { public static void main(String arg[]){ //@debug start log("debug:let say this is a debug code or logging"); //@debug end System.out.println("HELLO WORLD"); } //@debug start private static void log(String msg) { System.out.println("LOG: " + msg); } //@debug end } src-live/HelloWorld.java ------------------------ // see http://issues.apache.org/bugzilla/show_bug.cgi?id=28738 public class HelloWorld { public static void main(String arg[]){ System.out.println("HELLO WORLD"); } } Build-Output: ------------- Buildfile: build.xml [echo] ************* Debug Mode ************* [delete] Deleting directory C:\tmp\anttests\preprocessor\classes [mkdir] Created dir: C:\tmp\anttests\preprocessor\classes [javac] Compiling 1 source file to C:\tmp\anttests\preprocessor\classes [java] LOG: debug:let say this is a debug code or logging [java] HELLO WORLD [echo] ************* LIVE Mode ************* [delete] Deleting directory C:\tmp\anttests\preprocessor\classes [delete] Deleting directory C:\tmp\anttests\preprocessor\src-live [mkdir] Created dir: C:\tmp\anttests\preprocessor\classes [copy] Copying 1 file to C:\tmp\anttests\preprocessor\src-live [javac] Compiling 1 source file to C:\tmp\anttests\preprocessor\classes [java] HELLO WORLD BUILD SUCCESSFUL Total time: 3 seconds I suggest you close this bug if this is ok for you.
Here are a couple of other options: Use aspects (AspectJ, for example) to aspect in/out your debugging code. On a slightly less intense way, check out VPP - Velocity PreProcessor - http://vpp.sourceforge.net/
I´ve described the <replaceregexp> way in the wiki [1]. But I would prefer a real preprocessor... [1] http://wiki.apache.org/ant/AntOddities "Implementing a PreProcessor".