|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license. |
3 | 3 |
|
4 | | -import { BranchCoverage, CancellationToken, DeclarationCoverage, DetailedCoverage, FileCoverage, Position, StatementCoverage, TestCoverageProvider, Uri } from 'vscode'; |
| 4 | +import { BranchCoverage, DeclarationCoverage, FileCoverage, FileCoverageDetail, Position, StatementCoverage, TestRun, Uri } from 'vscode'; |
5 | 5 | import { getJacocoReportBasePath } from '../utils/coverageUtils'; |
6 | 6 | import { executeJavaLanguageServerCommand } from '../utils/commandUtils'; |
7 | 7 | import { JavaTestRunnerDelegateCommands } from '../constants'; |
8 | 8 |
|
9 | | -export class JavaTestCoverageProvider implements TestCoverageProvider { |
| 9 | +export class JavaTestCoverageProvider { |
10 | 10 |
|
11 | | - private projectNames: Set<string>; |
| 11 | + private coverageDetails: Map<Uri, FileCoverageDetail[]> = new Map<Uri, FileCoverageDetail[]>(); |
12 | 12 |
|
13 | | - constructor() { |
14 | | - this.projectNames = new Set<string>(); |
15 | | - } |
16 | | - |
17 | | - public addProject(projectName: string): void { |
18 | | - this.projectNames.add(projectName); |
19 | | - } |
20 | | - |
21 | | - public async provideFileCoverage(token: CancellationToken): Promise<FileCoverage[]> { |
22 | | - const fileCoverages: FileCoverage[] = []; |
23 | | - for (const projectName of this.projectNames) { |
24 | | - const sourceFileCoverages: ISourceFileCoverage[] = await executeJavaLanguageServerCommand<void>(JavaTestRunnerDelegateCommands.GET_COVERAGE_DETAIL, |
25 | | - projectName, getJacocoReportBasePath(projectName), token) || []; |
26 | | - if (token.isCancellationRequested) { |
27 | | - return []; |
28 | | - } |
29 | | - |
30 | | - for (const sourceFileCoverage of sourceFileCoverages) { |
31 | | - const uri: Uri = Uri.parse(sourceFileCoverage.uriString); |
32 | | - const detailedCoverage: DetailedCoverage[] = []; |
33 | | - for (const lineCoverage of sourceFileCoverage.lineCoverages) { |
34 | | - const branchCoverages: BranchCoverage[] = []; |
35 | | - for (const branchCoverage of lineCoverage.branchCoverages) { |
36 | | - branchCoverages.push(new BranchCoverage(branchCoverage.hit, new Position(lineCoverage.lineNumber - 1, 0))); |
37 | | - } |
38 | | - const statementCoverage: StatementCoverage = new StatementCoverage(lineCoverage.hit, |
39 | | - new Position(lineCoverage.lineNumber - 1, 0), branchCoverages); |
40 | | - detailedCoverage.push(statementCoverage); |
41 | | - } |
42 | | - for (const methodCoverage of sourceFileCoverage.methodCoverages) { |
43 | | - const functionCoverage: DeclarationCoverage = new DeclarationCoverage(methodCoverage.name, methodCoverage.hit, |
44 | | - new Position(methodCoverage.lineNumber - 1, 0)); |
45 | | - detailedCoverage.push(functionCoverage); |
| 13 | + public async provideFileCoverage(run: TestRun, projectName: string): Promise<void> { |
| 14 | + const sourceFileCoverages: ISourceFileCoverage[] = await executeJavaLanguageServerCommand<void>(JavaTestRunnerDelegateCommands.GET_COVERAGE_DETAIL, |
| 15 | + projectName, getJacocoReportBasePath(projectName)) || []; |
| 16 | + for (const sourceFileCoverage of sourceFileCoverages) { |
| 17 | + const uri: Uri = Uri.parse(sourceFileCoverage.uriString); |
| 18 | + const detailedCoverage: FileCoverageDetail[] = []; |
| 19 | + for (const lineCoverage of sourceFileCoverage.lineCoverages) { |
| 20 | + const branchCoverages: BranchCoverage[] = []; |
| 21 | + for (const branchCoverage of lineCoverage.branchCoverages) { |
| 22 | + branchCoverages.push(new BranchCoverage(branchCoverage.hit, new Position(lineCoverage.lineNumber - 1, 0))); |
46 | 23 | } |
47 | | - fileCoverages.push(FileCoverage.fromDetails(uri, detailedCoverage)); |
| 24 | + const statementCoverage: StatementCoverage = new StatementCoverage(lineCoverage.hit, |
| 25 | + new Position(lineCoverage.lineNumber - 1, 0), branchCoverages); |
| 26 | + detailedCoverage.push(statementCoverage); |
| 27 | + } |
| 28 | + for (const methodCoverage of sourceFileCoverage.methodCoverages) { |
| 29 | + const functionCoverage: DeclarationCoverage = new DeclarationCoverage(methodCoverage.name, methodCoverage.hit, |
| 30 | + new Position(methodCoverage.lineNumber - 1, 0)); |
| 31 | + detailedCoverage.push(functionCoverage); |
48 | 32 | } |
| 33 | + run.addCoverage(FileCoverage.fromDetails(uri, detailedCoverage)); |
| 34 | + this.coverageDetails.set(uri, detailedCoverage); |
49 | 35 | } |
50 | | - return fileCoverages; |
| 36 | + } |
| 37 | + |
| 38 | + public getCoverageDetails(uri: Uri): FileCoverageDetail[] { |
| 39 | + return this.coverageDetails.get(uri) || []; |
51 | 40 | } |
52 | 41 | } |
53 | 42 |
|
|
0 commit comments