从 javac 调用捕获堆栈跟踪

发布于 2024-11-02 05:29:21 字数 345 浏览 0 评论 0原文

我想做一些有趣的事情,我认为这是一个好词。我想知道是否有一种方法可以使用 javac 任务捕获与构建(当前我使用 ANT 构建)中的堆栈跟踪相关的文本。

一点历史,我正在使用 CI 服务器 CruiseControl,并且想要编写一个适配器来捕获失败构建的堆栈跟踪,并允许我解析哪些文件导致 javac 任务调用导致构建失败。例如,如果代码被签入一个存储库,其中包含另一个类的方法签名,但该类从未添加到存储库中,则 javac 任务将失败,并在该类中出现找不到符号异常。我希望能够读取堆栈跟踪以获取导致构建失败的类。

关于如何做到这一点有什么想法吗?我不想只读取日志文件并手动解析它(我觉得应该有更好的方法),但如果没有,那么我也可以走这条路。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间不值得 2024-11-09 05:29:21

首先,对于术语:编译器通常不会抛出异常(如果抛出异常,则编译器中可能存在错误,或者您的文件系统出现问题,或类似的情况),因此没有堆栈跟踪。

编译时您看到的是编译器输出,包括任何编译器错误消息。

看看 ant 的 javac 任务,似乎没有办法将输出重定向到某个地方,这意味着只能通过解析整个 ant 运行的输出来解析它。

通过使用编译器 API (javax.tools) 并将 DiagnosticListener 添加到编译器运行中,您可能会做得更好。不过,您必须自己将其包装到蚂蚁任务中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文