diff --git a/src/k8s/console.ts b/src/k8s/console.ts index e06c78adb..4ff953855 100644 --- a/src/k8s/console.ts +++ b/src/k8s/console.ts @@ -6,7 +6,6 @@ import * as vscode from 'vscode'; import { Command } from "../odo"; import { KubeConfigUtils } from "../util/kubeUtils"; -import open = require("open"); import { OpenShiftItem } from '../openshift/openshiftItem'; const k8sConfig = new KubeConfigUtils(); @@ -33,54 +32,62 @@ export class Console extends OpenShiftItem { } static async openBuildConfig(context: { id: any; }) { + let url = ''; if (!context) { vscode.window.showErrorMessage("Cannot load the build config"); return; } const consoleUrl = await Console.fetchOpenshiftConsoleUrl(); if (await Console.fetchClusterVersion() === null) { - return await open(`${consoleUrl}/k8s/ns/${context.id}/buildconfigs`); + url = `${consoleUrl}/k8s/ns/${context.id}/buildconfigs`; } else { - return await open(`${clusterUrl}/console/project/${project}/browse/builds/${context.id}?tab=history`); + url = `${clusterUrl}/console/project/${project}/browse/builds/${context.id}?tab=history`; } + return vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); } static async openDeploymentConfig(context: { id: any; }) { + let url = ''; if (!context) { vscode.window.showErrorMessage("Cannot load the deployment config"); return; } const consoleUrl = await Console.fetchOpenshiftConsoleUrl(); if (await Console.fetchClusterVersion() === null) { - return await open(`${consoleUrl}/k8s/ns/${context.id}/deploymentconfigs`); + url = `${consoleUrl}/k8s/ns/${context.id}/deploymentconfigs`; } else { - return await open(`${clusterUrl}/console/project/${project}/browse/dc/${context.id}?tab=history`); + url = `${clusterUrl}/console/project/${project}/browse/dc/${context.id}?tab=history`; } + return vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); } static async openImageStream(context: { id: any; }) { + let url = ''; if (!context) { vscode.window.showErrorMessage("Cannot load the image stream"); return; } const consoleUrl = await this.fetchOpenshiftConsoleUrl(); if (await Console.fetchClusterVersion() === null) { - return await open(`${consoleUrl}/k8s/ns/${context.id}/imagestreams`); + url = `${consoleUrl}/k8s/ns/${context.id}/imagestreams`; } else { - return await open(`${clusterUrl}/console/project/${project}/browse/images/${context.id}?tab=history`); + url = `${clusterUrl}/console/project/${project}/browse/images/${context.id}?tab=history`; } + return vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); } static async openProject(context: { id: any; }) { + let url = ''; if (!context) { vscode.window.showErrorMessage("Cannot load the Project"); return; } const consoleUrl = await Console.fetchOpenshiftConsoleUrl(); if (await Console.fetchClusterVersion() === null) { - return await open(`${consoleUrl}/overview/ns/${context.id}`); + url = `${consoleUrl}/overview/ns/${context.id}`; } else { - return await open(`${consoleUrl}/console/project/${context.id}/overview`); + url = `${consoleUrl}/console/project/${context.id}/overview`; } + return vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(url)); } } \ No newline at end of file diff --git a/src/odo.ts b/src/odo.ts index 2afb69cfe..e05a2dee2 100644 --- a/src/odo.ts +++ b/src/odo.ts @@ -19,7 +19,6 @@ import * as odo from './odo/config'; import { ComponentSettings } from './odo/config'; import { GlyphChars } from './util/constants'; import { Subject } from 'rxjs'; -import open = require('open'); import { Progress } from './util/progress'; import { V1ServicePort, V1Service } from '@kubernetes/client-node'; @@ -1134,7 +1133,7 @@ export class OdoImpl implements Odo { if (projectsToMigrate.length > 0) { const choice = await window.showWarningMessage(`Some of the resources in cluster must be updated to work with latest release of OpenShift Connector Extension.`, 'Update', 'Don\'t check again', 'Help', 'Cancel'); if (choice === 'Help') { - open('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0'); + commands.executeCommand('vscode.open', Uri.parse(`https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0`)); this.subject.next(new OdoEventImpl('changed', this.getClusters()[0])); } else if (choice === 'Don\'t check again') { workspace.getConfiguration("openshiftConnector").update("disableCheckForMigration", true, true); diff --git a/src/openshift/cluster.ts b/src/openshift/cluster.ts index 25ac355a0..fe0382e75 100644 --- a/src/openshift/cluster.ts +++ b/src/openshift/cluster.ts @@ -5,9 +5,8 @@ import { Command } from "../odo"; import { OpenShiftItem } from './openshiftItem'; -import { window, commands, env, QuickPickItem, ExtensionContext } from 'vscode'; +import { window, commands, env, QuickPickItem, ExtensionContext, Uri } from 'vscode'; import { CliExitData, Cli } from "../cli"; -import open = require("open"); import { TokenStore } from "../util/credentialManager"; import { KubeConfigUtils } from '../util/kubeUtils'; import { Filters } from "../util/filters"; @@ -69,7 +68,7 @@ export class Cluster extends OpenShiftItem { const serverUrl = await Cluster.odo.execute(Command.showServerUrl()); consoleUrl = `${serverUrl.stdout}/console`; } - open(consoleUrl); + return commands.executeCommand('vscode.open', Uri.parse(consoleUrl)); } static async switchContext() { diff --git a/src/openshift/component.ts b/src/openshift/component.ts index d952652a2..ec2b066e6 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -7,7 +7,6 @@ import { OpenShiftItem } from './openshiftItem'; import { OpenShiftObject, Command, ContextType, ComponentType } from '../odo'; import { window, commands, QuickPickItem, Uri, workspace, ExtensionContext } from 'vscode'; import { Progress } from '../util/progress'; -import open = require('open'); import { ChildProcess } from 'child_process'; import { CliExitData } from '../cli'; import { isURL } from 'validator'; @@ -294,7 +293,7 @@ export class Component extends OpenShiftItem { await Component.undeploy(component); return null; case 'Help': - open('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0'); + commands.executeCommand('vscode.open', Uri.parse(`https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0`)); break; case 'Cancel': return null; @@ -352,9 +351,9 @@ export class Component extends OpenShiftItem { if (hostName.length >1) { selectRoute = await window.showQuickPick(hostName, {placeHolder: "This Component has multiple URLs. Select the desired URL to open in browser."}); if (!selectRoute) return null; - return open(`${selectRoute.label}`); + return commands.executeCommand('vscode.open', Uri.parse(`${selectRoute.label}`)); } else { - return open(`${hostName[0].label}`); + return commands.executeCommand('vscode.open', Uri.parse(`${hostName[0].label}`)); } } else if (unpushedUrl.length > 0) { return `${unpushedUrl.length} unpushed URL in the local config. Use \'Push\' command before opening URL in browser.`; diff --git a/src/openshift/url.ts b/src/openshift/url.ts index 51117e399..489e3df63 100644 --- a/src/openshift/url.ts +++ b/src/openshift/url.ts @@ -4,11 +4,10 @@ *-----------------------------------------------------------------------------------------------*/ import { OpenShiftObject, Command } from '../odo'; -import { window, QuickPickItem } from 'vscode'; +import { window, QuickPickItem, commands, Uri } from 'vscode'; import { V1ServicePort } from '@kubernetes/client-node'; import { OpenShiftItem } from './openshiftItem'; import { Progress } from "../util/progress"; -import open = require('open'); import { ChildProcess } from 'child_process'; export class Url extends OpenShiftItem{ @@ -80,7 +79,7 @@ export class Url extends OpenShiftItem{ urlObject = result.filter((value) => (value.metadata.name === treeItem.getName())); } if (urlObject[0].status.state === 'Pushed') { - open(`${urlObject[0].spec.protocol}://${urlObject[0].spec.host}`); + return commands.executeCommand('vscode.open', Uri.parse(`${urlObject[0].spec.protocol}://${urlObject[0].spec.host}`)); } else { window.showInformationMessage('Selected URL is not created in cluster. Use \'Push\' command before opening URL in browser.'); } diff --git a/src/tools.ts b/src/tools.ts index ee5d1ff4a..5d9d96eb6 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -8,7 +8,6 @@ import { Archive } from "./util/archive"; import { which } from "shelljs"; import { DownloadUtil } from "./util/download"; import hasha = require("hasha"); -import open = require("open"); import * as vscode from 'vscode'; import * as path from 'path'; import * as fsex from 'fs-extra'; @@ -94,7 +93,7 @@ export class ToolsConfig { toolLocation = toolCacheLocation; } } else if (response === `Help`) { - open('https://github.com/redhat-developer/vscode-openshift-tools#dependencies'); + vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(`https://github.com/redhat-developer/vscode-openshift-tools#dependencies`)); } } if (toolLocation) { diff --git a/test/unit/openshift/component.test.ts b/test/unit/openshift/component.test.ts index 8f9d80c10..2aa68e0e0 100644 --- a/test/unit/openshift/component.test.ts +++ b/test/unit/openshift/component.test.ts @@ -41,19 +41,15 @@ suite('OpenShift/Component', () => { let getProjects: sinon.SinonStub; let getApps: sinon.SinonStub; let Component: any; - let opnStub: sinon.SinonStub; let infoStub: sinon.SinonStub; let fetchTag: sinon.SinonStub; let commandStub: sinon.SinonStub; setup(() => { sandbox = sinon.createSandbox(); - opnStub = sandbox.stub(); sandbox.stub(vscode.workspace, "updateWorkspaceFolders"); fetchTag = sandbox.stub(Refs, 'fetchTag').resolves (new Map([['HEAD', 'shanumb']])); - Component = pq('../../../src/openshift/component', { - open: opnStub - }).Component; + Component = pq('../../../src/openshift/component', {}).Component; termStub = sandbox.stub(OdoImpl.prototype, 'executeInTerminal'); execStub = sandbox.stub(OdoImpl.prototype, 'execute').resolves({ stdout: "" }); sandbox.stub(OdoImpl.prototype, 'getServices'); @@ -1127,7 +1123,7 @@ suite('OpenShift/Component', () => { showWarningMessageStub.onSecondCall().resolves(undefined); const result = await Component.push(componentItem); - expect(opnStub).calledOnceWith('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0'); + expect(commandStub).calledOnceWith('vscode.open', vscode.Uri.parse('https://github.com/redhat-developer/vscode-openshift-tools/wiki/Migration-to-v0.1.0')); expect(result).null; }); }); @@ -1192,7 +1188,7 @@ suite('OpenShift/Component', () => { ] }), stderr: ''}); await Component.openUrl(null); - expect(opnStub).calledOnceWith('https://url'); + expect(commandStub).calledOnceWith('vscode.open', vscode.Uri.parse('https://url')); }); test('gets URLs for the component and if there is more than one asks which one to open it in browser and opens selected', async () => { @@ -1221,7 +1217,7 @@ suite('OpenShift/Component', () => { ] }), stderr: ''}); await Component.openUrl(null); - expect(opnStub).calledOnceWith('https://url1'); + expect(commandStub).calledOnceWith('vscode.open', vscode.Uri.parse('https://url1')); }); test('gets URLs for the component, if there is more than one asks which one to open it in browser and exits if selection is canceled', async () => { @@ -1250,7 +1246,7 @@ suite('OpenShift/Component', () => { ] }), stderr: ''}); await Component.openUrl(null); - expect(opnStub.callCount).equals(0); + expect(commandStub.callCount).equals(0); }); test('request to create url for component if it does not exist, creates the URL if confirmed by user and opens it in browser.' , async () => { @@ -1271,14 +1267,14 @@ suite('OpenShift/Component', () => { ] }), stderr: ''}); await Component.openUrl(null); - expect(opnStub).calledOnceWith('https://url'); + expect(commandStub).calledOnceWith('vscode.open', vscode.Uri.parse('https://url')); }); test('request to create url for component if it does not exist and exits when not confirmed' , async () => { sandbox.stub(vscode.window, 'showInformationMessage').resolves('Cancel'); sandbox.stub(Component, 'listUrl').resolves(null); await Component.openUrl(null); - expect(opnStub).is.not.called; + expect(commandStub).is.not.called; }); test('request to create url for component if it does not exist' , async () => {