mirror of
https://github.com/actions/setup-java.git
synced 2025-04-22 02:46:46 +00:00
Add fix for major coretto version and ea. (#1)
* Fix typo in README.md (#419)
`diractory` -> `directory`
* Revert "Add support for Oracle JDK (#401)" (#421)
This reverts commit 6cdf39a6b6
.
Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
* adding check for prerelease
* add debug lines
* add minor fix
* expand e2e tests with corretto
Co-authored-by: Ashley <73482956+ascopes@users.noreply.github.com>
Co-authored-by: Brian Cristante <33549821+brcrista@users.noreply.github.com>
This commit is contained in:
parent
10d2aa6bfd
commit
a7975de1a7
12 changed files with 7373 additions and 7726 deletions
|
@ -7,7 +7,6 @@ import { TemurinDistribution, TemurinImplementation } from './temurin/installer'
|
|||
import { LibericaDistributions } from './liberica/installer';
|
||||
import { MicrosoftDistributions } from './microsoft/installer';
|
||||
import { CorrettoDistribution } from './corretto/installer';
|
||||
import { OracleDistribution } from './oracle/installer';
|
||||
|
||||
enum JavaDistribution {
|
||||
Adopt = 'adopt',
|
||||
|
@ -18,8 +17,7 @@ enum JavaDistribution {
|
|||
Liberica = 'liberica',
|
||||
JdkFile = 'jdkfile',
|
||||
Microsoft = 'microsoft',
|
||||
Corretto = 'corretto',
|
||||
Oracle = 'oracle'
|
||||
Corretto = 'corretto'
|
||||
}
|
||||
|
||||
export function getJavaDistribution(
|
||||
|
@ -45,8 +43,6 @@ export function getJavaDistribution(
|
|||
return new MicrosoftDistributions(installerOptions);
|
||||
case JavaDistribution.Corretto:
|
||||
return new CorrettoDistribution(installerOptions);
|
||||
case JavaDistribution.Oracle:
|
||||
return new OracleDistribution(installerOptions);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { JavaBase } from '../base-installer';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
|
||||
import { HttpCodes } from '@actions/http-client';
|
||||
|
||||
const ORACLE_DL_BASE = 'https://download.oracle.com/java';
|
||||
|
||||
export class OracleDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Oracle', installerOptions);
|
||||
}
|
||||
|
||||
protected async downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults> {
|
||||
core.info(
|
||||
`Downloading Java ${javaRelease.version} (${this.distribution}) from ${javaRelease.url} ...`
|
||||
);
|
||||
const javaArchivePath = await tc.downloadTool(javaRelease.url);
|
||||
|
||||
core.info(`Extracting Java archive...`);
|
||||
let extension = getDownloadArchiveExtension();
|
||||
|
||||
let extractedJavaPath = await extractJdkFile(javaArchivePath, extension);
|
||||
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const version = this.getToolcacheVersionName(javaRelease.version);
|
||||
|
||||
let javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
this.toolcacheFolderName,
|
||||
version,
|
||||
this.architecture
|
||||
);
|
||||
|
||||
return { version: javaRelease.version, path: javaPath };
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(range: string): Promise<JavaDownloadRelease> {
|
||||
const arch = this.distributionArchitecture();
|
||||
if (arch !== 'x64' && arch !== 'aarch64') {
|
||||
throw new Error(`Unsupported architecture: ${this.architecture}`);
|
||||
}
|
||||
|
||||
if (!this.stable) {
|
||||
throw new Error('Early access versions are not supported');
|
||||
}
|
||||
|
||||
if (this.packageType !== 'jdk') {
|
||||
throw new Error('Oracle JDK provides only the `jdk` package type');
|
||||
}
|
||||
|
||||
const platform = this.getPlatform();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
let major;
|
||||
let fileUrl;
|
||||
if (range.includes('.')) {
|
||||
major = range.split('.')[0];
|
||||
fileUrl = `${ORACLE_DL_BASE}/${major}/archive/jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
||||
} else {
|
||||
major = range;
|
||||
fileUrl = `${ORACLE_DL_BASE}/${range}/latest/jdk-${range}_${platform}-${arch}_bin.${extension}`;
|
||||
}
|
||||
|
||||
if (parseInt(major) < 17) {
|
||||
throw new Error('Oracle JDK is only supported for JDK 17 and later');
|
||||
}
|
||||
|
||||
const response = await this.http.head(fileUrl);
|
||||
|
||||
if (response.message.statusCode === HttpCodes.NotFound) {
|
||||
throw new Error(`Could not find Oracle JDK for SemVer ${range}`);
|
||||
}
|
||||
|
||||
if (response.message.statusCode !== HttpCodes.OK) {
|
||||
throw new Error(
|
||||
`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`
|
||||
);
|
||||
}
|
||||
|
||||
return { url: fileUrl, version: range };
|
||||
}
|
||||
|
||||
public getPlatform(platform: NodeJS.Platform = process.platform): OsVersions {
|
||||
switch (platform) {
|
||||
case 'darwin':
|
||||
return 'macos';
|
||||
case 'win32':
|
||||
return 'windows';
|
||||
case 'linux':
|
||||
return 'linux';
|
||||
default:
|
||||
throw new Error(
|
||||
`Platform '${platform}' is not supported. Supported platforms: 'linux', 'macos', 'windows'`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
export type OsVersions = 'linux' | 'macos' | 'windows';
|
|
@ -1,12 +1,7 @@
|
|||
import fs from 'fs';
|
||||
import * as core from '@actions/core';
|
||||
import * as auth from './auth';
|
||||
import {
|
||||
getBooleanInput,
|
||||
isCacheFeatureAvailable,
|
||||
getVersionFromFileContent,
|
||||
avoidOldNotation
|
||||
} from './util';
|
||||
import { getBooleanInput, isCacheFeatureAvailable, getVersionFromFileContent } from './util';
|
||||
import * as toolchains from './toolchains';
|
||||
import * as constants from './constants';
|
||||
import { restore } from './cache';
|
||||
|
@ -53,12 +48,13 @@ async function run() {
|
|||
.trim();
|
||||
|
||||
const version = getVersionFromFileContent(content, distributionName);
|
||||
core.debug(`Parsed version from file '${version}'`);
|
||||
|
||||
if (!version) {
|
||||
throw new Error(`No supported version was found in file ${versionFile}`);
|
||||
}
|
||||
|
||||
await installVersion(version as string, installerInputsOptions);
|
||||
await installVersion(version, installerInputsOptions);
|
||||
}
|
||||
|
||||
for (const [index, version] of versions.entries()) {
|
||||
|
|
17
src/util.ts
17
src/util.ts
|
@ -111,24 +111,29 @@ export function getVersionFromFileContent(
|
|||
if (!fileContent) {
|
||||
return null;
|
||||
}
|
||||
const tentativeVersion = avoidOldNotation(fileContent);
|
||||
|
||||
let version = semver.validRange(tentativeVersion)
|
||||
? tentativeVersion
|
||||
: semver.coerce(tentativeVersion);
|
||||
core.debug(`Version from file '${fileContent}'`);
|
||||
|
||||
const tentativeVersion = avoidOldNotation(fileContent);
|
||||
const rawVersion = tentativeVersion.split('-')[0];
|
||||
|
||||
let version = semver.validRange(rawVersion) ? tentativeVersion : semver.coerce(tentativeVersion);
|
||||
|
||||
core.debug(`Range version from file is '${version}'`);
|
||||
|
||||
if (!version) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
||||
version = semver.major(version).toString();
|
||||
const coerceVersion = semver.coerce(version) ?? version;
|
||||
version = semver.major(coerceVersion).toString();
|
||||
}
|
||||
|
||||
return version.toString();
|
||||
}
|
||||
|
||||
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
|
||||
export function avoidOldNotation(content: string): string {
|
||||
function avoidOldNotation(content: string): string {
|
||||
return content.startsWith('1.') ? content.substring(2) : content;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue