Skip to content

Commit 9250e42

Browse files
committed
Automatically intercept JVM processes in terminals
1 parent af0fb51 commit 9250e42

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

overrides/java-agent.jar

1.73 MB
Binary file not shown.

src/interceptors/terminal/terminal-env-overrides.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const OVERRIDES_DIR = path.join(APP_ROOT, 'overrides');
1010
const OVERRIDE_RUBYGEMS_PATH = path.join(OVERRIDES_DIR, 'gems');
1111
const OVERRIDE_PYTHONPATH = path.join(OVERRIDES_DIR, 'pythonpath');
1212

13+
export const OVERRIDE_JAVA_AGENT = path.join(OVERRIDES_DIR, 'java-agent.jar');
14+
1315
const OVERRIDE_JS_SCRIPT = path.join(OVERRIDES_DIR, 'js', 'prepend-node.js');
1416
const NODE_OPTION = `--require ${
1517
// Avoid quoting except when necessary, because node 8 doesn't support quotes here
@@ -27,6 +29,10 @@ export function getTerminalEnvVars(
2729
): { [key: string]: string } {
2830
const proxyUrl = `http://127.0.0.1:${proxyPort}`;
2931

32+
const javaAgentOption = `-javaagent:${
33+
OVERRIDE_JAVA_AGENT
34+
}=127.0.0.1|${proxyPort}|${httpsConfig.certPath}`;
35+
3036
return {
3137
'http_proxy': proxyUrl,
3238
'HTTP_PROXY': proxyUrl,
@@ -84,6 +90,13 @@ export function getTerminalEnvVars(
8490
// subprocesses. Otherwise e.g. --max-http-header-size breaks old Node/Electron.
8591
'NODE_OPTIONS': currentEnv === 'runtime-inherit'
8692
? `$NODE_OPTIONS ${NODE_OPTION}`
87-
: NODE_OPTION
93+
: NODE_OPTION,
94+
95+
// Attach our Java agent to all launched Java processes:
96+
'JAVA_TOOL_OPTIONS': currentEnv === 'runtime-inherit'
97+
? `$JAVA_TOOL_OPTIONS ${javaAgentOption}`
98+
: currentEnv.JAVA_TOOL_OPTIONS
99+
? `${currentEnv.JAVA_TOOL_OPTIONS} ${javaAgentOption}`
100+
: javaAgentOption
88101
};
89102
}

0 commit comments

Comments
 (0)