@@ -15,23 +15,9 @@ import { Refs, Ref, Type } from '../util/refs';
1515import { Delayer } from '../util/async' ;
1616import { Platform } from '../util/platform' ;
1717import path = require( 'path' ) ;
18- import fs = require( 'fs-extra' ) ;
1918import globby = require( 'globby' ) ;
2019import { 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-
3521export 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
0 commit comments