Skip to content

Commit

Permalink
feat(maven-wrapper): wrapperVersion support (#31809)
Browse files Browse the repository at this point in the history
  • Loading branch information
JackPGreen authored Oct 11, 2024
1 parent 1ca7d26 commit 97dac5e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
14 changes: 14 additions & 0 deletions lib/modules/manager/maven-wrapper/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ describe('modules/manager/maven-wrapper/extract', () => {
]);
});

it('extracts version for property file with only a wrapper version', () => {
const res = extractPackageFile('wrapperVersion=3.3.1');
expect(res?.deps).toEqual([
{
currentValue: '3.3.1',
replaceString: '3.3.1',
datasource: 'maven',
depName: 'maven-wrapper',
packageName: 'org.apache.maven.wrapper:maven-wrapper',
versioning: 'maven',
},
]);
});

it('extracts version for property file with only a maven url', () => {
const res = extractPackageFile(onlyMavenProperties);
expect(res?.deps).toEqual([
Expand Down
35 changes: 22 additions & 13 deletions lib/modules/manager/maven-wrapper/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,38 @@ import type { MavenVersionExtract, Version } from './types';

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

const WRAPPER_URL_REGEX = regEx(
'^(?:wrapperUrl\\s*=\\s*)(?<url>\\S*-(?<version>\\d+\\.\\d+(?:\\.\\d+)?(?:-\\w+)*)(?:.jar))',
'^(?:wrapperUrl\\s*=\\s*)(?<replaceString>\\S*-(?<version>\\d+\\.\\d+(?:\\.\\d+)?(?:-\\w+)*)(?:.jar))',
);

// https://regex101.com/r/7x1Otq/3
const WRAPPER_VERSION_REGEX = regEx(
'^(?:wrapperVersion\\s*=\\s*)(?<replaceString>(?<version>\\d+\\.\\d+(?:\\.\\d+)?))',
);

function extractVersions(fileContent: string): MavenVersionExtract {
const lines = coerceArray(fileContent?.split(newlineRegex));
const maven = extractLineInfo(lines, DISTRIBUTION_URL_REGEX) ?? undefined;
const wrapper = extractLineInfo(lines, WRAPPER_URL_REGEX) ?? undefined;
const wrapper =
extractLineInfo(lines, WRAPPER_URL_REGEX, WRAPPER_VERSION_REGEX) ??
undefined;
return { maven, wrapper };
}

function extractLineInfo(lines: string[], regex: RegExp): Version | null {
function extractLineInfo(lines: string[], ...regexs: RegExp[]): Version | null {
for (const line of lines) {
if (line.match(regex)) {
const match = regex.exec(line);
if (match?.groups) {
return {
url: match.groups.url,
version: match.groups.version,
};
for (const regex of regexs) {
if (line.match(regex)) {
const match = regex.exec(line);
if (match?.groups) {
return {
replaceString: match.groups.replaceString,
version: match.groups.version,
};
}
}
}
}
Expand All @@ -49,7 +58,7 @@ export function extractPackageFile(
depName: 'maven',
packageName: 'org.apache.maven:apache-maven',
currentValue: extractResult.maven?.version,
replaceString: extractResult.maven?.url,
replaceString: extractResult.maven?.replaceString,
datasource: MavenDatasource.id,
versioning,
};
Expand All @@ -61,7 +70,7 @@ export function extractPackageFile(
depName: 'maven-wrapper',
packageName: 'org.apache.maven.wrapper:maven-wrapper',
currentValue: extractResult.wrapper?.version,
replaceString: extractResult.wrapper?.url,
replaceString: extractResult.wrapper?.replaceString,
datasource: MavenDatasource.id,
versioning,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/maven-wrapper/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface Version {
url: string;
replaceString: string;
version: string;
}

Expand Down

0 comments on commit 97dac5e

Please sign in to comment.