55
66import * as vscode from 'vscode'
77import * as fs from 'fs' // eslint-disable-line no-restricted-imports
8- import * as os from 'os'
9- import * as xml2js from 'xml2js'
108import path from 'path'
119import { getLogger } from '../../shared/logger'
1210import * as CodeWhispererConstants from '../models/constants'
@@ -18,7 +16,6 @@ import {
1816 FolderInfo ,
1917 ZipManifest ,
2018 TransformByQStatus ,
21- DB ,
2219 TransformationType ,
2320 TransformationCandidateProject ,
2421} from '../models/model'
@@ -56,7 +53,6 @@ import { MetadataResult } from '../../shared/telemetry/telemetryClient'
5653import { submitFeedback } from '../../feedback/vue/submitFeedback'
5754import { placeholder } from '../../shared/vscode/commands2'
5855import {
59- AbsolutePathDetectedError ,
6056 AlternateDependencyVersionsNotFoundError ,
6157 JavaHomeNotSetError ,
6258 JobStartError ,
@@ -69,8 +65,8 @@ import {
6965 getCodeIssueSnippetFromPom ,
7066 getDependenciesFolderInfo ,
7167 getJsonValuesFromManifestFile ,
72- highlightPomIssueInProject ,
7368 parseVersionsListFromPomFile ,
69+ setMaven ,
7470 writeLogs ,
7571} from '../service/transformByQ/transformFileHandler'
7672import { sleep } from '../../shared/utilities/timeoutUtils'
@@ -81,7 +77,6 @@ import { setContext } from '../../shared/vscode/setContext'
8177import { makeTemporaryToolkitFolder } from '../../shared'
8278import globals from '../../shared/extensionGlobals'
8379import { convertDateToTimestamp } from '../../shared/datetime'
84- import { isWin } from '../../shared/vscode/env'
8580import { findStringInDirectory } from '../../shared/utilities/workspaceUtils'
8681
8782function getFeedbackCommentData ( ) {
@@ -111,63 +106,6 @@ export async function processSQLConversionTransformFormInput(pathToProject: stri
111106 // targetJDKVersion defaults to JDK17, the only supported version, which is fine
112107}
113108
114- export async function validateSQLMetadataFile ( fileContents : string , message : any ) {
115- try {
116- const sctData = await xml2js . parseStringPromise ( fileContents )
117- const dbEntities = sctData [ 'tree' ] [ 'instances' ] [ 0 ] [ 'ProjectModel' ] [ 0 ] [ 'entities' ] [ 0 ]
118- const sourceDB = dbEntities [ 'sources' ] [ 0 ] [ 'DbServer' ] [ 0 ] [ '$' ] [ 'vendor' ] . trim ( ) . toUpperCase ( )
119- const targetDB = dbEntities [ 'targets' ] [ 0 ] [ 'DbServer' ] [ 0 ] [ '$' ] [ 'vendor' ] . trim ( ) . toUpperCase ( )
120- const sourceServerName = dbEntities [ 'sources' ] [ 0 ] [ 'DbServer' ] [ 0 ] [ '$' ] [ 'name' ] . trim ( )
121- transformByQState . setSourceServerName ( sourceServerName )
122- if ( sourceDB !== DB . ORACLE ) {
123- transformByQState . getChatMessenger ( ) ?. sendUnrecoverableErrorResponse ( 'unsupported-source-db' , message . tabID )
124- return false
125- } else if ( targetDB !== DB . AURORA_POSTGRESQL && targetDB !== DB . RDS_POSTGRESQL ) {
126- transformByQState . getChatMessenger ( ) ?. sendUnrecoverableErrorResponse ( 'unsupported-target-db' , message . tabID )
127- return false
128- }
129- transformByQState . setSourceDB ( sourceDB )
130- transformByQState . setTargetDB ( targetDB )
131-
132- const serverNodeLocations =
133- sctData [ 'tree' ] [ 'instances' ] [ 0 ] [ 'ProjectModel' ] [ 0 ] [ 'relations' ] [ 0 ] [ 'server-node-location' ]
134- const schemaNames = new Set < string > ( )
135- serverNodeLocations . forEach ( ( serverNodeLocation : any ) => {
136- const schemaNodes = serverNodeLocation [ 'FullNameNodeInfoList' ] [ 0 ] [ 'nameParts' ] [ 0 ] [
137- 'FullNameNodeInfo'
138- ] . filter ( ( node : any ) => node [ '$' ] [ 'typeNode' ] . toLowerCase ( ) === 'schema' )
139- schemaNodes . forEach ( ( node : any ) => {
140- schemaNames . add ( node [ '$' ] [ 'nameNode' ] . toUpperCase ( ) )
141- } )
142- } )
143- transformByQState . setSchemaOptions ( schemaNames ) // user will choose one of these
144- getLogger ( ) . info (
145- `CodeTransformation: Parsed .sct file with source DB: ${ sourceDB } , target DB: ${ targetDB } , source host name: ${ sourceServerName } , and schema names: ${ Array . from ( schemaNames ) } `
146- )
147- } catch ( err : any ) {
148- getLogger ( ) . error ( 'CodeTransformation: Error parsing .sct file. %O' , err )
149- transformByQState . getChatMessenger ( ) ?. sendUnrecoverableErrorResponse ( 'error-parsing-sct-file' , message . tabID )
150- return false
151- }
152- return true
153- }
154-
155- export async function setMaven ( ) {
156- let mavenWrapperExecutableName = isWin ( ) ? 'mvnw.cmd' : 'mvnw'
157- const mavenWrapperExecutablePath = path . join ( transformByQState . getProjectPath ( ) , mavenWrapperExecutableName )
158- if ( fs . existsSync ( mavenWrapperExecutablePath ) ) {
159- if ( mavenWrapperExecutableName === 'mvnw' ) {
160- mavenWrapperExecutableName = './mvnw' // add the './' for non-Windows
161- } else if ( mavenWrapperExecutableName === 'mvnw.cmd' ) {
162- mavenWrapperExecutableName = '.\\mvnw.cmd' // add the '.\' for Windows
163- }
164- transformByQState . setMavenName ( mavenWrapperExecutableName )
165- } else {
166- transformByQState . setMavenName ( 'mvn' )
167- }
168- getLogger ( ) . info ( `CodeTransformation: using Maven ${ transformByQState . getMavenName ( ) } ` )
169- }
170-
171109async function validateJavaHome ( ) : Promise < boolean > {
172110 const versionData = await getVersionData ( )
173111 let javaVersionUsedByMaven = versionData [ 1 ]
@@ -290,41 +228,6 @@ export async function finalizeTransformByQ(status: string) {
290228 }
291229}
292230
293- export async function parseBuildFile ( ) {
294- try {
295- const absolutePaths = [ 'users/' , 'system/' , 'volumes/' , 'c:\\' , 'd:\\' ]
296- const alias = path . basename ( os . homedir ( ) )
297- absolutePaths . push ( alias )
298- const buildFilePath = path . join ( transformByQState . getProjectPath ( ) , 'pom.xml' )
299- if ( fs . existsSync ( buildFilePath ) ) {
300- const buildFileContents = fs . readFileSync ( buildFilePath ) . toString ( ) . toLowerCase ( )
301- const detectedPaths = [ ]
302- for ( const absolutePath of absolutePaths ) {
303- if ( buildFileContents . includes ( absolutePath ) ) {
304- detectedPaths . push ( absolutePath )
305- }
306- }
307- if ( detectedPaths . length > 0 ) {
308- const warningMessage = CodeWhispererConstants . absolutePathDetectedMessage (
309- detectedPaths . length ,
310- path . basename ( buildFilePath ) ,
311- detectedPaths . join ( ', ' )
312- )
313- transformByQState . getChatControllers ( ) ?. errorThrown . fire ( {
314- error : new AbsolutePathDetectedError ( warningMessage ) ,
315- tabID : ChatSessionManager . Instance . getSession ( ) . tabID ,
316- } )
317- getLogger ( ) . info ( 'CodeTransformation: absolute path potentially in build file' )
318- return warningMessage
319- }
320- }
321- } catch ( err : any ) {
322- // swallow error
323- getLogger ( ) . error ( `CodeTransformation: error scanning for absolute paths, tranformation continuing: ${ err } ` )
324- }
325- return undefined
326- }
327-
328231export async function preTransformationUploadCode ( ) {
329232 await vscode . commands . executeCommand ( 'aws.amazonq.transformationHub.focus' )
330233
@@ -488,21 +391,6 @@ export async function initiateHumanInTheLoopPrompt(jobId: string) {
488391 return false
489392}
490393
491- export async function openHilPomFile ( ) {
492- const humanInTheLoopManager = HumanInTheLoopManager . instance
493- await highlightPomIssueInProject (
494- humanInTheLoopManager . getNewPomFileVirtualFileReference ( ) ,
495- HumanInTheLoopManager . instance . diagnosticCollection ,
496- humanInTheLoopManager . getManifestFileValues ( ) . sourcePomVersion
497- )
498- }
499-
500- export async function openBuildLogFile ( ) {
501- const logFilePath = transformByQState . getPreBuildLogFilePath ( )
502- const doc = await vscode . workspace . openTextDocument ( logFilePath )
503- await vscode . window . showTextDocument ( doc )
504- }
505-
506394export async function terminateHILEarly ( jobID : string ) {
507395 // Call resume with "REJECTED" state which will put our service
508396 // back into the normal flow and will not trigger HIL again for this step
0 commit comments