-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathjavaServerStarter.ts
More file actions
96 lines (88 loc) · 3.47 KB
/
javaServerStarter.ts
File metadata and controls
96 lines (88 loc) · 3.47 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
import { globSync } from 'glob';
import * as os from 'os';
import * as path from 'path';
import { workspace } from 'vscode';
import { Executable, ExecutableOptions } from 'vscode-languageclient/node';
import { RequirementsData } from './requirements';
const DEBUG = startedInDebugMode();
const DEBUG_PORT = 1064;
const MICROPROFILE_SERVER_NAME = 'org.eclipse.lsp4mp.ls-uber.jar';
const MICROPROFILE_SERVER_MAIN_CLASS = 'org.eclipse.lsp4mp.ls.MicroProfileServerLauncher';
export function prepareExecutable(requirements: RequirementsData, microprofileJavaExtensions: string[]): Executable {
const executable: Executable = Object.create(null);
const options: ExecutableOptions = Object.create(null);
options.env = process.env;
executable.options = options;
executable.command = path.resolve(requirements.tooling_jre + '/bin/java');
executable.args = prepareParams(microprofileJavaExtensions);
return executable;
}
function prepareParams(microprofileJavaExtensions: string[]): string[] {
const params: string[] = [];
if (DEBUG) {
if (process.env.SUSPEND_SERVER === 'true') {
params.push(`-agentlib:jdwp=transport=dt_socket,server=y,address=${DEBUG_PORT}`);
} else {
params.push(`-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${DEBUG_PORT},quiet=y`);
}
}
const vmargs = workspace.getConfiguration("microprofile.tools").get("server.vmargs", '');
if (os.platform() === 'win32') {
const watchParentProcess = '-DwatchParentProcess=';
if (vmargs.indexOf(watchParentProcess) < 0) {
params.push(watchParentProcess + 'false');
}
}
// Disable logging unless the user specifically sets it to a different value.
// Logging can cause issues, since sometimes it writes to standard out.
// See https://github.com/redhat-developer/vscode-java/issues/2577.
if (vmargs.indexOf("-Xlog:") < 0) {
params.push("-Xlog:disable");
}
parseVMargs(params, vmargs);
const serverHome: string = path.resolve(__dirname, '../server');
const microprofileServerFound: Array<string> = globSync(`**/${MICROPROFILE_SERVER_NAME}`, { cwd: serverHome });
if (microprofileServerFound.length) {
let mpJavaExtensionsClasspath = '';
if (microprofileJavaExtensions.length > 0) {
const classpathSeperator = os.platform() === 'win32' ? ';' : ':';
mpJavaExtensionsClasspath = classpathSeperator + microprofileJavaExtensions.join(classpathSeperator);
}
params.push('-cp');
params.push(`${serverHome}/*` + mpJavaExtensionsClasspath);
params.push(MICROPROFILE_SERVER_MAIN_CLASS);
} else {
throw new Error('Unable to find required Language Server JARs');
}
return params;
}
function hasDebugFlag(args: string[]): boolean {
if (args) {
// See https://nodejs.org/en/docs/guides/debugging-getting-started/
return args.some(arg => /^--inspect/.test(arg) || /^--debug/.test(arg));
}
return false;
}
function startedInDebugMode(): boolean {
const args: string[] = process.execArgv;
return hasDebugFlag(args);
}
// exported for tests
export function parseVMargs(params: string[], vmargsLine: string): void {
if (!vmargsLine) {
return;
}
const vmargs = vmargsLine.match(/(?:[^\s"]+|"[^"]*")+/g);
if (vmargs === null) {
return;
}
vmargs.forEach(arg => {
// remove all standalone double quotes
arg = arg.replace(/(\\)?"/g, ($0, $1) => { return ($1 ? $0 : ''); });
// unescape all escaped double quotes
arg = arg.replace(/(\\)"/g, '"');
if (params.indexOf(arg) < 0) {
params.push(arg);
}
});
}