生成 Checkstyle 报告(带有扩展检查) [英] Generating Checkstyle Reports (with extended checks)
问题描述
我有一些自己的扩展检查.我已将它们作为插件导出,在 Eclipse 中,它们显示警告/错误.所以扩展检查工作正常.
I have some own extended checks. I have exported them as plug-in and in Eclipse, they are showing warning/error. So the extended checks are working fine.
现在我想以HTML 格式生成违规报告.
Now I want to generate a report of the violations in HTML format.
我已经检查了这个,这有效如果 rule.xml 文件中不包含扩展检查,那很好.但是在扩展检查的情况下,ant build 会给出错误.
I have checked this, and this works fine if no extended checks are included in rule.xml file. But in case of extended checks, the ant build is giving the error.
错误是:
BUILD FAILED
D:\Java_Work\JUnit_CheckStyle\buildCheckStyle.xml:12: Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate InterfaceModifier
InterfaceModifier 是我的扩展检查,它在 eclipse 中工作正常.
InterfaceModifier is my extended check, and it works fine in eclipse.
在 build.xml 中,在哪里提供 extendedCheck.jar 以便我获得所需的结果?
In build.xml, where to provide the extendedCheck.jar so that I get the required result?
推荐答案
我找到了以下解决方案,效果很好.
I have found out the following solution, which is working fine.
- 提取checkstyle-x.x-all.jar
- 复制解压目录中的扩展类
- 将扩展检查的元数据、消息和属性文件复制到同一目录中.
- 如果任何文件都存在,则编辑该文件并添加扩展检查的内容.
- 创建一个包含所有这些的新 .jar 文件.
- 在ant build.xml
中,设置这个.jar为classpath
- extract checkstyle-x.x-all.jar
- copy the extended classes in the extracted directory
- copy the metadata,message and properties file of extended check in the same directory.
- if any of the file is alreasy present, then edit the file and add the content from extended checks.
- create a new .jar file including all these.
- in ant build.xml
<taskdef>
, set this .jar asclasspath
比如,完成到第 2 步后,我发现 checkstyle_packages.xml 已经存在,所以我编辑它并将扩展的内容添加到适当的位置.
Like, after done till 2nd step, I found checkstyle_packages.xml is already present, so I edit it and added the content from extended one in proper position.
以前的版本:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-packages PUBLIC
"-//Puppy Crawl//DTD Package Names 1.0//EN"
"http://www.puppycrawl.com/dtds/packages_1_0.dtd">
<checkstyle-packages>
<package name="com.puppycrawl.tools.checkstyle">
<package name="checks">
<package name="annotation"/>
<package name="blocks"/>
<package name="coding"/>
<package name="design"/>
<package name="duplicates"/>
<package name="header"/>
<package name="imports"/>
<package name="indentation"/>
<package name="javadoc"/>
<package name="metrics"/>
<package name="modifier"/>
<package name="naming"/>
<package name="regexp"/>
<package name="sizes"/>
<package name="whitespace"/>
</package>
<package name="filters"/>
</package>
</checkstyle-packages>
更改版本:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE checkstyle-packages PUBLIC
"-//Puppy Crawl//DTD Package Names 1.0//EN"
"http://www.puppycrawl.com/dtds/packages_1_0.dtd">
<checkstyle-packages>
<package name="com.puppycrawl.tools.checkstyle">
<package name="checks">
<package name="annotation"/>
<package name="blocks"/>
<package name="coding"/>
<package name="design"/>
<package name="duplicates"/>
<package name="header"/>
<package name="imports"/>
<package name="indentation"/>
<package name="javadoc"/>
<package name="metrics"/>
<package name="modifier"/>
<package name="naming"/>
<package name="regexp"/>
<package name="sizes"/>
<package name="whitespace"/>
</package>
<package name="filters"/>
</package>
<!-- Added this lines -->
<package name="myCheck">
<package name="checks"/>
</package>
<!-- -->
</checkstyle-packages>
现在构建文件成功运行,在报告中我也违反了扩展检查.
now the build file is running successfully and in the report I'm getting violation of extended checks too.
这篇关于生成 Checkstyle 报告(带有扩展检查)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!