Skip to content

Commit 4ad2336

Browse files
jisedlacthurka
authored andcommitted
Changes & cleanup to better support tests
1 parent 47ef95c commit 4ad2336

File tree

2 files changed

+17
-28
lines changed

2 files changed

+17
-28
lines changed

integrations/vscode/src/parameters.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ export function perfMaxStringConstLength(): string {
5252
return '-J-XX:PerfMaxStringConstLength=10240';
5353
}
5454

55-
export async function jdkHome(predefinedJDK?: string): Promise<string | undefined> {
55+
export async function jdkHome(predefinedJdk?: string): Promise<string | undefined> {
5656
if (vscode.workspace.getConfiguration().get<boolean>(USE_JDK_PATH_FOR_STARTUP_KEY)) {
57-
if (predefinedJDK) {
58-
return `--jdkhome ${predefinedJDK}`;
59-
}
60-
const jdkPath = await jdk.getPath();
57+
const jdkPath = predefinedJdk || await jdk.getPath();
6158
if (!jdkPath) {
6259
throw new Error();
6360
}

integrations/vscode/src/runningProcesses.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,6 @@ export type RunningProcess = {
3636
};
3737

3838
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[]){
5639
const jdkPath = await jdk.getPath();
5740
if (!jdkPath) {
5841
return undefined;
@@ -63,8 +46,8 @@ export async function GetRunningJavaProcesses(ignore?: number[]){
6346
}
6447
try {
6548
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');
6851
const processes: QuickPickProcess[] = [];
6952
parts1.forEach(p1 => {
7053
const p2 = parts2.find(p2 => p2.pid === p1.pid);
@@ -74,12 +57,20 @@ export async function GetRunningJavaProcesses(ignore?: number[]){
7457
});
7558
resolve(processes);
7659
});
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+
}
7869
} catch (err) {
7970
vscode.window.showErrorMessage(`Failed to read running Java processes: ${err}`);
8071
return undefined;
8172
}
82-
}
73+
}
8374

8475
class QuickPickProcess implements vscode.QuickPickItem{
8576

@@ -110,8 +101,9 @@ class QuickPickProcess implements vscode.QuickPickItem{
110101

111102
}
112103

113-
async function processJpsCommand(cmd: string): Promise<RunningProcess[]> {
104+
export async function getUsingJps(jpsPath: string, command: string = '-v'): Promise<RunningProcess[]> {
114105
return new Promise<RunningProcess[]>((resolve, reject) => {
106+
const cmd = `"${jpsPath}" ${command}`;
115107
cp.exec(cmd, async (error: any, stdout: string) => {
116108
if (error) {
117109
reject(error);
@@ -181,7 +173,7 @@ function searchProcesses() {
181173
}
182174
if (SEARCHED_PROCESSES.length) {
183175
if (SEARCH_PROCESSES_JPS_PATH) {
184-
processJpsCommand(`"${SEARCH_PROCESSES_JPS_PATH}" -v`).then(results => {
176+
getUsingJps(SEARCH_PROCESSES_JPS_PATH).then(results => {
185177
if (results.length) {
186178
for (let index = SEARCHED_PROCESSES.length - 1; index >= 0; index--) {
187179
const process = SEARCHED_PROCESSES[index];

0 commit comments

Comments
 (0)