@@ -13,20 +13,19 @@ import {
1313 SingleTokenUpdate ,
1414 TokenUpdater ,
1515} from '../../utils/apex/parser/apexparser' ;
16- import { sfProject } from '../../utils/sfcli/project/sfProject' ;
1716import { FileUtil , File } from '../../utils/file/fileUtil' ;
1817import { Logger } from '../../utils/logger' ;
1918import { ApexAssessmentInfo } from '../../utils' ;
2019import { FileDiffUtil } from '../../utils/lwcparser/fileutils/FileDiffUtil' ;
2120import { Stringutil } from '../../utils/StringValue/stringutil' ;
2221import { Constants } from '../../utils/constants/stringContants' ;
22+ import { ComponentType , createProgressBar } from '../base' ;
2323import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration' ;
2424
2525Messages . importMessagesDirectory ( __dirname ) ;
2626const assessMessages = Messages . loadMessages ( '@salesforce/plugin-omnistudio-migration-tool' , 'assess' ) ;
2727const migrateMessages = Messages . loadMessages ( '@salesforce/plugin-omnistudio-migration-tool' , 'migrate' ) ;
2828
29- const APEXCLASS = 'Apexclass' ;
3029const APEX_CLASS_PATH = '/force-app/main/default/classes' ;
3130const CALLABLE = 'System.Callable' ;
3231const VLOCITY_OPEN_INTERFACE2 = 'VlocityOpenInterface2' ;
@@ -57,15 +56,12 @@ export class ApexMigration extends BaseRelatedObjectMigration {
5756 Logger . logVerbose ( migrateMessages . getMessage ( 'startingApexMigration' , [ this . projectPath ] ) ) ;
5857 const pwd = shell . pwd ( ) ;
5958 shell . cd ( this . projectPath ) ;
60- // const targetOrg: Org = this.org;
61- // sfProject.retrieve(APEXCLASS, targetOrg.getUsername());
6259 Logger . info ( migrateMessages . getMessage ( 'processingApexFilesForMigration' ) ) ;
6360 const apexAssessmentInfos = this . processApexFiles ( this . projectPath , 'migration' ) ;
6461 Logger . info ( migrateMessages . getMessage ( 'successfullyProcessedApexFilesForMigration' , [ apexAssessmentInfos . length ] ) ) ;
6562 Logger . logVerbose (
6663 migrateMessages . getMessage ( 'apexMigrationResults' , [ JSON . stringify ( apexAssessmentInfos , null , 2 ) ] )
6764 ) ;
68- // sfProject.deploy(APEXCLASS, targetOrg.getUsername());
6965 shell . cd ( pwd ) ;
7066 return apexAssessmentInfos ;
7167 }
@@ -74,7 +70,6 @@ export class ApexMigration extends BaseRelatedObjectMigration {
7470 Logger . logVerbose ( assessMessages . getMessage ( 'startingApexAssessment' , [ this . projectPath ] ) ) ;
7571 const pwd = shell . pwd ( ) ;
7672 shell . cd ( this . projectPath ) ;
77- sfProject . retrieve ( APEXCLASS , this . org . getUsername ( ) ) ;
7873 Logger . info ( assessMessages . getMessage ( 'processingApexFilesForAssessment' ) ) ;
7974 const apexAssessmentInfos = this . processApexFiles ( this . projectPath , 'assessment' ) ;
8075 Logger . info ( assessMessages . getMessage ( 'successfullyProcessedApexFilesForAssessment' , [ apexAssessmentInfos . length ] ) ) ;
@@ -89,25 +84,40 @@ export class ApexMigration extends BaseRelatedObjectMigration {
8984 let files : File [ ] = [ ] ;
9085 files = FileUtil . readFilesSync ( dir ) ;
9186 Logger . logVerbose ( assessMessages . getMessage ( 'foundApexFilesInDirectory' , [ files . length , dir ] ) ) ;
87+ const progressBar =
88+ type . toLowerCase ( ) === 'migration'
89+ ? createProgressBar ( 'Migrating' , Constants . ApexComponentName as ComponentType )
90+ : createProgressBar ( 'Assessing' , Constants . ApexComponentName as ComponentType ) ;
91+ let progressCounter = 0 ;
92+ // Only show progress bar if verbose mode is disabled
93+ progressBar . start ( files . length , progressCounter ) ;
9294 const fileAssessmentInfo : ApexAssessmentInfo [ ] = [ ] ;
95+ const processingErrorsList : string [ ] = [ ] ;
9396 for ( const file of files ) {
9497 if ( file . ext !== '.cls' ) {
9598 Logger . logVerbose ( assessMessages . getMessage ( 'skippingNonApexFile' , [ file . name ] ) ) ;
99+ progressBar . update ( ++ progressCounter ) ;
96100 continue ;
97101 }
98102 try {
99103 Logger . logVerbose ( assessMessages . getMessage ( 'processingApexFile' , [ file . name ] ) ) ;
100104 const apexAssementInfo = this . processApexFile ( file , type ) ;
101105 if ( apexAssementInfo && apexAssementInfo . diff . length < 3 ) {
102- Logger . logVerbose ( assessMessages . getMessage ( 'skippingApexFileFewChanges' , [ file . name ] ) ) ;
106+ Logger . logVerbose ( assessMessages . getMessage ( 'skippingApexFileNoChanges' , [ file . name ] ) ) ;
107+ progressBar . update ( ++ progressCounter ) ;
103108 continue ;
104109 }
105110 fileAssessmentInfo . push ( apexAssementInfo ) ;
106111 Logger . logVerbose ( assessMessages . getMessage ( 'successfullyProcessedApexFile' , [ file . name ] ) ) ;
112+ progressBar . update ( ++ progressCounter ) ;
107113 } catch ( err ) {
108- Logger . error ( assessMessages . getMessage ( 'errorProcessingApexFile' , [ file . name ] ) , err ) ;
114+ processingErrorsList . push ( assessMessages . getMessage ( 'errorProcessingApexFile' , [ file . name ] ) ) ;
115+ progressBar . update ( ++ progressCounter ) ;
109116 }
110- Logger . logVerbose ( assessMessages . getMessage ( 'successfullyProcessedApexFile' , [ file . name ] ) ) ;
117+ }
118+ progressBar . stop ( ) ;
119+ if ( processingErrorsList . length > 0 ) {
120+ Logger . error ( processingErrorsList . join ( '\n' ) ) ;
111121 }
112122 return fileAssessmentInfo ;
113123 }
@@ -191,7 +201,10 @@ export class ApexMigration extends BaseRelatedObjectMigration {
191201 tokenUpdates . push ( new RangeTokenUpdate ( CALLABLE , tokens [ 0 ] , tokens [ 1 ] ) ) ;
192202 tokenUpdates . push ( new InsertAfterTokenUpdate ( this . callMethodBody ( ) , parser . classDeclaration ) ) ;
193203 } else if ( implementsInterface . has ( this . vlocityOpenInterface ) ) {
194- Logger . error ( assessMessages . getMessage ( 'fileImplementsVlocityOpenInterface' , [ file . name ] ) ) ;
204+ Logger . logger . info ( assessMessages . getMessage ( 'fileImplementsVlocityOpenInterface' , [ file . name ] ) ) ;
205+ const tokens = implementsInterface . get ( this . vlocityOpenInterface ) ;
206+ tokenUpdates . push ( new RangeTokenUpdate ( CALLABLE , tokens [ 0 ] , tokens [ 1 ] ) ) ;
207+ tokenUpdates . push ( new InsertAfterTokenUpdate ( this . callMethodBody ( ) , parser . classDeclaration ) ) ;
195208 }
196209 return tokenUpdates ;
197210 }
@@ -260,7 +273,6 @@ export class ApexMigration extends BaseRelatedObjectMigration {
260273 const newName = `'${ Stringutil . cleanName ( token . text ) } '` ;
261274 if ( token . text === newName ) continue ;
262275 Logger . info ( assessMessages . getMessage ( 'inApexDrNameWillBeUpdated' , [ file . name , token . text , newName ] ) ) ;
263- Logger . log ( assessMessages . getMessage ( 'inApexDrNameWillBeUpdated' , [ file . name , token . text , newName ] ) ) ;
264276 tokenUpdates . push ( new SingleTokenUpdate ( newName , token ) ) ;
265277 }
266278 }
0 commit comments