Skip to content

Commit 3d1b447

Browse files
author
David Hasani
committed
final csb commit
1 parent 28e50be commit 3d1b447

File tree

11 files changed

+48
-39
lines changed

11 files changed

+48
-39
lines changed

packages/amazonq/test/e2e/amazonq/transformByQ.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('Amazon Q Code Transformation', function () {
150150
waitIntervalInMs: 1000,
151151
})
152152

153-
// Add this back when custom 1P upgrades support is ready
153+
// TO-DO: add this back when releasing CSB
154154
/*
155155
const customDependencyVersionPrompt = tab.getChatItems().pop()
156156
assert.strictEqual(

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import {
5757
openBuildLogFile,
5858
parseBuildFile,
5959
validateSQLMetadataFile,
60-
validateYamlFile,
60+
validateCustomVersionsFile,
6161
} from '../../../codewhisperer/service/transformByQ/transformFileHandler'
6262
import { getAuthType } from '../../../auth/utils'
6363
import fs from '../../../shared/fs/fs'
@@ -461,7 +461,7 @@ export class GumbyController {
461461

462462
this.messenger.sendOneOrMultipleDiffsMessage(oneOrMultipleDiffsSelection, message.tabID)
463463
this.promptJavaHome('source', message.tabID)
464-
// When custom 1P upgrades ready, delete line above and uncomment line below
464+
// TO-DO: delete line above and uncomment line below when releasing CSB
465465
// await this.messenger.sendCustomDependencyVersionMessage(message.tabID)
466466
})
467467
}
@@ -586,15 +586,17 @@ export class GumbyController {
586586
canSelectMany: false,
587587
openLabel: 'Select',
588588
filters: {
589-
'.YAML file': ['yaml'], // Restrict user to only pick a .yaml file
589+
'YAML file': ['yaml'], // restrict user to only pick a .yaml file
590590
},
591591
})
592592
if (!fileUri || fileUri.length === 0) {
593593
return
594594
}
595595
const fileContents = await fs.readFileText(fileUri[0].fsPath)
596-
const isValidYaml = await validateYamlFile(fileContents, message)
597-
if (!isValidYaml) {
596+
const isValidFile = await validateCustomVersionsFile(fileContents)
597+
598+
if (!isValidFile) {
599+
this.messenger.sendUnrecoverableErrorResponse('invalid-custom-versions-file', message.tabID)
598600
return
599601
}
600602
this.messenger.sendMessage('Received custom dependency version YAML file.', message.tabID, 'ai-prompt')
@@ -686,7 +688,13 @@ export class GumbyController {
686688
const pathToJavaHome = extractPath(data.message)
687689
if (pathToJavaHome) {
688690
transformByQState.setSourceJavaHome(pathToJavaHome)
689-
this.promptJavaHome('target', data.tabID) // get target JDK path right after saving source JDK path
691+
// if source and target JDK versions are the same, just re-use the source JAVA_HOME and start the build
692+
if (transformByQState.getTargetJDKVersion() === transformByQState.getSourceJDKVersion()) {
693+
transformByQState.setTargetJavaHome(pathToJavaHome)
694+
await this.prepareLanguageUpgradeProject(data.tabID)
695+
} else {
696+
this.promptJavaHome('target', data.tabID)
697+
}
690698
} else {
691699
this.messenger.sendUnrecoverableErrorResponse('invalid-java-home', data.tabID)
692700
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type UnrecoverableErrorType =
5050
| 'job-start-failed'
5151
| 'unsupported-source-db'
5252
| 'unsupported-target-db'
53-
| 'missing-yaml-key'
53+
| 'invalid-custom-versions-file'
5454
| 'error-parsing-sct-file'
5555
| 'invalid-zip-no-sct-file'
5656
| 'invalid-from-to-jdk'
@@ -462,8 +462,8 @@ export class Messenger {
462462
case 'unsupported-target-db':
463463
message = CodeWhispererConstants.invalidMetadataFileUnsupportedTargetDB
464464
break
465-
case 'missing-yaml-key':
466-
message = CodeWhispererConstants.invalidYamlFileMissingKey
465+
case 'invalid-custom-versions-file':
466+
message = CodeWhispererConstants.invalidCustomVersionsFileMessage
467467
break
468468
case 'error-parsing-sct-file':
469469
message = CodeWhispererConstants.invalidMetadataFileErrorParsing
@@ -647,7 +647,7 @@ ${codeSnippet}
647647
this.sendInProgressMessage(tabID, message)
648648
}
649649

650-
public sendInProgressMessage(tabID: string, message: string, messageName?: string) {
650+
public sendInProgressMessage(tabID: string, message: string) {
651651
this.dispatcher.sendAsyncEventProgress(
652652
new AsyncEventProgressMessage(tabID, { inProgress: true, message: undefined })
653653
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export async function compileProject() {
117117
await prepareProjectDependencies(dependenciesFolder, modulePath)
118118
} catch (err) {
119119
// open build-logs.txt file to show user error logs
120-
await writeAndShowBuildLogs()
120+
await writeAndShowBuildLogs(true)
121121
throw err
122122
}
123123
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ export const invalidMetadataFileUnsupportedSourceDB =
599599
export const invalidMetadataFileUnsupportedTargetDB =
600600
'I can only convert SQL for migrations to Aurora PostgreSQL or Amazon RDS for PostgreSQL target databases. The provided .sct file indicates another target database for this migration.'
601601

602-
export const invalidYamlFileMissingKey =
603-
'Your YAML file is not formatted correctly. Make sure that the .yaml file you upload follows the format of the sample file provided.'
602+
export const invalidCustomVersionsFileMessage =
603+
'Your .YAML file is not formatted correctly. Make sure that the .YAML file you upload follows the format of the sample file provided.'
604604

605605
export const invalidMetadataFileErrorParsing =
606606
"It looks like the .sct file you provided isn't valid. Make sure that you've uploaded the .zip file you retrieved from your schema conversion in AWS DMS."

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,8 @@ export class ZipManifest {
685685
buildLogs: string = 'build-logs.txt'
686686
version: string = '1.0'
687687
hilCapabilities: string[] = ['HIL_1pDependency_VersionUpgrade']
688-
transformCapabilities: string[] = ['EXPLAINABILITY_V1', 'CLIENT_SIDE_BUILD']
688+
// TO-DO: add 'CLIENT_SIDE_BUILD' here when releasing
689+
transformCapabilities: string[] = ['EXPLAINABILITY_V1']
689690
customBuildCommand: string = 'clean test'
690691
requestedConversions?: {
691692
sqlConversion?: {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { UserWrittenCodeTracker } from '../../tracker/userWrittenCodeTracker'
5454
import { AuthUtil } from '../../util/authUtil'
5555
import { DiffModel } from './transformationResultsViewProvider'
5656
import { spawnSync } from 'child_process' // eslint-disable-line no-restricted-imports
57+
import { isClientSideBuildEnabled } from '../../../dev/config'
5758

5859
export function getSha256(buffer: Buffer) {
5960
const hasher = crypto.createHash('sha256')
@@ -395,6 +396,7 @@ export async function zipCode(
395396
dependenciesCopied = true
396397
}
397398

399+
// TO-DO: decide where exactly to put the YAML file / what to name it
398400
if (transformByQState.getCustomDependencyVersionFilePath() && zipManifest instanceof ZipManifest) {
399401
zip.addLocalFile(
400402
transformByQState.getCustomDependencyVersionFilePath(),
@@ -701,7 +703,9 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
701703
break
702704
}
703705

706+
// TO-DO: remove isClientSideBuildEnabled when releasing CSB
704707
if (
708+
isClientSideBuildEnabled &&
705709
status === 'TRANSFORMING' &&
706710
transformByQState.getTransformationType() === TransformationType.LANGUAGE_UPGRADE
707711
) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ export function getDependenciesFolderInfo(): FolderInfo {
2727
}
2828
}
2929

30-
export async function writeAndShowBuildLogs() {
30+
export async function writeAndShowBuildLogs(isLocalInstall: boolean = false) {
3131
const logFilePath = path.join(os.tmpdir(), 'build-logs.txt')
3232
writeFileSync(logFilePath, transformByQState.getBuildLog())
3333
const doc = await vscode.workspace.openTextDocument(logFilePath)
3434
if (!transformByQState.getBuildLog().includes('clean install succeeded')) {
35-
// only show the log if the build failed
36-
await vscode.window.showTextDocument(doc, { viewColumn: vscode.ViewColumn.Two })
35+
// only show the log if the build failed; show it in second column for intermediate builds only
36+
const options = isLocalInstall ? undefined : { viewColumn: vscode.ViewColumn.Two }
37+
await vscode.window.showTextDocument(doc, options)
3738
}
3839
return logFilePath
3940
}
@@ -115,12 +116,11 @@ export async function parseBuildFile() {
115116
return undefined
116117
}
117118

118-
export async function validateYamlFile(fileContents: string, message: any) {
119+
export async function validateCustomVersionsFile(fileContents: string) {
119120
const requiredKeys = ['dependencyManagement:', 'identifier:', 'targetVersion:']
120121
for (const key of requiredKeys) {
121122
if (!fileContents.includes(key)) {
122-
getLogger().info(`CodeTransformation: missing yaml key: ${key}`)
123-
transformByQState.getChatMessenger()?.sendUnrecoverableErrorResponse('missing-yaml-key', message.tabID)
123+
getLogger().info(`CodeTransformation: .YAML file is missing required key: ${key}`)
124124
return false
125125
}
126126
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { spawnSync } from 'child_process' // eslint-disable-line no-restricted-i
1111
import { CodeTransformBuildCommand, telemetry } from '../../../shared/telemetry/telemetry'
1212
import { CodeTransformTelemetryState } from '../../../amazonqGumby/telemetry/codeTransformTelemetryState'
1313
import { ToolkitError } from '../../../shared/errors'
14-
import { setMaven, writeAndShowBuildLogs } from './transformFileHandler'
14+
import { setMaven } from './transformFileHandler'
1515
import { throwIfCancelled } from './transformApiHandler'
1616
import { sleep } from '../../../shared/utilities/timeoutUtils'
1717

@@ -58,7 +58,7 @@ function installProjectDependencies(dependenciesFolder: FolderInfo, modulePath:
5858
)
5959
throw new ToolkitError(`Maven ${argString} error`, { code: 'MavenExecutionError' })
6060
} else {
61-
transformByQState.appendToBuildLog(`Maven clean install succeeded`)
61+
transformByQState.appendToBuildLog(`mvn clean install succeeded`)
6262
}
6363
})
6464
}
@@ -75,8 +75,6 @@ function copyProjectDependencies(dependenciesFolder: FolderInfo, modulePath: str
7575
'-q',
7676
]
7777

78-
transformByQState.appendToBuildLog(`Running ${baseCommand} ${args.join(' ')}`)
79-
8078
let environment = process.env
8179
if (transformByQState.getSourceJavaHome()) {
8280
environment = { ...process.env, JAVA_HOME: transformByQState.getSourceJavaHome() }
@@ -93,13 +91,10 @@ function copyProjectDependencies(dependenciesFolder: FolderInfo, modulePath: str
9391
let errorLog = ''
9492
errorLog += spawnResult.error ? JSON.stringify(spawnResult.error) : ''
9593
errorLog += `${spawnResult.stderr}\n${spawnResult.stdout}`
96-
transformByQState.appendToBuildLog(`${baseCommand} ${args} failed: \n ${errorLog}`)
9794
getLogger().info(
9895
`CodeTransformation: Maven command ${baseCommand} ${args} failed, but still continuing with transformation: ${errorLog}`
9996
)
10097
throw new Error('Maven copy-deps error')
101-
} else {
102-
transformByQState.appendToBuildLog(`Maven dependency:copy-dependencies succeeded`)
10398
}
10499
}
105100

@@ -122,8 +117,6 @@ export async function prepareProjectDependencies(dependenciesFolder: FolderInfo,
122117
installProjectDependencies(dependenciesFolder, rootPomPath)
123118
} catch (err) {
124119
void vscode.window.showErrorMessage(CodeWhispererConstants.cleanInstallErrorNotification)
125-
// open build-logs.txt file to show user error logs
126-
await writeAndShowBuildLogs()
127120
throw err
128121
}
129122

packages/core/src/dev/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ export const betaUrl = {
1010
amazonq: '',
1111
toolkit: '',
1212
}
13+
14+
// TO-DO: remove when releasing CSB
15+
export const isClientSideBuildEnabled = false

0 commit comments

Comments
 (0)