Jacoco exclude classes from report

和自甴很熟 提交于 2020-01-06 15:51:05

问题


I am using the example on 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.


回答1:


Sounds like you may be wanting the Excludes: in Code Coverage Preferences ?




回答2:


I'd say in analyzeStructure() you should not call 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. 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.




回答3:


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

  3. mvn clean install to recompile the jacoco source code.

  4. Pass excludeClassPathArrayList in Analyzer class constructor and generate report.

You can see excluded classes also exclude from generated report. As the implementation is very simple so I do not provide code example.



来源:https://stackoverflow.com/questions/30042709/jacoco-exclude-classes-from-report

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!