Skip to content

Commit 17f5cc8

Browse files
committed
Include oc and odo in vsix for all supported platforms
Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent a35a7f5 commit 17f5cc8

File tree

17 files changed

+129
-202
lines changed

17 files changed

+129
-202
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
out
22
node_modules
33
.vscode-test/
4+
test/fixtures/workspace/.vscode/
45
*.vsix
56
coverage/
67
toFile

build/bundle-tools.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*-----------------------------------------------------------------------------------------------
2+
* Copyright (c) Red Hat, Inc. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4+
*-----------------------------------------------------------------------------------------------*/
5+
6+
import { DownloadUtil } from './download';
7+
import { Archive } from '../src/util/archive';
8+
9+
import hasha = require('hasha');
10+
import mkdirp = require('mkdirp');
11+
import path = require('path');
12+
import fs = require('fs-extra');
13+
import configData = require('../src/tools.json');
14+
15+
async function verifyTools(): Promise<void> {
16+
for (const key in configData) {
17+
for (const OS in configData[key].platform) {
18+
const targetFolder = path.resolve('.', 'out', 'tools', OS);
19+
console.info(`Download tools to '${targetFolder}'`);
20+
await downloadFileAndCreateSha256(
21+
targetFolder,
22+
configData[key].platform[OS].dlFileName,
23+
configData[key].platform[OS].url,
24+
configData[key].platform[OS].sha256sum,
25+
configData[key].platform[OS].cmdFileName,
26+
configData[key].platform[OS].filePrefix);
27+
}
28+
}
29+
}
30+
31+
async function downloadFileAndCreateSha256(targetFolder: string, fileName: string, reqURL: string, sha256sum: string, cmdFileName: string, filePrefix?: string) {
32+
mkdirp.sync(targetFolder);
33+
const currentFile = path.join(targetFolder, fileName);
34+
console.log(`${currentFile} download started from ${reqURL}`);
35+
await DownloadUtil.downloadFile(reqURL, currentFile, (current) => console.log(`${current }%`));
36+
const currentSHA256 = await hasha.fromFile(currentFile, {algorithm: 'sha256'});
37+
if (currentSHA256 === sha256sum) {
38+
console.log( `[INFO] ${currentFile} is downloaded and sha256 is correct`);
39+
} else {
40+
throw Error(`${currentFile} is downloaded and sha256 is not correct`);
41+
}
42+
await Archive.extract(currentFile, targetFolder, cmdFileName, filePrefix);
43+
fs.removeSync(currentFile);
44+
}
45+
46+
verifyTools();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*-----------------------------------------------------------------------------------------------*/
55

66
/* eslint-disable @typescript-eslint/no-var-requires */
7+
/* eslint-disable no-unused-expressions */
78
import * as fs from 'fs-extra';
89

910
const { promisify } = require('util');

build/unit-tests.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ async function main(): Promise<void> {
1717
const extensionTestsPath = path.resolve(__dirname, '../../out/test/unit/');
1818

1919
// Download VS Code, unzip it and run the integration test
20-
console.log(extensionDevelopmentPath, extensionTestsPath);
21-
await runTests({ extensionDevelopmentPath, extensionTestsPath });
20+
await runTests({
21+
extensionDevelopmentPath, extensionTestsPath
22+
});
2223
} catch (err) {
2324
console.error(err);
2425
process.exit(1);

build/verify-tools.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
* Licensed under the MIT License. See LICENSE file in the project root for license information.
44
*-----------------------------------------------------------------------------------------------*/
55

6-
import { DownloadUtil } from '../src/util/download';
7-
8-
'use strict';
6+
import { DownloadUtil } from './download';
97

108
import hasha = require('hasha');
119
import mkdirp = require('mkdirp');
@@ -52,4 +50,4 @@ cp.exec('git diff --name-only origin/master -- .', async (error, stdout) => {
5250
} else {
5351
console.log('tools.json is not changed, skipping download verification');
5452
}
55-
});
53+
});

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"main": "./out/src/extension",
3838
"scripts": {
3939
"verify": "node ./out/build/verify-tools.js",
40-
"vscode:prepublish": "npm run build",
40+
"vscode:prepublish": "npm run build && node ./out/build/bundle-tools.js",
4141
"compile": "tsc -p ./",
4242
"watch": "tsc -watch -p ./",
4343
"clean": "rm -rf out || rmdir out /s /q || echo 'no out folder, ignoring errors'",
@@ -1072,6 +1072,12 @@
10721072
"type": "boolean",
10731073
"default": false,
10741074
"description": "Disable check if migration is required for resources created with previous version of the extension and migration request message."
1075+
},
1076+
"openshiftConnector.searchForToolsInPath": {
1077+
"Title": "Search CLI tools in PATH locations before using included binaries",
1078+
"type": "boolean",
1079+
"default": false,
1080+
"description": "Force extension to search for `oc` and `odo` CLI tools in PATH locations before using bundled binaries."
10751081
}
10761082
}
10771083
}

src/oc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Oc {
3434

3535
let toolLocation: string;
3636
if (!message) {
37-
toolLocation = await ToolsConfig.detectOrDownload('oc');
37+
toolLocation = await ToolsConfig.detect('oc');
3838
if (!toolLocation) {
3939
message = 'Cannot run \'oc create\'. OKD CLI client tool cannot be found.';
4040
}

src/odo.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -891,19 +891,15 @@ export class OdoImpl implements Odo {
891891

892892
public async executeInTerminal(command: string, cwd: string = process.cwd(), name = 'OpenShift'): Promise<void> {
893893
const cmd = command.split(' ')[0];
894-
const toolLocation = await ToolsConfig.detectOrDownload(cmd);
895-
let toolDirLocation: string;
896-
if (toolLocation) {
897-
toolDirLocation = path.dirname(toolLocation);
898-
}
894+
const toolLocation = await ToolsConfig.detect(cmd);
899895
const terminal: Terminal = WindowUtil.createTerminal(name, cwd);
900-
terminal.sendText(toolDirLocation ? command.replace(cmd, `"${toolLocation}"`).replace(new RegExp(`&& ${cmd}`, 'g'), `&& "${toolLocation}"`) : command, true);
896+
terminal.sendText(toolLocation === cmd ? command : command.replace(cmd, `"${toolLocation}"`).replace(new RegExp(`&& ${cmd}`, 'g'), `&& "${toolLocation}"`), true);
901897
terminal.show();
902898
}
903899

904900
public async execute(command: string, cwd?: string, fail = true): Promise<CliExitData> {
905901
const cmd = command.split(' ')[0];
906-
const toolLocation = await ToolsConfig.detectOrDownload(cmd);
902+
const toolLocation = await ToolsConfig.detect(cmd);
907903
return OdoImpl.cli.execute(
908904
toolLocation ? command.replace(cmd, `"${toolLocation}"`).replace(new RegExp(`&& ${cmd}`, 'g'), `&& "${toolLocation}"`) : command,
909905
cwd ? {cwd} : { }

src/openshift/component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,9 @@ export class Component extends OpenShiftItem {
540540
const isNode = tag.annotations.tags.includes('nodejs');
541541
const JAVA_EXT = 'redhat.java';
542542
const JAVA_DEBUG_EXT = 'vscjava.vscode-java-debug';
543-
let result: undefined | PromiseLike<string>;
544-
if (component.compType === ComponentType.LOCAL && (isJava || isNode)) {
545-
const toolLocation = await ToolsConfig.detectOrDownload(`odo`);
543+
let result: undefined | string | PromiseLike<string>;
544+
if (isJava || isNode) {
545+
const toolLocation = await ToolsConfig.detect(`odo`);
546546
if (isJava) {
547547
const jlsIsActive = extensions.getExtension(JAVA_EXT);
548548
const jdIsActive = extensions.getExtension(JAVA_DEBUG_EXT);

src/tools.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"versionRange": "1.0.2",
88
"versionRangeLabel": "v1.0.2",
99
"dlFileName": "odo",
10-
"cmdFileName": "odo",
1110
"filePrefix": "",
1211
"platform": {
1312
"win32": {
@@ -19,12 +18,14 @@
1918
"darwin": {
2019
"url": "https://mirror.openshift.com/pub/openshift-v4/clients/odo/v1.0.2/odo-darwin-amd64.tar.gz",
2120
"sha256sum": "af50916c359b5a383f983c6776f166728497076ff1226e0ef97a3926b447b71e",
22-
"dlFileName": "odo-darwin-amd64.tar.gz"
21+
"dlFileName": "odo-darwin-amd64.tar.gz",
22+
"cmdFileName": "odo"
2323
},
2424
"linux": {
2525
"url": "https://mirror.openshift.com/pub/openshift-v4/clients/odo/v1.0.2/odo-linux-amd64.tar.gz",
2626
"sha256sum": "14640b4fd76c6bd863b5f2a5f871760054cd085da4bc87dc0499eb8a0f9389b3",
27-
"dlFileName": "odo-linux-amd64.tar.gz"
27+
"dlFileName": "odo-linux-amd64.tar.gz",
28+
"cmdFileName": "odo"
2829
}
2930
}
3031
},
@@ -47,14 +48,16 @@
4748
"darwin": {
4849
"url": "https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-mac.zip",
4950
"sha256sum": "75d58500aec1a2cee9473dfa826c81199669dbc0f49806e31a13626b5e4cfcf0",
50-
"dlFileName": "oc.zip"
51+
"dlFileName": "oc.zip",
52+
"cmdFileName": "oc"
5153
},
5254
"linux": {
5355
"url": "https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz",
5456
"sha256sum": "4b0f07428ba854174c58d2e38287e5402964c9a9355f6c359d1242efd0990da3",
5557
"fileName": "oc.tar.gz",
5658
"dlFileName": "oc.tar.gz",
57-
"filePrefix": "openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit"
59+
"filePrefix": "openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit",
60+
"cmdFileName": "oc"
5861
}
5962
}
6063
}

0 commit comments

Comments
 (0)