forked from redhat-developer/vscode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaServerStarter.ts
More file actions
111 lines (101 loc) · 3.68 KB
/
javaServerStarter.ts
File metadata and controls
111 lines (101 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { window, commands, WorkspaceConfiguration, workspace } from 'vscode'
import { StreamInfo } from 'vscode-languageclient';
import * as requirements from './requirements';
import * as path from 'path';
import { Commands } from './commands';
const glob = require('glob');
declare var v8debug;
const DEBUG = (typeof v8debug === 'object') || startedInDebugMode();
let electron = require('./electron_j');
export function runServer(workspacePath, javaConfig): Thenable < StreamInfo > {
return requirements.resolveRequirements().catch(error => {
//show error
window.showErrorMessage(error.message, error.label).then((selection) => {
if (error.label && error.label === selection && error.openUrl) {
commands.executeCommand(Commands.OPEN_BROWSER, error.openUrl);
}
});
// rethrow to disrupt the chain.
throw error;
}).then(requirements => {
return new Promise<StreamInfo>(function (resolve, reject) {
let child = path.resolve(requirements.java_home + '/bin/java');
let params = prepareParams(requirements,javaConfig, workspacePath);
if (!params) {
return reject('Can not determine Java launch parameters for server');
}
console.log('Executing ' + child + ' ' + params.join(' '));
electron.fork(child, params, {}, function (err, result) {
if (err) { return reject(err); }
if (result) { return resolve(result); }
});
});
});
}
function prepareParams(requirements, javaConfiguration, workspacePath) {
let params = [];
if (DEBUG) {
params.push('-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044');
// suspend=y is the default. Use this form if you need to debug the server startup code:
// params.push('-agentlib:jdwp=transport=dt_socket,server=y,address=1044');
}
if (requirements.java_version > 8) {
params.push('--add-modules=ALL-SYSTEM');
params.push('--add-opens');
params.push('java.base/java.util=ALL-UNNAMED');
params.push('--add-opens');
params.push('java.base/java.lang=ALL-UNNAMED');
}
params.push('-Declipse.application=org.eclipse.jdt.ls.core.id1');
params.push('-Dosgi.bundles.defaultStartLevel=4');
params.push('-Declipse.product=org.eclipse.jdt.ls.core.product');
if (DEBUG) {
params.push('-Dlog.protocol=true');
params.push('-Dlog.level=ALL');
}
let vmargs = javaConfiguration.get('jdt.ls.vmargs', '');
parseVMargs(params, vmargs);
let server_home: string = path.resolve(__dirname, '../../server');
let launchersFound: Array<string> = glob.sync('**/plugins/org.eclipse.equinox.launcher_*.jar', { cwd: server_home });
if (launchersFound.length) {
params.push('-jar'); params.push(path.resolve(server_home, launchersFound[0]));
} else {
return null;
}
//select configuration directory according to OS
let configDir = 'config_win';
if (process.platform === 'darwin') {
configDir = 'config_mac';
} else if (process.platform === 'linux') {
configDir = 'config_linux';
}
params.push('-configuration'); params.push(path.resolve(__dirname, '../../server', configDir));
params.push('-data'); params.push(workspacePath);
return params;
}
function startedInDebugMode(): boolean {
let args = (process as any).execArgv;
if (args) {
return args.some((arg) => /^--debug=?/.test(arg) || /^--debug-brk=?/.test(arg));
};
return false;
}
//exported for tests
export function parseVMargs(params: any[], vmargsLine: string) {
if (!vmargsLine) {
return;
}
let vmargs = vmargsLine.match(/(?:[^\s"]+|"[^"]*")+/g);
if (vmargs === null) {
return;
}
vmargs.forEach(arg => {
//remove all standalone double quotes
arg = arg.replace(/(\\)?"/g, function ($0, $1) { return ($1 ? $0 : ''); });
//unescape all escaped double quotes
arg = arg.replace(/(\\)"/g, '"');
if (params.indexOf(arg) < 0) {
params.push(arg);
}
});
}