Skip to content

Commit b8f883f

Browse files
authored
fix(amazon-q): transform fails if whitespace in user-provided JAVA_HOME #4633
Problem: When customers provide a path to JDK installation that contains whitespace we fail to use it when executing Maven to build the customers project. E.g. passing: /Library/Java/JavaVirtualMachines/jdk 8 with spaces/amazon-corretto-8.jdk/Contents/Home fails with: I'm sorry, I could not locate your Java installation. To troubleshoot, see the [Amazon Q documentation.](https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#maven-commands-failing) Solution: 1. Use `path` to parse input instead of string manipulation (previously split on whitespace) 3. Update messaging on windows of how to check for Java installation. Testing: 1. Ran it on mac using `/Library/Java/JavaVirtualMachines/jdk 8 with spaces/amazon-corretto-8.jdk/Contents/Home` 2. Ran it on Windows
1 parent db1d16c commit b8f883f

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q Code Transform: Handle whitespaces in manually entered JAVA_HOME"
4+
}

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,18 @@ export class GumbyController {
342342
}
343343
}
344344

345+
/**
346+
* Examples:
347+
* ```
348+
* extractPath("./some/path/here") => "C:/some/root/some/path/here"
349+
* extractPath("C:/some/nonexistent/path/here") => undefined
350+
* extractPath("C:/some/filepath/.txt") => undefined
351+
* ```
352+
*
353+
* @param text
354+
* @returns the absolute path if path points to existing folder, otherwise undefined
355+
*/
345356
function extractPath(text: string): string | undefined {
346-
const words = text.split(/\s+/) // Split text into words by whitespace
347-
348-
// Filter words that are formatted like paths and do exist as local directories
349-
const paths = words.find(word => fs.existsSync(word) && fs.lstatSync(word).isDirectory())
350-
351-
return paths
357+
const resolvedPath = path.resolve(text)
358+
return fs.existsSync(resolvedPath) && fs.lstatSync(resolvedPath).isDirectory() ? resolvedPath : undefined
352359
}

packages/core/src/amazonqGumby/chat/controller/messenger/stringConstants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
export const enterJavaHomeMessage = 'Enter the path to JDK '
88

99
export const windowsJavaHomeHelpMessage =
10-
'To find the JAVA_HOME path, run the following command in a new IDE terminal: `cd C:ProgramFilesJava` and then `dir`. If you see your JDK version, run `cd JDK<version>` and then `cd` to show the path.'
10+
'To find the JAVA_HOME path, run the following command in a new IDE terminal: `cd "C:\\Program Files\\Java" && dir`. If you see your JDK version, run `cd <version>` and then `cd` to show the path.'
1111

1212
export const nonWindowsJava8HomeHelpMessage =
1313
'To find the JAVA_HOME path, run the following command in a new IDE terminal: `/usr/libexec/java_home -v 1.8`'

0 commit comments

Comments
 (0)