1
1
import { window , workspace , Disposable , OutputChannel } from 'vscode' ;
2
2
3
3
import 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;
5
7
6
8
function getCommand ( ) : string {
7
9
return workspace . getConfiguration ( ) . get ( 'gradle.useCommand' , 'gradlew' ) ;
@@ -11,14 +13,31 @@ function getTasksArgs(): string {
11
13
return workspace . getConfiguration ( ) . get ( 'gradle.tasks.args' , '' ) ;
12
14
}
13
15
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
+
14
29
function runTask (
15
30
task : GradleTask ,
16
- outputChannel ? : OutputChannel
31
+ outputChannel : OutputChannel
17
32
) : Thenable < void > {
18
33
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 ) ;
20
36
const { rootPath : cwd } = workspace ;
21
37
38
+ outputChannel . show ( ) ;
39
+ outputChannel . append ( `${ feedback } \n` ) ;
40
+
22
41
return ProcessRegistry . create ( cmd , { cwd } , outputChannel ) . then (
23
42
( ) => statusbar . dispose ( ) ,
24
43
err => {
@@ -28,4 +47,4 @@ function runTask(
28
47
) ;
29
48
}
30
49
31
- export default { getCommand , getTasksArgs , runTask } ;
50
+ export default { getTasks , runTask } ;
0 commit comments