Skip to content
Snippets Groups Projects
Commit d33ca43e authored by Ryan Murfitt's avatar Ryan Murfitt Committed by Rhys Arkins
Browse files

feat(gradle): Support Kotlin DSL extra properties (#4493)

parent 4c78f5d5
Branches
Tags 19.48.0
No related merge requests found
......@@ -33,6 +33,7 @@ export function updateGradleVersion(
updateLocalVariables,
updateGlobalVariables,
updatePropertyFileGlobalVariables,
updateKotlinVariablesByExtra,
];
// eslint-disable-next-line guard-for-in
......@@ -142,6 +143,24 @@ function updateGlobalVariables(
return null;
}
function updateKotlinVariablesByExtra(
dependency: GradleDependency,
buildGradleContent: string,
newVersion: string
): string | null {
const variable = variables[`${dependency.group}:${dependency.name}`];
if (variable) {
const regex = new RegExp(
`(val ${variable} by extra(?: {|\\()\\s*")(.*)("\\s*[})])`
);
const match = buildGradleContent.match(regex);
if (match) {
return buildGradleContent.replace(regex, `$1${newVersion}$3`);
}
}
return null;
}
function updatePropertyFileGlobalVariables(
dependency: GradleDependency,
buildGradleContent: string,
......
......@@ -289,4 +289,48 @@ describe('lib/manager/gradle/updateGradleVersion', () => {
);
expect(updatedGradleFile).toEqual('String mysqlVersion = "7.0.0"');
});
it('should replace a external extra variable assigned to a Kotlin named argument dependency', () => {
const gradleFile = `compile(group = "mysql" ,
name = "mysql-connector-java",
version = mysqlVersion)
`;
const mysqlDependency = {
group: 'mysql',
depGroup: 'mysql',
name: 'mysql-connector-java',
version: '6.0.5',
};
collectVersionVariables([mysqlDependency], gradleFile);
const gradleWithVersionFile = 'val mysqlVersion by extra("6.0.5")';
const updatedGradleFile = updateGradleVersion(
gradleWithVersionFile,
mysqlDependency,
'7.0.0'
);
expect(updatedGradleFile).toEqual('val mysqlVersion by extra("7.0.0")');
});
it('should replace a external lazy extra variable assigned to a Kotlin named argument dependency', () => {
const gradleFile = `compile(group = "mysql" ,
name = "mysql-connector-java",
version = mysqlVersion)
`;
const mysqlDependency = {
group: 'mysql',
depGroup: 'mysql',
name: 'mysql-connector-java',
version: '6.0.5',
};
collectVersionVariables([mysqlDependency], gradleFile);
const gradleWithVersionFile = 'val mysqlVersion by extra { "6.0.5" }';
const updatedGradleFile = updateGradleVersion(
gradleWithVersionFile,
mysqlDependency,
'7.0.0'
);
expect(updatedGradleFile).toEqual('val mysqlVersion by extra { "7.0.0" }');
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment