From 54134f36d03e197b890b1f8c874790f56710a853 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Wed, 15 May 2019 16:44:20 +0800 Subject: [PATCH] feat: Automatically add --enable-preview to vmargs when necessary --- src/constants/commands.ts | 2 ++ src/runners/runnerExecutor.ts | 10 ++++++++++ src/utils/commandUtils.ts | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/constants/commands.ts b/src/constants/commands.ts index 8e750f04..b93aadae 100644 --- a/src/constants/commands.ts +++ b/src/constants/commands.ts @@ -13,6 +13,8 @@ export namespace JavaTestRunnerDelegateCommands { export const SEARCH_TEST_LOCATION: string = 'vscode.java.test.search.location'; export const RESOLVE_RUNTIME_CLASSPATH: string = 'vscode.java.test.runtime.classpath'; export const GET_PROJECT_INFO: string = 'vscode.java.test.project.info'; + // This is a command from the Java Debugger + export const JAVA_CHECK_PROJECT_SETTINGS: string = 'vscode.java.checkProjectSettings'; } export namespace JavaTestRunnerCommands { diff --git a/src/runners/runnerExecutor.ts b/src/runners/runnerExecutor.ts index 89fea95f..ee044b4f 100644 --- a/src/runners/runnerExecutor.ts +++ b/src/runners/runnerExecutor.ts @@ -9,6 +9,7 @@ import { IExecutionConfig } from '../runConfigs'; import { testReportProvider } from '../testReportProvider'; import { testResultManager } from '../testResultManager'; import { testStatusBarProvider } from '../testStatusBarProvider'; +import { shouldEnablePreviewFlag } from '../utils/commandUtils'; import { loadRunConfig } from '../utils/configUtils'; import { resolve } from '../utils/settingUtils'; import { ITestRunner } from './ITestRunner'; @@ -47,6 +48,15 @@ class RunnerExecutor { continue; } + // Auto add '--enable-preview' vmArgs if the java project enables COMPILER_PB_ENABLE_PREVIEW_FEATURES flag. + if (await shouldEnablePreviewFlag('', tests[0].project)) { + if (config.vmargs) { + config.vmargs.push('--enable-preview'); + } else { + config.vmargs = ['--enable-preview']; + } + } + await window.withProgress( { location: ProgressLocation.Notification, cancellable: true }, async (progress: Progress, token: CancellationToken): Promise => { diff --git a/src/utils/commandUtils.ts b/src/utils/commandUtils.ts index 0d5c3eee..ba4ef1e1 100644 --- a/src/utils/commandUtils.ts +++ b/src/utils/commandUtils.ts @@ -38,6 +38,24 @@ export async function resolveRuntimeClassPath(paths: string[]): Promise { + return await executeJavaLanguageServerCommand( + JavaTestRunnerDelegateCommands.JAVA_CHECK_PROJECT_SETTINGS, JSON.stringify({ + className, + projectName, + inheritedOptions, + expectedOptions, + })) || false; +} + +const COMPILER_PB_ENABLE_PREVIEW_FEATURES: string = 'org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures'; +export async function shouldEnablePreviewFlag(className: string, projectName: string): Promise { + const expectedOptions: { [x: string]: string; } = { + [COMPILER_PB_ENABLE_PREVIEW_FEATURES]: 'enabled', + }; + return await checkProjectSettings(className, projectName, true, expectedOptions); +} + async function executeJavaLanguageServerCommand(...rest: any[]): Promise { try { return await commands.executeCommand(JavaLanguageServerCommands.EXECUTE_WORKSPACE_COMMAND, ...rest);