Skip to content

Commit 97dac5e

Browse files
authored
feat(maven-wrapper): wrapperVersion support (#31809)
1 parent 1ca7d26 commit 97dac5e

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

lib/modules/manager/maven-wrapper/extract.spec.ts

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ describe('modules/manager/maven-wrapper/extract', () => {
4949
]);
5050
});
5151

52+
it('extracts version for property file with only a wrapper version', () => {
53+
const res = extractPackageFile('wrapperVersion=3.3.1');
54+
expect(res?.deps).toEqual([
55+
{
56+
currentValue: '3.3.1',
57+
replaceString: '3.3.1',
58+
datasource: 'maven',
59+
depName: 'maven-wrapper',
60+
packageName: 'org.apache.maven.wrapper:maven-wrapper',
61+
versioning: 'maven',
62+
},
63+
]);
64+
});
65+
5266
it('extracts version for property file with only a maven url', () => {
5367
const res = extractPackageFile(onlyMavenProperties);
5468
expect(res?.deps).toEqual([

lib/modules/manager/maven-wrapper/extract.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,38 @@ import type { MavenVersionExtract, Version } from './types';
88

99
// https://regex101.com/r/IcOs7P/1
1010
const DISTRIBUTION_URL_REGEX = regEx(
11-
'^(?:distributionUrl\\s*=\\s*)(?<url>\\S*-(?<version>\\d+\\.\\d+(?:\\.\\d+)?(?:-\\w+)*)-(?<type>bin|all)\\.zip)\\s*$',
11+
'^(?:distributionUrl\\s*=\\s*)(?<replaceString>\\S*-(?<version>\\d+\\.\\d+(?:\\.\\d+)?(?:-\\w+)*)-(?<type>bin|all)\\.zip)\\s*$',
1212
);
1313

1414
const WRAPPER_URL_REGEX = regEx(
15-
'^(?:wrapperUrl\\s*=\\s*)(?<url>\\S*-(?<version>\\d+\\.\\d+(?:\\.\\d+)?(?:-\\w+)*)(?:.jar))',
15+
'^(?:wrapperUrl\\s*=\\s*)(?<replaceString>\\S*-(?<version>\\d+\\.\\d+(?:\\.\\d+)?(?:-\\w+)*)(?:.jar))',
16+
);
17+
18+
// https://regex101.com/r/7x1Otq/3
19+
const WRAPPER_VERSION_REGEX = regEx(
20+
'^(?:wrapperVersion\\s*=\\s*)(?<replaceString>(?<version>\\d+\\.\\d+(?:\\.\\d+)?))',
1621
);
1722

1823
function extractVersions(fileContent: string): MavenVersionExtract {
1924
const lines = coerceArray(fileContent?.split(newlineRegex));
2025
const maven = extractLineInfo(lines, DISTRIBUTION_URL_REGEX) ?? undefined;
21-
const wrapper = extractLineInfo(lines, WRAPPER_URL_REGEX) ?? undefined;
26+
const wrapper =
27+
extractLineInfo(lines, WRAPPER_URL_REGEX, WRAPPER_VERSION_REGEX) ??
28+
undefined;
2229
return { maven, wrapper };
2330
}
2431

25-
function extractLineInfo(lines: string[], regex: RegExp): Version | null {
32+
function extractLineInfo(lines: string[], ...regexs: RegExp[]): Version | null {
2633
for (const line of lines) {
27-
if (line.match(regex)) {
28-
const match = regex.exec(line);
29-
if (match?.groups) {
30-
return {
31-
url: match.groups.url,
32-
version: match.groups.version,
33-
};
34+
for (const regex of regexs) {
35+
if (line.match(regex)) {
36+
const match = regex.exec(line);
37+
if (match?.groups) {
38+
return {
39+
replaceString: match.groups.replaceString,
40+
version: match.groups.version,
41+
};
42+
}
3443
}
3544
}
3645
}
@@ -49,7 +58,7 @@ export function extractPackageFile(
4958
depName: 'maven',
5059
packageName: 'org.apache.maven:apache-maven',
5160
currentValue: extractResult.maven?.version,
52-
replaceString: extractResult.maven?.url,
61+
replaceString: extractResult.maven?.replaceString,
5362
datasource: MavenDatasource.id,
5463
versioning,
5564
};
@@ -61,7 +70,7 @@ export function extractPackageFile(
6170
depName: 'maven-wrapper',
6271
packageName: 'org.apache.maven.wrapper:maven-wrapper',
6372
currentValue: extractResult.wrapper?.version,
64-
replaceString: extractResult.wrapper?.url,
73+
replaceString: extractResult.wrapper?.replaceString,
6574
datasource: MavenDatasource.id,
6675
versioning,
6776
};

lib/modules/manager/maven-wrapper/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface Version {
2-
url: string;
2+
replaceString: string;
33
version: string;
44
}
55

0 commit comments

Comments
 (0)