Skip to content

Commit 79e3a49

Browse files
authored
git+binary workflow fix (#1158)
* 1. Add context folder selection at start for git workflow 2. Check for component folder already existing * fix tslint issues * remove class declaration from workspace.ts * fix path validation function
1 parent e268b89 commit 79e3a49

File tree

2 files changed

+24
-64
lines changed

2 files changed

+24
-64
lines changed

src/openshift/component.ts

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,9 @@ import { Refs, Ref, Type } from '../util/refs';
1515
import { Delayer } from '../util/async';
1616
import { Platform } from '../util/platform';
1717
import path = require('path');
18-
import fs = require('fs-extra');
1918
import globby = require('globby');
2019
import { selectWorkspaceFolder } from '../util/workspace';
2120

22-
interface WorkspaceFolderItem extends QuickPickItem {
23-
uri: Uri;
24-
}
25-
26-
class CreateWorkspaceItem implements QuickPickItem {
27-
28-
constructor() { }
29-
30-
get label(): string { return `$(plus) Add new workspace folder.`; }
31-
get description(): string { return 'Folder which does not have an openshift context'; }
32-
33-
}
34-
3521
export class Component extends OpenShiftItem {
3622
public static extensionContext: ExtensionContext;
3723
static async getOpenshiftData(context: OpenShiftObject): Promise<OpenShiftObject> {
@@ -426,7 +412,10 @@ export class Component extends OpenShiftItem {
426412
let application: OpenShiftObject = context;
427413
if (!application) application = await Component.getOpenshiftData(context);
428414
if (!application) return null;
415+
const workspacePath = await selectWorkspaceFolder();
416+
if (!workspacePath) return null;
429417
const delayer = new Delayer<string>(500);
418+
430419
const repoURI = await window.showInputBox({
431420
prompt: 'Git repository URI',
432421
validateInput: (value: string) => {
@@ -459,65 +448,26 @@ export class Component extends OpenShiftItem {
459448

460449
if (!componentTypeVersion) return null;
461450

462-
const folder = await window.showOpenDialog({
463-
canSelectFiles: false,
464-
canSelectFolders: true,
465-
canSelectMany: false,
466-
defaultUri: Uri.file(Platform.getUserHomePath()),
467-
openLabel: "Select Context Folder for Component"
468-
});
469-
470-
if (!folder) return null;
471-
472451
window.showInformationMessage('Do you want to clone git repository for created Component?', 'Yes', 'No').then((value) => {
473452
value === 'Yes' && commands.executeCommand('git.clone', repoURI);
474453
});
475454

476-
await Component.odo.createComponentFromGit(application, componentTypeName, componentTypeVersion, componentName, repoURI, folder[0], gitRef.label);
455+
await Component.odo.createComponentFromGit(application, componentTypeName, componentTypeVersion, componentName, repoURI, workspacePath, gitRef.label);
477456
return `Component '${componentName}' successfully created`;
478457
}
479458

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

482461
let application: OpenShiftObject = context;
483-
let folder: WorkspaceFolderItem[] = [];
462+
484463
if (!application) application = await Component.getOpenshiftData(context);
464+
485465
if (!application) return null;
486-
if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) {
487-
folder = workspace.workspaceFolders.filter(
488-
(value) => {
489-
let result = true;
490-
try {
491-
result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile();
492-
} catch (ignore) {
493-
}
494-
return result;
495-
}
496-
).map(
497-
(folder) => ({ label: `$(file-directory) ${folder.uri.fsPath}`, uri: folder.uri })
498-
);
499-
}
500-
const addWorkspaceFolder = new CreateWorkspaceItem();
501-
const choice: any = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select context folder"});
502466

503-
if (!choice) return null;
504-
let workspacePath: Uri;
505-
506-
if (choice.label === addWorkspaceFolder.label) {
507-
const folders = await window.showOpenDialog({
508-
canSelectFiles: false,
509-
canSelectFolders: true,
510-
canSelectMany: false,
511-
defaultUri: Uri.file(Platform.getUserHomePath()),
512-
openLabel: "Add context Folder for Component"
513-
});
514-
if (!folders) return null;
515-
workspacePath = folders[0];
516-
} else {
517-
workspacePath = choice.uri;
518-
}
467+
const workspacePath = await selectWorkspaceFolder();
519468

520469
if (!workspacePath) return null;
470+
521471
const globPath = process.platform === 'win32' ? workspacePath.fsPath.replace(/\\/g, '/') : workspacePath.path;
522472
const paths = globby.sync(`${globPath}/*.+(jar|war)`, { extglob: true });
523473

src/util/workspace.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class CreateWorkspaceItem implements QuickPickItem {
1111

1212
constructor() { }
1313

14-
get label(): string { return `$(plus) Add new workspace folder.`; }
15-
get description(): string { return 'Folder which does not have an openshift context'; }
14+
get label(): string { return `$(plus) Add new context folder.`; }
15+
get description(): string { return 'Folder which does not have an OpenShift context'; }
1616

1717
}
1818

@@ -33,7 +33,8 @@ export async function selectWorkspaceFolder(): Promise<Uri> {
3333
);
3434
}
3535
const addWorkspaceFolder = new CreateWorkspaceItem();
36-
const choice: any = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select workspace folder"});
36+
const choice: any = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select context folder"});
37+
if (!choice) return null;
3738

3839
let workspacePath: Uri;
3940

@@ -43,12 +44,21 @@ export async function selectWorkspaceFolder(): Promise<Uri> {
4344
canSelectFolders: true,
4445
canSelectMany: false,
4546
defaultUri: Uri.file(Platform.getUserHomePath()),
46-
openLabel: "Add workspace Folder for Component"
47+
openLabel: "Add context folder for component in workspace."
4748
});
4849
if (!folders) return null;
49-
workspacePath = folders[0];
50+
if (await checkComponentFolder(folders[0])) {
51+
window.showInformationMessage('The folder selected already contains a component. Please select a different folder.');
52+
return this.selectWorkspaceFolder();
53+
} else {
54+
workspacePath = folders[0];
55+
}
5056
} else if (choice) {
5157
workspacePath = choice.uri;
5258
}
5359
return workspacePath;
54-
}
60+
}
61+
62+
async function checkComponentFolder(folder: Uri) {
63+
return fs.existsSync(path.join(folder.fsPath, '.odo', 'config.yaml'));
64+
}

0 commit comments

Comments
 (0)