Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions src/runners/runnerExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<any>, token: CancellationToken): Promise<void> => {
Expand Down
18 changes: 18 additions & 0 deletions src/utils/commandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ export async function resolveRuntimeClassPath(paths: string[]): Promise<string[]
JavaTestRunnerDelegateCommands.RESOLVE_RUNTIME_CLASSPATH, paths) || []);
}

export async function checkProjectSettings(className: string, projectName: string, inheritedOptions: boolean, expectedOptions: {[key: string]: string}): Promise<boolean> {
return await executeJavaLanguageServerCommand<boolean>(
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<boolean> {
const expectedOptions: { [x: string]: string; } = {
[COMPILER_PB_ENABLE_PREVIEW_FEATURES]: 'enabled',
};
return await checkProjectSettings(className, projectName, true, expectedOptions);
}

async function executeJavaLanguageServerCommand<T>(...rest: any[]): Promise<T | undefined> {
try {
return await commands.executeCommand<T>(JavaLanguageServerCommands.EXECUTE_WORKSPACE_COMMAND, ...rest);
Expand Down