Skip to content
Draft
20 changes: 20 additions & 0 deletions packages/zowe-explorer-api/__mocks__/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ export enum QuickPickItemKind {
Default = 0,
}

/**
* A location in the editor at which progress notifications can be shown.
*/
export enum ProgressLocation {
SourceControl = 1,
Window = 10,
Notification = 15,
}

/**
* Represents a tab within a {@link TabGroup group of tabs}.
* Tabs are merely the graphical representation within the editor area.
Expand Down Expand Up @@ -496,6 +505,17 @@ export namespace window {
};
}

export function showInputBox(_options?: any): Thenable<string | undefined> {
return Promise.resolve(undefined);
}

export function withProgress<R>(
_options: { location: any; title?: string; cancellable?: boolean },
task: (progress: { report: (value: { increment?: number; message?: string }) => void }, token: any) => Thenable<R>
): Thenable<R> {
return task({ report: () => {} }, { isCancellationRequested: false, onCancellationRequested: () => ({ dispose: () => {} }) }) as Thenable<R>;
}

/**
* Options to configure the behavior of the message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export namespace Gui {
export function warningMessage() {
return undefined;
}

export function setStatusBarMessage(_text: string, _timeoutOrThenable?: number | Promise<any>): { dispose(): void } {
return { dispose: () => {} };
}
}

export class ZoweVsCodeExtension {
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/src/trees/shared/SharedInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class SharedInit {

// Zowe Native registrations
const zoweExplorerApi = ZoweExplorerApiRegister.getInstance().getExplorerExtenderApi();
context.subscriptions.push(...zowex.registerCommands(context, zoweExplorerApi));
context.subscriptions.push(...zowex.Utilities.registerCommands(context, zoweExplorerApi));
context.subscriptions.push(zowex.SshClientCache.initialize(zoweExplorerApi.getProfilesCache()));
zowex.handleNativeSshSettings(context);

Expand Down
5 changes: 2 additions & 3 deletions packages/zowex-for-zowe-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
"lint:test": "eslint --format stylish \"tests/**/*.ts\"",
"madge": "madge -c --no-color --no-spinner --exclude __mocks__ --extensions js,ts src/",
"package": "echo 'zowex: nothing to package.'",
"oldtest": "vitest run --coverage",
"oldtest:ui": "vitest --ui --coverage",
"oldtest:watch": "vitest --watch",
"test": "vitest run --coverage",
"test:ui": "vitest --ui --coverage",
"test:watch": "vitest --watch",
"watch": "tsc --watch -p ./"
},
"dependencies": {
Expand Down
136 changes: 76 additions & 60 deletions packages/zowex-for-zowe-explorer/src/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,71 +18,87 @@ import { SshClientCache } from "./SshClientCache";
import { SshErrorHandler } from "./SshErrorHandler";
import { deployWithProgress } from "./ServerDeployment";

export function registerCommands(context: vscode.ExtensionContext, zoweExplorerApi: IApiExplorerExtender): vscode.Disposable[] {
const profCache = zoweExplorerApi.getProfilesCache();
return [
vscode.commands.registerCommand(`zowe.zowex.connect`, async (profName?: string) => {
imperative.Logger.getAppLogger().trace("Running connect command for profile %s", profName);
const vscePromptApi = new VscePromptApi(await profCache.getProfileInfo());
const profile = await vscePromptApi.promptForProfile(profName, { prioritizeProjectLevelConfig: false });
if (!profile?.profile) {
return;
}
const defaultServerPath = ConfigUtils.getServerPath(profile.profile);
const deployDirectory = await vscePromptApi.promptForDeployDirectory(profile.profile.host, defaultServerPath);
if (!deployDirectory) {
return;
}
export class Utilities {
public static registerCommands(_context: vscode.ExtensionContext, zoweExplorerApi: IApiExplorerExtender): vscode.Disposable[] {
return [
vscode.commands.registerCommand(`zowe.zowex.connect`, async (profName?: string) => {
await Utilities.connectCallback(zoweExplorerApi, profName);
}),
vscode.commands.registerCommand(`zowe.zowex.restart`, async (profName?: string) => {
await Utilities.restartCallback(zoweExplorerApi, profName);
}),
vscode.commands.registerCommand(`zowe.zowex.uninstall`, async (profName?: string) => {
await Utilities.uninstallCallback(zoweExplorerApi, profName);
}),
];
}

const sshSession = ZSshUtils.buildSession(profile.profile);
const deployStatus = await deployWithProgress(sshSession, deployDirectory);
if (!deployStatus) {
return;
}
private static async connectCallback(zoweExplorerApi: IApiExplorerExtender, profName?: string): Promise<void> {
imperative.Logger.getAppLogger().trace("Running connect command for profile %s", profName);
const profCache = zoweExplorerApi.getProfilesCache();
const vscePromptApi = new VscePromptApi(await profCache.getProfileInfo());
const profile = await vscePromptApi.promptForProfile(profName, { prioritizeProjectLevelConfig: false });
if (!profile?.profile) {
return;
}
const defaultServerPath = ConfigUtils.getServerPath(profile.profile);
const deployDirectory = await vscePromptApi.promptForDeployDirectory(profile.profile.host, defaultServerPath);
if (!deployDirectory) {
return;
}

await ConfigUtils.showSessionInTree(profile.name!, true, zoweExplorerApi);
const infoMsg = `Installed Zowe Remote SSH server on ${(profile.profile.host as string) ?? profile.name}`;
imperative.Logger.getAppLogger().info(infoMsg);
await Gui.showMessage(infoMsg);
}),
vscode.commands.registerCommand(`zowe.zowex.restart`, async (profName?: string) => {
imperative.Logger.getAppLogger().trace("Running restart command for profile %s", profName);
const vscePromptApi = new VscePromptApi(await profCache.getProfileInfo());
const profile = await vscePromptApi.promptForProfile(profName, { prioritizeProjectLevelConfig: false, disableCreateNewProfile: true });
if (!profile?.profile) {
return;
}
const sshSession = ZSshUtils.buildSession(profile.profile);
const deployStatus = await deployWithProgress(sshSession, deployDirectory);
if (!deployStatus) {
return;
}

await SshClientCache.inst.connect(profile, { restart: true, retryRequests: false });
await ConfigUtils.showSessionInTree(profile.name!, true, zoweExplorerApi);
const infoMsg = `Installed Zowe Remote SSH server on ${(profile.profile.host as string) ?? profile.name}`;
imperative.Logger.getAppLogger().info(infoMsg);
await Gui.showMessage(infoMsg);
}

imperative.Logger.getAppLogger().info(`Restarted Zowe Remote SSH server on ${(profile.profile?.host as string) ?? profile.name}`);
const statusMsg = Gui.setStatusBarMessage("Restarted Zowe Remote SSH server");
setTimeout(() => {
statusMsg.dispose();
// eslint-disable-next-line no-magic-numbers
}, 5000);
}),
vscode.commands.registerCommand(`zowe.zowex.uninstall`, async (profName?: string) => {
imperative.Logger.getAppLogger().trace("Running uninstall command for profile %s", profName);
const vscePromptApi = new VscePromptApi(await profCache.getProfileInfo());
const profile = await vscePromptApi.promptForProfile(profName, { prioritizeProjectLevelConfig: false, disableCreateNewProfile: true });
if (!profile?.profile) {
return;
}
private static async restartCallback(zoweExplorerApi: IApiExplorerExtender, profName?: string): Promise<void> {
imperative.Logger.getAppLogger().trace("Running restart command for profile %s", profName);
const profCache = zoweExplorerApi.getProfilesCache();
const vscePromptApi = new VscePromptApi(await profCache.getProfileInfo());
const profile = await vscePromptApi.promptForProfile(profName, { prioritizeProjectLevelConfig: false, disableCreateNewProfile: true });
if (!profile?.profile) {
return;
}

SshClientCache.inst.end(profile);
const serverPath = ConfigUtils.getServerPath(profile.profile);
await ConfigUtils.showSessionInTree(profile.name!, false, zoweExplorerApi);
await SshClientCache.inst.connect(profile, { restart: true, retryRequests: false });

// Create error callback for uninstall operation
const errorCallback = SshErrorHandler.getInstance().createErrorCallback(ZoweExplorerApiType.All, "Server uninstall");
await ZSshUtils.uninstallServer(ZSshUtils.buildSession(profile.profile), serverPath, {
onError: errorCallback,
});
imperative.Logger.getAppLogger().info(`Restarted Zowe Remote SSH server on ${(profile.profile?.host as string) ?? profile.name}`);
const statusMsg = Gui.setStatusBarMessage("Restarted Zowe Remote SSH server");
setTimeout(() => {
statusMsg.dispose();
// eslint-disable-next-line no-magic-numbers
}, 5000);
}

const infoMsg = `Uninstalled Zowe Remote SSH server from ${(profile.profile.host as string) ?? profile.name}`;
imperative.Logger.getAppLogger().info(infoMsg);
await Gui.showMessage(infoMsg);
}),
];
private static async uninstallCallback(zoweExplorerApi: IApiExplorerExtender, profName?: string): Promise<void> {
imperative.Logger.getAppLogger().trace("Running uninstall command for profile %s", profName);
const profCache = zoweExplorerApi.getProfilesCache();
const vscePromptApi = new VscePromptApi(await profCache.getProfileInfo());
const profile = await vscePromptApi.promptForProfile(profName, { prioritizeProjectLevelConfig: false, disableCreateNewProfile: true });
if (!profile?.profile) {
return;
}

SshClientCache.inst.end(profile);
const serverPath = ConfigUtils.getServerPath(profile.profile);
await ConfigUtils.showSessionInTree(profile.name!, false, zoweExplorerApi);

// Create error callback for uninstall operation
const errorCallback = SshErrorHandler.getInstance().createErrorCallback(ZoweExplorerApiType.All, "Server uninstall");
await ZSshUtils.uninstallServer(ZSshUtils.buildSession(profile.profile), serverPath, {
onError: errorCallback,
});

const infoMsg = `Uninstalled Zowe Remote SSH server from ${(profile.profile.host as string) ?? profile.name}`;
imperative.Logger.getAppLogger().info(infoMsg);
await Gui.showMessage(infoMsg);
}
}
2 changes: 1 addition & 1 deletion packages/zowex-for-zowe-explorer/src/api/SshUssApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class SshUssApi extends SshCommonApi implements MainframeInteraction.IUss
throw new Error("File no longer exists");
}
const isDir = ussItem.apiResponse.items[0].mode.startsWith("d");
let success = false;
let success = true;
if (attributes.tag) {
const response = await (
await this.client
Expand Down
11 changes: 11 additions & 0 deletions packages/zowex-for-zowe-explorer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

export * from "./api";
export * from "./ConfigUtils";
export * from "./NativeSshHelper";
Expand Down
Loading
Loading