diff --git a/packages/zowe-explorer/src/extension.ts b/packages/zowe-explorer/src/extension.ts index 9a2a8569af..ca109a857f 100644 --- a/packages/zowe-explorer/src/extension.ts +++ b/packages/zowe-explorer/src/extension.ts @@ -42,7 +42,7 @@ import SpoolProvider from "./SpoolProvider"; import * as nls from "vscode-nls"; import { TsoCommandHandler } from "./command/TsoCommandHandler"; import { cleanTempDir, moveTempFolder, hideTempFolder } from "./utils/TempFolder"; -import { standardizeSettings } from "./utils/SettingsConfig"; +import { SettingsConfig } from "./utils/SettingsConfig"; import { UIViews } from "./shared/ui-views"; // Set up localization @@ -306,7 +306,7 @@ export async function activate(context: vscode.ExtensionContext): Promise - key.match(new RegExp("Zowe-*|Zowe\\s*", "g")) -); - -const currentVersionNumber = semver.major( - vscode.extensions.getExtension("zowe.vscode-extension-for-zowe").packageJSON.version -); - -async function promptReload() { - // Prompt user to reload VS Code window - const reloadButton = localize("standardization.reload.button", "Reload Window"); - const infoMsg = localize( - "standardization.reload.infoMessage", - "Settings have been successfully migrated for Zowe Explorer version 2 and above. To apply these settings, please reload your VS Code window." - ); - await vscode.window.showInformationMessage(infoMsg, ...[reloadButton])?.then(async (selection) => { - if (selection === reloadButton) { - await vscode.commands.executeCommand("workbench.action.reloadWindow"); +export class SettingsConfig { + public static async standardizeSettings(): Promise { + const globalIsNotMigrated = + SettingsConfig.configurations.inspect(globals.SETTINGS_VERSION).globalValue !== + SettingsConfig.currentVersionNumber; + const workspaceIsNotMigrated = + SettingsConfig.configurations.inspect(globals.SETTINGS_VERSION).workspaceValue !== + SettingsConfig.currentVersionNumber; + const workspaceIsOpen = vscode.workspace.workspaceFolders !== undefined; + const zoweSettingsExist = SettingsConfig.zoweOldConfigurations.length > 0; + + if (!zoweSettingsExist) { + return; } - }); -} - -export async function standardizeGlobalSettings() { - let globalIsMigrated = - (await configurations.inspect(globals.SETTINGS_VERSION).globalValue) !== currentVersionNumber; - // Standardize global settings when old Zowe settings were found - if (zoweOldConfigurations.length > 0) { - zoweOldConfigurations.forEach(async (configuration) => { - let globalValue: any = await configurations.inspect(configuration).globalValue; - - // Adjust fetching of value due to schema change - if (configuration === "Zowe-Temp-Folder-Location") { - globalValue = globalValue ? globalValue.folderPath : globalValue; - } - - const newSetting = configurationDictionary[configuration]; + if (workspaceIsNotMigrated && workspaceIsOpen) { + await SettingsConfig.standardizeWorkspaceSettings(); + } - if (globalValue !== undefined) { - await configurations.update(newSetting, globalValue, vscode.ConfigurationTarget.Global); - globalIsMigrated = true; + if (globalIsNotMigrated) { + await SettingsConfig.standardizeGlobalSettings(); + } + } + // Dictionary describing translation from old configuration names to new standardized names + private static configurationDictionary = { + "Zowe-Default-Datasets-Binary": globals.SETTINGS_DS_DEFAULT_BINARY, + "Zowe-Default-Datasets-C": globals.SETTINGS_DS_DEFAULT_C, + "Zowe-Default-Datasets-Classic": globals.SETTINGS_DS_DEFAULT_CLASSIC, + "Zowe-Default-Datasets-PDS": globals.SETTINGS_DS_DEFAULT_PDS, + "Zowe-Default-Datasets-PS": globals.SETTINGS_DS_DEFAULT_PS, + "Zowe-Temp-Folder-Location": globals.SETTINGS_TEMP_FOLDER_PATH, + "Zowe Security: Credential Key": globals.SETTINGS_SECURITY_CREDENTIAL_PLUGIN, + "Zowe Commands: History": globals.SETTINGS_COMMANDS_HISTORY, + "Zowe Commands: Always edit": globals.SETTINGS_COMMANDS_ALWAYS_EDIT, + "Zowe-Automatic-Validation": globals.SETTINGS_AUTOMATIC_PROFILE_VALIDATION, + "Zowe-DS-Persistent": globals.SETTINGS_DS_HISTORY, + "Zowe-USS-Persistent": globals.SETTINGS_USS_HISTORY, + "Zowe-Jobs-Persistent": globals.SETTINGS_JOBS_HISTORY, + }; + private static configurations = vscode.workspace.getConfiguration(); + private static zoweOldConfigurations = Object.keys(SettingsConfig.configurations).filter((key) => + key.match(new RegExp("Zowe-*|Zowe\\s*", "g")) + ); + private static currentVersionNumber = semver.major( + vscode.extensions.getExtension("zowe.vscode-extension-for-zowe").packageJSON.version + ); + private static async promptReload(): Promise { + // Prompt user to reload VS Code window + const reloadButton = localize("standardization.reload.button", "Reload Window"); + const infoMsg = localize( + "standardization.reload.infoMessage", + "Settings have been successfully migrated for Zowe Explorer version 2 and above. To apply these settings, please reload your VS Code window." + ); + await vscode.window.showInformationMessage(infoMsg, ...[reloadButton])?.then(async (selection) => { + if (selection === reloadButton) { + await vscode.commands.executeCommand("workbench.action.reloadWindow"); } }); } - if (globalIsMigrated) { - await configurations.update(globals.SETTINGS_VERSION, currentVersionNumber, vscode.ConfigurationTarget.Global); - await promptReload(); - } -} - -export async function standardizeWorkspaceSettings() { - let workspaceIsNotMigrated = - (await configurations.inspect(globals.SETTINGS_VERSION).workspaceValue) !== currentVersionNumber; + private static async standardizeGlobalSettings(): Promise { + let globalIsMigrated = + SettingsConfig.configurations.inspect(globals.SETTINGS_VERSION).globalValue !== + SettingsConfig.currentVersionNumber; - // Standardize workspace settings when old Zowe settings were found - if (zoweOldConfigurations.length > 0) { - zoweOldConfigurations - .filter((c) => !c.match(new RegExp("Zowe-[A-Za-z]+-Persistent|Zowe Commands: History", "g"))) - .forEach(async (configuration) => { - let workspaceValue: any = await configurations.inspect(configuration).workspaceValue; + // Standardize global settings when old Zowe settings were found + if (SettingsConfig.zoweOldConfigurations.length > 0) { + SettingsConfig.zoweOldConfigurations.forEach(async (configuration) => { + let globalValue: any = SettingsConfig.configurations.inspect(configuration).globalValue; + // Adjust fetching of value due to schema change if (configuration === "Zowe-Temp-Folder-Location") { - workspaceValue = workspaceValue ? workspaceValue.folderPath : workspaceValue; + globalValue = globalValue ? globalValue.folderPath : globalValue; } - const newSetting = configurationDictionary[configuration]; + const newSetting = SettingsConfig.configurationDictionary[configuration]; - if (workspaceValue !== undefined) { - await configurations.update(newSetting, workspaceValue, vscode.ConfigurationTarget.Workspace); - workspaceIsNotMigrated = true; + if (globalValue !== undefined) { + await SettingsConfig.configurations.update( + newSetting, + globalValue, + vscode.ConfigurationTarget.Global + ); + globalIsMigrated = true; } }); - } + } - if (workspaceIsNotMigrated) { - await configurations.update( - globals.SETTINGS_VERSION, - currentVersionNumber, - vscode.ConfigurationTarget.Workspace - ); + if (globalIsMigrated) { + await SettingsConfig.configurations.update( + globals.SETTINGS_VERSION, + SettingsConfig.currentVersionNumber, + vscode.ConfigurationTarget.Global + ); + await SettingsConfig.promptReload(); + } } -} -export async function standardizeSettings() { - const globalIsNotMigrated = - (await configurations.inspect(globals.SETTINGS_VERSION).globalValue) !== currentVersionNumber; - const workspaceIsNotMigrated = - (await configurations.inspect(globals.SETTINGS_VERSION).workspaceValue) !== currentVersionNumber; - const workspaceIsOpen = vscode.workspace.workspaceFolders !== undefined; + private static async standardizeWorkspaceSettings(): Promise { + let workspaceIsMigrated = false; + // Standardize workspace settings when old Zowe settings were found + if (SettingsConfig.zoweOldConfigurations.length > 0) { + // filter to only supported workspace configurations in scope + const filteredConfigurations = SettingsConfig.zoweOldConfigurations.filter( + (c) => !c.match(new RegExp("Zowe-[A-Za-z]+-Persistent|Zowe Commands: History", "g")) + ); - if (workspaceIsNotMigrated && workspaceIsOpen) { - await standardizeWorkspaceSettings(); - } + for (const configuration of filteredConfigurations) { + let workspaceValue: any = SettingsConfig.configurations.inspect(configuration).workspaceValue; - if (globalIsNotMigrated) { - await standardizeGlobalSettings(); + if (configuration === "Zowe-Temp-Folder-Location") { + workspaceValue = workspaceValue ? workspaceValue.folderPath : workspaceValue; + } + + const newSetting = SettingsConfig.configurationDictionary[configuration]; + + if (workspaceValue !== undefined) { + await SettingsConfig.configurations.update( + newSetting, + workspaceValue, + vscode.ConfigurationTarget.Workspace + ); + workspaceIsMigrated = true; + } + } + } + + if (workspaceIsMigrated) { + await SettingsConfig.configurations.update( + globals.SETTINGS_VERSION, + SettingsConfig.currentVersionNumber, + vscode.ConfigurationTarget.Workspace + ); + } } }