@@ -41,8 +41,8 @@ import { MetadataResult } from '../../../shared/telemetry/telemetryClient'
4141import request from '../../../shared/request'
4242import { JobStoppedError , ZipExceedsSizeLimitError } from '../../../amazonqGumby/errors'
4343import {
44- copyDirectory ,
4544 createLocalBuildUploadZip ,
45+ extractOriginalProjectSources ,
4646 loadManifestFile ,
4747 writeAndShowBuildLogs ,
4848} from './transformFileHandler'
@@ -253,7 +253,8 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl
253253 */
254254const mavenExcludedExtensions = [ '.repositories' , '.sha1' ]
255255
256- const sourceExcludedExtensions = [ '.DS_Store' ]
256+ // exclude .DS_Store (not relevant) and Maven executables (can cause permissions issues when building if user has not ran 'chmod')
257+ const sourceExcludedExtensions = [ '.DS_Store' , 'mvnw' , 'mvnw.cmd' ]
257258
258259/**
259260 * Determines if the specified file path corresponds to a Maven metadata file
@@ -726,8 +727,14 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
726727
727728async function attemptLocalBuild ( ) {
728729 const jobId = transformByQState . getJobId ( )
729- const artifactId = await getClientInstructionArtifactId ( jobId )
730- getLogger ( ) . info ( `CodeTransformation: found artifactId = ${ artifactId } ` )
730+ let artifactId
731+ try {
732+ artifactId = await getClientInstructionArtifactId ( jobId )
733+ getLogger ( ) . info ( `CodeTransformation: found artifactId = ${ artifactId } ` )
734+ } catch ( e : any ) {
735+ // don't throw error so that we can try to get progress updates again in next polling cycle
736+ getLogger ( ) . error ( `CodeTransformation: failed to get client instruction artifact ID = %O` , e )
737+ }
731738 if ( artifactId ) {
732739 const clientInstructionsPath = await downloadClientInstructions ( jobId , artifactId )
733740 getLogger ( ) . info (
@@ -750,7 +757,7 @@ async function getClientInstructionArtifactId(jobId: string) {
750757
751758async function downloadClientInstructions ( jobId : string , artifactId : string ) {
752759 const exportDestination = `downloadClientInstructions_${ jobId } _${ artifactId } `
753- const exportZipPath = path . join ( os . tmpdir ( ) , ` ${ exportDestination } .zip` )
760+ const exportZipPath = path . join ( os . tmpdir ( ) , exportDestination )
754761
755762 const exportContext : ExportContext = {
756763 transformationExportContext : {
@@ -766,34 +773,30 @@ async function downloadClientInstructions(jobId: string, artifactId: string) {
766773}
767774
768775async function processClientInstructions ( jobId : string , clientInstructionsPath : any , artifactId : string ) {
769- const sourcePath = transformByQState . getProjectPath ( )
770- const destinationPath = path . join ( os . tmpdir ( ) , jobId , artifactId , 'originalCopy' )
771- await copyDirectory ( sourcePath , destinationPath )
776+ const destinationPath = path . join ( os . tmpdir ( ) , `originalCopy_${ jobId } _${ artifactId } ` )
777+ await extractOriginalProjectSources ( destinationPath )
772778 getLogger ( ) . info ( `CodeTransformation: copied project to ${ destinationPath } ` )
773779 const diffModel = new DiffModel ( )
774- diffModel . parseDiff ( clientInstructionsPath , destinationPath , undefined , 1 , true )
780+ diffModel . parseDiff ( clientInstructionsPath , path . join ( destinationPath , 'sources' ) , undefined , 1 , true )
775781 // show user the diff.patch
776782 const doc = await vscode . workspace . openTextDocument ( clientInstructionsPath )
777783 await vscode . window . showTextDocument ( doc , { viewColumn : vscode . ViewColumn . One } )
778784 await runClientSideBuild ( transformByQState . getProjectCopyFilePath ( ) , artifactId )
779785}
780786
781- export async function runClientSideBuild ( projectPath : string , clientInstructionArtifactId : string ) {
782- // baseCommand will be one of: '.\mvnw.cmd', './mvnw', 'mvn'
787+ export async function runClientSideBuild ( projectCopyPath : string , clientInstructionArtifactId : string ) {
783788 const baseCommand = transformByQState . getMavenName ( )
784- const args = [ 'clean' ]
789+ const args = [ ]
785790 if ( transformByQState . getCustomBuildCommand ( ) === CodeWhispererConstants . skipUnitTestsBuildCommand ) {
786791 args . push ( 'test-compile' )
787792 } else {
788793 args . push ( 'test' )
789794 }
790- // TO-DO / QUESTION: why not use the build command from the downloaded manifest?
791- transformByQState . appendToBuildLog ( `Running ${ baseCommand } ${ args } ` )
792795 const environment = { ...process . env , JAVA_HOME : transformByQState . getTargetJavaHome ( ) }
793796
794797 const argString = args . join ( ' ' )
795798 const spawnResult = spawnSync ( baseCommand , args , {
796- cwd : projectPath ,
799+ cwd : projectCopyPath ,
797800 shell : true ,
798801 encoding : 'utf-8' ,
799802 env : environment ,
@@ -804,11 +807,11 @@ export async function runClientSideBuild(projectPath: string, clientInstructionA
804807 transformByQState . appendToBuildLog ( buildLogs )
805808 await writeAndShowBuildLogs ( )
806809
807- const baseDir = path . join (
810+ const uploadZipBaseDir = path . join (
808811 os . tmpdir ( ) ,
809812 `clientInstructionsResult_${ transformByQState . getJobId ( ) } _${ clientInstructionArtifactId } `
810813 )
811- const zipPath = await createLocalBuildUploadZip ( baseDir , spawnResult . status , spawnResult . stdout )
814+ const uploadZipPath = await createLocalBuildUploadZip ( uploadZipBaseDir , spawnResult . status , spawnResult . stdout )
812815
813816 // upload build results
814817 const uploadContext : UploadContext = {
@@ -817,14 +820,16 @@ export async function runClientSideBuild(projectPath: string, clientInstructionA
817820 uploadArtifactType : 'ClientBuildResult' ,
818821 } ,
819822 }
820- getLogger ( ) . info ( `CodeTransformation: uploading client build results at ${ zipPath } and resuming job now` )
821- await uploadPayload ( zipPath , uploadContext )
823+ getLogger ( ) . info ( `CodeTransformation: uploading client build results at ${ uploadZipPath } and resuming job now` )
824+ await uploadPayload ( uploadZipPath , uploadContext )
822825 await resumeTransformationJob ( transformByQState . getJobId ( ) , 'COMPLETED' )
823826 try {
824- await fs . delete ( transformByQState . getProjectCopyFilePath ( ) , { recursive : true } )
827+ await fs . delete ( projectCopyPath , { recursive : true } )
828+ await fs . delete ( uploadZipBaseDir , { recursive : true } )
829+ // TODO: do we need to delete the downloaded client instructions and uploadZipPath? they can help in debugging
825830 } catch {
826831 getLogger ( ) . error (
827- `CodeTransformation: failed to delete project copy at ${ transformByQState . getProjectCopyFilePath ( ) } after client-side build`
832+ `CodeTransformation: failed to delete project copy and uploadZipBaseDir after client-side build`
828833 )
829834 }
830835}
0 commit comments