mirror of
https://github.com/actions/setup-java.git
synced 2025-04-19 17:36:45 +00:00
Tests and pathing
This commit is contained in:
parent
02c1a8e374
commit
72c20b3e34
3 changed files with 41 additions and 3 deletions
|
@ -51,7 +51,7 @@ describe('installer tests', () => {
|
||||||
}
|
}
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
it('Acquires version of Java if no matching version is installed', async () => {
|
it('Installs version of Java from jdkFile if no matching version is installed', async () => {
|
||||||
await installer.getJava('12', 'x64', javaFilePath);
|
await installer.getJava('12', 'x64', javaFilePath);
|
||||||
const JavaDir = path.join(toolDir, 'Java', '12.0.0', 'x64');
|
const JavaDir = path.join(toolDir, 'Java', '12.0.0', 'x64');
|
||||||
|
|
||||||
|
@ -69,6 +69,24 @@ describe('installer tests', () => {
|
||||||
expect(thrown).toBe(true);
|
expect(thrown).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Downloads java if no file given', async () => {
|
||||||
|
await installer.getJava('8.0.102', 'x64', '');
|
||||||
|
const JavaDir = path.join(toolDir, 'Java', '8.0.102', 'x64');
|
||||||
|
|
||||||
|
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
|
||||||
|
expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true);
|
||||||
|
}, 100000);
|
||||||
|
|
||||||
|
it('Throws if invalid directory to jdk', async () => {
|
||||||
|
let thrown = false;
|
||||||
|
try {
|
||||||
|
await installer.getJava('1000', 'x64', 'bad path');
|
||||||
|
} catch {
|
||||||
|
thrown = true;
|
||||||
|
}
|
||||||
|
expect(thrown).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('Uses version of Java installed in cache', async () => {
|
it('Uses version of Java installed in cache', async () => {
|
||||||
const JavaDir: string = path.join(toolDir, 'Java', '250.0.0', 'x64');
|
const JavaDir: string = path.join(toolDir, 'Java', '250.0.0', 'x64');
|
||||||
await io.mkdirP(JavaDir);
|
await io.mkdirP(JavaDir);
|
||||||
|
|
|
@ -60,7 +60,7 @@ function getJava(version, arch, jdkFile) {
|
||||||
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
|
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
|
||||||
const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir);
|
const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir);
|
||||||
core.debug(`jdk extracted to ${jdkDir}`);
|
core.debug(`jdk extracted to ${jdkDir}`);
|
||||||
toolPath = yield tc.cacheDir(jdkDir, 'Java', `${version}.0.0`, arch);
|
toolPath = yield tc.cacheDir(jdkDir, 'Java', normalizeVersion(version), arch);
|
||||||
}
|
}
|
||||||
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
|
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
|
||||||
core.exportVariable('JAVA_HOME', toolPath);
|
core.exportVariable('JAVA_HOME', toolPath);
|
||||||
|
@ -69,6 +69,13 @@ function getJava(version, arch, jdkFile) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getJava = getJava;
|
exports.getJava = getJava;
|
||||||
|
function normalizeVersion(version) {
|
||||||
|
const versionArray = version.split('.');
|
||||||
|
const major = versionArray[0];
|
||||||
|
const minor = versionArray.length > 1 ? versionArray[1] : '0';
|
||||||
|
const patch = versionArray.length > 2 ? versionArray[2] : '0';
|
||||||
|
return `${major}.${minor}.${patch}`;
|
||||||
|
}
|
||||||
function getFileEnding(file) {
|
function getFileEnding(file) {
|
||||||
let fileEnding = '';
|
let fileEnding = '';
|
||||||
if (file.endsWith('.tar')) {
|
if (file.endsWith('.tar')) {
|
||||||
|
|
|
@ -54,7 +54,12 @@ export async function getJava(
|
||||||
tempDir
|
tempDir
|
||||||
);
|
);
|
||||||
core.debug(`jdk extracted to ${jdkDir}`);
|
core.debug(`jdk extracted to ${jdkDir}`);
|
||||||
toolPath = await tc.cacheDir(jdkDir, 'Java', `${version}.0.0`, arch);
|
toolPath = await tc.cacheDir(
|
||||||
|
jdkDir,
|
||||||
|
'Java',
|
||||||
|
normalizeVersion(version),
|
||||||
|
arch
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
|
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
|
||||||
|
@ -63,6 +68,14 @@ export async function getJava(
|
||||||
core.addPath(path.join(toolPath, 'bin'));
|
core.addPath(path.join(toolPath, 'bin'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeVersion(version: string) {
|
||||||
|
const versionArray = version.split('.');
|
||||||
|
const major = versionArray[0];
|
||||||
|
const minor = versionArray.length > 1 ? versionArray[1] : '0';
|
||||||
|
const patch = versionArray.length > 2 ? versionArray[2] : '0';
|
||||||
|
return `${major}.${minor}.${patch}`;
|
||||||
|
}
|
||||||
|
|
||||||
function getFileEnding(file: string): string {
|
function getFileEnding(file: string): string {
|
||||||
let fileEnding = '';
|
let fileEnding = '';
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue