package org.jacoco.examples.expressions;
import java.io.File;
import java.io.IOException;
import org.jacoco.core.analysis.Analyzer;
import org.jacoco.core.analysis.CoverageBuilder;
import org.jacoco.core.analysis.IBundleCoverage;
import org.jacoco.core.tools.ExecFileLoader;
import org.jacoco.report.DirectorySourceFileLocator;
import org.jacoco.report.FileMultiReportOutput;
import org.jacoco.report.IReportVisitor;
import org.jacoco.report.html.HTMLFormatter;
public class Testjacoco {
private final String title;
private final File executionDataFile;
private final File classesDirectory;
private final File sourceDirectory;
private final File reportDirectory;
private ExecFileLoader execFileLoader;
public Testjacoco(final File projectDirectory ) {
this.title = projectDirectory.getName();
this.executionDataFile = new File("D:/coverage/jacoco-client.exec");//覆盖率的exec文件地址 这个就是刚才生成的文件,引用到就可以了
this.classesDirectory = new File("D:/java/t7/webapps/xxx/WEB-INF/classes");//目录下必须包含源码编译过的class文件,用来统计覆盖率.tomcat中的class文件地址
// this.sourceDirectory =null;
this.sourceDirectory = new File("D:/work/xxx/src");//源码的/src/main/java,只有写了源码地址覆盖率报告才能打开到代码层。使用jar只有数据结果
this.reportDirectory = new File("D:/work/xxx/jacoco_report");//要保存报告的地址,报告输出的地址
}
public void create() throws IOException {
loadExecutionData();
final IBundleCoverage bundleCoverage = analyzeStructure();
createReport(bundleCoverage);
}
private void createReport(final IBundleCoverage bundleCoverage)
throws IOException {
final HTMLFormatter htmlFormatter = new HTMLFormatter();
final IReportVisitor visitor = htmlFormatter
.createVisitor(new FileMultiReportOutput(reportDirectory));
visitor.visitInfo(execFileLoader.getSessionInfoStore().getInfos(),
execFileLoader.getExecutionDataStore().getContents());
visitor.visitBundle(bundleCoverage, new DirectorySourceFileLocator(
sourceDirectory, "utf-8", 4));
visitor.visitEnd();
}
private void loadExecutionData() throws IOException {
execFileLoader = new ExecFileLoader();
execFileLoader.load(executionDataFile);
}
private IBundleCoverage analyzeStructure() throws IOException {
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(
execFileLoader.getExecutionDataStore(), coverageBuilder);
analyzer.analyzeAll(classesDirectory);
return coverageBuilder.getBundle(title);
}
public static void main(final String[] args) throws IOException {
Testjacoco generator = new Testjacoco(new File(""));
generator.create();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jacoco获取exec和获取report
共13个文件
xml:3个
java:2个
class:2个
需积分: 36 26 下载量 95 浏览量
2019-02-21
16:32:16
上传
评论
收藏 16KB ZIP 举报
温馨提示
jacoco获取exec和获取覆盖率html的report,maven项目,pom文件没配置,自己搞一下
资源推荐
资源详情
资源评论
收起资源包目录
build.zip (13个子文件)
build
target
test-classes
org
jacoco
examples
parser
ExecutionDataClient.class 2KB
classes
META-INF
maven
org.jacoco
org.jacoco.examples.maven
pom.xml 2KB
pom.properties 250B
MANIFEST.MF 104B
org
jacoco
examples
expressions
Testjacoco.class 3KB
parser
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.jdt.core.prefs 243B
src
test
java
org
jacoco
examples
parser
ExecutionDataClient.java 2KB
main
java
org
jacoco
examples
expressions
Testjacoco.java 3KB
.project 580B
pom-offline.xml 3KB
.classpath 1KB
pom-it.xml 3KB
共 13 条
- 1
资源评论
woshi811
- 粉丝: 12
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功