@@ -25,15 +25,13 @@ import {
25
25
processSQLConversionTransformFormInput ,
26
26
startTransformByQ ,
27
27
stopTransformByQ ,
28
- validateCanCompileProject ,
29
28
getValidSQLConversionCandidateProjects ,
30
29
openHilPomFile ,
31
30
} from '../../../codewhisperer/commands/startTransformByQ'
32
31
import { JDKVersion , TransformationCandidateProject , transformByQState } from '../../../codewhisperer/models/model'
33
32
import {
34
33
AbsolutePathDetectedError ,
35
34
AlternateDependencyVersionsNotFoundError ,
36
- JavaHomeNotSetError ,
37
35
JobStartError ,
38
36
ModuleUploadError ,
39
37
NoJavaProjectsFoundError ,
@@ -59,8 +57,10 @@ import {
59
57
openBuildLogFile ,
60
58
parseBuildFile ,
61
59
validateSQLMetadataFile ,
60
+ validateCustomVersionsFile ,
62
61
} from '../../../codewhisperer/service/transformByQ/transformFileHandler'
63
62
import { getAuthType } from '../../../auth/utils'
63
+ import fs from '../../../shared/fs/fs'
64
64
65
65
// These events can be interactions within the chat,
66
66
// or elsewhere in the IDE
@@ -243,7 +243,7 @@ export class GumbyController {
243
243
CodeTransformTelemetryState . instance . setSessionId ( )
244
244
245
245
this . sessionStorage . getSession ( ) . conversationState = ConversationState . WAITING_FOR_TRANSFORMATION_OBJECTIVE
246
- this . messenger . sendStaticTextResponse ( 'choose-transformation-objective' , message . tabID )
246
+ this . messenger . sendMessage ( CodeWhispererConstants . chooseTransformationObjective , message . tabID , 'ai-prompt' )
247
247
this . messenger . sendChatInputEnabled ( message . tabID , true )
248
248
this . messenger . sendUpdatePlaceholder (
249
249
message . tabID ,
@@ -299,7 +299,7 @@ export class GumbyController {
299
299
const validProjects = await this . validateSQLConversionProjects ( message )
300
300
if ( validProjects . length > 0 ) {
301
301
this . sessionStorage . getSession ( ) . updateCandidateProjects ( validProjects )
302
- await this . messenger . sendSelectSQLMetadataFileMessage ( message . tabID )
302
+ this . messenger . sendSelectSQLMetadataFileMessage ( message . tabID )
303
303
}
304
304
} )
305
305
. catch ( ( err ) => {
@@ -383,6 +383,18 @@ export class GumbyController {
383
383
case ButtonActions . SELECT_SQL_CONVERSION_METADATA_FILE :
384
384
await this . processMetadataFile ( message )
385
385
break
386
+ case ButtonActions . SELECT_CUSTOM_DEPENDENCY_VERSION_FILE :
387
+ await this . processCustomDependencyVersionFile ( message )
388
+ break
389
+ case ButtonActions . CONTINUE_TRANSFORMATION_FORM :
390
+ this . messenger . sendMessage (
391
+ CodeWhispererConstants . continueWithoutYamlMessage ,
392
+ message . tabID ,
393
+ 'ai-prompt'
394
+ )
395
+ transformByQState . setCustomDependencyVersionFilePath ( '' )
396
+ this . promptJavaHome ( 'source' , message . tabID )
397
+ break
386
398
case ButtonActions . VIEW_TRANSFORMATION_HUB :
387
399
await vscode . commands . executeCommand ( GumbyCommands . FOCUS_TRANSFORMATION_HUB , CancelActionPositions . Chat )
388
400
break
@@ -403,7 +415,7 @@ export class GumbyController {
403
415
await this . continueJobWithSelectedDependency ( message )
404
416
break
405
417
case ButtonActions . CANCEL_DEPENDENCY_FORM :
406
- this . messenger . sendUserPrompt ( 'Cancel' , message . tabID )
418
+ this . messenger . sendMessage ( 'Cancel' , message . tabID , 'prompt' )
407
419
await this . continueTransformationWithoutHIL ( message )
408
420
break
409
421
case ButtonActions . OPEN_FILE :
@@ -448,11 +460,27 @@ export class GumbyController {
448
460
} )
449
461
450
462
this . messenger . sendOneOrMultipleDiffsMessage ( oneOrMultipleDiffsSelection , message . tabID )
451
- // perform local build
452
- await this . validateBuildWithPromptOnError ( message )
463
+ this . promptJavaHome ( 'source' , message . tabID )
464
+ // TO-DO: delete line above and uncomment line below when releasing CSB
465
+ // await this.messenger.sendCustomDependencyVersionMessage(message.tabID)
453
466
} )
454
467
}
455
468
469
+ private promptJavaHome ( type : 'source' | 'target' , tabID : any ) {
470
+ let jdkVersion = undefined
471
+ if ( type === 'source' ) {
472
+ this . sessionStorage . getSession ( ) . conversationState = ConversationState . PROMPT_SOURCE_JAVA_HOME
473
+ jdkVersion = transformByQState . getSourceJDKVersion ( )
474
+ } else if ( type === 'target' ) {
475
+ this . sessionStorage . getSession ( ) . conversationState = ConversationState . PROMPT_TARGET_JAVA_HOME
476
+ jdkVersion = transformByQState . getTargetJDKVersion ( )
477
+ }
478
+ const message = MessengerUtils . createJavaHomePrompt ( jdkVersion )
479
+ this . messenger . sendMessage ( message , tabID , 'ai-prompt' )
480
+ this . messenger . sendChatInputEnabled ( tabID , true )
481
+ this . messenger . sendUpdatePlaceholder ( tabID , CodeWhispererConstants . enterJavaHomePlaceholder )
482
+ }
483
+
456
484
private async handleUserLanguageUpgradeProjectChoice ( message : any ) {
457
485
await telemetry . codeTransform_submitSelection . run ( async ( ) => {
458
486
const pathToProject : string = message . formSelectedValues [ 'GumbyTransformLanguageUpgradeProjectForm' ]
@@ -521,66 +549,59 @@ export class GumbyController {
521
549
} )
522
550
}
523
551
524
- private async prepareLanguageUpgradeProject ( message : { pathToJavaHome : string ; tabID : string } ) {
525
- if ( message . pathToJavaHome ) {
526
- transformByQState . setJavaHome ( message . pathToJavaHome )
527
- getLogger ( ) . info (
528
- `CodeTransformation: using JAVA_HOME = ${ transformByQState . getJavaHome ( ) } since source JDK does not match Maven JDK`
529
- )
530
- }
531
-
532
- // Pre-build project locally
552
+ private async prepareLanguageUpgradeProject ( tabID : string ) {
553
+ // build project locally
533
554
try {
534
555
this . sessionStorage . getSession ( ) . conversationState = ConversationState . COMPILING
535
- this . messenger . sendCompilationInProgress ( message . tabID )
556
+ this . messenger . sendCompilationInProgress ( tabID )
536
557
await compileProject ( )
537
558
} catch ( err : any ) {
538
- this . messenger . sendUnrecoverableErrorResponse ( 'could-not-compile-project' , message . tabID )
559
+ this . messenger . sendUnrecoverableErrorResponse ( 'could-not-compile-project' , tabID )
539
560
// reset state to allow "Start a new transformation" button to work
540
561
this . sessionStorage . getSession ( ) . conversationState = ConversationState . IDLE
541
562
throw err
542
563
}
543
564
544
- this . messenger . sendCompilationFinished ( message . tabID )
565
+ this . messenger . sendCompilationFinished ( tabID )
545
566
546
567
// since compilation can potentially take a long time, double check auth
547
568
const authState = await AuthUtil . instance . getChatAuthState ( )
548
569
if ( authState . amazonQ !== 'connected' ) {
549
- void this . messenger . sendAuthNeededExceptionMessage ( authState , message . tabID )
570
+ void this . messenger . sendAuthNeededExceptionMessage ( authState , tabID )
550
571
this . sessionStorage . getSession ( ) . isAuthenticating = true
551
572
return
552
573
}
553
574
554
575
// give user a non-blocking warning if build file appears to contain absolute paths
555
576
await parseBuildFile ( )
556
577
557
- this . messenger . sendAsyncEventProgress (
558
- message . tabID ,
559
- true ,
560
- undefined ,
561
- GumbyNamedMessages . JOB_SUBMISSION_STATUS_MESSAGE
562
- )
563
- this . messenger . sendJobSubmittedMessage ( message . tabID )
578
+ this . messenger . sendAsyncEventProgress ( tabID , true , undefined , GumbyNamedMessages . JOB_SUBMISSION_STATUS_MESSAGE )
579
+ this . messenger . sendJobSubmittedMessage ( tabID )
564
580
this . sessionStorage . getSession ( ) . conversationState = ConversationState . JOB_SUBMITTED
565
581
await startTransformByQ ( )
566
582
}
567
583
568
- // only for Language Upgrades
569
- private async validateBuildWithPromptOnError ( message : any | undefined = undefined ) : Promise < void > {
570
- try {
571
- // Check Java Home is set (not yet prebuilding)
572
- await validateCanCompileProject ( )
573
- } catch ( err : any ) {
574
- if ( err instanceof JavaHomeNotSetError ) {
575
- this . sessionStorage . getSession ( ) . conversationState = ConversationState . PROMPT_JAVA_HOME
576
- this . messenger . sendStaticTextResponse ( 'java-home-not-set' , message . tabID )
577
- this . messenger . sendChatInputEnabled ( message . tabID , true )
578
- this . messenger . sendUpdatePlaceholder ( message . tabID , 'Enter the path to your Java installation.' )
579
- }
584
+ private async processCustomDependencyVersionFile ( message : any ) {
585
+ const fileUri = await vscode . window . showOpenDialog ( {
586
+ canSelectMany : false ,
587
+ openLabel : 'Select' ,
588
+ filters : {
589
+ 'YAML file' : [ 'yaml' ] , // restrict user to only pick a .yaml file
590
+ } ,
591
+ } )
592
+ if ( ! fileUri || fileUri . length === 0 ) {
580
593
return
581
594
}
595
+ const fileContents = await fs . readFileText ( fileUri [ 0 ] . fsPath )
596
+ const isValidFile = await validateCustomVersionsFile ( fileContents )
582
597
583
- await this . prepareLanguageUpgradeProject ( message )
598
+ if ( ! isValidFile ) {
599
+ this . messenger . sendUnrecoverableErrorResponse ( 'invalid-custom-versions-file' , message . tabID )
600
+ return
601
+ }
602
+ this . messenger . sendMessage ( 'Received custom dependency version YAML file.' , message . tabID , 'ai-prompt' )
603
+ transformByQState . setCustomDependencyVersionFilePath ( fileUri [ 0 ] . fsPath )
604
+ this . promptJavaHome ( 'source' , message . tabID )
584
605
}
585
606
586
607
private async processMetadataFile ( message : any ) {
@@ -657,19 +678,34 @@ export class GumbyController {
657
678
}
658
679
659
680
private async processHumanChatMessage ( data : { message : string ; tabID : string } ) {
660
- this . messenger . sendUserPrompt ( data . message , data . tabID )
681
+ this . messenger . sendMessage ( data . message , data . tabID , 'prompt' )
661
682
this . messenger . sendChatInputEnabled ( data . tabID , false )
662
- this . messenger . sendUpdatePlaceholder ( data . tabID , 'Open a new tab to chat with Q' )
683
+ this . messenger . sendUpdatePlaceholder ( data . tabID , CodeWhispererConstants . openNewTabPlaceholder )
663
684
664
685
const session = this . sessionStorage . getSession ( )
665
686
switch ( session . conversationState ) {
666
- case ConversationState . PROMPT_JAVA_HOME : {
687
+ case ConversationState . PROMPT_SOURCE_JAVA_HOME : {
667
688
const pathToJavaHome = extractPath ( data . message )
668
689
if ( pathToJavaHome ) {
669
- await this . prepareLanguageUpgradeProject ( {
670
- pathToJavaHome,
671
- tabID : data . tabID ,
672
- } )
690
+ transformByQState . setSourceJavaHome ( pathToJavaHome )
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
+ }
698
+ } else {
699
+ this . messenger . sendUnrecoverableErrorResponse ( 'invalid-java-home' , data . tabID )
700
+ }
701
+ break
702
+ }
703
+
704
+ case ConversationState . PROMPT_TARGET_JAVA_HOME : {
705
+ const pathToJavaHome = extractPath ( data . message )
706
+ if ( pathToJavaHome ) {
707
+ transformByQState . setTargetJavaHome ( pathToJavaHome )
708
+ await this . prepareLanguageUpgradeProject ( data . tabID ) // build right after we get target JDK path
673
709
} else {
674
710
this . messenger . sendUnrecoverableErrorResponse ( 'invalid-java-home' , data . tabID )
675
711
}
@@ -747,7 +783,7 @@ export class GumbyController {
747
783
} )
748
784
}
749
785
750
- this . messenger . sendStaticTextResponse ( 'end-HIL-early' , message . tabID )
786
+ this . messenger . sendMessage ( CodeWhispererConstants . continueWithoutHilMessage , message . tabID , 'ai-prompt' )
751
787
}
752
788
}
753
789
0 commit comments