Catch the Stack Trace from a javac call
I am looking to do something a little, well interesting I think would be a good word. I was wondering if there was a way to catch the text associated with a stack trace from a build (currently I use ANT to build) using the javac task.
A little history, I am using a CI server, CruiseControl, and want to write an adapter that will catch the stack trace from a failed build, and allow for me to parse out which files caused the build to fail from a javac task call. So for example, if code was checked into a repository that 开发者_JS百科had a method signature from another class in it, but that class was never added to the repository, the javac task would fail with a cannot find symbol exception in the class. I want to be able to read the stack trace to get the class that caused the build failure.
Any ideas on how to do this? I would prefer not to have to just read in the log file and parse it out manually (I feel like there should be a better way) but if there isn't then I can just go that route as well.
First, for terminology: The compiler normally does not throw exceptions (if it does, there likely is a bug in the compiler, or your file system makes problems, or something like this), so there is no stack trace.
What you see when compiling is the compiler output, including any compiler error messages.
Looking at ant's javac
task, there seems to be no way to redirect the output somewhere, which means parsing it is only possible by parsing the output of the whole ant run.
You might do better by using the Compiler API (javax.tools) and adding a DiagnosticListener to the compiler run. You would have to wrap this into an ant task yourself, though.
精彩评论