Skip to content

Commit 444a05e

Browse files
author
David Hasani
committed
start work to detect embedded sql
1 parent 72aac52 commit 444a05e

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { getVersionData } from '../../../codewhisperer/service/transformByQ/tran
6363
import AdmZip from 'adm-zip'
6464
import { AuthError } from '../../../auth/sso/server'
6565
import { isSQLTransformReady } from '../../../dev/config'
66+
import { spawnSync } from 'child_process'
6667

6768
// These events can be interactions within the chat,
6869
// or elsewhere in the IDE
@@ -189,10 +190,35 @@ export class GumbyController {
189190
this.messenger.sendCommandMessage(data)
190191
}
191192

193+
// silently check if user has open Java projects using embedded SQL
194+
private async anyProjectContainsEmbeddedOracleSQL() {
195+
try {
196+
// gets just open Java projects
197+
const projects = await getValidSQLConversionCandidateProjects()
198+
for (const project of projects) {
199+
// case-insensitive, recursive search, display only count of matching lines
200+
const args = ['-i', '-r', '-c', 'oracle.jdbc.OracleDriver']
201+
// TO-DO: handle Windows
202+
const spawnResult = spawnSync('grep', args, {
203+
cwd: project.path,
204+
shell: true,
205+
encoding: 'utf-8',
206+
})
207+
if (spawnResult.status !== 0) {
208+
return false
209+
}
210+
// TO-DO: parse stdout for the count of matching lines
211+
}
212+
} catch (err) {
213+
return false
214+
}
215+
return true
216+
}
217+
192218
private async transformInitiated(message: any) {
193219
// feature flag for SQL transformations
194-
if (!isSQLTransformReady) {
195-
// TODO: if (!projectContainsEmbeddedSQLUsingOracle)
220+
const containsOracleSQL = await this.anyProjectContainsEmbeddedOracleSQL()
221+
if (!isSQLTransformReady && !containsOracleSQL) {
196222
await this.handleLanguageUpgrade(message)
197223
return
198224
}

0 commit comments

Comments
 (0)