Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git+binary workflow fix #1158

Merged
merged 4 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
66 changes: 8 additions & 58 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,9 @@ import { Refs, Ref, Type } from '../util/refs';
import { Delayer } from '../util/async';
import { Platform } from '../util/platform';
import path = require('path');
import fs = require('fs-extra');
import globby = require('globby');
import { selectWorkspaceFolder } from '../util/workspace';

interface WorkspaceFolderItem extends QuickPickItem {
uri: Uri;
}

class CreateWorkspaceItem implements QuickPickItem {

constructor() { }

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

}

export class Component extends OpenShiftItem {
public static extensionContext: ExtensionContext;
static async getOpenshiftData(context: OpenShiftObject): Promise<OpenShiftObject> {
Expand Down Expand Up @@ -426,7 +412,10 @@ export class Component extends OpenShiftItem {
let application: OpenShiftObject = context;
if (!application) application = await Component.getOpenshiftData(context);
if (!application) return null;
const workspacePath = await selectWorkspaceFolder();
if (!workspacePath) return null;
const delayer = new Delayer<string>(500);

const repoURI = await window.showInputBox({
prompt: 'Git repository URI',
validateInput: (value: string) => {
Expand Down Expand Up @@ -459,65 +448,26 @@ 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;

window.showInformationMessage('Do you want to clone git repository for created Component?', 'Yes', 'No').then((value) => {
value === 'Yes' && commands.executeCommand('git.clone', repoURI);
});

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

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;
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;
}
const workspacePath = await selectWorkspaceFolder();

if (!workspacePath) return null;

const globPath = process.platform === 'win32' ? workspacePath.fsPath.replace(/\\/g, '/') : workspacePath.path;
const paths = globby.sync(`${globPath}/*.+(jar|war)`, { extglob: true });

Expand Down
22 changes: 16 additions & 6 deletions src/util/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class CreateWorkspaceItem implements QuickPickItem {

constructor() { }

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

}

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

let workspacePath: Uri;

Expand All @@ -43,12 +44,21 @@ export async function selectWorkspaceFolder(): Promise<Uri> {
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(Platform.getUserHomePath()),
openLabel: "Add workspace Folder for Component"
openLabel: "Add context folder for component in workspace."
});
if (!folders) return null;
workspacePath = folders[0];
if (await checkComponentFolder(folders[0])) {
window.showInformationMessage('The folder selected already contains a component. Please select a different folder.');
return this.selectWorkspaceFolder();
} else {
workspacePath = folders[0];
}
} else if (choice) {
workspacePath = choice.uri;
}
return workspacePath;
}
}

async function checkComponentFolder(folder: Uri) {
return fs.existsSync(path.join(folder.fsPath, '.odo', 'config.yaml'));
}