衡量 JSP 项目大小的好方法是什么?
给定一个现有的 JSP 项目,我想了解一下该项目“视图”部分的复杂性/大小。以下是我到目前为止所做的工作:
- 提取过去 x 个月内从生产服务器编译的 JSP 列表(这消除了“死”jsps)。
- 编写了一个快速扫描器来查找导入到编译页面中的 JSP 片段文件。
- 从文件系统中提取文件的大小和时间戳。
现在我有了一个页面列表和导入到这些页面中的片段,以及它们的大小以及它们上次编译和更改的时间。
但我真正需要知道的是这个页面有多复杂;其中一些页面上有大量 Java 代码。这是一个大项目,因此要检查每个页面和尺寸会很乏味,而且可能不太准确。
我打算编写另一个扫描仪来测量 <% 和 %> 之间的代码,但我想知道是否有某种指标生成器已经可以做到这一点。我希望它输出页面有多大以及页面上的代码有多大。重点是将小页、中页、大页和巨页分开,因此绝对测量不如相对测量重要。
编辑: 编写了另一个扫描器来计算 JavaScript 行数、Java (Scriptlet) 行数、HTML 行数和 taglib 使用实例的数量。因此,通过使用扫描仪的结果,我得到了一些表明“复杂性”的参数。不是很干净,但目前还可以。
Given an existing JSP project, I would like to get a feel for the complexity/size of the "view" portion of the project. Here's what I've done so far:
- Pulled the list of JSP's that have been compiled from the production server within the last x months (that eliminates 'dead' jsps).
- Wrote a quick scanner to find the JSP fragment files that are imported into the compiled pages.
- Pulled the size of the file and the timestamp off the file system.
So now I have a list of pages and the fragments imported into those pages, along with their size, and the last time they were compiled and changed.
But what I really need to know is how complicated the page is; some of these pages have a whole lot of Java code on them. It's a big project, so to go through each page and size it would be tedious and probably not that accurate.
I was going to write another scanner that measured the code between <% and %>, but I wondered if there was some kind of metrics generator out there that could already do that. I would like it to output how "big" the page was and how "big" the code on the page was. The point is to segregate the small, medium, big, and huge pages, so the absolute measurement is less important than the relative.
EDIT:
Wrote another scanner to count number of JavaScript lines, Java (Scriptlet) lines, HTML lines, and instances of taglib useage. So by using the results of the scanner, I have some parameters that would indicate 'complexity'. Not real clean, but it's ok for now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以问题是 HTML 中散布着一些 Java 代码,因此没有标准的度量工具可以工作。
还没有完全现成,但我们的源代码搜索引擎可能非常接近。这是一个通过使用语言精确的词法提取对源代码进行索引来搜索大型代码库的工具。这里的相关性在于,它计算索引文件的 SLOC、评论计数、Halstead 和 Cyclomatic 度量,因此如果您只是忽略搜索功能,您也可以获得指标。这些指标生成为一个 XML 文件(每个源文件有一个“记录”),因此您可以对它们进行任何您想要的进一步处理。请参阅链接网页上的指标讨论。
虽然我们确实有 JSP 词法分析器,但尚未使用搜索引擎对其进行测试。我们已经构建了数十个词法分析器,因此这对我们来说应该很容易做到(并且我们很乐意这样做)。这将直接产生您想要的答案。
如果您不想走这条路,您可以遵循提取 <% 和 %> 之间的代码的简单想法,将其转储到与原始 JSP 文件并行的文件中,
并通过搜索引擎的(生产)Java 词素提取器将该代码交给搜索引擎,并以这种方式获取指标。词法分析器在处理格式错误的文件方面非常强大,因此提取的 Java 片段总体上可能不太合法这一事实不会对其造成任何困扰。
So the issue is that you have smatterings of Java code interspersed with the html, so no standard metrics tool will work.
Not quite off the shelf, but our Source Code Search Engine might come pretty close. This is a tool for searching large code bases by indexing the source code using langauge-accurate lexical extraction. The relevance here is that it computes SLOC, comment counts, Halstead and Cyclomatic measures of the files it indexes, so you get metrics if you simply ignore the search feature. The metrics are generated to an XML file (with one "record" per source file) so you can do whatever further processing you want on them. See the metrics discussion on the linked web page.
While we do have a JSP lexer, it hasn't been tested with the Search Engine yet. We've built dozens of lexers so this should be pretty easy for us to do (and we'd be happy to do it). That would produce the answer you want directly.
If you didn't want to go down that path, you could follow through with your simple idea of extracting the code between <% and %>, dump it into files parallel to the original JSP files,
and hand that code to the search engine through its (production) Java lexeme extractor for the Search Engine, and get your metrics that way. The lexers are very robust in the fact of malformed files, so the fact that the Java fragments extracted might not collectively be quite legal wont bother it a bit.