如何构建 Java 类的元模型以通过代码分析生成服务图?

发布于 2024-12-09 20:12:05 字数 530 浏览 7 评论 0原文

我们有一个构建在 EJB 3.0 之上的 SOA 系统。我们正在手动维护一个“服务概览图”,它显示哪些业务服务调用哪些域服务。这是乏味的,容易出错的,没有人愿意这样做:-/

这就是为什么我正在寻找一种方法来自动生成这些图表。我认为代码分析是一条出路。

有人知道有一个可以很好地分析java代码的工具吗?我想到了某种元模型,我可以查询它来构建图表。

类似于:

  1. 解析根目录 xyz 中的所有文件并为每个类构建元模型 a) 例如它还使用哪些其他类 b) 哪些类使用该类 c) 它实现了哪些接口 d) 它的文件名是什么 e)等等,我想你知道我的意思
  2. 给我一个你找到的所有文件的元模型(java/class)
  3. 生成图形(手工制作)
  4. 以“.dot”(有向图)文件格式输出图形
  5. 使用“dot”工具将图形生成为 png、pdf、svg...

我们已经通过“grepping”文件找到了一个简单的解决方案...但这并不完美。

任何帮助将不胜

感激 马塞尔

we have a SOA system built on top of EJB 3.0. we are manually maintaining a "service overview map" which shows which business services call which domain services. this is tedious, error prone and nobody wants to do it :-/

that's why i am looking for a way to automate the generation of these diagrams. i think code analysis is the way to go.

does anybody know of a tool that does good code analysis for java? i think of some kind of meta model which i can query to built the graph.

something like:

  1. parse all files from root dir xyz and built the meta model for each class
    a) e.g. which other classes does it use
    b) which classes use this class
    c) which interfaces does it implement
    d) what is it's filename
    e) and so on, i guess you know what i mean
  2. give me a meta model of all the files you found (java/class)
  3. generate the graph (hand made)
  4. output the graph in ".dot" (directed graph) file format
  5. use the "dot" tool to generate the graph as png, pdf, svg...

we already have a simple solution by "grepping" through the files.... but this is not perfect.

any help would be appreciated

cheers
marcel

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

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

发布评论

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

评论(3

扬花落满肩 2024-12-16 20:12:05

另一种方法是在已编译的类文件或源代码本身上使用 ASM 执行相同的操作。

An alternative would be to do the same thing using ASM on the compiled class files or on the source code itself.

醉南桥 2024-12-16 20:12:05

哈。不到一个月前,我为我们的 EJB 2.0 庞然大物编写了这个确切的系统。这就是我所做的:

  • 下载了 Java Parser
  • 编写了一个递归目录 walker
  • 编写了一个基于树的数据结构使我能够存储依赖项。
  • 编写了一个 .dot 文件输出器。

我花了大约一周的时间,当我更新它以通过twopi引擎将文件输出为.svg图像时,结果证明非常成功;我们现在可以在浏览器中导航类图,以快速识别潜在重构的感兴趣区域,并将其集成到我们的自动化构建环境中。

如果您需要更多信息,请给我留言。

Hah. I wrote this exact system not one month ago for our EJB 2.0 behemoth. Here is what I did:

  • downloaded the Java Parser
  • wrote a recursive directory walker
  • wrote a tree-based data structure that allowed me to store dependencies.
  • wrote a .dot file outputter.

It took me about a week and it proved very successful when I updated it to output the files as .svg images via the twopi engine; we can now navigate class diagrams in the browser to quickly identify areas of interest for potential refactoring, and are integrating it into our automated build environment.

Drop me a pm if you need more info.

情定在深秋 2024-12-16 20:12:05

有一个名为 MoDisco 的 eclipse 框架,它符合您的需求。它包括几个元模型(Java、JSP...)。

您可以全面了解项目,包括配置文件或部署描述符。

There is an eclipse framework called MoDisco which corresponds to your need. It includes several meta model (Java, JSP, ...).

You can get a complete picture of your project including config files or deployment descriptors.

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