ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Surette <psure...@espial.com>
Subject problem with filtering/IDE integration
Date Tue, 05 Feb 2002 16:12:35 GMT
(Before I begin, yes I know about log4j etc. but prefer
the solution outlined below)

I use filters to replace static final constant DEBUG flags at
build time. Basically, I define a static final constant
at the top of each build file like this:

public class Introspector {
    private static final boolean DEBUG =
"@Introspector.debug@".equalsIgnoreCase( "true" ) ||
"@debug@".equalsIgnoreCase( "true" );

sprinkled through the file I have statements like this:
        if (DEBUG) System.out.println("links = "+links.toString());

I have a src.replace.properties file like this:
debug=false
#SqlUtil.debug = true
Introspector.debug = true

Then, before I compile the sources, I run them through a filter
like this:
    <target name="copysources" depends="prepare">
        <copy todir="filteresources">
            <fileset dir="sources">
                <patternset refid="source.pattern"/>
            </fileset>
            <filterset>
                <filtersfile file="${src.replace.properties}"/>
            </filterset>
        </copy>
    </target>

When I compile, I use the filteredsources directory as my
sources directory. This allows me to very easily turn
debugging on an off either globally or on a per-file
basis by editing the src.replace.properties file. 
For a release build I can turn off all debugging
and all the if (DEBUG) statements get optimized out by
the compiler, so there is not performance penalty at
all for having the debug statements in there.

Here's the problem:
~~~~~~~~~~~~~~~~~~~
When I invoke ant from within an IDE, compilation errors
occur in the filteredsources directory, not the sources
directory. Normally I could click on the error message
and the IDE would take me to the line in the source file,
but in this case it takes me to the line in the
filteredsources file, which is a temporary file that
I should never edit.

I'm thinking I might be able to write a custom logger
to solve this problem, but I was wondering if there
was a better way. The custom logger would basically
do a 'sed' on the output fo the javac task, replacing
'filteredsources' with 'sources' everywhere, thus fooling
the IDE into taking me to the right file.

Has anyone else encountered this problem? I would think
it would bite just about anyone who uses filtering,
but maybe noone filters their sources?

Does anyone have a better suggestion than the custom
logger? 

Why I like this better than log4j
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I don't want any vestige of this debugging code to
appear in the final code. With log4j, unless you 
protect the calls with an if (STATIC_FINAL_BOOLEAN)
wrapper, you will end up generating messages that will
never be used. So you will encounter the same 
problem. Also it's an extra API that I don't really
need to solve this problem.

Although I guess you could get away with
a single static final and only do the filtering for
release builds, thereby solving the problem for
development builds...

- Phil Surette

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message