44 */
55import * as vscode from 'vscode'
66import path from 'path'
7- import { tempDirPath , testGenerationLogsDir } from '../../shared/filesystemUtilities'
7+ import { tempDirPath } from '../../shared/filesystemUtilities'
88import { getLogger , getNullLogger } from '../../shared/logger/logger'
99import * as CodeWhispererConstants from '../models/constants'
1010import { fs } from '../../shared/fs/fs'
1111import { runtimeLanguageContext } from './runtimeLanguageContext'
1212import { CodewhispererLanguage } from '../../shared/telemetry/telemetry.gen'
13- import {
14- CurrentWsFolders ,
15- collectFiles ,
16- defaultExcludePatterns ,
17- getWorkspacePaths ,
18- } from '../../shared/utilities/workspaceUtils'
13+ import { CurrentWsFolders , collectFiles , getWorkspacePaths } from '../../shared/utilities/workspaceUtils'
1914import {
2015 FileSizeExceededError ,
2116 NoActiveFileError ,
2217 NoSourceFilesError ,
2318 ProjectSizeExceededError ,
2419} from '../models/errors'
25- import { ProjectZipError } from '../../amazonqTest/error'
2620import { normalize } from '../../shared/utilities/pathUtils'
2721import { ZipStream } from '../../shared/utilities/zipStream'
2822import { getTextContent } from '../../shared/utilities/textDocumentUtilities'
@@ -41,11 +35,6 @@ export interface ZipMetadata {
4135 language : CodewhispererLanguage | undefined
4236}
4337
44- export interface GenerateZipOptions {
45- includeGitDiff ?: boolean
46- silent ?: boolean
47- }
48-
4938export interface ZipProjectOptions {
5039 projectPath ?: string
5140 includeGitDiff ?: boolean
@@ -88,7 +77,7 @@ export class ZipUtil {
8877 return ZipUtil . aboveByteLimit ( current + adding , 'project' )
8978 }
9079
91- protected async zipFile ( uri : vscode . Uri | undefined , includeGitDiffHeader ?: boolean ) {
80+ public async zipFile ( uri : vscode . Uri | undefined , includeGitDiffHeader ?: boolean ) {
9281 if ( ! uri ) {
9382 throw new NoActiveFileError ( )
9483 }
@@ -121,9 +110,10 @@ export class ZipUtil {
121110 if ( ZipUtil . aboveByteLimit ( this . _totalSize , 'file' ) ) {
122111 throw new FileSizeExceededError ( )
123112 }
124- const zipFilePath = this . getZipDirPath ( ) + CodeWhispererConstants . codeScanZipExt
113+ const zipDirPath = this . getZipDirPath ( )
114+ const zipFilePath = zipDirPath + CodeWhispererConstants . codeScanZipExt
125115 await zip . finalizeToFile ( zipFilePath )
126- return zipFilePath
116+ return this . getGenerateZipResult ( zipDirPath , zipFilePath )
127117 }
128118
129119 protected getZipEntryPath ( projectName : string , relativePath : string ) {
@@ -188,7 +178,7 @@ export class ZipUtil {
188178 await processDirectory ( metadataDir )
189179 }
190180
191- protected async zipProject (
181+ public async zipProject (
192182 workspaceFolders : CurrentWsFolders ,
193183 excludePatterns : string [ ] ,
194184 options ?: ZipProjectOptions
@@ -263,27 +253,6 @@ export class ZipUtil {
263253 }
264254 }
265255
266- protected async processTestCoverageFiles ( targetPath : string ) {
267- // TODO: will be removed post release
268- const coverageFilePatterns = [ '**/coverage.xml' , '**/coverage.json' , '**/coverage.txt' ]
269- let files : vscode . Uri [ ] = [ ]
270-
271- for ( const pattern of coverageFilePatterns ) {
272- files = await vscode . workspace . findFiles ( pattern )
273- if ( files . length > 0 ) {
274- break
275- }
276- }
277-
278- await Promise . all (
279- files . map ( async ( file ) => {
280- const fileName = path . basename ( file . path )
281- const targetFilePath = path . join ( targetPath , fileName )
282- await fs . copy ( file . path , targetFilePath )
283- } )
284- )
285- }
286-
287256 protected processTextFile (
288257 zip : ZipStream ,
289258 uri : vscode . Uri ,
@@ -337,82 +306,6 @@ export class ZipUtil {
337306 return this . _zipDir
338307 }
339308
340- public async generateZipCodeScanForFile (
341- uri : vscode . Uri | undefined ,
342- options ?: GenerateZipOptions
343- ) : Promise < ZipMetadata > {
344- try {
345- const zipDirPath = this . getZipDirPath ( )
346- const zipFilePath = await this . zipFile ( uri , options ?. includeGitDiff )
347-
348- return this . getGenerateZipResult ( zipDirPath , zipFilePath , options ?. silent )
349- } catch ( error ) {
350- getLogger ( ) . error ( 'Zip error caused by: %O' , error )
351- throw error
352- }
353- }
354-
355- public async generateZipCodeScanForProject ( options ?: GenerateZipOptions ) : Promise < ZipMetadata > {
356- try {
357- // We assume there is at least one workspace open.
358- const workspaceFolders = [ ...( vscode . workspace . workspaceFolders ?? [ ] ) ] as CurrentWsFolders
359-
360- return await this . zipProject ( workspaceFolders , defaultExcludePatterns , {
361- includeGitDiff : options ?. includeGitDiff ,
362- includeNonWorkspaceFiles : true ,
363- silent : options ?. silent ,
364- } )
365- } catch ( error ) {
366- getLogger ( ) . error ( 'Zip error caused by: %O' , error )
367- throw error
368- }
369- }
370-
371- public async generateZipTestGen ( projectPath : string , initialExecution : boolean ) : Promise < ZipMetadata > {
372- try {
373- const zipDirPath = this . getZipDirPath ( )
374-
375- const metadataDir = path . join ( zipDirPath , 'utgRequiredArtifactsDir' )
376-
377- // Create directories
378- const dirs = {
379- metadata : metadataDir ,
380- buildAndExecuteLogDir : path . join ( metadataDir , 'buildAndExecuteLogDir' ) ,
381- repoMapDir : path . join ( metadataDir , 'repoMapData' ) ,
382- testCoverageDir : path . join ( metadataDir , 'testCoverageDir' ) ,
383- }
384- await Promise . all ( Object . values ( dirs ) . map ( ( dir ) => fs . mkdir ( dir ) ) )
385-
386- if ( ! initialExecution ) {
387- await this . processTestCoverageFiles ( dirs . testCoverageDir )
388-
389- const sourcePath = path . join ( testGenerationLogsDir , 'output.log' )
390- const targetPath = path . join ( dirs . buildAndExecuteLogDir , 'output.log' )
391- if ( await fs . exists ( sourcePath ) ) {
392- await fs . copy ( sourcePath , targetPath )
393- }
394- }
395- // We assume there is at least one workspace open.
396- const workspaceFolders = [ ...( vscode . workspace . workspaceFolders ?? [ ] ) ] . sort (
397- ( a , b ) => b . uri . fsPath . length - a . uri . fsPath . length
398- ) as CurrentWsFolders
399- return await this . zipProject (
400- workspaceFolders ,
401- [ ...CodeWhispererConstants . testGenExcludePatterns , ...defaultExcludePatterns ] ,
402- {
403- metadataDir,
404- projectPath,
405- silent : true ,
406- }
407- )
408- } catch ( error ) {
409- getLogger ( ) . error ( 'Zip error caused by: %s' , error )
410- throw new ProjectZipError (
411- error instanceof Error ? error . message : 'Unknown error occurred during zip operation'
412- )
413- }
414- }
415-
416309 protected async getGenerateZipResult (
417310 zipDirpath : string ,
418311 zipFilePath : string ,
0 commit comments