11package com .teamscale .jacoco .agent .testimpact ;
22
3- import static java .util .stream .Collectors .toList ;
4-
5- import java .io .File ;
6- import java .io .IOException ;
7- import java .util .ArrayList ;
8- import java .util .List ;
9-
10- import org .slf4j .Logger ;
11-
123import com .teamscale .client .ClusteredTestDetails ;
134import com .teamscale .client .JsonUtils ;
145import com .teamscale .client .PrioritizableTestCluster ;
156import com .teamscale .jacoco .agent .JacocoRuntimeController ;
16- import com .teamscale .jacoco .agent .options .AgentOptions ;
177import com .teamscale .jacoco .agent .logging .LoggingUtils ;
8+ import com .teamscale .jacoco .agent .options .AgentOptions ;
189import com .teamscale .report .testwise .jacoco .JaCoCoTestwiseReportGenerator ;
1910import com .teamscale .report .testwise .jacoco .cache .CoverageGenerationException ;
2011import com .teamscale .report .testwise .model .TestExecution ;
2314import com .teamscale .report .testwise .model .TestwiseCoverageReport ;
2415import com .teamscale .report .testwise .model .builder .TestCoverageBuilder ;
2516import com .teamscale .report .testwise .model .builder .TestwiseCoverageReportBuilder ;
17+ import org .slf4j .Logger ;
18+
19+ import java .io .File ;
20+ import java .io .IOException ;
21+ import java .util .ArrayList ;
22+ import java .util .List ;
23+
24+ import static java .util .stream .Collectors .toList ;
2625
2726/**
2827 * Base for strategies that produce testwise coverage information in JSON and store or send this data further.
@@ -45,16 +44,16 @@ public abstract class CoverageToJsonStrategyBase extends TestEventHandlerStrateg
4544 private final JaCoCoTestwiseReportGenerator reportGenerator ;
4645
4746 public CoverageToJsonStrategyBase (JacocoRuntimeController controller , AgentOptions agentOptions ,
48- JaCoCoTestwiseReportGenerator reportGenerator ) {
47+ JaCoCoTestwiseReportGenerator reportGenerator ) {
4948 super (agentOptions , controller );
5049 this .reportGenerator = reportGenerator ;
5150 }
5251
5352 @ Override
5453 public List <PrioritizableTestCluster > testRunStart (List <ClusteredTestDetails > availableTests ,
55- boolean includeNonImpactedTests ,
56- boolean includeAddedTests , boolean includeFailedAndSkipped ,
57- String baseline , String baselineRevision ) throws IOException {
54+ boolean includeNonImpactedTests ,
55+ boolean includeAddedTests , boolean includeFailedAndSkipped ,
56+ String baseline , String baselineRevision ) throws IOException {
5857 if (availableTests != null ) {
5958 this .availableTests = new ArrayList <>(availableTests );
6059 }
@@ -65,17 +64,16 @@ public List<PrioritizableTestCluster> testRunStart(List<ClusteredTestDetails> av
6564 @ Override
6665 public void testStart (String uniformPath ) {
6766 super .testStart (uniformPath );
68-
6967 if (availableTests .stream ().noneMatch (test -> test .uniformPath .equals (uniformPath ))) {
7068 // ensure that we can at least generate a report for the tests that were actually run,
7169 // even if the caller did not provide a list of tests up-front in testRunStart
72- availableTests .add (new ClusteredTestDetails (uniformPath , uniformPath , null , null , null ));
70+ availableTests .add (new ClusteredTestDetails (uniformPath , uniformPath , null , null ));
7371 }
7472 }
7573
7674 @ Override
7775 public TestInfo testEnd (String test ,
78- TestExecution testExecution ) throws JacocoRuntimeController .DumpException , CoverageGenerationException {
76+ TestExecution testExecution ) throws JacocoRuntimeController .DumpException , CoverageGenerationException {
7977 super .testEnd (test , testExecution );
8078 if (testExecution != null ) {
8179 testExecutions .add (testExecution );
@@ -100,6 +98,7 @@ public TestInfo testEnd(String test,
10098 public void testRunEnd (boolean partial ) throws IOException , CoverageGenerationException {
10199 if (testExecFile == null ) {
102100 logger .warn ("Tried to end a test run that contained no tests!" );
101+ clearTestRun ();
103102 return ;
104103 }
105104
@@ -132,16 +131,22 @@ private String createTestwiseCoverageReport(boolean partial) throws IOException,
132131 reportGenerator .updateClassDirCache ();
133132 TestwiseCoverage testwiseCoverage = reportGenerator .convert (testExecFile );
134133 logger .debug ("Created testwise coverage report (containing coverage for tests `{}`)" ,
135- testwiseCoverage .getTests ().values ().stream ().map (TestCoverageBuilder ::getUniformPath ).collect (toList ()));
134+ testwiseCoverage .getTests ().values ().stream ().map (TestCoverageBuilder ::getUniformPath )
135+ .collect (toList ()));
136136
137- TestwiseCoverageReport report = TestwiseCoverageReportBuilder .createFrom (availableTests , testwiseCoverage .getTests ().values (), testExecutions , partial );
137+ TestwiseCoverageReport report = TestwiseCoverageReportBuilder .createFrom (availableTests ,
138+ testwiseCoverage .getTests ().values (), testExecutions , partial );
138139
139140 testExecFile .delete ();
140141 testExecFile = null ;
141- availableTests .clear ();
142- testExecutions .clear ();
142+ clearTestRun ();
143143
144144 return JsonUtils .serializeToJson (report );
145145 }
146146
147+ private void clearTestRun () {
148+ availableTests .clear ();
149+ testExecutions .clear ();
150+ }
151+
147152}
0 commit comments