From 126b2865900d36b48c168a4ef8b23f48f297e6fe Mon Sep 17 00:00:00 2001 From: Gaurav Gupta Date: Wed, 4 Dec 2024 16:26:47 +0530 Subject: [PATCH] FISH-9450 Payara Tools for VSCode fails to pass environmental variables and start a Payara Micro instance --- src/main/fish/payara/project/Maven.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/fish/payara/project/Maven.ts b/src/main/fish/payara/project/Maven.ts index 468ce06..e500a00 100644 --- a/src/main/fish/payara/project/Maven.ts +++ b/src/main/fish/payara/project/Maven.ts @@ -293,28 +293,34 @@ export class Maven implements Build { '-Dplatform=micro' ]; - let process: ChildProcess = cp.spawn(mavenExe, cmdArgs, { cwd: project.targetFolder?.fsPath }); + let jdkHome; + let env = { ...process.env }; + if (this.payaraInstance && (jdkHome = this.payaraInstance.getJDKHome())) { + env['JAVA_HOME'] = jdkHome; + } + + let childProcess: ChildProcess = cp.spawn(mavenExe, cmdArgs, { cwd: project.targetFolder?.fsPath, shell: true, env: env }); - if (process.pid) { + if (childProcess.pid) { let outputChannel = ProjectOutputWindowProvider.getInstance().get(`${project.artifactId}`); outputChannel.show(false); let logCallback = (data: string | Buffer): void => outputChannel.append(data.toString()); - if (process.stdout !== null) { - process.stdout.on('data', logCallback); + if (childProcess.stdout !== null) { + childProcess.stdout.on('data', logCallback); } - if (process.stderr !== null) { - process.stderr.on('data', logCallback); + if (childProcess.stderr !== null) { + childProcess.stderr.on('data', logCallback); } - process.on('error', (err: Error) => { + childProcess.on('error', (err: Error) => { console.log('error: ' + err.message); }); - process.on('exit', (code: number) => { + childProcess.on('exit', (code: number) => { if (code === 0 && project.targetFolder && project.artifactId) { callback(vscode.Uri.file(path.join(project.targetFolder.fsPath, project.artifactId))); } }); } - return process; + return childProcess; } public startPayaraMicro(