mirror of
https://github.com/actions/setup-java.git
synced 2026-07-28 15:42:59 +00:00
Support archived OpenJDK release formats
This commit is contained in:
committed by
GitHub
parent
a7c4828ceb
commit
2c4a2dda70
@@ -46,6 +46,7 @@ const earlyAccessPage = `
|
|||||||
const archivePage = `
|
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/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/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>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function createDistribution(
|
function createDistribution(
|
||||||
@@ -88,7 +89,7 @@ describe('OpenJdkDistribution', () => {
|
|||||||
const result = await createDistribution()['findPackageForDownload']('26');
|
const result = await createDistribution()['findPackageForDownload']('26');
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
version: '26.0.2',
|
version: '26.0.2+10',
|
||||||
url: 'https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-x64_bin.tar.gz'
|
url: 'https://download.java.net/java/GA/jdk26.0.2/hash/10/GPL/openjdk-26.0.2_linux-x64_bin.tar.gz'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -97,10 +98,29 @@ describe('OpenJdkDistribution', () => {
|
|||||||
const result =
|
const result =
|
||||||
await createDistribution('26.0.1')['findPackageForDownload']('26.0.1');
|
await createDistribution('26.0.1')['findPackageForDownload']('26.0.1');
|
||||||
|
|
||||||
expect(result.version).toBe('26.0.1');
|
expect(result.version).toBe('26.0.1+8');
|
||||||
expect(result.url).toContain('/openjdk-26.0.1_linux-x64_bin.tar.gz');
|
expect(result.url).toContain('/openjdk-26.0.1_linux-x64_bin.tar.gz');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('resolves an exact GA build', async () => {
|
||||||
|
const result =
|
||||||
|
await createDistribution('26.0.2+10')['findPackageForDownload'](
|
||||||
|
'26.0.2+10'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.version).toBe('26.0.2+10');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('resolves a four-field Java version', async () => {
|
||||||
|
const result =
|
||||||
|
await createDistribution('18.0.1.1')['findPackageForDownload'](
|
||||||
|
'18.0.1+1'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.version).toBe('18.0.1+1');
|
||||||
|
expect(result.url).toContain('/openjdk-18.0.1.1_linux-x64_bin.tar.gz');
|
||||||
|
});
|
||||||
|
|
||||||
it('resolves an early-access release without requesting the archive', async () => {
|
it('resolves an early-access release without requesting the archive', async () => {
|
||||||
const result =
|
const result =
|
||||||
await createDistribution('27-ea')['findPackageForDownload']('27');
|
await createDistribution('27-ea')['findPackageForDownload']('27');
|
||||||
@@ -148,6 +168,23 @@ describe('OpenJdkDistribution', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parses legacy platform names and archive formats', () => {
|
||||||
|
const distribution = createDistribution();
|
||||||
|
const macRelease = distribution['parseReleases'](
|
||||||
|
'<a href="https://download.java.net/java/GA/jdk16/hash/7/GPL/openjdk-16_osx-x64_bin.tar.gz">tar.gz</a>',
|
||||||
|
'macos',
|
||||||
|
'x64'
|
||||||
|
);
|
||||||
|
const windowsRelease = distribution['parseReleases'](
|
||||||
|
'<a href="https://download.java.net/java/GA/jdk10/hash/13/GPL/openjdk-10_windows-x64_bin.tar.gz">tar.gz</a>',
|
||||||
|
'windows',
|
||||||
|
'x64'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(macRelease[0].version).toBe('16.0.0+7');
|
||||||
|
expect(windowsRelease[0].url.endsWith('.tar.gz')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('is registered in the distribution factory', () => {
|
it('is registered in the distribution factory', () => {
|
||||||
const distribution = getJavaDistribution('openjdk', {
|
const distribution = getJavaDistribution('openjdk', {
|
||||||
version: '26',
|
version: '26',
|
||||||
|
|||||||
Vendored
+18
-13
@@ -131909,8 +131909,8 @@ class OpenJdkDistribution extends JavaBase {
|
|||||||
info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
info(`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`);
|
||||||
let javaArchivePath = await downloadTool(javaRelease.url);
|
let javaArchivePath = await downloadTool(javaRelease.url);
|
||||||
info(`Extracting Java archive...`);
|
info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = javaRelease.url.endsWith('.zip') ? 'zip' : 'tar.gz';
|
||||||
if (process.platform === 'win32') {
|
if (extension === 'zip') {
|
||||||
javaArchivePath = renameWinArchive(javaArchivePath);
|
javaArchivePath = renameWinArchive(javaArchivePath);
|
||||||
}
|
}
|
||||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||||
@@ -131934,18 +131934,23 @@ class OpenJdkDistribution extends JavaBase {
|
|||||||
return response.readBody();
|
return response.readBody();
|
||||||
}
|
}
|
||||||
parseReleases(html, platform, arch) {
|
parseReleases(html, platform, arch) {
|
||||||
const extension = platform === 'windows' ? 'zip' : 'tar.gz';
|
const platformPattern = platform === 'macos' ? '(?:macos|osx)' : platform;
|
||||||
const pattern = new RegExp(`href="(https://download\\.java\\.net/[^"]+/openjdk-([^"_]+)_${platform}-${arch}_bin\\.${extension.replaceAll('.', '\\.')})"`, 'g');
|
const extensionPattern = platform === 'windows' ? '(?:zip|tar\\.gz)' : 'tar\\.gz';
|
||||||
return Array.from(html.matchAll(pattern), match => ({
|
const pattern = new RegExp(`href="(https://download\\.java\\.net/[^"]+/openjdk-([^"_]+)_${platformPattern}-${arch}_bin\\.${extensionPattern})"`, 'g');
|
||||||
version: this.toSemver(match[2]),
|
return Array.from(html.matchAll(pattern), match => {
|
||||||
url: match[1]
|
const url = match[1];
|
||||||
}));
|
const build = url.match(/\/(\d+)\/GPL\/openjdk-/)?.[1];
|
||||||
|
return {
|
||||||
|
version: this.toSemver(match[2], build),
|
||||||
|
url
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
toSemver(version) {
|
toSemver(version, urlBuild) {
|
||||||
const [javaVersion, build] = version.replace('-ea', '').split('+');
|
const [javaVersion, filenameBuild] = version.replace('-ea', '').split('+');
|
||||||
const normalizedVersion = javaVersion.includes('.')
|
const versionParts = javaVersion.split('.');
|
||||||
? javaVersion
|
const normalizedVersion = convertVersionToSemver(versionParts.length === 1 ? `${javaVersion}.0.0` : javaVersion);
|
||||||
: `${javaVersion}.0.0`;
|
const build = filenameBuild ?? (versionParts.length <= 3 ? urlBuild : undefined);
|
||||||
return build ? `${normalizedVersion}+${build}` : normalizedVersion;
|
return build ? `${normalizedVersion}+${build}` : normalizedVersion;
|
||||||
}
|
}
|
||||||
getPlatform(platform = process.platform) {
|
getPlatform(platform = process.platform) {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import {
|
|||||||
JavaInstallerResults
|
JavaInstallerResults
|
||||||
} from '../base-models.js';
|
} from '../base-models.js';
|
||||||
import {
|
import {
|
||||||
|
convertVersionToSemver,
|
||||||
extractJdkFile,
|
extractJdkFile,
|
||||||
getDownloadArchiveExtension,
|
|
||||||
isVersionSatisfies,
|
isVersionSatisfies,
|
||||||
renameWinArchive
|
renameWinArchive
|
||||||
} from '../../util.js';
|
} from '../../util.js';
|
||||||
@@ -62,8 +62,8 @@ export class OpenJdkDistribution extends JavaBase {
|
|||||||
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
let javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||||
|
|
||||||
core.info(`Extracting Java archive...`);
|
core.info(`Extracting Java archive...`);
|
||||||
const extension = getDownloadArchiveExtension();
|
const extension = javaRelease.url.endsWith('.zip') ? 'zip' : 'tar.gz';
|
||||||
if (process.platform === 'win32') {
|
if (extension === 'zip') {
|
||||||
javaArchivePath = renameWinArchive(javaArchivePath);
|
javaArchivePath = renameWinArchive(javaArchivePath);
|
||||||
}
|
}
|
||||||
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
const extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||||
@@ -116,23 +116,32 @@ export class OpenJdkDistribution extends JavaBase {
|
|||||||
platform: string,
|
platform: string,
|
||||||
arch: string
|
arch: string
|
||||||
): JavaDownloadRelease[] {
|
): JavaDownloadRelease[] {
|
||||||
const extension = platform === 'windows' ? 'zip' : 'tar.gz';
|
const platformPattern = platform === 'macos' ? '(?:macos|osx)' : platform;
|
||||||
|
const extensionPattern =
|
||||||
|
platform === 'windows' ? '(?:zip|tar\\.gz)' : 'tar\\.gz';
|
||||||
const pattern = new RegExp(
|
const pattern = new RegExp(
|
||||||
`href="(https://download\\.java\\.net/[^"]+/openjdk-([^"_]+)_${platform}-${arch}_bin\\.${extension.replaceAll('.', '\\.')})"`,
|
`href="(https://download\\.java\\.net/[^"]+/openjdk-([^"_]+)_${platformPattern}-${arch}_bin\\.${extensionPattern})"`,
|
||||||
'g'
|
'g'
|
||||||
);
|
);
|
||||||
|
|
||||||
return Array.from(html.matchAll(pattern), match => ({
|
return Array.from(html.matchAll(pattern), match => {
|
||||||
version: this.toSemver(match[2]),
|
const url = match[1];
|
||||||
url: match[1]
|
const build = url.match(/\/(\d+)\/GPL\/openjdk-/)?.[1];
|
||||||
}));
|
return {
|
||||||
|
version: this.toSemver(match[2], build),
|
||||||
|
url
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private toSemver(version: string): string {
|
private toSemver(version: string, urlBuild?: string): string {
|
||||||
const [javaVersion, build] = version.replace('-ea', '').split('+');
|
const [javaVersion, filenameBuild] = version.replace('-ea', '').split('+');
|
||||||
const normalizedVersion = javaVersion.includes('.')
|
const versionParts = javaVersion.split('.');
|
||||||
? javaVersion
|
const normalizedVersion = convertVersionToSemver(
|
||||||
: `${javaVersion}.0.0`;
|
versionParts.length === 1 ? `${javaVersion}.0.0` : javaVersion
|
||||||
|
);
|
||||||
|
const build =
|
||||||
|
filenameBuild ?? (versionParts.length <= 3 ? urlBuild : undefined);
|
||||||
return build ? `${normalizedVersion}+${build}` : normalizedVersion;
|
return build ? `${normalizedVersion}+${build}` : normalizedVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user