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 1 commit
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
58 changes: 11 additions & 47 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Platform } from '../util/platform';
import path = require('path');
import fs = require('fs-extra');
import globby = require('globby');
import { selectWorkspaceFolder } from '../util/workspace';
import { workspaceUtil } from '../util/workspaceUtil';

interface WorkspaceFolderItem extends QuickPickItem {
uri: Uri;
Expand Down Expand Up @@ -380,7 +380,7 @@ export class Component extends OpenShiftItem {

if (!application) application = await Component.getOpenshiftData(context);
if (!application) return null;
const workspacePath = await selectWorkspaceFolder();
const workspacePath = await workspaceUtil.selectWorkspaceFolder();
if (!workspacePath) return null;

const componentList: Array<OpenShiftObject> = await Component.odo.getComponents(application);
Expand Down Expand Up @@ -426,7 +426,10 @@ export class Component extends OpenShiftItem {
let application: OpenShiftObject = context;
if (!application) application = await Component.getOpenshiftData(context);
if (!application) return null;
const workspacePath = await workspaceUtil.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 +462,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 workspaceUtil.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 Expand Up @@ -560,7 +524,7 @@ export class Component extends OpenShiftItem {
throw new Error(`Cannot import unknown Component type '${componentType}'.`);
}

const workspaceFolder = await selectWorkspaceFolder();
const workspaceFolder = await workspaceUtil.selectWorkspaceFolder();
if (!workspaceFolder) return null;
return await Progress.execFunctionWithProgress(`Importing component '${compName}'`, async (progress) => {
try {
Expand Down
54 changes: 0 additions & 54 deletions src/util/workspace.ts

This file was deleted.

67 changes: 67 additions & 0 deletions src/util/workspaceUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { workspace, QuickPickItem, window, Uri } from "vscode";
import { Platform } from "./platform";
import path = require('path');
import fs = require('fs-extra');

interface WorkspaceFolderItem extends QuickPickItem {
uri: Uri;
}

class CreateWorkspaceItem implements QuickPickItem {

constructor() { }

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

}

export class workspaceUtil {

static async selectWorkspaceFolder(): Promise<Uri> {
let folder: WorkspaceFolderItem[] = [];
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 === addWorkspaceFolder) {
const folders = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: Uri.file(Platform.getUserHomePath()),
openLabel: "Add context folder for component in workspace."
});
if (!folders) return null;
if (await this.checkComponentFolder(folders[0])) {
window.showErrorMessage('The folder selected already contains a component. Please select a different folder');
mohitsuman marked this conversation as resolved.
Show resolved Hide resolved
return null;
} else {
workspacePath = folders[0];
}
} else if (choice) {
workspacePath = choice.uri;
}
return workspacePath;
}

static async checkComponentFolder(folder) {
return fs.existsSync(path.join(folder.path, '.odo', 'config.yaml'));
}
}