Skip to content

Commit

Permalink
Added more JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ekaterina-tatanova committed Jun 30, 2020
1 parent d9a0449 commit 9c3bfd6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@
"loc.messages.UsePreinstalledJava": "Use preinstalled JDK from %s",
"loc.messages.WrongArchiveStructure": "JDK file is not valid. Verify if JDK file contains only one root folder with 'bin' inside.",
"loc.messages.NewJDKIsNotInstalled": "New JDK is not installed.",
"loc.messages.UnsupportedDMGArchiveStructure": "JDK file is not supported. Verify if JDK file contains exactly one folder inside.",
"loc.messages.NoPKGFile": "Could not find PKG file",
"loc.messages.SeveralPKGFiles": "Found more than one PKG files",
"loc.messages.InstallJDK": "Installing JDK",
"loc.messages.AttachDiskImage": "Attaching a disk image",
"loc.messages.DetachDiskImage": "Detaching a disk image"
"loc.messages.UnsupportedDMGStructure": "JDK file is not supported. Verify if JDK file contains exactly one folder inside.",
"loc.messages.NoPKGFile": "Could not find PKG file.",
"loc.messages.SeveralPKGFiles": "Found more than one PKG files.",
"loc.messages.InstallJDK": "Installing JDK.",
"loc.messages.AttachDiskImage": "Attaching a disk image.",
"loc.messages.DetachDiskImage": "Detaching a disk image.",
"loc.messages.PkgPathDoesNotExist": "Package path does not exist."
}
26 changes: 21 additions & 5 deletions Tasks/JavaToolInstallerV0/javatoolinstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ function buildFilePath(localPathRoot: string, fileEnding: string, fileNameAndPat
return extractSource;
}

/**
* Return file ending if it is supported. Otherwise throw an error.
* @param JDKfile Path to a file.
*/
function getSupportedFileEnding(file: string): string {
for (const fileEnding of supportedFileEndings) {
if (file.endsWith(fileEnding)) {
Expand Down Expand Up @@ -127,7 +131,12 @@ async function installJDK(sourceFile: string, fileExtension: string, archiveExtr
let pkgPath: string = getPackagePath(volumePath);
jdkDirectory = await installPkg(pkgPath);

await detach(volumePath);
try {
await detach(volumePath);
}
catch(error) {
taskLib.error(error.message);
}
}
else if (fileExtension === '.pkg' && os.platform() === 'darwin') {
jdkDirectory = await installPkg(sourceFile);
Expand All @@ -141,19 +150,21 @@ 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.
*/
function getVolumePath(volumes: Set<string>): string {
const newVolumes: string[] = fs.readdirSync(VOLUMES_FOLDER).filter(volume => !volumes.has(volume));

if (newVolumes.length !== 1) {
throw new Error(taskLib.loc('UnsupportedDMGArchiveStructure'));
throw new Error(taskLib.loc('UnsupportedDMGStructure'));
}
return path.join(VOLUMES_FOLDER, newVolumes[0]);
}

/**
* Get path to a .pkg file.
* Only for macOS.
* @param volumePath Path to the folder containing a .pkg file.
*/
function getPackagePath(volumePath: string): string {
Expand All @@ -169,6 +180,10 @@ function getPackagePath(volumePath: string): string {
}

async function installPkg(pkgPath: string): Promise<string> {
if (!fs.existsSync(pkgPath)) {
throw new Error('PkgPathDoesNotExist');
}

console.log(taskLib.loc('InstallJDK'));

// Using set because 'includes' array method requires tsconfig option "lib": ["ES2017"]
Expand All @@ -187,8 +202,8 @@ async function installPkg(pkgPath: string): Promise<string> {
}

/**
* Run a tool with `sudo` on Linux and macOS
* Precondition: `toolName` executable is in PATH
* Run a tool with `sudo` on Linux and macOS.
* Precondition: `toolName` executable is in PATH.
*/
function sudo(toolName: string): ToolRunner {
if (os.platform() === 'win32') {
Expand All @@ -212,14 +227,15 @@ async function attach(sourceFile: string): Promise<void> {

/**
* Install a .pkg file.
* Only for macOS.
* @param pkgPath Path to a .pkg file.
*/
async function runPkgInstaller(pkgPath: string): Promise<void> {
try {
const installer = sudo('installer');
installer.line(`-package "${pkgPath}" -target /`);
await installer.exec();
} catch (e) {
} catch (error) {
taskLib.debug('Failed to install pkg file');
}
}
Expand Down
13 changes: 7 additions & 6 deletions Tasks/JavaToolInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@
"UsePreinstalledJava": "Use preinstalled JDK from %s",
"WrongArchiveStructure": "JDK file is not valid. Verify if JDK file contains only one root folder with 'bin' inside.",
"NewJDKIsNotInstalled": "New JDK is not installed.",
"UnsupportedDMGArchiveStructure": "JDK file is not supported. Verify if JDK file contains exactly one folder inside.",
"NoPKGFile": "Could not find PKG file",
"SeveralPKGFiles": "Found more than one PKG files",
"InstallJDK": "Installing JDK",
"AttachDiskImage": "Attaching a disk image",
"DetachDiskImage": "Detaching a disk image"
"UnsupportedDMGStructure": "JDK file is not supported. Verify if JDK file contains exactly one folder inside.",
"NoPKGFile": "Could not find PKG file.",
"SeveralPKGFiles": "Found more than one PKG files.",
"InstallJDK": "Installing JDK.",
"AttachDiskImage": "Attaching a disk image.",
"DetachDiskImage": "Detaching a disk image.",
"PkgPathDoesNotExist": "Package path does not exist."
}
}
5 changes: 3 additions & 2 deletions Tasks/JavaToolInstallerV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@
"UsePreinstalledJava": "ms-resource:loc.messages.UsePreinstalledJava",
"WrongArchiveStructure": "ms-resource:loc.messages.WrongArchiveStructure",
"NewJDKIsNotInstalled": "ms-resource:loc.messages.NewJDKIsNotInstalled",
"UnsupportedDMGArchiveStructure": "ms-resource:loc.messages.UnsupportedDMGArchiveStructure",
"UnsupportedDMGStructure": "ms-resource:loc.messages.UnsupportedDMGStructure",
"NoPKGFile": "ms-resource:loc.messages.NoPKGFile",
"SeveralPKGFiles": "ms-resource:loc.messages.SeveralPKGFiles",
"InstallJDK": "ms-resource:loc.messages.InstallJDK",
"AttachDiskImage": "ms-resource:loc.messages.AttachDiskImage",
"DetachDiskImage": "ms-resource:loc.messages.DetachDiskImage"
"DetachDiskImage": "ms-resource:loc.messages.DetachDiskImage",
"PkgPathDoesNotExist": "ms-resource:loc.messages.PkgPathDoesNotExist"
}
}

0 comments on commit 9c3bfd6

Please sign in to comment.