Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down
Loading