Skip to content

Commit 5b156d2

Browse files
authored
fix: Track the version of the test framework (#1608)
Signed-off-by: Sheng Chen <[email protected]>
1 parent c50f2c2 commit 5b156d2

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

java-extension/com.microsoft.java.test.target/com.microsoft.java.test.tp.target

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
<unit id="org.eclipse.jdt.source.feature.group" version="0.0.0"/>
1010
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
1111
<unit id="org.mockito.mockito-core" version="0.0.0"/>
12-
<repository location="https://download.eclipse.org/eclipse/updates/4.29/"/>
12+
<repository location="https://download.eclipse.org/eclipse/updates/4.28/R-4.28-202306050440/"/>
1313
</location>
1414
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
1515
<unit id="org.eclipse.xtext.xbase.lib" version="0.0.0"/>
16-
<repository location="https://download.eclipse.org/releases/2023-06/"/>
16+
<repository location="https://download.eclipse.org/releases/2023-03/"/>
1717
</location>
1818
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
1919
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.21.0/"/>

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@
5555
"main": "./main.js",
5656
"contributes": {
5757
"javaExtensions": [
58-
"./server/junit-jupiter-api_5.10.0.jar",
59-
"./server/junit-jupiter-engine_5.10.0.jar",
60-
"./server/junit-jupiter-migrationsupport_5.10.0.jar",
61-
"./server/junit-jupiter-params_5.10.0.jar",
62-
"./server/junit-platform-commons_1.10.0.jar",
63-
"./server/junit-platform-engine_1.10.0.jar",
64-
"./server/junit-platform-launcher_1.10.0.jar",
65-
"./server/junit-platform-runner_1.10.0.jar",
66-
"./server/junit-platform-suite-api_1.10.0.jar",
67-
"./server/junit-platform-suite-commons_1.10.0.jar",
68-
"./server/junit-platform-suite-engine_1.10.0.jar",
69-
"./server/junit-vintage-engine_5.10.0.jar",
58+
"./server/junit-jupiter-api_5.9.3.jar",
59+
"./server/junit-jupiter-engine_5.9.3.jar",
60+
"./server/junit-jupiter-migrationsupport_5.9.3.jar",
61+
"./server/junit-jupiter-params_5.9.3.jar",
62+
"./server/junit-platform-commons_1.9.3.jar",
63+
"./server/junit-platform-engine_1.9.3.jar",
64+
"./server/junit-platform-launcher_1.9.3.jar",
65+
"./server/junit-platform-runner_1.9.3.jar",
66+
"./server/junit-platform-suite-api_1.9.3.jar",
67+
"./server/junit-platform-suite-commons_1.9.3.jar",
68+
"./server/junit-platform-suite-engine_1.9.3.jar",
69+
"./server/junit-vintage-engine_5.9.3.jar",
7070
"./server/org.apiguardian.api_1.1.2.jar",
7171
"./server/org.eclipse.jdt.junit4.runtime_1.3.0.v20220609-1843.jar",
7272
"./server/org.eclipse.jdt.junit5.runtime_1.1.100.v20220907-0450.jar",
73-
"./server/org.opentest4j_1.3.0.jar",
73+
"./server/org.opentest4j_1.2.0.jar",
7474
"./server/com.microsoft.java.test.plugin-0.39.1.jar"
7575
],
7676
"viewsWelcome": [

src/controller/testController.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
import * as _ from 'lodash';
5+
import * as path from 'path';
56
import { CancellationToken, DebugConfiguration, Disposable, FileSystemWatcher, RelativePattern, TestController, TestItem, TestRun, TestRunProfileKind, TestRunRequest, tests, TestTag, Uri, window, workspace, WorkspaceFolder } from 'vscode';
67
import { instrumentOperation, sendError, sendInfo } from 'vscode-extension-telemetry-wrapper';
78
import { refreshExplorer } from '../commands/testExplorerCommands';
@@ -215,9 +216,6 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
215216
testRun: run,
216217
workspaceFolder,
217218
};
218-
sendInfo(operationId, {
219-
testFramework: TestKind[testContext.kind],
220-
});
221219
const runner: BaseRunner | undefined = getRunnerByContext(testContext);
222220
if (!runner) {
223221
window.showErrorMessage(`Failed to get suitable runner for the test kind: ${testContext.kind}.`);
@@ -228,6 +226,7 @@ export const runTests: (request: TestRunRequest, option: IRunOption) => any = in
228226
const resolvedConfiguration: DebugConfiguration = mergeConfigurations(option.launchConfiguration, config) ?? await resolveLaunchConfigurationForRunner(runner, testContext, config);
229227
resolvedConfiguration.__progressId = option.progressReporter?.getId();
230228
delegatedToDebugger = true;
229+
trackTestFrameworkVersion(testContext.kind, resolvedConfiguration.classPaths, resolvedConfiguration.modulePaths);
231230
await runner.run(resolvedConfiguration, token, option.progressReporter);
232231
} catch(error) {
233232
window.showErrorMessage(error.message || 'Failed to run tests.');
@@ -543,6 +542,36 @@ function getRunnerByContext(testContext: IRunTestContext): BaseRunner | undefine
543542
}
544543
}
545544

545+
function trackTestFrameworkVersion(testKind: TestKind, classpaths: string[], modulepaths: string[]) {
546+
let artifactPattern: RegExp;
547+
switch (testKind) {
548+
case TestKind.JUnit:
549+
artifactPattern = /junit-(\d+\.\d+\.\d+(-[a-zA-Z\d]+)?).jar/;
550+
break;
551+
case TestKind.JUnit5:
552+
artifactPattern = /junit-jupiter-api-(\d+\.\d+\.\d+(-[a-zA-Z\d]+)?).jar/;
553+
break;
554+
case TestKind.TestNG:
555+
artifactPattern = /testng-(\d+\.\d+\.\d+(-[a-zA-Z\d]+)?).jar/;
556+
break;
557+
default:
558+
return;
559+
}
560+
let version: string = 'unknown';
561+
for (const entry of [...classpaths, ...modulepaths]) {
562+
const fileName: string = path.basename(entry);
563+
const match: RegExpMatchArray | null = artifactPattern.exec(fileName);
564+
if (match) {
565+
version = match[1];
566+
break;
567+
}
568+
}
569+
sendInfo('', {
570+
testFramework: testKind,
571+
version,
572+
});
573+
}
574+
546575
interface IRunOption {
547576
isDebug: boolean;
548577
progressReporter?: IProgressReporter;

0 commit comments

Comments
 (0)