Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
129 changes: 95 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -928,15 +928,16 @@
"sinon": "^7.4.1",
"sinon-chai": "^3.3.0",
"tmp": "0.1.0",
"tslint": "^5.18.0",
"typescript": "^3.5.3",
"tslint": "^5.19.0",
"typescript": "^3.6.2",
"vscode": "^1.1.36",
"walker": "^1.0.7"
},
"dependencies": {
"@kubernetes/client-node": "^0.10.2",
"binary-search": "^1.3.6",
"byline": "^5.0.0",
"filehound": "^1.17.3",
Comment thread
mohitsuman marked this conversation as resolved.
Outdated
"fs-extra": "^8.1.0",
"git-fetch-pack": "^0.1.1",
"git-transport-protocol": "^0.1.0",
Expand Down
6 changes: 3 additions & 3 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export interface Odo {
deleteApplication(application: OpenShiftObject): Promise<OpenShiftObject>;
createComponentFromGit(application: OpenShiftObject, type: string, version: string, name: string, repoUri: string, context: Uri, ref: string): Promise<OpenShiftObject>;
createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, path: Uri): Promise<OpenShiftObject>;
createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, path: Uri, context: Uri): Promise<OpenShiftObject>;
createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, path: string, context: Uri): Promise<OpenShiftObject>;
Comment thread
mohitsuman marked this conversation as resolved.
Outdated
deleteComponent(component: OpenShiftObject): Promise<OpenShiftObject>;
undeployComponent(component: OpenShiftObject): Promise<OpenShiftObject>;
deleteNotPushedComponent(component: OpenShiftObject): Promise<OpenShiftObject>;
Expand Down Expand Up @@ -917,8 +917,8 @@ export class OdoImpl implements Odo {
return null;
}

public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, context: Uri): Promise<OpenShiftObject> {
await this.execute(Command.createBinaryComponent(application.getParent().getName(), application.getName(), type, version, name, location.fsPath, context.fsPath));
public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: string, context: Uri): Promise<OpenShiftObject> {
await this.execute(Command.createBinaryComponent(application.getParent().getName(), application.getName(), type, version, name, location, context.fsPath));
if (workspace.workspaceFolders) {
const targetApplication = (await this.getApplications(application.getParent())).find((value) => value === application);
if (!targetApplication) {
Expand Down
66 changes: 52 additions & 14 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { Delayer } from '../util/async';
import { Platform } from '../util/platform';
import path = require('path');
import fs = require('fs-extra');
import FileHound = require('filehound');

interface WorkspaceFolderItem extends QuickPickItem {
uri: Uri;
}
Expand Down Expand Up @@ -482,12 +484,58 @@ export class Component extends OpenShiftItem {
}

static async createFromBinary(context: OpenShiftObject): Promise<string> {

let application: OpenShiftObject = context;
let folder: WorkspaceFolderItem[] = [];
if (!application) application = await Component.getOpenshiftData(context);
if (!application) return null;
const binaryFile = await window.showOpenDialog({
openLabel: 'Select the binary file'
});
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
folder = workspace.workspaceFolders.filter(
(value) => {
let result = true;
try {
result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile();
} catch (ignore) {
}
return result;
}
).map(
(folder) => ({ label: `$(file-directory) ${folder.uri.fsPath}`, uri: folder.uri })
);
}
const addWorkspaceFolder = new CreateWorkspaceItem();
const choice: any = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select context folder"});

if (!choice) return null;
let workspacePath: Uri;

if (choice.label === addWorkspaceFolder.label) {
const folders = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(Platform.getUserHomePath()),
openLabel: "Add context Folder for Component"
});
if (!folders) return null;
workspacePath = folders[0];
} else {
workspacePath = choice.uri;
}

if (!workspacePath) return null;

const binaryFiles = await FileHound.create()
.path(workspacePath.path)
.ignoreHiddenDirectories()
.ext(['jar', 'war'])
Comment thread
mohitsuman marked this conversation as resolved.
Outdated
.find();

if (binaryFiles.length === 0) return window.showInformationMessage("No binary file present in the context folder selected. We currently only support .jar and .war files. If you need support for any other file, please raise an issue.");
Comment thread
mohitsuman marked this conversation as resolved.
Outdated

const binaryFileObj: QuickPickItem[] = binaryFiles.map((file) => ({ label: `$(file-zip) ${file.split('/').pop()}`, description: `${file}`}));

const binaryFile: any = await window.showQuickPick(binaryFileObj, {placeHolder: "Select binary file"});

if (!binaryFile) return null;

Expand All @@ -504,17 +552,7 @@ export class Component extends OpenShiftItem {

if (!componentTypeVersion) return null;

const folder = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(Platform.getUserHomePath()),
openLabel: "Select Context Folder for Component"
});

if (!folder) return null;

await Component.odo.createComponentFromBinary(application, componentTypeName, componentTypeVersion, componentName, binaryFile[0], folder[0]);
await Component.odo.createComponentFromBinary(application, componentTypeName, componentTypeVersion, componentName, binaryFile.description, workspacePath);
return `Component '${componentName}' successfully created`;
}
}