On Thu, Aug 20, 2009 at 9:08 AM, Stefan Walter<s...@gegenunendlich.de> wrote:
> is there a good/elegant recipe for selecting those source files that javac
> chose to compile?

Yes. Introspect the .class files to know which source files they came from.

Assumes debug info in left in the .class, but you can tell javac that
you only want to keep the SourceFile attribute I think, instead of the
full debug info. I used this technique successfully to find "orphan"
class file in my build tree to delete them, when doing incremental
builds.

My selector used a custom class file parser (single 600 line .java
file, with comments) that a colleague wrote as a learning exercise,
because it was easiest for me, but libraries like ASM, BCEL, Javassist
can do the parsing for you. All you need is to read the "SourceFile"
attribute, that's it. Using ASM's SAX-like parser should make that
easy and fast. All .class files for inner or package-private classes
from a given .java file will have the same "SourceFile" attribute.

Make a selector or task or custom resource collection of that, that
does the copy of those sources, you have an elegant solution. Requires
coding though :) --DD

/**
 * An Ant file selector that matches class file
 * which has no corresponding Java source file.
 * <p>
 * Note that class files compiled without debug information (specifically
 * the SourceFile attribute of the class file) will be ignored by this
 * selector.
 */
public class OrphanClassFileSelector extends BaseExtendSelector { ... }

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to