Skip to content

Commit

Permalink
only show users oracle sql projects
Browse files Browse the repository at this point in the history
  • Loading branch information
David Hasani committed Nov 12, 2024
1 parent 3d9f274 commit 6dfcbaa
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 45 deletions.
13 changes: 1 addition & 12 deletions packages/core/src/amazonq/webview/ui/tabs/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { isSQLTransformReady } from '../../../../dev/config'
import { TabType } from '../storages/tabsStorage'

export type TabTypeData = {
Expand Down Expand Up @@ -34,16 +33,6 @@ What would you like to work on?`,
gumby: {
title: 'Q - Code Transformation',
placeholder: 'Open a new tab to chat with Q',
welcome: isSQLTransformReady
? `Welcome to code transformation!
I can help you with the following tasks:
- Upgrade your Java 8 and Java 11 codebases to Java 17
- Convert embedded SQL from Oracle databases to PostgreSQL
What would you like to do? You can enter 'language upgrade' or 'SQL conversion'.`
: `Welcome to code transformation!
I can help you upgrade your Java 8 and 11 codebases to Java 17.`,
welcome: 'Welcome to Code Transformation!',
},
}
35 changes: 7 additions & 28 deletions packages/core/src/amazonqGumby/chat/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
getValidSQLConversionCandidateProjects,
validateSQLMetadataFile,
} from '../../../codewhisperer/commands/startTransformByQ'
import { JDKVersion, transformByQState } from '../../../codewhisperer/models/model'
import { JDKVersion, TransformationCandidateProject, transformByQState } from '../../../codewhisperer/models/model'
import {
AbsolutePathDetectedError,
AlternateDependencyVersionsNotFoundError,
Expand Down Expand Up @@ -62,8 +62,6 @@ import { getStringHash } from '../../../shared/utilities/textUtilities'
import { getVersionData } from '../../../codewhisperer/service/transformByQ/transformMavenHandler'
import AdmZip from 'adm-zip'
import { AuthError } from '../../../auth/sso/server'
import { isSQLTransformReady } from '../../../dev/config'
import { spawnSync } from 'child_process'

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

// silently check if user has open Java projects using embedded SQL
private async anyProjectContainsEmbeddedOracleSQL() {
private async transformInitiated(message: any) {
// silently check for projects eligible for SQL conversion
let embeddedSQLProjects: TransformationCandidateProject[] = []
try {
// gets just open Java projects
const projects = await getValidSQLConversionCandidateProjects()
for (const project of projects) {
// case-insensitive, recursive search, display only count of matching lines
const args = ['-i', '-r', '-c', 'oracle.jdbc.OracleDriver']
// TO-DO: handle Windows
const spawnResult = spawnSync('grep', args, {
cwd: project.path,
shell: true,
encoding: 'utf-8',
})
if (spawnResult.status !== 0) {
return false
}
// TO-DO: parse stdout for the count of matching lines
}
embeddedSQLProjects = await getValidSQLConversionCandidateProjects()
} catch (err) {
return false
getLogger().error(`Error validating SQL conversion projects: ${err}`)
}
return true
}

private async transformInitiated(message: any) {
// feature flag for SQL transformations
const containsOracleSQL = await this.anyProjectContainsEmbeddedOracleSQL()
if (!isSQLTransformReady && !containsOracleSQL) {
if (embeddedSQLProjects.length === 0) {
await this.handleLanguageUpgrade(message)
return
}
Expand Down
25 changes: 24 additions & 1 deletion packages/core/src/codewhisperer/commands/startTransformByQ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
TransformByQStatus,
DB,
TransformationType,
TransformationCandidateProject,
} from '../models/model'
import { convertDateToTimestamp } from '../../shared/utilities/textUtilities'
import {
Expand Down Expand Up @@ -80,6 +81,7 @@ import { HumanInTheLoopManager } from '../service/transformByQ/humanInTheLoopMan
import { setContext } from '../../shared/vscode/setContext'
import { makeTemporaryToolkitFolder } from '../../shared'
import globals from '../../shared/extensionGlobals'
import { spawnSync } from 'child_process'

function getFeedbackCommentData() {
const jobId = transformByQState.getJobId()
Expand Down Expand Up @@ -734,7 +736,28 @@ export async function getValidLanguageUpgradeCandidateProjects() {
export async function getValidSQLConversionCandidateProjects() {
const openProjects = await getOpenProjects()
const javaProjects = await getJavaProjects(openProjects)
return javaProjects
const embeddedSQLProjects: TransformationCandidateProject[] = []
for (const project of javaProjects) {
// as long as at least one of these strings is found, project contains embedded SQL statements
const searchStrings = ['oracle.jdbc.OracleDriver', 'jdbc:oracle:thin:@//', 'jdbc:oracle:oci:@//']
for (const str of searchStrings) {
const command = process.platform === 'win32' ? 'findstr' : 'grep'
// case-insensitive, recursive search
const args = command === 'findstr' ? ['/i', '/s', str] : ['-i', '-r', str]
const spawnResult = spawnSync(command, args, {
cwd: project.path,
shell: true, // TO-DO: better for this to be false? Test on project with a space in the name
encoding: 'utf-8',
})
// in case our search unexpectedly fails, still allow user to transform that project
// also, anything in stdout here means search string was detected
if (spawnResult.status !== 0 || spawnResult.error || spawnResult.stdout.trim()) {
embeddedSQLProjects.push(project)
break
}
}
}
return embeddedSQLProjects
}

export async function setTransformationToRunningState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function isExcludedSourceFile(path: string): boolean {
}

// zip all dependency files and all source files excluding "target" (contains large JARs) plus ".git" and ".idea" (may appear in diff.patch)
function getFilesRecursively(dir: string, isDependenciesFolder: boolean): string[] {
export function getFilesRecursively(dir: string, isDependenciesFolder: boolean): string[] {
const entries = nodefs.readdirSync(dir, { withFileTypes: true })
const files = entries.flatMap((entry) => {
const res = path.resolve(dir, entry.name)
Expand Down
3 changes: 0 additions & 3 deletions packages/core/src/dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ export const betaUrl = {
amazonq: '',
toolkit: '',
}

// feature flag for SQL transformations
export const isSQLTransformReady = true
14 changes: 14 additions & 0 deletions packages/core/src/test/codewhisperer/commands/transformByQ.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
updateJobHistory,
zipCode,
getTableMapping,
getFilesRecursively,
} from '../../../codewhisperer/service/transformByQ/transformApiHandler'
import {
validateOpenProjects,
Expand Down Expand Up @@ -288,6 +289,19 @@ describe('transformByQ', function () {
})
})

it(`WHEN getFilesRecursively on source code THEN ignores excluded directories`, async function () {
const sourceFolder = path.join(tempDir, 'src')
await fs.mkdir(sourceFolder)
await fs.writeFile(path.join(sourceFolder, 'HelloWorld.java'), 'sample content for the test file')

const gitFolder = path.join(tempDir, '.git')
await fs.mkdir(gitFolder)
await fs.writeFile(path.join(gitFolder, 'config'), 'sample content for the test file')

const zippedFiles = getFilesRecursively(tempDir, false)
assert.strictEqual(zippedFiles.length, 1)
})

it(`WHEN getTableMapping on complete step 0 progressUpdates THEN map IDs to tables`, async function () {
const stepZeroProgressUpdates = [
{
Expand Down

0 comments on commit 6dfcbaa

Please sign in to comment.