fix(gradle): Additional matches for dependency versions (#6477)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
Sergio Zharinov 2020-06-10 12:30:20 +04:00 committed by GitHub
parent aed8d75c73
commit d320573e3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 129 additions and 2 deletions

View file

@ -30,6 +30,16 @@
"name": "scala-logging_%%",
"group": "com.typesafe.scala-logging",
"version": "3.9.0"
},
{
"name": "foo",
"group": "foo",
"version": null
},
{
"name": "bar",
"group": "bar",
"version": null
}
]
}

View file

@ -211,6 +211,26 @@ Array [
"https://jitpack.io",
],
},
Object {
"currentValue": "1.2.3",
"depGroup": "foo",
"depName": "foo:foo",
"name": "foo",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
Object {
"currentValue": "3.4.5",
"depGroup": "bar",
"depName": "bar:bar",
"name": "bar",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
],
"packageFile": "build.gradle",
},
@ -269,6 +289,26 @@ Array [
"https://jitpack.io",
],
},
Object {
"currentValue": "1.2.3",
"depGroup": "foo",
"depName": "foo:foo",
"name": "foo",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
Object {
"currentValue": "3.4.5",
"depGroup": "bar",
"depName": "bar:bar",
"name": "bar",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
],
"packageFile": "subproject/build.gradle",
},
@ -354,6 +394,26 @@ Array [
"https://jitpack.io",
],
},
Object {
"currentValue": "1.2.3",
"depGroup": "foo",
"depName": "foo:foo",
"name": "foo",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
Object {
"currentValue": "3.4.5",
"depGroup": "bar",
"depName": "bar:bar",
"name": "bar",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
],
"packageFile": "foo/build.gradle",
},
@ -439,6 +499,26 @@ Array [
"https://jitpack.io",
],
},
Object {
"currentValue": "1.2.3",
"depGroup": "foo",
"depName": "foo:foo",
"name": "foo",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
Object {
"currentValue": "3.4.5",
"depGroup": "bar",
"depName": "bar:bar",
"name": "bar",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
],
"packageFile": "build.gradle.kts",
},
@ -497,6 +577,26 @@ Array [
"https://jitpack.io",
],
},
Object {
"currentValue": "1.2.3",
"depGroup": "foo",
"depName": "foo:foo",
"name": "foo",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
Object {
"currentValue": "3.4.5",
"depGroup": "bar",
"depName": "bar:bar",
"name": "bar",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2/",
"https://jitpack.io",
],
},
],
"packageFile": "subproject/build.gradle.kts",
},

View file

@ -137,6 +137,14 @@ function kotlinPluginVariableVersionFormatMatch(
);
}
function dependencyStringVariableExpressionFormatMatch(
dependency: GradleDependency
): RegExp {
return regEx(
`\\s*dependency\\s+['"]${dependency.group}:${dependency.name}:([^'"]+)['"](?:\\s|;|})`
);
}
function variableDefinitionFormatMatch(variable: string): RegExp {
return regEx(`(${variable}\\s*=\\s*?["'])(.*)(["'])`);
}
@ -162,16 +170,22 @@ export function collectVersionVariables(
moduleStringVariableInterpolationVersionFormatMatch(dependency),
groovyPluginVariableVersionFormatMatch(dependency),
kotlinPluginVariableVersionFormatMatch(dependency),
dependencyStringVariableExpressionFormatMatch(dependency),
...moduleMapVariableVersionFormatMatch(dependency),
...moduleKotlinNamedArgumentVariableVersionFormatMatch(dependency),
];
const depName = `${dependency.group}:${dependency.name}`;
for (const regex of regexes) {
const match = regex.exec(buildGradleContent);
if (match) {
variables[`${dependency.group}:${dependency.name}`] = match[1];
variables[depName] = match[1];
}
}
if (!dep.currentValue && variables[depName]) {
dep.currentValue = variables[depName];
}
}
}

View file

@ -53,7 +53,10 @@ async function setupMocks() {
const exec: jest.Mock<typeof _exec> = require('child_process').exec;
const util: jest.Mocked<typeof _util> = require('../../util');
utilfs.readLocalFile.mockResolvedValue('some content');
utilfs.readLocalFile.mockResolvedValue(`
dependency 'foo:foo:1.2.3'
dependency "bar:bar:3.4.5"
`);
env.getChildProcessEnv.mockReturnValue(envMock.basic);
await util.setUtilConfig(baseConfig);