11import { window , workspace , Disposable , OutputChannel } from 'vscode' ;
22
33import ProcessRegistry from './ProcessRegistry' ;
4- import { GradleTask } from './TaskRegistry' ;
4+ import GradleTask from './GradleTask' ;
5+
6+ const TASK_REGEX : RegExp = / $ \s * ( [ a - z 0 - 9 ] + ) \s - \s ( .* ) $ / gim;
57
68function getCommand ( ) : string {
79 return workspace . getConfiguration ( ) . get ( 'gradle.useCommand' , 'gradlew' ) ;
@@ -11,14 +13,31 @@ function getTasksArgs(): string {
1113 return workspace . getConfiguration ( ) . get ( 'gradle.tasks.args' , '' ) ;
1214}
1315
16+ function getTasks ( ) : Thenable < GradleTask [ ] > {
17+ const cmd = `${ getCommand ( ) } --console plain tasks ${ getTasksArgs ( ) } ` ;
18+ const { rootPath : cwd } = workspace ;
19+ return ProcessRegistry . create ( cmd , { cwd } ) . then ( stdout => {
20+ let match : RegExpExecArray | null = null ;
21+ const tasks : GradleTask [ ] = [ ] ;
22+ while ( ( match = TASK_REGEX . exec ( stdout ) ) !== null ) {
23+ tasks . push ( new GradleTask ( match [ 1 ] , match [ 2 ] ) ) ;
24+ }
25+ return tasks . sort ( ( a , b ) => a . label . localeCompare ( b . label ) ) ;
26+ } ) ;
27+ }
28+
1429function runTask (
1530 task : GradleTask ,
16- outputChannel ? : OutputChannel
31+ outputChannel : OutputChannel
1732) : Thenable < void > {
1833 const cmd = `${ getCommand ( ) } ${ task . label } ` ;
19- const statusbar : Disposable = window . setStatusBarMessage ( `Running ${ cmd } ` ) ;
34+ const feedback = `Running ${ cmd } ` ;
35+ const statusbar : Disposable = window . setStatusBarMessage ( feedback ) ;
2036 const { rootPath : cwd } = workspace ;
2137
38+ outputChannel . show ( ) ;
39+ outputChannel . append ( `${ feedback } \n` ) ;
40+
2241 return ProcessRegistry . create ( cmd , { cwd } , outputChannel ) . then (
2342 ( ) => statusbar . dispose ( ) ,
2443 err => {
@@ -28,4 +47,4 @@ function runTask(
2847 ) ;
2948}
3049
31- export default { getCommand , getTasksArgs , runTask } ;
50+ export default { getTasks , runTask } ;
0 commit comments