Skip to content

Commit

Permalink
Corrected return types
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaterina-tatanova committed Jul 6, 2020
1 parent 7a4c920 commit 2cd2229
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 10 additions & 3 deletions Tasks/JavaToolInstallerV0/javatoolinstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ async function getJava(versionSpec: string) {
}

/**
* Return file ending if it is supported. Otherwise throw an error.
* Get file ending if it is supported. Otherwise throw an error.
* Find file ending, not extension. For example, there is supported .tar.gz file ending but the extension is .gz.
* @param file Path to a file.
* @returns string
*/
function getSupportedFileEnding(file: string): string {
const fileEnding: string = supportedFileEndings.find(ending => file.endsWith(ending));
Expand All @@ -104,6 +106,7 @@ function getSupportedFileEnding(file: string): string {
* @param sourceFile Path to JDK file.
* @param fileExtension JDK file extension.
* @param archiveExtractLocation Path to folder to extract a JDK.
* @returns string
*/
async function installJDK(sourceFile: string, fileExtension: string, archiveExtractLocation: string, extendedJavaHome: string, versionSpec: string): Promise<string> {
let jdkDirectory;
Expand Down Expand Up @@ -140,6 +143,7 @@ async function installJDK(sourceFile: string, fileExtension: string, archiveExtr
* Get the path to a folder inside the VOLUMES_FOLDER.
* Only for macOS.
* @param volumes VOLUMES_FOLDER contents before attaching a disk image.
* @returns string
*/
function getVolumePath(volumes: Set<string>): string {
const newVolumes: string[] = fs.readdirSync(VOLUMES_FOLDER).filter(volume => !volumes.has(volume));
Expand All @@ -154,6 +158,7 @@ function getVolumePath(volumes: Set<string>): string {
* Get path to a .pkg file.
* Only for macOS.
* @param volumePath Path to the folder containing a .pkg file.
* @returns string
*/
function getPackagePath(volumePath: string): string {
const packages: string[] = fs.readdirSync(volumePath).filter(file => file.endsWith('.pkg'));
Expand Down Expand Up @@ -202,12 +207,14 @@ async function installPkg(pkgPath: string, extendedJavaHome: string, versionSpec
/**
* Install a .pkg file.
* Only for macOS.
* Returns promise with return code.
* @param pkgPath Path to a .pkg file.
* @returns number
*/
async function runPkgInstaller(pkgPath: string): Promise<void> {
async function runPkgInstaller(pkgPath: string): Promise<number> {
const installer = sudo('installer');
installer.line(`-package "${pkgPath}" -target /`);
await installer.exec();
return await installer.exec();
}

run();
14 changes: 10 additions & 4 deletions Tasks/JavaToolInstallerV0/taskutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function sleepFor(sleepDurationInMilliSeconds: number): Promise<any> {
* Build a path to file in local root.
* @param localPathRoot Path to the folder where file should be located.
* @param fileNameAndPath Path to the file which name should be taken.
* @returns string
*/
export function buildFilePath(localPathRoot: string, fileNameAndPath: string): string {
const fileName = fileNameAndPath.split(/[\\\/]/).pop();
Expand All @@ -25,6 +26,7 @@ export function buildFilePath(localPathRoot: string, fileNameAndPath: string): s
/**
* Run a tool with `sudo` on Linux and macOS.
* Precondition: `toolName` executable is in PATH.
* @returns ToolRunner
*/
export function sudo(toolName: string): ToolRunner {
if (os.platform() === 'win32') {
Expand All @@ -38,22 +40,26 @@ export function sudo(toolName: string): ToolRunner {
/**
* Attach a disk image.
* Only for macOS.
* Returns promise with return code.
* @param sourceFile Path to a disk image file.
* @returns number
*/
export async function attach(sourceFile: string): Promise<void> {
export async function attach(sourceFile: string): Promise<number> {
console.log(tl.loc('AttachDiskImage'));
const hdiutil = sudo('hdiutil');
hdiutil.line(`attach "${sourceFile}"`);
await hdiutil.exec();
return await hdiutil.exec();
}

/**
* Detach a disk image.
* Returns promise with return code.
* @param volumePath Path to the attached disk image.
* @returns number
*/
export async function detach(volumePath: string): Promise<void> {
export async function detach(volumePath: string): Promise<number> {
console.log(tl.loc('DetachDiskImage'));
const hdiutil = sudo('hdiutil');
hdiutil.line(`detach "${volumePath}"`);
await hdiutil.exec();
return await hdiutil.exec();
}

0 comments on commit 2cd2229

Please sign in to comment.