@@ -36,23 +36,6 @@ export type RunningProcess = {
36
36
} ;
37
37
38
38
export async function select ( ignore ?: number [ ] ) : Promise < RunningProcess | undefined > {
39
- const processes = await GetRunningJavaProcesses ( ignore ) ;
40
- if ( processes ) {
41
- const selected = await vscode . window . showQuickPick ( processes , {
42
- title : 'Select Running Java Process' ,
43
- placeHolder : 'Select the process to be monitored by VisualVM'
44
- } ) ;
45
- if ( selected ) {
46
- return { pid : selected . pid , displayName : selected . label } ;
47
- } else {
48
- return undefined ;
49
- }
50
- } else {
51
- return undefined ;
52
- }
53
- }
54
-
55
- export async function GetRunningJavaProcesses ( ignore ?: number [ ] ) {
56
39
const jdkPath = await jdk . getPath ( ) ;
57
40
if ( ! jdkPath ) {
58
41
return undefined ;
@@ -63,8 +46,8 @@ export async function GetRunningJavaProcesses(ignore?: number[]){
63
46
}
64
47
try {
65
48
const processes : Promise < QuickPickProcess [ ] > = new Promise ( async ( resolve ) => {
66
- const parts1 = await processJpsCommand ( `" ${ jpsPath } " -v` ) ;
67
- const parts2 = await processJpsCommand ( `" ${ jpsPath } " -lm` ) ;
49
+ const parts1 = await getUsingJps ( jpsPath , '-v' ) ;
50
+ const parts2 = await getUsingJps ( jpsPath , ' -lm' ) ;
68
51
const processes : QuickPickProcess [ ] = [ ] ;
69
52
parts1 . forEach ( p1 => {
70
53
const p2 = parts2 . find ( p2 => p2 . pid === p1 . pid ) ;
@@ -74,12 +57,20 @@ export async function GetRunningJavaProcesses(ignore?: number[]){
74
57
} ) ;
75
58
resolve ( processes ) ;
76
59
} ) ;
77
- return processes ;
60
+ const selected = await vscode . window . showQuickPick ( processes , {
61
+ title : 'Select Running Java Process' ,
62
+ placeHolder : 'Select the process to be monitored by VisualVM'
63
+ } ) ;
64
+ if ( selected ) {
65
+ return { pid : selected . pid , displayName : selected . label } ;
66
+ } else {
67
+ return undefined ;
68
+ }
78
69
} catch ( err ) {
79
70
vscode . window . showErrorMessage ( `Failed to read running Java processes: ${ err } ` ) ;
80
71
return undefined ;
81
72
}
82
- }
73
+ }
83
74
84
75
class QuickPickProcess implements vscode . QuickPickItem {
85
76
@@ -110,8 +101,9 @@ class QuickPickProcess implements vscode.QuickPickItem{
110
101
111
102
}
112
103
113
- async function processJpsCommand ( cmd : string ) : Promise < RunningProcess [ ] > {
104
+ export async function getUsingJps ( jpsPath : string , command : string = '-v' ) : Promise < RunningProcess [ ] > {
114
105
return new Promise < RunningProcess [ ] > ( ( resolve , reject ) => {
106
+ const cmd = `"${ jpsPath } " ${ command } ` ;
115
107
cp . exec ( cmd , async ( error : any , stdout : string ) => {
116
108
if ( error ) {
117
109
reject ( error ) ;
@@ -181,7 +173,7 @@ function searchProcesses() {
181
173
}
182
174
if ( SEARCHED_PROCESSES . length ) {
183
175
if ( SEARCH_PROCESSES_JPS_PATH ) {
184
- processJpsCommand ( `" ${ SEARCH_PROCESSES_JPS_PATH } " -v` ) . then ( results => {
176
+ getUsingJps ( SEARCH_PROCESSES_JPS_PATH ) . then ( results => {
185
177
if ( results . length ) {
186
178
for ( let index = SEARCHED_PROCESSES . length - 1 ; index >= 0 ; index -- ) {
187
179
const process = SEARCHED_PROCESSES [ index ] ;
0 commit comments