mirror of
https://github.com/actions/setup-java.git
synced 2026-07-28 15:14:30 +02:00
Resolve legacy OpenJDK build metadata
This commit is contained in:
@@ -47,6 +47,8 @@ const archivePage = `
|
||||
<a href="https://download.java.net/java/GA/jdk26.0.1/hash/8/GPL/openjdk-26.0.1_linux-x64_bin.tar.gz">tar.gz</a>
|
||||
<a href="https://download.java.net/java/GA/jdk25/hash/36/GPL/openjdk-25_linux-x64_bin.tar.gz">tar.gz</a>
|
||||
<a href="https://download.java.net/java/GA/jdk18.0.1.1/hash/2/GPL/openjdk-18.0.1.1_linux-x64_bin.tar.gz">tar.gz</a>
|
||||
<th>9.0.4 (build 9.0.4+11)</th>
|
||||
<a href="https://download.java.net/java/GA/jdk9/9.0.4/binaries/openjdk-9.0.4_linux-x64_bin.tar.gz">tar.gz</a>
|
||||
`;
|
||||
|
||||
function createDistribution(
|
||||
@@ -111,6 +113,16 @@ describe('OpenJdkDistribution', () => {
|
||||
expect(result.version).toBe('26.0.2+10');
|
||||
});
|
||||
|
||||
it('resolves an exact build from a legacy archive heading', async () => {
|
||||
const result =
|
||||
await createDistribution('9.0.4+11')['findPackageForDownload'](
|
||||
'9.0.4+11'
|
||||
);
|
||||
|
||||
expect(result.version).toBe('9.0.4+11');
|
||||
expect(result.url).toContain('/binaries/openjdk-9.0.4_linux-x64_bin');
|
||||
});
|
||||
|
||||
it('resolves a four-field Java version', async () => {
|
||||
const result =
|
||||
await createDistribution('18.0.1.1')['findPackageForDownload'](
|
||||
|
||||
Vendored
+11
-1
@@ -131939,13 +131939,23 @@ class OpenJdkDistribution extends JavaBase {
|
||||
const pattern = new RegExp(`href="(https://download\\.java\\.net/[^"]+/openjdk-([^"_]+)_${platformPattern}-${arch}_bin\\.${extensionPattern})"`, 'g');
|
||||
return Array.from(html.matchAll(pattern), match => {
|
||||
const url = match[1];
|
||||
const build = url.match(/\/(\d+)\/(?:GPL\/)?openjdk-/)?.[1];
|
||||
const build = url.match(/\/(\d+)\/(?:GPL\/)?openjdk-/)?.[1] ??
|
||||
this.findBuildInArchiveHeading(html, match.index, match[2]);
|
||||
return {
|
||||
version: this.toSemver(match[2], build),
|
||||
url
|
||||
};
|
||||
});
|
||||
}
|
||||
findBuildInArchiveHeading(html, assetIndex, version) {
|
||||
const headings = Array.from(html.slice(0, assetIndex).matchAll(/\(build\s+([^)]+)\)/g));
|
||||
const headingVersion = headings.at(-1)?.[1];
|
||||
if (!headingVersion) {
|
||||
return undefined;
|
||||
}
|
||||
const [javaVersion, build] = headingVersion.split('+');
|
||||
return javaVersion === version ? build : undefined;
|
||||
}
|
||||
toSemver(version, urlBuild) {
|
||||
const [javaVersion, filenameBuild] = version.replace('-ea', '').split('+');
|
||||
const versionParts = javaVersion.split('.');
|
||||
|
||||
@@ -126,7 +126,9 @@ export class OpenJdkDistribution extends JavaBase {
|
||||
|
||||
return Array.from(html.matchAll(pattern), match => {
|
||||
const url = match[1];
|
||||
const build = url.match(/\/(\d+)\/(?:GPL\/)?openjdk-/)?.[1];
|
||||
const build =
|
||||
url.match(/\/(\d+)\/(?:GPL\/)?openjdk-/)?.[1] ??
|
||||
this.findBuildInArchiveHeading(html, match.index, match[2]);
|
||||
return {
|
||||
version: this.toSemver(match[2], build),
|
||||
url
|
||||
@@ -134,6 +136,23 @@ export class OpenJdkDistribution extends JavaBase {
|
||||
});
|
||||
}
|
||||
|
||||
private findBuildInArchiveHeading(
|
||||
html: string,
|
||||
assetIndex: number,
|
||||
version: string
|
||||
): string | undefined {
|
||||
const headings = Array.from(
|
||||
html.slice(0, assetIndex).matchAll(/\(build\s+([^)]+)\)/g)
|
||||
);
|
||||
const headingVersion = headings.at(-1)?.[1];
|
||||
if (!headingVersion) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const [javaVersion, build] = headingVersion.split('+');
|
||||
return javaVersion === version ? build : undefined;
|
||||
}
|
||||
|
||||
private toSemver(version: string, urlBuild?: string): string {
|
||||
const [javaVersion, filenameBuild] = version.replace('-ea', '').split('+');
|
||||
const versionParts = javaVersion.split('.');
|
||||
|
||||
Reference in New Issue
Block a user