Bug 28738 - debugging with ant
debugging with ant
Status: CLOSED FIXED
Product: Ant
Classification: Unclassified
Component: Other
unspecified
Other other
: P3 enhancement (vote)
: ---
Assigned To: Ant Notifications List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2004-05-03 12:05 UTC by Anil Pathak
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anil Pathak 2004-05-03 12:05:53 UTC
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.
Comment 1 Jan Mat 2004-05-03 12:11:46 UTC
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
Comment 2 Matt Benson 2004-05-03 14:32:30 UTC
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...
Comment 3 Jan Mat 2004-05-03 15:16:13 UTC
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.
Comment 4 Erik Hatcher 2004-05-03 15:24:35 UTC
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/
Comment 5 Jan Mat 2004-05-03 15:34:27 UTC
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".