Skip to content

Commit

Permalink
feat(manager/gradle): add support for new header used by gradle-consi…
Browse files Browse the repository at this point in the history
…stent-versions plugin (#27895)
  • Loading branch information
Churro committed Mar 13, 2024
1 parent a765822 commit 291defc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/manager/gradle/extract/consistent-versions-plugin.ts
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 291defc

Please sign in to comment.