Skip to content

Commit 595ce83

Browse files
author
David Hasani
committed
feat(amazonq): java21 support
1 parent f004173 commit 595ce83

File tree

8 files changed

+43
-10
lines changed

8 files changed

+43
-10
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ export class GumbyController {
483483
message.tabID
484484
)
485485

486+
if (fromJDKVersion === JDKVersion.JDK21 && toJDKVersion === JDKVersion.JDK17) {
487+
this.messenger.sendUnrecoverableErrorResponse('invalid-from-to-jdk', message.tabID)
488+
return
489+
}
490+
486491
await processLanguageUpgradeTransformFormInput(pathToProject, fromJDKVersion, toJDKVersion)
487492
await this.messenger.sendSkipTestsPrompt(message.tabID)
488493
})

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export type UnrecoverableErrorType =
5151
| 'unsupported-target-db'
5252
| 'error-parsing-sct-file'
5353
| 'invalid-zip-no-sct-file'
54+
| 'invalid-from-to-jdk'
5455

5556
export enum GumbyNamedMessages {
5657
COMPILATION_PROGRESS_MESSAGE = 'gumbyProjectCompilationMessage',
@@ -176,7 +177,9 @@ export class Messenger {
176177
this.dispatcher.sendAsyncEventProgress(
177178
new AsyncEventProgressMessage(tabID, {
178179
inProgress: true,
179-
message: CodeWhispererConstants.userPatchDescriptionChatMessage,
180+
message: CodeWhispererConstants.userPatchDescriptionChatMessage(
181+
transformByQState.getTargetJDKVersion() ?? ''
182+
),
180183
})
181184
)
182185

@@ -233,6 +236,10 @@ export class Messenger {
233236
value: JDKVersion.JDK17,
234237
label: JDKVersion.JDK17,
235238
},
239+
{
240+
value: JDKVersion.JDK21,
241+
label: JDKVersion.JDK21,
242+
},
236243
],
237244
})
238245

@@ -246,6 +253,10 @@ export class Messenger {
246253
value: JDKVersion.JDK17,
247254
label: JDKVersion.JDK17,
248255
},
256+
{
257+
value: JDKVersion.JDK21,
258+
label: JDKVersion.JDK21,
259+
},
249260
],
250261
})
251262

@@ -481,6 +492,9 @@ export class Messenger {
481492
case 'invalid-zip-no-sct-file':
482493
message = CodeWhispererConstants.invalidMetadataFileNoSctFile
483494
break
495+
case 'invalid-from-to-jdk':
496+
message = CodeWhispererConstants.invalidFromToJdkChatMessage
497+
break
484498
}
485499

486500
this.sendJobFinishedMessage(tabID, message)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export default class MessengerUtils {
5252
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(11)}`
5353
} else if (jdkVersion === JDKVersion.JDK17) {
5454
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(17)}`
55+
} else if (jdkVersion === JDKVersion.JDK21) {
56+
javaHomePrompt += ` ${CodeWhispererConstants.macJavaVersionHomeHelpChatMessage(21)}`
5557
}
5658
} else {
5759
javaHomePrompt += ` ${CodeWhispererConstants.linuxJavaHomeHelpChatMessage}`

packages/core/src/codewhisperer/client/user-service-2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,7 @@
26062606
},
26072607
"TransformationJavaRuntimeEnv": {
26082608
"type": "string",
2609-
"enum": ["JVM_8", "JVM_11", "JVM_17"]
2609+
"enum": ["JVM_8", "JVM_11", "JVM_17", "JVM_21"]
26102610
},
26112611
"TransformationJob": {
26122612
"type": "structure",
@@ -2629,7 +2629,7 @@
26292629
},
26302630
"TransformationLanguage": {
26312631
"type": "string",
2632-
"enum": ["JAVA_8", "JAVA_11", "JAVA_17", "C_SHARP", "COBOL", "PL_I", "JCL"]
2632+
"enum": ["JAVA_8", "JAVA_11", "JAVA_17", "JAVA_21", "C_SHARP", "COBOL", "PL_I", "JCL"]
26332633
},
26342634
"TransformationLanguages": {
26352635
"type": "list",

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ async function validateJavaHome(): Promise<boolean> {
119119
javaVersionUsedByMaven = JDKVersion.JDK11
120120
} else if (javaVersionUsedByMaven === '17.') {
121121
javaVersionUsedByMaven = JDKVersion.JDK17
122+
} else if (javaVersionUsedByMaven === '21.') {
123+
javaVersionUsedByMaven = JDKVersion.JDK21
122124
}
123125
}
124126
if (javaVersionUsedByMaven !== transformByQState.getSourceJDKVersion()) {

packages/core/src/codewhisperer/models/constants.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ export const AWSTemplateKeyWords = ['AWSTemplateFormatVersion', 'Resources', 'AW
2222

2323
export const AWSTemplateCaseInsensitiveKeyWords = ['cloudformation', 'cfn', 'template', 'description']
2424

25+
// TO-DO: make sure all Strings look good for Java 21
2526
const patchDescriptions: { [key: string]: string } = {
2627
'Prepare minimal upgrade to Java 17':
27-
'This diff patch covers the set of upgrades for Springboot, JUnit, and PowerMockito frameworks.',
28+
'This diff patch covers the set of upgrades for Springboot, JUnit, and PowerMockito frameworks in Java 17.',
29+
'Prepare minimal upgrade to Java 21':
30+
'This diff patch covers the set of upgrades for Springboot, JUnit, and PowerMockito frameworks in Java 21.',
2831
'Popular Enterprise Specifications and Application Frameworks upgrade':
2932
'This diff patch covers the set of upgrades for Jakarta EE 10, Hibernate 6.2, and Micronaut 3.',
3033
'HTTP Client Utilities, Apache Commons Utilities, and Web Frameworks':
@@ -505,14 +508,14 @@ export const codeTransformLocThreshold = 100000
505508
export const jobStartedChatMessage =
506509
'I am starting to transform your code. It can take 10 to 30 minutes to upgrade your code, depending on the size of your project. To monitor progress, go to the Transformation Hub. If I run into any issues, I might pause the transformation to get input from you on how to proceed.'
507510

508-
export const chooseTransformationObjective = `I can help you with the following tasks:\n- Upgrade your Java 8 and Java 11 codebases to Java 17, or upgrade Java 17 code with up to date libraries and other dependencies.\n- Convert embedded SQL code for Oracle to PostgreSQL database migrations in AWS DMS. [Learn more](https://docs.aws.amazon.com/dms/latest/userguide/schema-conversion-embedded-sql.html).\n\nWhat would you like to do? You can enter "language upgrade" or "sql conversion".`
511+
export const chooseTransformationObjective = `I can help you with the following tasks:\n- Upgrade your Java 8, Java 11, and Java 17 codebases to Java 17 or Java 21.\n- Upgrade Java 17 or Java 21 code with up-to-date libraries and other dependencies.\n- Convert embedded SQL code for Oracle to PostgreSQL database migrations in AWS DMS. [Learn more](https://docs.aws.amazon.com/dms/latest/userguide/schema-conversion-embedded-sql.html).\n\nWhat would you like to do? You can enter "language upgrade" or "sql conversion".`
509512

510513
export const chooseTransformationObjectivePlaceholder = 'Enter "language upgrade" or "sql conversion"'
511514

512-
export const userPatchDescriptionChatMessage = `
515+
export const userPatchDescriptionChatMessage = (version: string) => `
513516
If you'd like to update and test your code with fewer changes at a time, I can divide the transformation results into separate diff patches. If applicable to your application, I can split up the diffs up into the following groups of upgrades. Here are the upgrades included in each diff:
514517
515-
• Minimal Compatible Library Upgrade to Java 17: Dependencies to the minimum compatible versions in Java 17, including Springboot, JUnit, and PowerMockito.
518+
• Minimal Compatible Library Upgrade to Java ${version}: Dependencies to the minimum compatible versions in Java ${version}, including Springboot, JUnit, and PowerMockito.
516519
517520
• Popular Enterprise Specifications Application Frameworks: Popular enterprise and application frameworks like Jakarta EE, Hibernate, and Micronaut 3.
518521
@@ -597,6 +600,9 @@ export const invalidMetadataFileErrorParsing =
597600
export const invalidMetadataFileNoSctFile =
598601
"An .sct file is required for transformation. Make sure that you've uploaded the .zip file you retrieved from your schema conversion in AWS DMS."
599602

603+
export const invalidFromToJdkChatMessage =
604+
"I can't transform a project from Java 21 to Java 17, but I can upgrade Java 21 code with up to date libraries and other dependencies. Try again with a supported language upgrade."
605+
600606
export const sqlMetadataFileReceived =
601607
'I found the following source database, target database, and host based on the schema conversion metadata you provided:'
602608

packages/core/src/codewhisperer/models/model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ export enum JDKVersion {
648648
JDK8 = '8',
649649
JDK11 = '11',
650650
JDK17 = '17',
651+
JDK21 = '21',
651652
UNSUPPORTED = 'UNSUPPORTED',
652653
}
653654

@@ -739,7 +740,7 @@ export class TransformByQState {
739740

740741
private sourceJDKVersion: JDKVersion | undefined = undefined
741742

742-
private targetJDKVersion: JDKVersion = JDKVersion.JDK17
743+
private targetJDKVersion: JDKVersion | undefined = undefined
743744

744745
private produceMultipleDiffs: boolean = false
745746

@@ -1131,7 +1132,7 @@ export class TransformByQState {
11311132
this.payloadFilePath = ''
11321133
this.metadataPathSQL = ''
11331134
this.sourceJDKVersion = undefined
1134-
this.targetJDKVersion = JDKVersion.JDK17
1135+
this.targetJDKVersion = undefined
11351136
this.sourceDB = undefined
11361137
this.targetDB = undefined
11371138
this.sourceServerName = ''

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ export async function zipCode(
436436
export async function startJob(uploadId: string) {
437437
const sourceLanguageVersion = `JAVA_${transformByQState.getSourceJDKVersion()}`
438438
const targetLanguageVersion = `JAVA_${transformByQState.getTargetJDKVersion()}`
439+
// TO-DO: remove these logs statements
440+
console.log('sourceLanguageVersion', sourceLanguageVersion)
441+
console.log('targetLanguageVersion', targetLanguageVersion)
439442
try {
440443
const response = await codeWhisperer.codeWhispererClient.codeModernizerStartCodeTransformation({
441444
workspaceState: {
@@ -445,7 +448,7 @@ export async function startJob(uploadId: string) {
445448
transformationSpec: {
446449
transformationType: CodeWhispererConstants.transformationType, // shared b/w language upgrades & sql conversions for now
447450
source: { language: sourceLanguageVersion }, // dummy value of JDK8 used for SQL conversions just so that this API can be called
448-
target: { language: targetLanguageVersion }, // always JDK17
451+
target: { language: targetLanguageVersion }, // JAVA_17 or JAVA_21
449452
},
450453
})
451454
getLogger().info('CodeTransformation: called startJob API successfully')

0 commit comments

Comments
 (0)