有没有办法用 JaCoCo Java API 检测 jar 文件?
Is there a way to instrument jar files with JaCoCo Java API?
我要从 Emma 迁移过来。到 JaCoCo,到目前为止一切正常。我正在努力处理的其中一个部分是代码 EMMA 正在检测一组依赖于主项目的子项目的 jar 文件。
在 EMMA 上,代码如下所示:
InstrProcessor processor = InstrProcessor.create();
processor.setInstrPath(getFilePaths(jars), false);
processor.setOutMode(OutMode.OUT_MODE_OVERWRITE);
processor.setMetaOutFile(metadataFile.getAbsolutePath());
processor.setMetaOutMerge(merge);
processor.run();
我找到的最接近 JaCoCo 的是 Instrumenter class,但它似乎只接收文件输入流。 JavaDoc 中没有关于它工作的提示。有什么想法吗?
引用 JavaDoc of a method org.jacoco.core.instr.Instrumenter#instrumentAll
:
Creates a instrumented version of the given resource depending on its type. Class files and the content of archive files are instrumented. All other files are copied without modification.
即
try (
FileInputStream in = new FileInputStream("input.jar");
FileOutputStream out = new FileOutputStream("output.jar");
) {
instrumenter.instrumentAll(in, out, "input.jar");
}
这正是 instrumentation of JAR files implemented in JaCoCo Command Line Interface。
我要从 Emma 迁移过来。到 JaCoCo,到目前为止一切正常。我正在努力处理的其中一个部分是代码 EMMA 正在检测一组依赖于主项目的子项目的 jar 文件。
在 EMMA 上,代码如下所示:
InstrProcessor processor = InstrProcessor.create();
processor.setInstrPath(getFilePaths(jars), false);
processor.setOutMode(OutMode.OUT_MODE_OVERWRITE);
processor.setMetaOutFile(metadataFile.getAbsolutePath());
processor.setMetaOutMerge(merge);
processor.run();
我找到的最接近 JaCoCo 的是 Instrumenter class,但它似乎只接收文件输入流。 JavaDoc 中没有关于它工作的提示。有什么想法吗?
引用 JavaDoc of a method org.jacoco.core.instr.Instrumenter#instrumentAll
:
Creates a instrumented version of the given resource depending on its type. Class files and the content of archive files are instrumented. All other files are copied without modification.
即
try (
FileInputStream in = new FileInputStream("input.jar");
FileOutputStream out = new FileOutputStream("output.jar");
) {
instrumenter.instrumentAll(in, out, "input.jar");
}
这正是 instrumentation of JAR files implemented in JaCoCo Command Line Interface。