mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 09:56:46 +00:00
Merge branch 'main' into ibm-semeru
This commit is contained in:
commit
a04857f594
34 changed files with 1654 additions and 380 deletions
|
@ -5,9 +5,10 @@ import * as core from '@actions/core';
|
|||
import os from 'os';
|
||||
|
||||
import * as auth from '../src/auth';
|
||||
import { M2_DIR, MVN_SETTINGS_FILE } from '../src/constants';
|
||||
|
||||
const m2Dir = path.join(__dirname, auth.M2_DIR);
|
||||
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);
|
||||
const m2Dir = path.join(__dirname, M2_DIR);
|
||||
const settingsFile = path.join(m2Dir, MVN_SETTINGS_FILE);
|
||||
|
||||
describe('auth tests', () => {
|
||||
let spyOSHomedir: jest.SpyInstance;
|
||||
|
@ -38,7 +39,7 @@ describe('auth tests', () => {
|
|||
const password = 'TOLKIEN';
|
||||
|
||||
const altHome = path.join(__dirname, 'runner', 'settings');
|
||||
const altSettingsFile = path.join(altHome, auth.SETTINGS_FILE);
|
||||
const altSettingsFile = path.join(altHome, MVN_SETTINGS_FILE);
|
||||
await io.rmRF(altHome); // ensure it doesn't already exist
|
||||
|
||||
await auth.createAuthenticationSettings(id, username, password, altHome, true);
|
||||
|
|
|
@ -98,7 +98,7 @@ describe('dependency cache', () => {
|
|||
await expect(restore('gradle')).rejects.toThrowError(
|
||||
`No file in ${projectRoot(
|
||||
workspace
|
||||
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt], make sure you have checked out the target repository`
|
||||
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt,gradle/*.versions.toml], make sure you have checked out the target repository`
|
||||
);
|
||||
});
|
||||
it('downloads cache based on build.gradle', async () => {
|
||||
|
@ -112,6 +112,15 @@ describe('dependency cache', () => {
|
|||
it('downloads cache based on build.gradle.kts', async () => {
|
||||
createFile(join(workspace, 'build.gradle.kts'));
|
||||
|
||||
await restore('gradle');
|
||||
expect(spyCacheRestore).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
||||
});
|
||||
it('downloads cache based on libs.versions.toml', async () => {
|
||||
createDirectory(join(workspace, 'gradle'));
|
||||
createFile(join(workspace, 'gradle', 'libs.versions.toml'));
|
||||
|
||||
await restore('gradle');
|
||||
expect(spyCacheRestore).toBeCalled();
|
||||
expect(spyWarning).not.toBeCalled();
|
||||
|
|
|
@ -3,6 +3,8 @@ import { HttpClient } from '@actions/http-client';
|
|||
import { AdoptDistribution, AdoptImplementation } from '../../src/distributions/adopt/installer';
|
||||
import { JavaInstallerOptions } from '../../src/distributions/base-models';
|
||||
|
||||
import os from 'os';
|
||||
|
||||
let manifestData = require('../data/adopt.json') as [];
|
||||
|
||||
describe('getAvailableVersions', () => {
|
||||
|
@ -128,6 +130,35 @@ describe('getAvailableVersions', () => {
|
|||
expect(distribution.toolcacheFolderName).toBe(expected);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
['amd64', 'x64'],
|
||||
['arm64', 'aarch64']
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: string) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
version: '17',
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
};
|
||||
|
||||
const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`;
|
||||
|
||||
const distribution = new AdoptDistribution(installerOptions, AdoptImplementation.Hotspot);
|
||||
const baseUrl = 'https://api.adoptopenjdk.net/v3/assets/version/%5B1.0,100.0%5D';
|
||||
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptopenjdk&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
|
||||
distribution['getPlatformOption'] = () => 'mac';
|
||||
|
||||
await distribution['getAvailableVersions']();
|
||||
|
||||
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
|
|
|
@ -12,6 +12,8 @@ import {
|
|||
JavaInstallerResults
|
||||
} from '../../src/distributions/base-models';
|
||||
|
||||
import os from 'os';
|
||||
|
||||
class EmptyJavaBase extends JavaBase {
|
||||
constructor(installerOptions: JavaInstallerOptions) {
|
||||
super('Empty', installerOptions);
|
||||
|
@ -192,6 +194,8 @@ describe('setupJava', () => {
|
|||
|
||||
spyCoreSetOutput = jest.spyOn(core, 'setOutput');
|
||||
spyCoreSetOutput.mockImplementation(() => undefined);
|
||||
|
||||
jest.spyOn(os, 'arch').mockReturnValue('x86');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -212,6 +216,10 @@ describe('setupJava', () => {
|
|||
[
|
||||
{ version: '11.0.8', architecture: 'x86', packageType: 'jdk', checkLatest: false },
|
||||
{ version: installedJavaVersion, path: javaPath }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: '', packageType: 'jdk', checkLatest: false },
|
||||
{ version: installedJavaVersion, path: javaPath }
|
||||
]
|
||||
])('should find java locally for %s', (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
|
@ -237,6 +245,10 @@ describe('setupJava', () => {
|
|||
[
|
||||
{ version: '11', architecture: 'x64', packageType: 'jre', checkLatest: false },
|
||||
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x64'), version: '11.0.9' }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: '', packageType: 'jre', checkLatest: false },
|
||||
{ path: path.join('toolcache', 'Java_Empty_jre', '11.0.9', 'x86'), version: '11.0.9' }
|
||||
]
|
||||
])('download java with configuration %s', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
|
@ -245,7 +257,7 @@ describe('setupJava', () => {
|
|||
expect(spyCoreAddPath).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalled();
|
||||
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||
`JAVA_HOME_${input.version}_${input.architecture.toLocaleUpperCase()}`,
|
||||
`JAVA_HOME_${input.version}_${(input.architecture || 'x86').toLocaleUpperCase()}`,
|
||||
expected.path
|
||||
);
|
||||
expect(spyCoreSetOutput).toHaveBeenCalled();
|
||||
|
@ -260,6 +272,10 @@ describe('setupJava', () => {
|
|||
[
|
||||
{ version: '11.0.9', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||
{ version: '11.0.9', path: javaPathInstalled }
|
||||
],
|
||||
[
|
||||
{ version: '11.0.9', architecture: '', packageType: 'jdk', checkLatest: true },
|
||||
{ version: '11.0.9', path: javaPathInstalled }
|
||||
]
|
||||
])('should check the latest java version for %s and resolve locally', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
|
@ -283,6 +299,10 @@ describe('setupJava', () => {
|
|||
[
|
||||
{ version: '11.0.x', architecture: 'x86', packageType: 'jdk', checkLatest: true },
|
||||
{ version: actualJavaVersion, path: javaPathInstalled }
|
||||
],
|
||||
[
|
||||
{ version: '11', architecture: '', packageType: 'jdk', checkLatest: true },
|
||||
{ version: actualJavaVersion, path: javaPathInstalled }
|
||||
]
|
||||
])('should check the latest java version for %s and download', async (input, expected) => {
|
||||
mockJavaBase = new EmptyJavaBase(input);
|
||||
|
|
|
@ -3,6 +3,8 @@ import { JavaInstallerOptions } from '../../src/distributions/base-models';
|
|||
|
||||
import { CorrettoDistribution } from '../../src/distributions/corretto/installer';
|
||||
import * as util from '../../src/util';
|
||||
import os from 'os';
|
||||
import { isGeneratorFunction } from 'util/types';
|
||||
|
||||
const manifestData = require('../data/corretto.json') as [];
|
||||
|
||||
|
@ -142,6 +144,33 @@ describe('getAvailableVersions', () => {
|
|||
"Could not find satisfied version for SemVer '4'"
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['arm64', 'aarch64'],
|
||||
['amd64', 'x64']
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: string) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
|
||||
const version = '17';
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
version,
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
};
|
||||
|
||||
const distribution = new CorrettoDistribution(installerOptions);
|
||||
mockPlatform(distribution, 'macos');
|
||||
|
||||
const expectedLink = `https://corretto.aws/downloads/resources/17.0.2.8.1/amazon-corretto-17.0.2.8.1-macosx-${distroArch}.tar.gz`;
|
||||
|
||||
const availableVersion = await distribution['findPackageForDownload'](version);
|
||||
expect(availableVersion).not.toBeNull();
|
||||
expect(availableVersion.url).toBe(expectedLink);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const mockPlatform = (distribution: CorrettoDistribution, platform: string) => {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { LibericaDistributions } from '../../src/distributions/liberica/installer';
|
||||
import { ArchitectureOptions, LibericaVersion } from '../../src/distributions/liberica/models';
|
||||
import { HttpClient } from '@actions/http-client';
|
||||
import os from 'os';
|
||||
|
||||
const manifestData = require('../data/liberica.json') as LibericaVersion[];
|
||||
|
||||
|
@ -61,6 +62,39 @@ describe('getAvailableVersions', () => {
|
|||
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
|
||||
});
|
||||
|
||||
type DistroArch = {
|
||||
bitness: string;
|
||||
arch: string;
|
||||
};
|
||||
it.each([
|
||||
['amd64', { bitness: '64', arch: 'x86' }],
|
||||
['arm64', { bitness: '64', arch: 'arm' }]
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: DistroArch) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
|
||||
const distribution = new LibericaDistributions({
|
||||
version: '17',
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
|
||||
const additionalParams =
|
||||
'&installation-type=archive&fields=downloadUrl%2Cversion%2CfeatureVersion%2CinterimVersion%2C' +
|
||||
'updateVersion%2CbuildVersion';
|
||||
distribution['getPlatformOption'] = () => 'macos';
|
||||
|
||||
const buildUrl = `https://api.bell-sw.com/v1/liberica/releases?os=macos&bundle-type=jdk&bitness=${distroArch.bitness}&arch=${distroArch.arch}&build-type=all${additionalParams}`;
|
||||
|
||||
await distribution['getAvailableVersions']();
|
||||
|
||||
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
|
||||
}
|
||||
);
|
||||
|
||||
it('load available versions', async () => {
|
||||
const distribution = new LibericaDistributions({
|
||||
version: '11',
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
import { MicrosoftDistributions } from '../../src/distributions/microsoft/installer';
|
||||
import os from 'os';
|
||||
import data from '../../src/distributions/microsoft/microsoft-openjdk-versions.json';
|
||||
import * as httpm from '@actions/http-client';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
let distribution: MicrosoftDistributions;
|
||||
let spyGetManifestFromRepo: jest.SpyInstance;
|
||||
let spyDebug: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
distribution = new MicrosoftDistributions({
|
||||
|
@ -10,12 +16,22 @@ describe('findPackageForDownload', () => {
|
|||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
|
||||
spyGetManifestFromRepo = jest.spyOn(httpm.HttpClient.prototype, 'getJson');
|
||||
spyGetManifestFromRepo.mockReturnValue({
|
||||
result: data,
|
||||
statusCode: 200,
|
||||
headers: {}
|
||||
});
|
||||
|
||||
spyDebug = jest.spyOn(core, 'debug');
|
||||
spyDebug.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
'17.0.1',
|
||||
'17.0.1',
|
||||
'17.0.1+12.1',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-17.0.1.12.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
|
@ -25,12 +41,12 @@ describe('findPackageForDownload', () => {
|
|||
],
|
||||
[
|
||||
'16.0.x',
|
||||
'16.0.2',
|
||||
'16.0.2+7.1',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-16.0.2.7.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
'11.0.13',
|
||||
'11.0.13',
|
||||
'11.0.13+8.1',
|
||||
'https://aka.ms/download-jdk/microsoft-jdk-11.0.13.8.1-{{OS_TYPE}}-x64.{{ARCHIVE_TYPE}}'
|
||||
],
|
||||
[
|
||||
|
@ -61,38 +77,33 @@ describe('findPackageForDownload', () => {
|
|||
expect(result.url).toBe(url);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['amd64', 'x64'],
|
||||
['arm64', 'aarch64']
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: string) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
jest.spyOn(os, 'platform').mockReturnValue('linux');
|
||||
|
||||
const version = '17';
|
||||
const distro = new MicrosoftDistributions({
|
||||
version,
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
|
||||
const result = await distro['findPackageForDownload'](version);
|
||||
const expectedUrl = `https://aka.ms/download-jdk/microsoft-jdk-17.0.3-linux-${distroArch}.tar.gz`;
|
||||
|
||||
expect(result.url).toBe(expectedUrl);
|
||||
}
|
||||
);
|
||||
|
||||
it('should throw an error', async () => {
|
||||
await expect(distribution['findPackageForDownload']('8')).rejects.toThrow(
|
||||
/Could not find satisfied version for SemVer */
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPlatformOption', () => {
|
||||
const distributions = new MicrosoftDistributions({
|
||||
architecture: 'x64',
|
||||
version: '11',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
|
||||
it.each([
|
||||
['linux', 'tar.gz', 'linux'],
|
||||
['darwin', 'tar.gz', 'macos'],
|
||||
['win32', 'zip', 'windows']
|
||||
])('os version %s -> %s', (input, expectedArchive, expectedOs) => {
|
||||
const actual = distributions['getPlatformOption'](input as NodeJS.Platform);
|
||||
|
||||
expect(actual.archive).toEqual(expectedArchive);
|
||||
expect(actual.os).toEqual(expectedOs);
|
||||
});
|
||||
|
||||
it.each(['aix', 'android', 'freebsd', 'openbsd', 'netbsd', 'solaris', 'cygwin'])(
|
||||
'not support os version %s',
|
||||
input => {
|
||||
expect(() => distributions['getPlatformOption'](input as NodeJS.Platform)).toThrow(
|
||||
/Platform '\w+' is not supported\. Supported platforms: .+/
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { HttpClient } from '@actions/http-client';
|
||||
|
||||
import os from 'os';
|
||||
import {
|
||||
TemurinDistribution,
|
||||
TemurinImplementation
|
||||
|
@ -109,6 +109,35 @@ describe('getAvailableVersions', () => {
|
|||
expect(distribution.toolcacheFolderName).toBe(expected);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
['amd64', 'x64'],
|
||||
['arm64', 'aarch64']
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: string) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(distroArch);
|
||||
|
||||
const installerOptions: JavaInstallerOptions = {
|
||||
version: '17',
|
||||
architecture: '',
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
};
|
||||
|
||||
const expectedParameters = `os=mac&architecture=${distroArch}&image_type=jdk&release_type=ga&jvm_impl=hotspot&page_size=20&page=0`;
|
||||
|
||||
const distribution = new TemurinDistribution(installerOptions, TemurinImplementation.Hotspot);
|
||||
const baseUrl = 'https://api.adoptium.net/v3/assets/version/%5B1.0,100.0%5D';
|
||||
const expectedUrl = `${baseUrl}?project=jdk&vendor=adoptium&heap_size=normal&sort_method=DEFAULT&sort_order=DESC&${expectedParameters}`;
|
||||
distribution['getPlatformOption'] = () => 'mac';
|
||||
|
||||
await distribution['getAvailableVersions']();
|
||||
|
||||
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(expectedUrl);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('findPackageForDownload', () => {
|
||||
|
|
|
@ -3,6 +3,7 @@ import * as semver from 'semver';
|
|||
import { ZuluDistribution } from '../../src/distributions/zulu/installer';
|
||||
import { IZuluVersions } from '../../src/distributions/zulu/models';
|
||||
import * as utils from '../../src/util';
|
||||
import os from 'os';
|
||||
|
||||
const manifestData = require('../data/zulu-releases-default.json') as [];
|
||||
|
||||
|
@ -72,6 +73,34 @@ describe('getAvailableVersions', () => {
|
|||
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
|
||||
});
|
||||
|
||||
type DistroArch = {
|
||||
bitness: string;
|
||||
arch: string;
|
||||
};
|
||||
it.each([
|
||||
['amd64', { bitness: '64', arch: 'x86' }],
|
||||
['arm64', { bitness: '64', arch: 'arm' }]
|
||||
])(
|
||||
'defaults to os.arch(): %s mapped to distro arch: %s',
|
||||
async (osArch: string, distroArch: DistroArch) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
|
||||
const distribution = new ZuluDistribution({
|
||||
version: '17',
|
||||
architecture: '', // to get default value
|
||||
packageType: 'jdk',
|
||||
checkLatest: false
|
||||
});
|
||||
distribution['getPlatformOption'] = () => 'macos';
|
||||
const buildUrl = `https://api.azul.com/zulu/download/community/v1.0/bundles/?os=macos&ext=tar.gz&bundle_type=jdk&javafx=false&arch=${distroArch.arch}&hw_bitness=${distroArch.bitness}&release_status=ga`;
|
||||
|
||||
await distribution['getAvailableVersions']();
|
||||
|
||||
expect(spyHttpClient.mock.calls).toHaveLength(1);
|
||||
expect(spyHttpClient.mock.calls[0][0]).toBe(buildUrl);
|
||||
}
|
||||
);
|
||||
|
||||
it('load available versions', async () => {
|
||||
const distribution = new ZuluDistribution({
|
||||
version: '11',
|
||||
|
|
292
__tests__/toolchains.test.ts
Normal file
292
__tests__/toolchains.test.ts
Normal file
|
@ -0,0 +1,292 @@
|
|||
import * as fs from 'fs';
|
||||
import os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import * as toolchains from '../src/toolchains';
|
||||
import { M2_DIR, MVN_TOOLCHAINS_FILE } from '../src/constants';
|
||||
|
||||
const m2Dir = path.join(__dirname, M2_DIR);
|
||||
const toolchainsFile = path.join(m2Dir, MVN_TOOLCHAINS_FILE);
|
||||
|
||||
describe('toolchains tests', () => {
|
||||
let spyOSHomedir: jest.SpyInstance;
|
||||
let spyInfo: jest.SpyInstance;
|
||||
|
||||
beforeEach(async () => {
|
||||
await io.rmRF(m2Dir);
|
||||
spyOSHomedir = jest.spyOn(os, 'homedir');
|
||||
spyOSHomedir.mockReturnValue(__dirname);
|
||||
spyInfo = jest.spyOn(core, 'info');
|
||||
spyInfo.mockImplementation(() => null);
|
||||
}, 300000);
|
||||
|
||||
afterAll(async () => {
|
||||
try {
|
||||
await io.rmRF(m2Dir);
|
||||
} catch {
|
||||
console.log('Failed to remove test directories');
|
||||
}
|
||||
jest.resetAllMocks();
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
}, 100000);
|
||||
|
||||
it('creates toolchains.xml in alternate locations', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
};
|
||||
|
||||
const altHome = path.join(__dirname, 'runner', 'toolchains');
|
||||
const altToolchainsFile = path.join(altHome, MVN_TOOLCHAINS_FILE);
|
||||
await io.rmRF(altHome); // ensure it doesn't already exist
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: altHome,
|
||||
overwriteSettings: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(false);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(false);
|
||||
|
||||
expect(fs.existsSync(altHome)).toBe(true);
|
||||
expect(fs.existsSync(altToolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(altToolchainsFile, 'utf-8')).toEqual(
|
||||
toolchains.generateToolchainDefinition(
|
||||
'',
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
);
|
||||
|
||||
await io.rmRF(altHome);
|
||||
}, 100000);
|
||||
|
||||
it('creates toolchains.xml with minimal configuration', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
};
|
||||
|
||||
const result = `<?xml version="1.0"?>
|
||||
<toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>17</version>
|
||||
<vendor>Eclipse Temurin</vendor>
|
||||
<id>temurin_17</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||
toolchains.generateToolchainDefinition(
|
||||
'',
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
);
|
||||
expect(
|
||||
toolchains.generateToolchainDefinition(
|
||||
'',
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
).toEqual(result);
|
||||
}, 100000);
|
||||
|
||||
it('reuses existing toolchains.xml files', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
};
|
||||
|
||||
const originalFile = `<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.6</version>
|
||||
<vendor>Sun</vendor>
|
||||
<id>sun_1.6</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
const result = `<?xml version="1.0"?>
|
||||
<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.6</version>
|
||||
<vendor>Sun</vendor>
|
||||
<id>sun_1.6</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>17</version>
|
||||
<vendor>Eclipse Temurin</vendor>
|
||||
<id>temurin_17</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
|
||||
fs.mkdirSync(m2Dir, { recursive: true });
|
||||
fs.writeFileSync(toolchainsFile, originalFile);
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: true
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||
toolchains.generateToolchainDefinition(
|
||||
originalFile,
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
);
|
||||
expect(
|
||||
toolchains.generateToolchainDefinition(
|
||||
originalFile,
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
).toEqual(result);
|
||||
}, 100000);
|
||||
|
||||
it('does not overwrite existing toolchains.xml files', async () => {
|
||||
const jdkInfo = {
|
||||
version: '17',
|
||||
vendor: 'Eclipse Temurin',
|
||||
id: 'temurin_17',
|
||||
jdkHome: '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64'
|
||||
};
|
||||
|
||||
const originalFile = `<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>1.6</version>
|
||||
<vendor>Sun</vendor>
|
||||
<id>sun_1.6</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>/opt/jdk/sun/1.6</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
|
||||
fs.mkdirSync(m2Dir, { recursive: true });
|
||||
fs.writeFileSync(toolchainsFile, originalFile);
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
|
||||
await toolchains.createToolchainsSettings({
|
||||
jdkInfo,
|
||||
settingsDirectory: m2Dir,
|
||||
overwriteSettings: false
|
||||
});
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(originalFile);
|
||||
}, 100000);
|
||||
|
||||
it('generates valid toolchains.xml with minimal configuration', () => {
|
||||
const jdkInfo = {
|
||||
version: 'JAVA_VERSION',
|
||||
vendor: 'JAVA_VENDOR',
|
||||
id: 'VENDOR_VERSION',
|
||||
jdkHome: 'JAVA_HOME'
|
||||
};
|
||||
|
||||
const expectedToolchains = `<?xml version="1.0"?>
|
||||
<toolchains xmlns="https://maven.apache.org/TOOLCHAINS/1.1.0"
|
||||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://maven.apache.org/TOOLCHAINS/1.1.0 https://maven.apache.org/xsd/toolchains-1.1.0.xsd">
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>${jdkInfo.version}</version>
|
||||
<vendor>${jdkInfo.vendor}</vendor>
|
||||
<id>${jdkInfo.id}</id>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>${jdkInfo.jdkHome}</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>`;
|
||||
|
||||
expect(
|
||||
toolchains.generateToolchainDefinition(
|
||||
'',
|
||||
jdkInfo.version,
|
||||
jdkInfo.vendor,
|
||||
jdkInfo.id,
|
||||
jdkInfo.jdkHome
|
||||
)
|
||||
).toEqual(expectedToolchains);
|
||||
}, 100000);
|
||||
|
||||
it('creates toolchains.xml with correct id when none is supplied', async () => {
|
||||
const version = '17';
|
||||
const distributionName = 'temurin';
|
||||
const id = 'temurin_17';
|
||||
const jdkHome = '/opt/hostedtoolcache/Java_Temurin-Hotspot_jdk/17.0.1-12/x64';
|
||||
|
||||
await toolchains.configureToolchains(version, distributionName, jdkHome, undefined);
|
||||
|
||||
expect(fs.existsSync(m2Dir)).toBe(true);
|
||||
expect(fs.existsSync(toolchainsFile)).toBe(true);
|
||||
expect(fs.readFileSync(toolchainsFile, 'utf-8')).toEqual(
|
||||
toolchains.generateToolchainDefinition('', version, distributionName, id, jdkHome)
|
||||
);
|
||||
}, 100000);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue