diff --git a/packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts b/packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts index 91ee8f6639c..b16ea64022c 100644 --- a/packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts +++ b/packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts @@ -139,8 +139,14 @@ export function validateCustomVersionsFile(fileContents: string) { getLogger().info('CodeTransformation: .YAML file must contain at least dependencies or plugins') return `YAML file must contain at least \`dependencies\` or \`plugins\` under \`dependencyManagement\`` } - for (const item of dependenciesAndPlugins) { - const errorMessage = validateItem(item) + for (const item of dependencies) { + const errorMessage = validateItem(item, false) + if (errorMessage) { + return errorMessage + } + } + for (const item of plugins) { + const errorMessage = validateItem(item, true) if (errorMessage) { return errorMessage } @@ -153,10 +159,15 @@ export function validateCustomVersionsFile(fileContents: string) { } // return an error message, or undefined if item is valid -function validateItem(item: any, validOriginTypes: string[] = ['FIRST_PARTY', 'THIRD_PARTY']) { - if (!/^[^\s:]+:[^\s:]+$/.test(item.identifier)) { +function validateItem(item: any, isPlugin: boolean) { + const validOriginTypes = ['FIRST_PARTY', 'THIRD_PARTY'] + if (!isPlugin && !/^[^\s:]+:[^\s:]+$/.test(item.identifier)) { getLogger().info(`CodeTransformation: Invalid identifier format: ${item.identifier}`) - return `Invalid identifier format: \`${item.identifier}\`. Must be in format \`groupId:artifactId\` without spaces` + return `Invalid dependency identifier format: \`${item.identifier}\`. Must be in format \`groupId:artifactId\` without spaces` + } + if (isPlugin && !item.identifier?.trim()) { + getLogger().info('CodeTransformation: Missing identifier in plugin') + return 'Missing `identifier` in plugin' } if (!validOriginTypes.includes(item.originType)) { getLogger().info(`CodeTransformation: Invalid originType: ${item.originType}`) diff --git a/packages/core/src/test/codewhisperer/commands/transformByQ.test.ts b/packages/core/src/test/codewhisperer/commands/transformByQ.test.ts index f205f075872..3b12fcefbc0 100644 --- a/packages/core/src/test/codewhisperer/commands/transformByQ.test.ts +++ b/packages/core/src/test/codewhisperer/commands/transformByQ.test.ts @@ -65,7 +65,7 @@ dependencyManagement: targetVersion: "3.0.0" originType: "THIRD_PARTY" plugins: - - identifier: "com.example:plugin" + - identifier: "plugin.id" targetVersion: "1.2.0" versionProperty: "plugin.version" # Optional originType: "FIRST_PARTY" # or "THIRD_PARTY"` @@ -582,15 +582,21 @@ dependencyManagement: assert.strictEqual(errorMessage, `Missing required key: \`dependencyManagement\``) }) - it(`WHEN validateCustomVersionsFile on .yaml file with invalid identifier format THEN fails validation`, function () { + it(`WHEN validateCustomVersionsFile on .yaml file with invalid dependency identifier format THEN fails validation`, function () { const invalidFile = validCustomVersionsFile.replace('com.example:library1', 'com.example-library1') const errorMessage = validateCustomVersionsFile(invalidFile) assert.strictEqual( errorMessage, - `Invalid identifier format: \`com.example-library1\`. Must be in format \`groupId:artifactId\` without spaces` + `Invalid dependency identifier format: \`com.example-library1\`. Must be in format \`groupId:artifactId\` without spaces` ) }) + it(`WHEN validateCustomVersionsFile on .yaml file with missing plugin identifier format THEN fails validation`, function () { + const invalidFile = validCustomVersionsFile.replace('plugin.id', '') + const errorMessage = validateCustomVersionsFile(invalidFile) + assert.strictEqual(errorMessage, 'Missing `identifier` in plugin') + }) + it(`WHEN validateCustomVersionsFile on .yaml file with invalid originType THEN fails validation`, function () { const invalidFile = validCustomVersionsFile.replace('FIRST_PARTY', 'INVALID_TYPE') const errorMessage = validateCustomVersionsFile(invalidFile)