简体   繁体   English

Jacoco将类别从报告中排除

[英]Jacoco exclude classes from report

I am using the example on http://www.eclemma.org/jacoco/trunk/doc/examples/java/ReportGenerator.java 我正在使用http://www.eclemma.org/jacoco/trunk/doc/examples/java/ReportGenerator.java上的示例

I would like to exclude some classes from the report generation. 我想从报告生成中排除一些类。 I assume it has to be set in the Analyzer but I could find an example. 我认为必须在分析器中设置它,但我可以找到一个示例。

听起来您可能想要代码覆盖范围首选项中排除项:

I'd say in analyzeStructure() you should not call analyzer.analyzeAll(classesDirectory); 我会说,在analyzeStructure()您不应调用analyzer.analyzeAll(classesDirectory); , but iterate over the file tree in classesDirectory yourself, excluding the classes you don't want to have analyzed and then give the individual files to the analzyeAll() method. ,但您自己可以遍历classesDirectory的文件树,排除您不想分析的类,然后将各个文件提供给analzyeAll()方法。 But this is just blind guessing without having tried it. 但这只是盲目的猜测,没有尝试过。 So if you try and tell me it does not work, I'll delete my answer. 因此,如果您尝试告诉我它不起作用,我将删除答案。

  1. You can declare a new constructor that takes another array list argument(Do not change the previous constructor as other classes use it). 您可以声明一个新的构造函数,该构造函数接受另一个数组列表参数(不要更改以前的构造函数,因为其他类正在使用它)。

     public Analyzer(final ExecutionDataStore executionData, final ICoverageVisitor coverageVisitor, ArrayList<String> excludeClassPathArrayList) { this.executionData = executionData; this.coverageVisitor = coverageVisitor; this.stringPool = new StringPool(); this.excludeClassPathArrayList = excludeClassPathArrayList; } 
  2. Then modify method analyzeAll(final InputStream input, final String location) , in ContentTypeDetector.CLASSFILE: , you can do like this, if location contains exclude class path in arrary list, ignore them just like all other content types( return 0 ). 然后在ContentTypeDetector.CLASSFILE:修改方法analyzeAll(final InputStream input, final String location) ,可以这样做,如果location在arrary列表中包含排除类路径,则像所有其他内容类型一样忽略它们( return 0 )。

  3. mvn clean install to recompile the jacoco source code. mvn clean install重新编译jacoco源代码。

  4. Pass excludeClassPathArrayList in Analyzer class constructor and generate report. 在Analyzer类的构造函数中传递excludeClassPathArrayList并生成报告。

You can see excluded classes also exclude from generated report. 您可以看到排除的类也排除在生成的报告中。 As the implementation is very simple so I do not provide code example. 由于实现非常简单,因此我不提供代码示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM