feat(manager/gradle): add support for new header used by gradle-consistent-versions plugin (#27895)

This commit is contained in:
Johannes Feichtner 2024-03-13 06:04:21 +01:00 committed by GitHub
parent a7658221d8
commit 291defc7e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 6 deletions

View file

@ -20,6 +20,18 @@ describe('modules/manager/gradle/extract/consistent-versions-plugin', () => {
expect(usesGcv('othersub/versions.props', fsMock)).toBeFalse();
});
it('detects lock file header introduced with gradle-consistent-versions version 2.20.0', () => {
const fsMock = {
'build.gradle.kts': `(this file contains) 'com.palantir.consistent-versions'`,
'versions.props': `org.apache.lucene:* = 1.2.3`,
'versions.lock': stripIndent`
# Run ./gradlew writeVersionsLock to regenerate this file
org.apache.lucene:lucene-core:1.2.3`,
};
expect(usesGcv('versions.props', fsMock)).toBeTrue();
});
it('gradle-consistent-versions plugin correct position for CRLF and LF', () => {
const crlfProps = parsePropsFile(`a.b:c.d=1\r\na.b:c.e=2`);
expect(crlfProps).toBeArrayOfSize(2);
@ -47,7 +59,6 @@ describe('modules/manager/gradle/extract/consistent-versions-plugin', () => {
expect(parsedProps[0]).toMatchObject({ size: 1 }); // no 7 is valid exact dep
expect(parsedProps[1]).toMatchObject({ size: 1 }); // no 8 is valid glob dep
// lockfile
const parsedLock = parseLockFile(stripIndent`
# comment:foo.bar:1 (10 constraints: 95be0c15)
123.foo:bar:2 (10 constraints: 95be0c15)

View file

@ -8,8 +8,9 @@ import { isDependencyString, versionLikeSubstring } from '../utils';
export const VERSIONS_PROPS = 'versions.props';
export const VERSIONS_LOCK = 'versions.lock';
const LOCKFILE_HEADER_TEXT =
'# Run ./gradlew --write-locks to regenerate this file';
export const LOCKFIlE_HEADER_TEXT = regEx(
/^# Run \.\/gradlew (?:--write-locks|writeVersionsLock) to regenerate this file/,
);
/**
* Determines if Palantir gradle-consistent-versions is in use, https://github.com/palantir/gradle-consistent-versions.
@ -26,9 +27,8 @@ export function usesGcv(
versionsPropsFilename,
VERSIONS_LOCK,
);
return (
fileContents[versionsLockFile]?.startsWith(LOCKFILE_HEADER_TEXT) ?? false
);
return !!fileContents[versionsLockFile]?.match(LOCKFIlE_HEADER_TEXT);
}
/**