Skip to content

Commit

Permalink
feat(gradle): gradle-wrapper url is now inferred from the distributio…
Browse files Browse the repository at this point in the history
…nUrl from the gradle-wrapper.properties (#5786)

Signed-off-by: Mikhail Yakushin <driver733@gmail.com>

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
driver733 and viceice committed Mar 26, 2020
1 parent ddf986b commit 512abc0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# @See https://gradle.org/releases/
distributionUrl=https\://artifactory/gradle-wrapper-cache/distributions/gradle-4.8-bin.zip
distributionSha256Sum=336b6898b491f6334502d8074a6b8c2d73ed83b92123106bd4bf837f04111043
11 changes: 11 additions & 0 deletions lib/manager/gradle-wrapper/__snapshots__/update.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`manager/gradle-wrapper/update updateDependency replaces existing value (custom distributionUrl) 1`] = `
"distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
# @See https://gradle.org/releases/
distributionUrl=https\\\\://artifactory/gradle-wrapper-cache/distributions/gradle-5.0-bin.zip
distributionSha256Sum=17847c8e12b2bcfce26a79f425f082c31d4ded822f99a66127eee2d96bf18216
"
`;

exports[`manager/gradle-wrapper/update updateDependency replaces existing value 1`] = `
"distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
Expand Down
2 changes: 2 additions & 0 deletions lib/manager/gradle-wrapper/search.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const DISTRIBUTION_URL_REGEX = /^(?<assignment>distributionUrl\s*=\s*)\S*-(?<version>(\d|\.)+)-(?<type>bin|all)\.zip\s*$/;
export const DISTRIBUTION_CHECKSUM_REGEX = /^(?<assignment>distributionSha256Sum\s*=\s*)(?<checksum>(\w){64}).*$/;
export const DOWNLOAD_URL_REGEX = /^(?<http>http)\S*-(?<version>(\d|\.)+)-(?<type>bin|all)\.zip\s*$/;
export const VERSION_REGEX = /-(?<version>(\d|\.)+)-/;
21 changes: 21 additions & 0 deletions lib/manager/gradle-wrapper/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const propertiesFile2 = fs.readFileSync(
'lib/manager/gradle-wrapper/__fixtures__/gradle-wrapper-2.properties',
'utf8'
);
const propertiesFileCustomDistUrl = fs.readFileSync(
'lib/manager/gradle-wrapper/__fixtures__/gradle-wrapper-custom-distribution-url.properties',
'utf8'
);
const whitespacePropertiesFile = readFileSync(
resolve(__dirname, './__fixtures__/gradle-wrapper-whitespace.properties'),
'utf8'
Expand Down Expand Up @@ -75,6 +79,23 @@ describe('manager/gradle-wrapper/update', () => {
expect(res).toMatch(testUpgrades[5].checksum);
});

it('replaces existing value (custom distributionUrl)', async () => {
got.mockReturnValueOnce({
body: testUpgrades[5].checksum,
});
const res = await dcUpdate.updateDependency({
fileContent: propertiesFileCustomDistUrl,
upgrade: testUpgrades[5].data,
});
expect(res).toMatchSnapshot();
expect(res).not.toBeNull();
expect(res).not.toEqual(propertiesFileCustomDistUrl);
expect(res).toMatch(
'https\\://artifactory/gradle-wrapper-cache/distributions/gradle-5.0-bin.zip'
);
expect(res).toMatch(testUpgrades[5].checksum);
});

it('replaces in property files with whitespace', async () => {
got.mockReturnValueOnce({
body: testUpgrades[5].checksum,
Expand Down
11 changes: 9 additions & 2 deletions lib/manager/gradle-wrapper/update.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import got from '../../util/got';
import { logger } from '../../logger';
import { UpdateDependencyConfig } from '../common';
import { DISTRIBUTION_CHECKSUM_REGEX, DISTRIBUTION_URL_REGEX } from './search';
import {
DISTRIBUTION_CHECKSUM_REGEX,
DOWNLOAD_URL_REGEX,
VERSION_REGEX,
} from './search';

function replaceType(url: string): string {
return url.replace('bin', 'all');
Expand Down Expand Up @@ -41,7 +45,10 @@ export async function updateDependency({

lines[upgrade.managerData.lineNumber] = lines[
upgrade.managerData.lineNumber
].replace(DISTRIBUTION_URL_REGEX, `$<assignment>${downloadUrl}`);
].replace(
VERSION_REGEX,
`-${DOWNLOAD_URL_REGEX.exec(downloadUrl).groups.version}-`
);

if (upgrade.managerData.checksumLineNumber) {
lines[upgrade.managerData.checksumLineNumber] = lines[
Expand Down

0 comments on commit 512abc0

Please sign in to comment.