Skip to content

Commit

Permalink
put exact build command in manifest instead of flag
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hasani committed Sep 17, 2024
1 parent 225f4d4 commit 0b5c066
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 60 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/amazonqGumby/chat/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,11 @@ export class GumbyController {
private async handleSkipTestsSelection(message: any) {
const skipTestsSelection = message.formSelectedValues['GumbyTransformSkipTestsForm']
if (skipTestsSelection === CodeWhispererConstants.skipIntegrationTestsMessage) {
transformByQState.setSkipTestsFlag(CodeWhispererConstants.skipIntegrationTestsFlag)
transformByQState.setCustomBuildCommand(CodeWhispererConstants.skipIntegrationTestsBuildCommand)
} else if (skipTestsSelection === CodeWhispererConstants.skipAllTestsMessage) {
transformByQState.setSkipTestsFlag(CodeWhispererConstants.skipAllTestsFlag)
transformByQState.setCustomBuildCommand(CodeWhispererConstants.skipAllTestsBuildCommand)
} else {
transformByQState.setCustomBuildCommand(CodeWhispererConstants.doNotSkipTestsBuildCommand)
}
telemetry.codeTransform_submitSelection.emit({
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export class Messenger {
if (skipTestsText === CodeWhispererConstants.doNotSkipTestsMessage) {
skipTestsText = 'not skip tests'
}
const message = `Got it! Amazon Q will ${skipTestsText.toLowerCase()} when building your project.`
const message = `Ok, I will ${skipTestsText.toLowerCase()} when building your project.`
this.dispatcher.sendChatMessage(new ChatMessage({ message, messageType: 'prompt' }, tabID))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export async function preTransformationUploadCode() {

const transformZipManifest = new ZipManifest()
// if the user chose to skip tests, add the flag here
transformZipManifest.skipTestsFlag = transformByQState.getSkipTestsFlag()
transformZipManifest.customBuildCommand = transformByQState.getCustomBuildCommand()
const zipCodeResult = await zipCode({
dependenciesFolder: transformByQState.getDependencyFolderInfo()!,
modulePath: transformByQState.getProjectPath(),
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/codewhisperer/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,15 @@ export const skipTestsFormMessage =

export const doNotSkipTestsMessage = 'Do not skip tests'

export const doNotSkipTestsBuildCommand = 'verify'

export const skipIntegrationTestsMessage = 'Skip integration tests'

export const skipIntegrationTestsFlag = '-DskipITs'
export const skipIntegrationTestsBuildCommand = 'test'

export const skipAllTestsMessage = 'Skip all tests'

export const skipAllTestsFlag = '-DskipTests'
export const skipAllTestsBuildCommand = 'test-compile'

export const planTitle = 'Code Transformation plan by Amazon Q'

Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/codewhisperer/models/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class ZipManifest {
version: string = '1.0'
hilCapabilities: string[] = ['HIL_1pDependency_VersionUpgrade']
transformCapabilities: string[] = ['EXPLAINABILITY_V1']
skipTestsFlag: string = ''
customBuildCommand: string = ''
}

export interface IHilZipManifestParams {
Expand Down Expand Up @@ -375,7 +375,7 @@ export class TransformByQState {

private targetJDKVersion: JDKVersion = JDKVersion.JDK17

private skipTestsFlag: string = ''
private customBuildCommand: string = ''

private planFilePath: string = ''
private summaryFilePath: string = ''
Expand Down Expand Up @@ -440,8 +440,8 @@ export class TransformByQState {
return this.projectPath
}

public getSkipTestsFlag() {
return this.skipTestsFlag
public getCustomBuildCommand() {
return this.customBuildCommand
}

public getPreBuildLogFilePath() {
Expand Down Expand Up @@ -568,8 +568,8 @@ export class TransformByQState {
this.projectPath = path
}

public setSkipTestsFlag(flags: string) {
this.skipTestsFlag = flags
public setCustomBuildCommand(command: string) {
this.customBuildCommand = command
}

public setStartTime(time: string) {
Expand Down Expand Up @@ -667,7 +667,7 @@ export class TransformByQState {
this.jobFailureMetadata = ''
this.payloadFilePath = ''
this.errorLog = ''
this.skipTestsFlag = ''
this.customBuildCommand = ''
this.intervalId = undefined
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,7 @@ function installProjectDependencies(dependenciesFolder: FolderInfo, modulePath:
getLogger().error(
`CodeTransformation: Error in running Maven ${argString} command ${baseCommand} = ${errorLog}`
)
let errorReason = ''
if (spawnResult.stdout) {
errorReason = `Maven ${argString}: InstallationExecutionError`
/*
* adding this check here because these mvn commands sometimes generate a lot of output.
* rarely, a buffer overflow has resulted when these mvn commands are run with -X, -e flags
* which are not being used here (for now), but still keeping this just in case.
*/
if (Buffer.byteLength(spawnResult.stdout, 'utf-8') > CodeWhispererConstants.maxBufferSize) {
errorReason += '-BufferOverflow'
}
} else {
errorReason = `Maven ${argString}: InstallationSpawnError`
}
if (spawnResult.error) {
const errorCode = (spawnResult.error as any).code ?? 'UNKNOWN'
errorReason += `-${errorCode}`
}

// Explicitly set metric as failed since no exception was caught
telemetry.record({ result: MetadataResult.Fail, reason: errorReason })

telemetry.record({ result: MetadataResult.Fail, reason: (spawnResult.error as any).code })
throw new ToolkitError(`Maven ${argString} error`, { code: 'MavenExecutionError' })
} else {
transformByQState.appendToErrorLog(`${baseCommand} ${argString} succeeded`)
Expand All @@ -102,11 +81,12 @@ function copyProjectDependencies(dependenciesFolder: FolderInfo, modulePath: str
'-Dmdep.addParentPoms=true',
'-q',
]

let environment = process.env
// if JAVA_HOME not found or not matching project JDK, get user input for it and set here
if (transformByQState.getJavaHome() !== undefined) {
environment = { ...process.env, JAVA_HOME: transformByQState.getJavaHome() }
}

const spawnResult = spawnSync(baseCommand, args, {
cwd: modulePath,
shell: true,
Expand All @@ -119,30 +99,9 @@ function copyProjectDependencies(dependenciesFolder: FolderInfo, modulePath: str
errorLog += spawnResult.error ? JSON.stringify(spawnResult.error) : ''
errorLog += `${spawnResult.stderr}\n${spawnResult.stdout}`
transformByQState.appendToErrorLog(`${baseCommand} copy-dependencies failed: \n ${errorLog}`)
let errorReason = ''
if (spawnResult.stdout) {
errorReason = 'Maven Copy: CopyDependenciesExecutionError'
if (Buffer.byteLength(spawnResult.stdout, 'utf-8') > CodeWhispererConstants.maxBufferSize) {
errorReason += '-BufferOverflow'
}
} else {
errorReason = 'Maven Copy: CopyDependenciesSpawnError'
}
if (spawnResult.error) {
const errorCode = (spawnResult.error as any).code ?? 'UNKNOWN'
errorReason += `-${errorCode}`
}
getLogger().info(
`CodeTransformation: Maven copy-dependencies command ${baseCommand} failed, but still continuing with transformation: ${errorReason}, log: ${errorLog}`
`CodeTransformation: Maven copy-dependencies command ${baseCommand} failed, but still continuing with transformation: ${errorLog}`
)

let mavenBuildCommand = transformByQState.getMavenName()
// slashes not allowed in telemetry
if (mavenBuildCommand === './mvnw') {
mavenBuildCommand = 'mvnw'
} else if (mavenBuildCommand === '.\\mvnw.cmd') {
mavenBuildCommand = 'mvnw.cmd'
}
throw new Error('Maven copy-deps error')
} else {
transformByQState.appendToErrorLog(`${baseCommand} copy-dependencies succeeded`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe('transformByQ', function () {
const tempFileName = `testfile-${globals.clock.Date.now()}.zip`
transformByQState.setProjectPath(tempDir)
const transformManifest = new ZipManifest()
transformManifest.skipTestsFlag = '-DskipTests'
transformManifest.customBuildCommand = 'test-compile'
return zipCode({
dependenciesFolder: {
path: tempDir,
Expand All @@ -225,7 +225,7 @@ describe('transformByQ', function () {
const manifestBuffer = manifestEntry.getData()
const manifestText = manifestBuffer.toString('utf8')
const manifest = JSON.parse(manifestText)
assert.strictEqual(manifest.skipTestsFlag, '-DskipTests')
assert.strictEqual(manifest.customBuildCommand, 'test-compile')
})
})

Expand Down

0 comments on commit 0b5c066

Please sign in to comment.