mirror of
https://github.com/actions/setup-java.git
synced 2025-04-21 02:16:45 +00:00
handle 4th digit
This commit is contained in:
parent
fb17d0223d
commit
408d6f3eea
8 changed files with 3172 additions and 86 deletions
|
@ -9,14 +9,14 @@ import { JavaBase } from '../base-installer';
|
|||
import { IAdoptiumAvailableVersions } from './models';
|
||||
import { JavaInstallerOptions, JavaDownloadRelease, JavaInstallerResults } from '../base-models';
|
||||
import { MACOS_JAVA_CONTENT_POSTFIX } from '../../constants';
|
||||
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
|
||||
export class AdoptiumDistribution extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Adoptium', installerOptions);
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const availableVersionsWithBinaries = availableVersionsRaw
|
||||
.filter(item => item.binaries.length > 0)
|
||||
|
@ -28,7 +28,7 @@ export class AdoptiumDistribution extends JavaBase {
|
|||
});
|
||||
|
||||
const satisfiedVersions = availableVersionsWithBinaries
|
||||
.filter(item => semver.satisfies(item.version, version))
|
||||
.filter(item => isVersionSatisfies(version, item.version))
|
||||
.sort((a, b) => {
|
||||
return -semver.compareBuild(a.version, b.version);
|
||||
});
|
||||
|
@ -40,7 +40,7 @@ export class AdoptiumDistribution extends JavaBase {
|
|||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
throw new Error(
|
||||
`Could not find satisfied version for SemVer '${version.raw}'. ${availableOptionsMessage}`
|
||||
`Could not find satisfied version for SemVer '${version}'. ${availableOptionsMessage}`
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,7 @@ export class AdoptiumDistribution extends JavaBase {
|
|||
const platform = this.getPlatformOption();
|
||||
const arch = this.architecture;
|
||||
const imageType = this.packageType;
|
||||
const versionRange = '[1.0,100.0]'; // retrieve all available versions
|
||||
const encodedVersionRange = encodeURI(versionRange);
|
||||
const versionRange = encodeURI('[1.0,100.0]'); // retrieve all available versions
|
||||
const releaseType = this.stable ? 'ga' : 'ea';
|
||||
|
||||
console.time('adopt-retrieve-available-versions');
|
||||
|
@ -103,7 +102,7 @@ export class AdoptiumDistribution extends JavaBase {
|
|||
const availableVersions: IAdoptiumAvailableVersions[] = [];
|
||||
while (true) {
|
||||
const requestArguments = `${baseRequestArguments}&page_size=20&page=${page_index}`;
|
||||
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${encodedVersionRange}?${requestArguments}`;
|
||||
const availableVersionsUrl = `https://api.adoptopenjdk.net/v3/assets/version/${versionRange}?${requestArguments}`;
|
||||
if (core.isDebug() && page_index === 0) {
|
||||
// url is identical except page_index so print it once for debug
|
||||
core.debug(`Gathering available versions from '${availableVersionsUrl}'`);
|
||||
|
|
|
@ -3,12 +3,12 @@ import * as core from '@actions/core';
|
|||
import semver from 'semver';
|
||||
import path from 'path';
|
||||
import * as httpm from '@actions/http-client';
|
||||
import { getVersionFromToolcachePath } from '../util';
|
||||
import { getToolcachePath, getVersionFromToolcachePath, isVersionSatisfies } from '../util';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from './base-models';
|
||||
|
||||
export abstract class JavaBase {
|
||||
protected http: httpm.HttpClient;
|
||||
protected version: semver.Range;
|
||||
protected version: string;
|
||||
protected architecture: string;
|
||||
protected packageType: string;
|
||||
protected stable: boolean;
|
||||
|
@ -27,14 +27,14 @@ export abstract class JavaBase {
|
|||
}
|
||||
|
||||
protected abstract downloadTool(javaRelease: JavaDownloadRelease): Promise<JavaInstallerResults>;
|
||||
protected abstract findPackageForDownload(range: semver.Range): Promise<JavaDownloadRelease>;
|
||||
protected abstract findPackageForDownload(range: string): Promise<JavaDownloadRelease>;
|
||||
|
||||
public async setupJava(): Promise<JavaInstallerResults> {
|
||||
let foundJava = this.findInToolcache();
|
||||
if (foundJava) {
|
||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
} else {
|
||||
core.info(`Java ${this.version.raw} was not found in tool-cache. Trying to download...`);
|
||||
core.info(`Java ${this.version} was not found in tool-cache. Trying to download...`);
|
||||
const javaRelease = await this.findPackageForDownload(this.version);
|
||||
foundJava = await this.downloadTool(javaRelease);
|
||||
core.info(`Java ${foundJava.version} was downloaded`);
|
||||
|
@ -50,8 +50,7 @@ export abstract class JavaBase {
|
|||
return `Java_${this.distribution}_${this.packageType}`;
|
||||
}
|
||||
|
||||
protected getToolcacheVersionName(resolvedVersion: string): string {
|
||||
let version = resolvedVersion;
|
||||
protected getToolcacheVersionName(version: string): string {
|
||||
if (!this.stable) {
|
||||
const cleanVersion = semver.clean(version);
|
||||
return `${cleanVersion}-ea`;
|
||||
|
@ -67,13 +66,17 @@ export abstract class JavaBase {
|
|||
.filter(item => item.endsWith('-ea') === !this.stable);
|
||||
|
||||
const satisfiedVersions = availableVersions
|
||||
.filter(item => semver.satisfies(item.replace(/-ea$/, ''), this.version))
|
||||
.filter(item => isVersionSatisfies(this.version, item.replace(/-ea$/, '')))
|
||||
.sort(semver.rcompare);
|
||||
if (!satisfiedVersions || satisfiedVersions.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const javaPath = tc.find(this.toolcacheFolderName, satisfiedVersions[0], this.architecture);
|
||||
const javaPath = getToolcachePath(
|
||||
this.toolcacheFolderName,
|
||||
satisfiedVersions[0],
|
||||
this.architecture
|
||||
);
|
||||
if (!javaPath) {
|
||||
return null;
|
||||
}
|
||||
|
@ -84,21 +87,16 @@ export abstract class JavaBase {
|
|||
};
|
||||
}
|
||||
|
||||
protected setJavaDefault(version: string, toolPath: string) {
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
core.setOutput('distribution', this.distribution);
|
||||
core.setOutput('path', toolPath);
|
||||
core.setOutput('version', version);
|
||||
}
|
||||
|
||||
// this function validates and parse java version to its normal semver notation
|
||||
protected normalizeVersion(version: string) {
|
||||
let stable = true;
|
||||
|
||||
if (version.endsWith('-ea')) {
|
||||
version = version.replace(/-ea$/, '');
|
||||
stable = false;
|
||||
} else if (version.includes('-ea.')) {
|
||||
// transform '11.0.3-ea.2' -> '11.0.3+2'
|
||||
version = version.replace('-ea.', '+');
|
||||
stable = false;
|
||||
}
|
||||
|
||||
if (!semver.validRange(version)) {
|
||||
|
@ -108,8 +106,16 @@ export abstract class JavaBase {
|
|||
}
|
||||
|
||||
return {
|
||||
version: new semver.Range(version),
|
||||
version,
|
||||
stable
|
||||
};
|
||||
}
|
||||
|
||||
protected setJavaDefault(version: string, toolPath: string) {
|
||||
core.exportVariable('JAVA_HOME', toolPath);
|
||||
core.addPath(path.join(toolPath, 'bin'));
|
||||
core.setOutput('distribution', this.distribution);
|
||||
core.setOutput('path', toolPath);
|
||||
core.setOutput('version', version);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,7 @@ export class LocalDistribution extends JavaBase {
|
|||
if (foundJava) {
|
||||
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
} else {
|
||||
core.info(
|
||||
`Java ${this.version.raw} was not found in tool-cache. Trying to unpack JDK file...`
|
||||
);
|
||||
core.info(`Java ${this.version} was not found in tool-cache. Trying to unpack JDK file...`);
|
||||
if (!this.jdkFile) {
|
||||
throw new Error("'jdkFile' is not specified");
|
||||
}
|
||||
|
@ -39,7 +37,7 @@ export class LocalDistribution extends JavaBase {
|
|||
const extractedJavaPath = await extractJdkFile(jdkFilePath);
|
||||
const archiveName = fs.readdirSync(extractedJavaPath)[0];
|
||||
const archivePath = path.join(extractedJavaPath, archiveName);
|
||||
const javaVersion = this.version.raw;
|
||||
const javaVersion = this.version;
|
||||
|
||||
let javaPath = await tc.cacheDir(
|
||||
archivePath,
|
||||
|
@ -68,7 +66,7 @@ export class LocalDistribution extends JavaBase {
|
|||
return foundJava;
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
throw new Error('This method should not be implemented in local file provider');
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import semver from 'semver';
|
|||
|
||||
import { JavaBase } from '../base-installer';
|
||||
import { IZuluVersions } from './models';
|
||||
import { extractJdkFile, getDownloadArchiveExtension } from '../../util';
|
||||
import { extractJdkFile, getDownloadArchiveExtension, isVersionSatisfies } from '../../util';
|
||||
import { JavaDownloadRelease, JavaInstallerOptions, JavaInstallerResults } from '../base-models';
|
||||
|
||||
export class ZuluDistribution extends JavaBase {
|
||||
|
@ -15,7 +15,7 @@ export class ZuluDistribution extends JavaBase {
|
|||
super('Zulu', installerOptions);
|
||||
}
|
||||
|
||||
protected async findPackageForDownload(version: semver.Range): Promise<JavaDownloadRelease> {
|
||||
protected async findPackageForDownload(version: string): Promise<JavaDownloadRelease> {
|
||||
const availableVersionsRaw = await this.getAvailableVersions();
|
||||
const availableVersions = availableVersionsRaw.map(item => {
|
||||
return {
|
||||
|
@ -26,7 +26,7 @@ export class ZuluDistribution extends JavaBase {
|
|||
});
|
||||
|
||||
const satisfiedVersions = availableVersions
|
||||
.filter(item => semver.satisfies(item.version, version))
|
||||
.filter(item => isVersionSatisfies(version, item.version))
|
||||
.sort((a, b) => {
|
||||
// Azul provides two versions: jdk_version and azul_version
|
||||
// we should sort by both fields by descending
|
||||
|
@ -49,7 +49,7 @@ export class ZuluDistribution extends JavaBase {
|
|||
? `\nAvailable versions: ${availableOptions}`
|
||||
: '';
|
||||
throw new Error(
|
||||
`Could not find satisfied version for semver ${version.raw}. ${availableOptionsMessage}`
|
||||
`Could not find satisfied version for semver ${version}. ${availableOptionsMessage}`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue