Added destFile to set the file to write execution data to

This commit is contained in:
Erik C. Thauvin 2023-08-11 22:31:51 -07:00
parent 541ed74d9f
commit 951329595b
3 changed files with 22 additions and 3 deletions

2
.idea/misc.xml generated
View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<entry_points version="2.0"> <entry_points version="2.0">
@ -27,6 +28,7 @@
<pattern value="rife.bld.extension.JacocoReportOperation" method="fromProject" /> <pattern value="rife.bld.extension.JacocoReportOperation" method="fromProject" />
<pattern value="rife.bld.extension.JacocoReportOperation" method="writeReports" /> <pattern value="rife.bld.extension.JacocoReportOperation" method="writeReports" />
<pattern value="rife.bld.extension.JacocoReportOperationBuild" method="pmd" /> <pattern value="rife.bld.extension.JacocoReportOperationBuild" method="pmd" />
<pattern value="rife.bld.extension.JacocoReportOperation" method="destFile" />
</component> </component>
<component name="PDMPlugin"> <component name="PDMPlugin">
<option name="customRuleSets"> <option name="customRuleSets">

View file

@ -65,6 +65,10 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
* The location of the CSV report. * The location of the CSV report.
*/ */
File csv; File csv;
/**
* The file to write execution data to.
*/
File destFile;
/** /**
* The source file encoding. * The source file encoding.
*/ */
@ -94,6 +98,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
*/ */
File xml; File xml;
private IBundleCoverage analyze(ExecutionDataStore data) throws IOException { private IBundleCoverage analyze(ExecutionDataStore data) throws IOException {
var builder = new CoverageBuilder(); var builder = new CoverageBuilder();
var analyzer = new Analyzer(data, builder); var analyzer = new Analyzer(data, builder);
@ -120,6 +125,14 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
return this; return this;
} }
/**
* Sets the file to write execution data to.
*/
public JacocoReportOperation destFile(File destFile) {
this.destFile = destFile;
return this;
}
/** /**
* Sets the source file encoding. The platform encoding is used by default. * Sets the source file encoding. The platform encoding is used by default.
*/ */
@ -148,6 +161,10 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
var buildJacocoExecDir = Path.of(project.buildDirectory().getPath(), "jacoco").toFile(); var buildJacocoExecDir = Path.of(project.buildDirectory().getPath(), "jacoco").toFile();
var buildJacocoExec = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile(); var buildJacocoExec = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile();
if (destFile == null) {
destFile = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile();
}
if (execFiles.isEmpty()) { if (execFiles.isEmpty()) {
// project.testOperation().fromProject(project).javaOptions().javaAgent( // project.testOperation().fromProject(project).javaOptions().javaAgent(
// Path.of(project.libBldDirectory().getPath(), "org.jacoco.agent-" // Path.of(project.libBldDirectory().getPath(), "org.jacoco.agent-"
@ -156,7 +173,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
project.testOperation().fromProject(project).javaOptions().add("-javaagent:" + project.testOperation().fromProject(project).javaOptions().add("-javaagent:" +
Path.of(project.libBldDirectory().getPath(), "org.jacoco.agent-" Path.of(project.libBldDirectory().getPath(), "org.jacoco.agent-"
+ JaCoCo.VERSION.substring(0, JaCoCo.VERSION.lastIndexOf('.')) + "-runtime.jar") + JaCoCo.VERSION.substring(0, JaCoCo.VERSION.lastIndexOf('.')) + "-runtime.jar")
+ "=destfile=" + Path.of(buildJacocoExecDir.getPath(), "jacoco.exec")); + "=destfile=" + destFile.getPath());
try { try {
project.testOperation().execute(); project.testOperation().execute();
} catch (InterruptedException | ExitStatusException e) { } catch (InterruptedException | ExitStatusException e) {

View file

@ -62,8 +62,8 @@ class JacocoReportOperationTest {
assertThat(lines.anyMatch(s -> assertThat(lines.anyMatch(s ->
s.contains("<counter type=\"INSTRUCTION\" missed=\"0\" covered=\"3\"/>"))).isTrue(); s.contains("<counter type=\"INSTRUCTION\" missed=\"0\" covered=\"3\"/>"))).isTrue();
} }
assertThat(Path.of(html.getPath(), "com.example", "Examples.java.html")).exists();
// deleteOnExit(tempDir.toFile()); deleteOnExit(tempDir.toFile());
} }
JacocoReportOperation newJacocoReportOperation() { JacocoReportOperation newJacocoReportOperation() {