Skip to content

Commit 6dfcbaa

Browse files
author
David Hasani
committed
only show users oracle sql projects
1 parent 3d9f274 commit 6dfcbaa

File tree

6 files changed

+47
-45
lines changed

6 files changed

+47
-45
lines changed

packages/core/src/amazonq/webview/ui/tabs/constants.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import { isSQLTransformReady } from '../../../../dev/config'
65
import { TabType } from '../storages/tabsStorage'
76

87
export type TabTypeData = {
@@ -34,16 +33,6 @@ What would you like to work on?`,
3433
gumby: {
3534
title: 'Q - Code Transformation',
3635
placeholder: 'Open a new tab to chat with Q',
37-
welcome: isSQLTransformReady
38-
? `Welcome to code transformation!
39-
40-
I can help you with the following tasks:
41-
- Upgrade your Java 8 and Java 11 codebases to Java 17
42-
- Convert embedded SQL from Oracle databases to PostgreSQL
43-
44-
What would you like to do? You can enter 'language upgrade' or 'SQL conversion'.`
45-
: `Welcome to code transformation!
46-
47-
I can help you upgrade your Java 8 and 11 codebases to Java 17.`,
36+
welcome: 'Welcome to Code Transformation!',
4837
},
4938
}

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
getValidSQLConversionCandidateProjects,
3434
validateSQLMetadataFile,
3535
} from '../../../codewhisperer/commands/startTransformByQ'
36-
import { JDKVersion, transformByQState } from '../../../codewhisperer/models/model'
36+
import { JDKVersion, TransformationCandidateProject, transformByQState } from '../../../codewhisperer/models/model'
3737
import {
3838
AbsolutePathDetectedError,
3939
AlternateDependencyVersionsNotFoundError,
@@ -62,8 +62,6 @@ import { getStringHash } from '../../../shared/utilities/textUtilities'
6262
import { getVersionData } from '../../../codewhisperer/service/transformByQ/transformMavenHandler'
6363
import AdmZip from 'adm-zip'
6464
import { AuthError } from '../../../auth/sso/server'
65-
import { isSQLTransformReady } from '../../../dev/config'
66-
import { spawnSync } from 'child_process'
6765

6866
// These events can be interactions within the chat,
6967
// or elsewhere in the IDE
@@ -190,35 +188,16 @@ export class GumbyController {
190188
this.messenger.sendCommandMessage(data)
191189
}
192190

193-
// silently check if user has open Java projects using embedded SQL
194-
private async anyProjectContainsEmbeddedOracleSQL() {
191+
private async transformInitiated(message: any) {
192+
// silently check for projects eligible for SQL conversion
193+
let embeddedSQLProjects: TransformationCandidateProject[] = []
195194
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-
}
195+
embeddedSQLProjects = await getValidSQLConversionCandidateProjects()
212196
} catch (err) {
213-
return false
197+
getLogger().error(`Error validating SQL conversion projects: ${err}`)
214198
}
215-
return true
216-
}
217199

218-
private async transformInitiated(message: any) {
219-
// feature flag for SQL transformations
220-
const containsOracleSQL = await this.anyProjectContainsEmbeddedOracleSQL()
221-
if (!isSQLTransformReady && !containsOracleSQL) {
200+
if (embeddedSQLProjects.length === 0) {
222201
await this.handleLanguageUpgrade(message)
223202
return
224203
}

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
TransformByQStatus,
2121
DB,
2222
TransformationType,
23+
TransformationCandidateProject,
2324
} from '../models/model'
2425
import { convertDateToTimestamp } from '../../shared/utilities/textUtilities'
2526
import {
@@ -80,6 +81,7 @@ import { HumanInTheLoopManager } from '../service/transformByQ/humanInTheLoopMan
8081
import { setContext } from '../../shared/vscode/setContext'
8182
import { makeTemporaryToolkitFolder } from '../../shared'
8283
import globals from '../../shared/extensionGlobals'
84+
import { spawnSync } from 'child_process'
8385

8486
function getFeedbackCommentData() {
8587
const jobId = transformByQState.getJobId()
@@ -734,7 +736,28 @@ export async function getValidLanguageUpgradeCandidateProjects() {
734736
export async function getValidSQLConversionCandidateProjects() {
735737
const openProjects = await getOpenProjects()
736738
const javaProjects = await getJavaProjects(openProjects)
737-
return javaProjects
739+
const embeddedSQLProjects: TransformationCandidateProject[] = []
740+
for (const project of javaProjects) {
741+
// as long as at least one of these strings is found, project contains embedded SQL statements
742+
const searchStrings = ['oracle.jdbc.OracleDriver', 'jdbc:oracle:thin:@//', 'jdbc:oracle:oci:@//']
743+
for (const str of searchStrings) {
744+
const command = process.platform === 'win32' ? 'findstr' : 'grep'
745+
// case-insensitive, recursive search
746+
const args = command === 'findstr' ? ['/i', '/s', str] : ['-i', '-r', str]
747+
const spawnResult = spawnSync(command, args, {
748+
cwd: project.path,
749+
shell: true, // TO-DO: better for this to be false? Test on project with a space in the name
750+
encoding: 'utf-8',
751+
})
752+
// in case our search unexpectedly fails, still allow user to transform that project
753+
// also, anything in stdout here means search string was detected
754+
if (spawnResult.status !== 0 || spawnResult.error || spawnResult.stdout.trim()) {
755+
embeddedSQLProjects.push(project)
756+
break
757+
}
758+
}
759+
}
760+
return embeddedSQLProjects
738761
}
739762

740763
export async function setTransformationToRunningState() {

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ function isExcludedSourceFile(path: string): boolean {
251251
}
252252

253253
// zip all dependency files and all source files excluding "target" (contains large JARs) plus ".git" and ".idea" (may appear in diff.patch)
254-
function getFilesRecursively(dir: string, isDependenciesFolder: boolean): string[] {
254+
export function getFilesRecursively(dir: string, isDependenciesFolder: boolean): string[] {
255255
const entries = nodefs.readdirSync(dir, { withFileTypes: true })
256256
const files = entries.flatMap((entry) => {
257257
const res = path.resolve(dir, entry.name)

packages/core/src/dev/config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,3 @@ export const betaUrl = {
1010
amazonq: '',
1111
toolkit: '',
1212
}
13-
14-
// feature flag for SQL transformations
15-
export const isSQLTransformReady = true

packages/core/src/test/codewhisperer/commands/transformByQ.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
updateJobHistory,
3434
zipCode,
3535
getTableMapping,
36+
getFilesRecursively,
3637
} from '../../../codewhisperer/service/transformByQ/transformApiHandler'
3738
import {
3839
validateOpenProjects,
@@ -288,6 +289,19 @@ describe('transformByQ', function () {
288289
})
289290
})
290291

292+
it(`WHEN getFilesRecursively on source code THEN ignores excluded directories`, async function () {
293+
const sourceFolder = path.join(tempDir, 'src')
294+
await fs.mkdir(sourceFolder)
295+
await fs.writeFile(path.join(sourceFolder, 'HelloWorld.java'), 'sample content for the test file')
296+
297+
const gitFolder = path.join(tempDir, '.git')
298+
await fs.mkdir(gitFolder)
299+
await fs.writeFile(path.join(gitFolder, 'config'), 'sample content for the test file')
300+
301+
const zippedFiles = getFilesRecursively(tempDir, false)
302+
assert.strictEqual(zippedFiles.length, 1)
303+
})
304+
291305
it(`WHEN getTableMapping on complete step 0 progressUpdates THEN map IDs to tables`, async function () {
292306
const stepZeroProgressUpdates = [
293307
{

0 commit comments

Comments
 (0)