Skip to content
Snippets Groups Projects
Unverified Commit 512abc0f authored by Mikhail Yakushin's avatar Mikhail Yakushin Committed by GitHub
Browse files

feat(gradle): gradle-wrapper url is now inferred from the distributionUrl from...

feat(gradle): gradle-wrapper url is now inferred from the distributionUrl from the gradle-wrapper.properties (#5786)

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

Co-authored-by: default avatarMichael Kriese <michael.kriese@visualon.de>
parent ddf986b8
No related merge requests found
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
// 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
......
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|\.)+)-/;
......@@ -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'
......@@ -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,
......
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');
......@@ -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[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment