Skip to content

Commit 613bedd

Browse files
dhasani23David Hasani
andauthored
fix(CodeTransform): add check for zip size, show logs, get JAVA_HOME (#4452)
* fix(CodeTransform): add check for zip size and show logs * nit: fix message * remove duplicate metric emission * update error message * fix: just check size of ZIP file itself * update messages * add changelog * remove blank line --------- Co-authored-by: David Hasani <[email protected]>
1 parent bfcec27 commit 613bedd

File tree

9 files changed

+151
-63
lines changed

9 files changed

+151
-63
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "Amazon Q CodeTransformation: show user build logs for Maven install and copy-deps commands"
4+
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/toolkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4271,7 +4271,7 @@
42714271
},
42724272
"devDependencies": {
42734273
"@aws-sdk/types": "^3.13.1",
4274-
"@aws-toolkits/telemetry": "^1.0.186",
4274+
"@aws-toolkits/telemetry": "^1.0.188",
42754275
"@aws/fully-qualified-names": "^2.1.1",
42764276
"@cspotcode/source-map-support": "^0.8.1",
42774277
"@sinonjs/fake-timers": "^10.0.2",

packages/toolkit/src/amazonqFeatureDev/session/session.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ export class Session {
5151
if (!this.preloaderFinished) {
5252
await this.setupConversation(msg)
5353
this.preloaderFinished = true
54-
55-
telemetry.amazonq_startChat.emit({
56-
amazonqConversationId: this.conversationId,
57-
value: 1,
58-
result: 'Succeeded',
59-
credentialStartUrl: AuthUtil.instance.startUrl,
60-
})
61-
6254
this.messenger.sendAsyncEventProgress(this.tabID, true, undefined)
6355
}
6456
}

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ async function collectInput(validProjects: Map<vscode.QuickPickItem, JDKVersion
8888
} else if (state.sourceJavaVersion.label === 'Other') {
8989
telemetry.codeTransform_jobStartedCompleteFromPopupDialog.emit({
9090
codeTransformSessionId: codeTransformTelemetryState.getSessionId(),
91-
codeTransformJavaSourceVersionsAllowed: JDKToTelemetryValue(
92-
transformByQState.getSourceJDKVersion()!
93-
) as CodeTransformJavaSourceVersionsAllowed, // will be 'undefined'
91+
codeTransformJavaSourceVersionsAllowed: 'Other',
9492
codeTransformJavaTargetVersionsAllowed: JDKToTelemetryValue(
9593
transformByQState.getTargetJDKVersion()
9694
) as CodeTransformJavaTargetVersionsAllowed,
@@ -169,11 +167,14 @@ async function setMaven() {
169167
if (fs.existsSync(mavenWrapperExecutablePath)) {
170168
if (mavenWrapperExecutableName === 'mvnw') {
171169
mavenWrapperExecutableName = './mvnw' // add the './' for non-Windows
170+
} else if (mavenWrapperExecutableName === 'mvnw.cmd') {
171+
mavenWrapperExecutableName = '.\\mvnw.cmd' // add the '.\' for Windows
172172
}
173173
transformByQState.setMavenName(mavenWrapperExecutableName)
174174
} else {
175175
transformByQState.setMavenName('mvn')
176176
}
177+
getLogger().info(`CodeTransform: using Maven ${transformByQState.getMavenName()}`)
177178
}
178179

179180
async function validateJavaHome() {
@@ -188,16 +189,41 @@ async function validateJavaHome() {
188189
}
189190
}
190191
if (javaVersionUsedByMaven !== transformByQState.getSourceJDKVersion()) {
192+
telemetry.codeTransform_isDoubleClickedToTriggerInvalidProject.emit({
193+
codeTransformSessionId: codeTransformTelemetryState.getSessionId(),
194+
codeTransformPreValidationError: 'ProjectJDKDiffersFromMavenJDK',
195+
result: MetadataResult.Fail,
196+
reason: `${transformByQState.getSourceJDKVersion()} (project) - ${javaVersionUsedByMaven} (maven)`,
197+
})
198+
let javaHomePrompt = `${
199+
CodeWhispererConstants.enterJavaHomeMessage
200+
} ${transformByQState.getSourceJDKVersion()}. `
201+
if (os.platform() === 'win32') {
202+
javaHomePrompt += CodeWhispererConstants.windowsJavaHomeHelpMessage.replace(
203+
'JAVA_VERSION_HERE',
204+
transformByQState.getSourceJDKVersion()!
205+
)
206+
} else {
207+
const jdkVersion = transformByQState.getSourceJDKVersion()
208+
if (jdkVersion === JDKVersion.JDK8) {
209+
javaHomePrompt += CodeWhispererConstants.nonWindowsJava8HomeHelpMessage
210+
} else if (jdkVersion === JDKVersion.JDK11) {
211+
javaHomePrompt += CodeWhispererConstants.nonWindowsJava11HomeHelpMessage
212+
}
213+
}
191214
// means either javaVersionUsedByMaven is undefined or it does not match the project JDK
192-
// TO-DO: give user help on how to find JAVA_HOME for corresponding project JDK
193215
const javaHome = await vscode.window.showInputBox({
194216
title: CodeWhispererConstants.transformByQWindowTitle,
195-
prompt: `${CodeWhispererConstants.enterJavaHomeMessage} ${transformByQState.getSourceJDKVersion()}`,
217+
prompt: javaHomePrompt,
218+
ignoreFocusOut: true,
196219
})
197220
if (!javaHome || !javaHome.trim()) {
198221
throw new ToolkitError('No JAVA_HOME provided', { code: 'NoJavaHomePath' })
199222
}
200223
transformByQState.setJavaHome(javaHome.trim())
224+
getLogger().info(
225+
`CodeTransform: using JAVA_HOME = ${transformByQState.getJavaHome()} since source JDK does not match Maven JDK`
226+
)
201227
}
202228
}
203229

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

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ export const newCustomizationAvailableKey = 'CODEWHISPERER_NEW_CUSTOMIZATION_AVA
279279
export const selectProjectPrompt = 'Select the project you want to transform'
280280

281281
export const unsupportedJavaVersionSelectedMessage =
282-
'Thank you for trying our product. We currently only support Java 8 and 11. We appreciate you taking the time to use the product, and hope to expand support to more Java versions in the future.'
282+
'Thank you for trying our product. We currently only support Java 8 and 11. We appreciate you taking the time to use the product, and hope to expand support to more Java versions in the future. Please see: https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
283283

284284
export const transformByQWindowTitle = 'Amazon Q Code Transformation'
285285

@@ -296,9 +296,10 @@ export const transformByQCompletedMessage = 'Transformation completed'
296296
export const transformByQPartiallyCompletedMessage = 'Transformation partially completed'
297297

298298
export const noPomXmlFoundMessage =
299-
'None of your open Java projects are supported by Amazon Q Code Transformation. We were unable to find a pom.xml in any of your Java projects. We only support Java projects built on Maven at the moment.'
299+
'None of your open Java projects are supported by Amazon Q Code Transformation. We were unable to find a pom.xml in any of your Java projects. We only support Java projects built on Maven at the moment. Please see: https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
300300

301-
export const noActiveIdCMessage = 'Amazon Q Code Transformation requires an active IAM Identity Center connection'
301+
export const noActiveIdCMessage =
302+
'Amazon Q Code Transformation requires an active IAM Identity Center connection. Please see: https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
302303

303304
export const noOngoingJobMessage = 'No job is in-progress at the moment'
304305

@@ -316,32 +317,46 @@ export const viewProposedChangesMessage =
316317
export const changesAppliedMessage = 'Changes applied'
317318

318319
export const noSupportedJavaProjectsFoundMessage =
319-
'None of your open projects are supported by Amazon Q Code Transformation. We were unable to find a Java project. We only support Java projects built on Maven at the moment.'
320+
'None of your open projects are supported by Amazon Q Code Transformation. We were unable to find a Java project. We only support Java projects built on Maven at the moment. Please see: https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
320321

321322
export const dependencyDisclaimer =
322323
'Please confirm you are ready to proceed with the transformation. Amazon Q Code Transformation will upload the application code and its dependency binaries from your machine to start the upgrade. If you have not yet compiled the application on your local machine, please do so once before starting the upgrade. Install Maven to ensure all module dependencies are picked for Transformation.'
323324

324325
export const dependencyFolderName = 'transformation_dependencies_temp_'
325326

326327
export const installErrorMessage =
327-
'Failed to execute Maven install. It is possible that the upload does not include all dependencies. We will still attempt to complete the transformation.'
328+
'Failed to execute Maven install. Please see: https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
328329

329330
export const dependencyErrorMessage =
330-
'Failed to execute Maven copy-dependencies. It is possible that the upload does not include all dependencies. We will still attempt to complete the transformation.'
331+
'Failed to execute Maven copy-dependencies. Please see: https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
331332

332333
export const planIntroductionMessage =
333334
'We reviewed your Java JAVA_VERSION_HERE application and generated a transformation plan. Any code changes made to your application will be done in the sandbox so as to not interfere with your working repository. Once the transformation job is done, we will share the new code which you can review before acccepting the code changes. In the meantime, you can work on your codebase and invoke Q Chat to answer questions about your codebase.'
334335

335336
export const planDisclaimerMessage = '**Proposed transformation changes** \n\n\n'
336337

337-
export const enterJavaHomeMessage = 'Enter the value of JAVA_HOME for Java'
338+
export const enterJavaHomeMessage = 'Enter the path to JDK'
339+
340+
export const windowsJavaHomeHelpMessage =
341+
'In a terminal, try running "cd C:\\Program Files\\Java" and then "dir" to see a list of installed JDKs. Then "cd" into JDK JAVA_VERSION_HERE (if present) and run "cd" once more to get the path we need. It should look something like "C:\\Program Files\\Java\\jdk-11.0.1"'
342+
343+
export const nonWindowsJava8HomeHelpMessage =
344+
'Try running "/usr/libexec/java_home -v 1.8" in a terminal to find this. It should look something like "/Library/Java/JavaVirtualMachines/jdk-8.jdk/Contents/Home"'
345+
346+
export const nonWindowsJava11HomeHelpMessage =
347+
'Try running "/usr/libexec/java_home -v 11" in a terminal to find this. It should look something like "/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home"'
348+
349+
export const projectSizeTooLargeMessage =
350+
'Your project size exceeds the Amazon Q Code Transformation upload limit of 1GB. Please see: https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html'
338351

339352
export const JDK8VersionNumber = '52'
340353

341354
export const JDK11VersionNumber = '55'
342355

343356
export const numMillisecondsPerSecond = 1000
344357

358+
export const uploadZipSizeLimitInBytes = 1000000000 // 1GB
359+
345360
export const maxBufferSize = 1024 * 1024 // this is 1MB, the default max buffer size for stdout for spawnSync
346361

347362
export const transformByQStateRunningMessage = 'running'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ export class TransformByQState {
498498
this.polledJobStatus = '' // reset polled job status too
499499
this.jobFailureErrorMessage = ''
500500
this.payloadFilePath = ''
501+
this.errorLog = ''
501502
}
502503
}
503504

0 commit comments

Comments
 (0)