mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
fix(gradle): Support gradle versions as templates (#13576)
* fix(gradle): Support gradle versions as templates * More test
This commit is contained in:
parent
0fdede3547
commit
ee55afb3d9
3 changed files with 44 additions and 3 deletions
|
@ -71,6 +71,12 @@ describe('manager/gradle/shallow/parser', () => {
|
|||
${'baz = "1.2.3"'} | ${'id "foo.bar" version baz'} | ${{ depName: 'foo.bar', lookupName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }}
|
||||
${'baz = "1.2.3"'} | ${'id("foo.bar") version baz'} | ${{ depName: 'foo.bar', lookupName: 'foo.bar:foo.bar.gradle.plugin', currentValue: '1.2.3' }}
|
||||
${'baz = "1.3.71"'} | ${'kotlin("jvm") version baz'} | ${{ depName: 'org.jetbrains.kotlin.jvm', lookupName: 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin', currentValue: '1.3.71' }}
|
||||
${'z = "1.2.3"'} | ${'id "x.y" version "$z"'} | ${{ depName: 'x.y', lookupName: 'x.y:x.y.gradle.plugin', currentValue: '1.2.3' }}
|
||||
${''} | ${'id "x.y" version "$z"'} | ${{ depName: 'x.y', skipReason: SkipReason.UnknownVersion, currentValue: 'z' }}
|
||||
${''} | ${'id "x.y" version "x${y}z"'} | ${{ depName: 'x.y', skipReason: SkipReason.UnknownVersion }}
|
||||
${'z = "1.2.3"'} | ${'id("x.y") version "$z"'} | ${{ depName: 'x.y', lookupName: 'x.y:x.y.gradle.plugin', currentValue: '1.2.3' }}
|
||||
${''} | ${'id("x.y") version "$z"'} | ${{ depName: 'x.y', skipReason: SkipReason.UnknownVersion, currentValue: 'z' }}
|
||||
${''} | ${'id("x.y") version "x${y}z"'} | ${{ depName: 'x.y', skipReason: SkipReason.UnknownVersion }}
|
||||
`('$input', ({ def, input, output }) => {
|
||||
const { deps } = parseGradle([def, input].join('\n'));
|
||||
expect(deps).toMatchObject([output].filter(Boolean));
|
||||
|
|
|
@ -236,6 +236,29 @@ function processPlugin({
|
|||
dep.managerData = { fileReplacePosition, packageFile };
|
||||
dep.skipReason = SkipReason.UnknownVersion;
|
||||
}
|
||||
} else if (pluginVersion.type === TokenType.StringInterpolation) {
|
||||
const versionTpl = pluginVersion as StringInterpolation;
|
||||
const children = versionTpl.children;
|
||||
const [child] = children;
|
||||
if (child?.type === TokenType.Variable && children.length === 1) {
|
||||
const varData = variables[child.value];
|
||||
if (varData) {
|
||||
const currentValue = varData.value;
|
||||
const fileReplacePosition = varData.fileReplacePosition;
|
||||
dep.currentValue = currentValue;
|
||||
dep.managerData = { fileReplacePosition, packageFile };
|
||||
} else {
|
||||
const currentValue = child.value;
|
||||
const fileReplacePosition = child.offset;
|
||||
dep.currentValue = currentValue;
|
||||
dep.managerData = { fileReplacePosition, packageFile };
|
||||
dep.skipReason = SkipReason.UnknownVersion;
|
||||
}
|
||||
} else {
|
||||
const fileReplacePosition = versionTpl.offset;
|
||||
dep.managerData = { fileReplacePosition, packageFile };
|
||||
dep.skipReason = SkipReason.UnknownVersion;
|
||||
}
|
||||
} else {
|
||||
const currentValue = pluginVersion.value;
|
||||
const fileReplacePosition = pluginVersion.offset;
|
||||
|
@ -372,6 +395,8 @@ const matcherConfigs: SyntaxMatchConfig[] = [
|
|||
},
|
||||
{
|
||||
// id 'foo.bar' version '1.2.3'
|
||||
// id 'foo.bar' version fooBarVersion
|
||||
// id 'foo.bar' version "$fooBarVersion"
|
||||
matchers: [
|
||||
{
|
||||
matchType: TokenType.Word,
|
||||
|
@ -381,7 +406,11 @@ const matcherConfigs: SyntaxMatchConfig[] = [
|
|||
{ matchType: TokenType.String, tokenMapKey: 'pluginName' },
|
||||
{ matchType: TokenType.Word, matchValue: 'version' },
|
||||
{
|
||||
matchType: [TokenType.String, TokenType.Word],
|
||||
matchType: [
|
||||
TokenType.String,
|
||||
TokenType.Word,
|
||||
TokenType.StringInterpolation,
|
||||
],
|
||||
tokenMapKey: 'pluginVersion',
|
||||
},
|
||||
endOfInstruction,
|
||||
|
@ -390,6 +419,8 @@ const matcherConfigs: SyntaxMatchConfig[] = [
|
|||
},
|
||||
{
|
||||
// id('foo.bar') version '1.2.3'
|
||||
// id('foo.bar') version fooBarVersion
|
||||
// id('foo.bar') version "$fooBarVersion"
|
||||
matchers: [
|
||||
{
|
||||
matchType: TokenType.Word,
|
||||
|
@ -401,7 +432,11 @@ const matcherConfigs: SyntaxMatchConfig[] = [
|
|||
{ matchType: TokenType.RightParen },
|
||||
{ matchType: TokenType.Word, matchValue: 'version' },
|
||||
{
|
||||
matchType: [TokenType.String, TokenType.Word],
|
||||
matchType: [
|
||||
TokenType.String,
|
||||
TokenType.Word,
|
||||
TokenType.StringInterpolation,
|
||||
],
|
||||
tokenMapKey: 'pluginVersion',
|
||||
},
|
||||
endOfInstruction,
|
||||
|
|
|
@ -35,7 +35,7 @@ const lexer = moo.states({
|
|||
[TokenType.Comma]: ',',
|
||||
[TokenType.Operator]: /(?:==|\+=?|-=?|\/=?|\*\*?|\.+|:)/, // TODO #12870
|
||||
[TokenType.Assignment]: '=',
|
||||
[TokenType.Word]: { match: /[a-zA-Z$_][a-zA-Z0-9$_]+/ }, // TODO #12870
|
||||
[TokenType.Word]: { match: /[a-zA-Z$_][a-zA-Z0-9$_]*/ }, // TODO #12870
|
||||
[TokenType.LeftParen]: { match: '(' },
|
||||
[TokenType.RightParen]: { match: ')' },
|
||||
[TokenType.LeftBracket]: { match: '[' },
|
||||
|
|
Loading…
Reference in a new issue