Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to migrate the deprecated test run configuration #664

Merged
merged 5 commits into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
142 changes: 0 additions & 142 deletions launch.test.schema.json

This file was deleted.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"onCommand:java.test.cancel",
"onCommand:java.test.show.report",
"onCommand:java.test.show.output",
"onCommand:java.test.open.log"
"onCommand:java.test.open.log",
"onCommand:java.test.config.migrate"
],
"main": "./dist/extension",
"contributes": {
Expand Down Expand Up @@ -147,12 +148,11 @@
"dark": "resources/media/dark/refresh.svg"
},
"category": "Java"
}
],
"jsonValidation": [
},
{
"fileMatch": "launch.test.json",
"url": "./launch.test.schema.json"
"command": "java.test.config.migrate",
"title": "%contributes.commands.java.test.config.migrate.title%",
"category": "Java"
}
],
"configuration": {
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"contributes.commands.java.test.explorer.debug.config.title": "Debug With Configuration",
"contributes.commands.java.test.cancel.title": "Cancel Test Job",
"contributes.commands.java.test.explorer.refresh.title": "Refresh",
"contributes.commands.java.test.config.migrate.title": "Migrate Deprecated 'launch.test.json'",
"configuration.java.test.report.position.description": "Specify where to show the test report",
"configuration.java.test.log.level.description": "Specify the level of the test logs",
"configuration.java.test.message.hintForDeprecatedConfig.description": "Specify whether the extension will show hint dialog when deprecated configuration file is used",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"contributes.commands.java.test.explorer.debug.config.title": "根据配置文件调试",
"contributes.commands.java.test.cancel.title": "取消测试任务",
"contributes.commands.java.test.explorer.refresh.title": "刷新",
"contributes.commands.java.test.config.migrate.title": "迁移已弃用的 'launch.test.json' 文件",
"configuration.java.test.report.position.description": "设定测试报告的显示位置",
"configuration.java.test.log.level.description": "设定日志级别",
"configuration.java.test.message.hintForDeprecatedConfig.description": "设定插件是否会对使用弃用的配置文件进行提示",
Expand Down
1 change: 1 addition & 0 deletions src/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export namespace JavaTestRunnerCommands {
export const SHOW_TEST_OUTPUT: string = 'java.test.show.output';
export const OPEN_TEST_LOG: string = 'java.test.open.log';
export const JAVA_TEST_CANCEL: string = 'java.test.cancel';
export const JAVA_CONFIG_MIGRATE: string = 'java.test.config.migrate';
}
1 change: 0 additions & 1 deletion src/constants/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

export const MAX_CLASS_PATH_LENGTH: number = 4096;
export const CHILD_PROCESS_MAX_BUFFER_SIZE: number = 1024 * 1024;

export const LOG_FILE_NAME: string = 'java_test_runner.log';
export const LOG_FILE_MAX_SIZE: number = 5 * 1024 * 1024;
Expand Down
1 change: 1 addition & 0 deletions src/constants/dialogOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const LEARN_MORE: string = 'Learn More';
export const NEVER_SHOW: string = 'Never Show again';
export const YES: string = 'Yes';
export const NO: string = 'No';
export const OPEN_SETTING: string = 'Open Settings';
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { testFileWatcher } from './testFileWatcher';
import { testReportProvider } from './testReportProvider';
import { testResultManager } from './testResultManager';
import { testStatusBarProvider } from './testStatusBarProvider';
import { migrateTestConfig } from './utils/configUtils';

export async function activate(context: ExtensionContext): Promise<void> {
await initializeFromJsonFile(context.asAbsolutePath('./package.json'));
Expand Down Expand Up @@ -65,6 +66,7 @@ async function doActivate(_operationId: string, context: ExtensionContext): Prom
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.SHOW_TEST_OUTPUT, () => showOutputChannel()),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.OPEN_TEST_LOG, async () => await openLogFile(storagePath)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_CANCEL, async () => await runnerExecutor.cleanUp(true /* isCancel */)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_CONFIG_MIGRATE, async () => await migrateTestConfig()),
);
}

Expand Down
2 changes: 0 additions & 2 deletions src/runConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import { BUILTIN_CONFIG_NAME } from './constants/configs';

export interface IExecutionConfig {
name?: string;
projectName?: string;
workingDirectory?: string;
args?: any[];
vmargs?: any[];
env?: { [key: string]: string; };
preLaunchTask?: string;
}

export interface IExecutionConfigGroup {
Expand Down
1 change: 0 additions & 1 deletion src/runners/ITestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ITestResult } from './models';

export interface ITestRunner {
setup(tests: ITestItem[], isDebug: boolean, config?: IExecutionConfig): Promise<void>;
execPreLaunchTaskIfExist(): Promise<void>;
run(): Promise<ITestResult[]>;
cleanUp(isCancel: boolean): Promise<void>;
}
35 changes: 0 additions & 35 deletions src/runners/baseRunner/BaseRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as iconv from 'iconv-lite';
import * as os from 'os';
import * as path from 'path';
import { debug, Uri, workspace, WorkspaceConfiguration } from 'vscode';
import { CHILD_PROCESS_MAX_BUFFER_SIZE } from '../../constants/configs';
import { logger } from '../../logger/logger';
import { ITestItem } from '../../protocols';
import { IExecutionConfig } from '../../runConfigs';
Expand Down Expand Up @@ -153,40 +152,6 @@ export abstract class BaseRunner implements ITestRunner {
return commandParams;
}

public async execPreLaunchTaskIfExist(): Promise<void> {
return new Promise<void>((resolve: () => void, reject: (err: Error) => void): void => {
if (!this.config || !this.config.preLaunchTask) {
return resolve();
}

this.process = cp.exec(
this.config.preLaunchTask,
{
maxBuffer: CHILD_PROCESS_MAX_BUFFER_SIZE,
cwd: this.config.workingDirectory,
},
);

this.process.on('error', (err: Error) => {
logger.error('Failed to run pre-launch task', err);
return reject(err);
});
this.process.stderr.on('data', (data: Buffer) => {
logger.info(data.toString());
});
this.process.stdout.on('data', (data: Buffer) => {
logger.info(data.toString());
});
this.process.on('close', (signal: number) => {
if (signal && signal !== 0) {
return reject(new Error(`Prelaunch task exited with code ${signal}.`));
} else {
return resolve();
}
});
});
}

protected abstract getRunnerCommandParams(): string[];

private async getRunnerJarFilePath(): Promise<string> {
Expand Down
5 changes: 2 additions & 3 deletions src/runners/runnerExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { testCodeLensProvider } from '../codeLensProvider';
import { logger } from '../logger/logger';
import { ITestItem, TestKind } from '../protocols';
import { IExecutionConfig } from '../runConfigs';
import { testConfigManager } from '../testConfigManager';
import { testReportProvider } from '../testReportProvider';
import { testResultManager } from '../testResultManager';
import { testStatusBarProvider } from '../testStatusBarProvider';
import { loadRunConfig } from '../utils/configUtils';
import { resolve } from '../utils/settingUtils';
import { ITestRunner } from './ITestRunner';
import { JUnit4Runner } from './junit4Runner/Junit4Runner';
Expand Down Expand Up @@ -41,7 +41,7 @@ class RunnerExecutor {
for (const [runner, tests] of this._runnerMap.entries()) {
// The test items that belong to a test runner, here the test items should be in the same workspace folder.
const workspaceFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(Uri.parse(tests[0].location.uri));
const config: IExecutionConfig | undefined = await testConfigManager.loadRunConfig(workspaceFolder, isDebug);
const config: IExecutionConfig | undefined = await loadRunConfig(workspaceFolder);
if (!config) {
logger.info('Test job is canceled.');
continue;
Expand All @@ -56,7 +56,6 @@ class RunnerExecutor {
await runner.setup(tests, isDebug, resolve(config, Uri.parse(tests[0].location.uri)));
testStatusBarProvider.showRunningTest();
progress.report({ message: 'Running tests...'});
await runner.execPreLaunchTaskIfExist();
if (token.isCancellationRequested) {
return;
}
Expand Down