From 7ff44b2983186823c67b20cd16c1e96f002f7889 Mon Sep 17 00:00:00 2001 From: Marc Arndt Date: Sun, 23 Jun 2019 20:13:04 +0200 Subject: [PATCH 1/3] - refactor filesystem.files utility functions --- Utils/Functions/Filesystem/Files/script.js | 311 +++++++++++---------- 1 file changed, 157 insertions(+), 154 deletions(-) diff --git a/Utils/Functions/Filesystem/Files/script.js b/Utils/Functions/Filesystem/Files/script.js index 85bb4615ab..75cc9625d9 100644 --- a/Utils/Functions/Filesystem/Files/script.js +++ b/Utils/Functions/Filesystem/Files/script.js @@ -2,202 +2,205 @@ var fileAnalyser = Bean("fileAnalyser"); var fileUtilities = Bean("fileUtilities"); /** -* lists files and directories -* @param {string} directoryPath directory path -* @returns {string[]} list of files and directories -*/ -function ls(directoryPath) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - return fileUtilities.ls(new FileClass(directoryPath)); + * Lists all files and directories contained in the given path + * + * @param {string} directoryPath directory path + * @returns {string[]} list of files and directories + */ +function ls(directoryPath) { + return fileUtilities.ls(directoryPath); } /** -* creates directory -* @param {string} directoryPath directory path -* @returns {void} -*/ -function mkdir(directoryPath) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - fileUtilities.mkdir(new FileClass(directoryPath)); + * Creates the given directory + * + * @param {string} directoryPath directory path + * @returns {void} + */ +function mkdir(directoryPath) { + fileUtilities.mkdir(directoryPath); } /** -* check if file exists -* @param {string} filePath file path -* @returns {boolean} true if file exists -*/ -function fileExists(filePath) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - return new FileClass(filePath).exists(); + * Checks if the given file exists + * + * @param {string} filePath file path + * @returns {boolean} true if file exists + */ +function fileExists(filePath) { + return fileUtilities.exists(filePath); } /** -* returns file content -* @param {string} filePath file path -* @returns {string} content -*/ -function cat(filePath) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - return Bean("fileUtilities").getFileContent(new FileClass(filePath)); + * Returns the file content of the given file + * + * @param {string} filePath file path + * @returns {string} content + */ +function cat(filePath) { + return fileUtilities.getFileContent(filePath); } /** -* copies file -* @param {string} source source -* @param {string} target target -* @returns {void} -*/ -function cp(source, target) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - return Bean("fileUtilities").copy(new FileClass(source), new FileClass(target)); + * Copies the given source file to the target location + * + * @param {string} source Source file + * @param {string} target Target location + * @returns {void} + */ +function cp(source, target) { + return fileUtilities.copy(source, target); } /** -* returns file size -* @param {string} filePath file path -* @returns {number} file size -*/ -function getFileSize(filePath) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - return Bean("fileUtilities").getSize(new FileClass(filePath)); + * Returns the file size of the given file + * + * @param {string} filePath file path + * @returns {number} file size + */ +function getFileSize(filePath) { + return fileUtilities.getSize(filePath); } /** -* returns file name -* @param {string} filePath file path -* @returns {string} file name -*/ -function fileName(filePath) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - return new FileClass(filePath).getName(); + * Returns the file name of the given file + * + * @param {string} filePath file path + * @returns {string} file name + */ +function fileName(filePath) { + return fileUtilities.getFileName(filePath); } /** -* creates link -* @param {string} target target -* @param {string} destination destination -* @returns {void} -*/ -function lns(target, destination) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - return Bean("fileUtilities").createSymbolicLink(new FileClass(destination), new FileClass(target)); + * Creates a symbolic link + * + * @param {string} target target + * @param {string} link destination + * @returns {void} + */ +function lns(target, link) { + return fileUtilities.createSymbolicLink(link, target); } /** -* removes file -* @param {string} filePath file path -* @returns {void} -*/ -function remove(filePath) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - return Bean("fileUtilities").remove(new FileClass(filePath)); + * Removes the given file + * + * @param {string} filePath file path + * @returns {void} + */ +function remove(filePath) { + return fileUtilities.remove(filePath); } /** -* creates empty file -* @param {string} filePath file path -* @returns {void} -*/ -function touch(filePath) { // eslint-disable-line no-unused-vars - if (!fileExists(filePath)) { - var FileClass = Java.type('java.io.File'); - Bean("fileUtilities").writeToFile(new FileClass(filePath), ""); - } + * Creates the given file if it does not exist + * + * @param {string} filePath file path + * @returns {void} + */ +function touch(filePath) { + if (!fileExists(filePath)) { + fileUtilities.writeToFile(filePath, ""); + } } /** -* writes content into file -* @param {string} filePath file path -* @param {string} content content which shall be written -* @returns {void} -*/ -function writeToFile(filePath, content) { // eslint-disable-line no-unused-vars - var FileClass = Java.type('java.io.File'); - Bean("fileUtilities").writeToFile(new FileClass(filePath), content); + * Writes the given content to the given file + * + * @param {string} filePath file path + * @param {string} content content which shall be written + * @returns {void} + */ +function writeToFile(filePath, content) { + fileUtilities.writeToFile(filePath, content); } /** -* creates temporary file -* @param {string} extension file extension -* @returns {string} file path of created temporary file -*/ -function createTempFile(extension) { // eslint-disable-line no-unused-vars - var tmpFile = Bean("fileUtilities").createTmpFile(extension); - return tmpFile.getAbsolutePath(); + * Creates a new temporary file with the given file extension + * + * @param {string} extension file extension + * @returns {string} file path of created temporary file + */ +function createTempFile(extension) { + return fileUtilities.createTmpFile(extension); } /** - * creates temporary directory + * Creates a new temporary temporary directory + * * @returns {string} file path of created temporary directory */ -function createTempDir() { // eslint-disable-line no-unused-vars - var tmpFile = Bean("fileUtilities").createTmpDir(); - return tmpFile.getAbsolutePath(); -} - -/** -* Checksum prototype -* @constructor -*/ -function Checksum() { - this._method = "SHA"; - this._checksumCalculator = Bean("checksumCalculator"); +function createTempDir() { + return fileUtilities.createTmpDir(); } /** -* sets wizard -* @param {SetupWizard} wizard setup wizard -* @returns {Checksum} Checksum object -*/ -Checksum.prototype.wizard = function (wizard) { - this._wizard = wizard; - return this; -} - -/** -* sets checksum algorithm -* @param {string} algorithm algorithm (e.g. "SHA") -* @returns {Checksum} Checksum object -*/ -Checksum.prototype.method = function (algorithm) { - this._method = algorithm; - return this; -} - -/** -* sets file for which the checksum shall be computed -* @param {string} file file for which the checksum shall be computed -* @returns {Checksum} Checksum object -*/ -Checksum.prototype.of = function (file) { - this._file = file; - return this; -} - -/** -* returns calculated checksum -* @returns {string} calculated checksum -*/ -Checksum.prototype.get = function () { - if (this._wizard) { - var progressBar = this._wizard.progressBar(tr("Checking file consistency...")); - } - - return this._checksumCalculator.calculate(this._file, this._method, function (progressEntity) { - if (progressBar) { - progressBar.accept(progressEntity); - } - }); + * Sets the given file permissions + * + * @param {string} filePath file path + * @param {string} permissions file permissions (e.g. "r--r--r--") + * @returns {void} + */ +function chmod(filePath, permissions) { + fileUtilities.chmod(filePath, permissions); } /** -* sets file permissions -* @param {string} filePath file path -* @param {string} permissions file permissions (e.g. "r--r--r--") -* @returns {void} -*/ -function chmod(filePath, permissions) { // eslint-disable-line no-unused-vars - var permissionsObj = java.nio.file.attribute.PosixFilePermissions.fromString(permissions); - var filePathObj = java.nio.file.Paths.get(filePath); - java.nio.file.Files.setPosixFilePermissions(filePathObj, permissionsObj); + * Checksum + */ +class Checksum { + constructor() { + this.checksumCalculator = Bean("checksumCalculator"); + this._method = "SHA"; + } + + /** + * sets wizard + * @param {SetupWizard} wizard setup wizard + * @returns {Checksum} Checksum object + */ + wizard(wizard) { + this._wizard = wizard; + + return this; + } + + /** + * sets checksum algorithm + * @param {string} algorithm algorithm (e.g. "SHA") + * @returns {Checksum} Checksum object + */ + method(algorithm) { + this._method = algorithm; + + return this; + } + + /** + * sets file for which the checksum shall be computed + * @param {string} file file for which the checksum shall be computed + * @returns {Checksum} Checksum object + */ + of(file) { + this._file = file; + + return this; + } + + /** + * returns calculated checksum + * @returns {string} calculated checksum + */ + get() { + if (this._wizard) { + var progressBar = this._wizard.progressBar(tr("Checking file consistency...")); + } + + return this.checksumCalculator.calculate(this._file, this._method, function(progressEntity) { + if (progressBar) { + progressBar.accept(progressEntity); + } + }); + } } From dadfbb829abfbe14982855ddaab5b5d8fa3714d2 Mon Sep 17 00:00:00 2001 From: Marc Arndt Date: Tue, 25 Jun 2019 23:43:01 +0200 Subject: [PATCH 2/3] - fix formatting --- .../Wine/Tools/Wine Terminal Opener/script.js | 2 +- Utils/Functions/Filesystem/Files/script.js | 94 +++++++++---------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/Engines/Wine/Tools/Wine Terminal Opener/script.js b/Engines/Wine/Tools/Wine Terminal Opener/script.js index 86b3704b60..8589f0e151 100644 --- a/Engines/Wine/Tools/Wine Terminal Opener/script.js +++ b/Engines/Wine/Tools/Wine Terminal Opener/script.js @@ -8,7 +8,7 @@ var toolImplementation = { run: function (container) { var wine = new Wine() .prefix(container); - + var environment = []; environment["WINEPREFIX"] = wine.prefixDirectory(); environment["PATH"] = wine.binPath() + ":$PATH"; diff --git a/Utils/Functions/Filesystem/Files/script.js b/Utils/Functions/Filesystem/Files/script.js index 75cc9625d9..0b3160ffc4 100644 --- a/Utils/Functions/Filesystem/Files/script.js +++ b/Utils/Functions/Filesystem/Files/script.js @@ -8,7 +8,7 @@ var fileUtilities = Bean("fileUtilities"); * @returns {string[]} list of files and directories */ function ls(directoryPath) { - return fileUtilities.ls(directoryPath); + return fileUtilities.ls(directoryPath); } /** @@ -18,7 +18,7 @@ function ls(directoryPath) { * @returns {void} */ function mkdir(directoryPath) { - fileUtilities.mkdir(directoryPath); + fileUtilities.mkdir(directoryPath); } /** @@ -28,7 +28,7 @@ function mkdir(directoryPath) { * @returns {boolean} true if file exists */ function fileExists(filePath) { - return fileUtilities.exists(filePath); + return fileUtilities.exists(filePath); } /** @@ -38,7 +38,7 @@ function fileExists(filePath) { * @returns {string} content */ function cat(filePath) { - return fileUtilities.getFileContent(filePath); + return fileUtilities.getFileContent(filePath); } /** @@ -49,7 +49,7 @@ function cat(filePath) { * @returns {void} */ function cp(source, target) { - return fileUtilities.copy(source, target); + return fileUtilities.copy(source, target); } /** @@ -59,7 +59,7 @@ function cp(source, target) { * @returns {number} file size */ function getFileSize(filePath) { - return fileUtilities.getSize(filePath); + return fileUtilities.getSize(filePath); } /** @@ -69,7 +69,7 @@ function getFileSize(filePath) { * @returns {string} file name */ function fileName(filePath) { - return fileUtilities.getFileName(filePath); + return fileUtilities.getFileName(filePath); } /** @@ -80,7 +80,7 @@ function fileName(filePath) { * @returns {void} */ function lns(target, link) { - return fileUtilities.createSymbolicLink(link, target); + return fileUtilities.createSymbolicLink(link, target); } /** @@ -90,7 +90,7 @@ function lns(target, link) { * @returns {void} */ function remove(filePath) { - return fileUtilities.remove(filePath); + return fileUtilities.remove(filePath); } /** @@ -100,9 +100,9 @@ function remove(filePath) { * @returns {void} */ function touch(filePath) { - if (!fileExists(filePath)) { - fileUtilities.writeToFile(filePath, ""); - } + if (!fileExists(filePath)) { + fileUtilities.writeToFile(filePath, ""); + } } /** @@ -113,7 +113,7 @@ function touch(filePath) { * @returns {void} */ function writeToFile(filePath, content) { - fileUtilities.writeToFile(filePath, content); + fileUtilities.writeToFile(filePath, content); } /** @@ -123,7 +123,7 @@ function writeToFile(filePath, content) { * @returns {string} file path of created temporary file */ function createTempFile(extension) { - return fileUtilities.createTmpFile(extension); + return fileUtilities.createTmpFile(extension); } /** @@ -132,7 +132,7 @@ function createTempFile(extension) { * @returns {string} file path of created temporary directory */ function createTempDir() { - return fileUtilities.createTmpDir(); + return fileUtilities.createTmpDir(); } /** @@ -143,64 +143,64 @@ function createTempDir() { * @returns {void} */ function chmod(filePath, permissions) { - fileUtilities.chmod(filePath, permissions); + fileUtilities.chmod(filePath, permissions); } /** * Checksum */ class Checksum { - constructor() { - this.checksumCalculator = Bean("checksumCalculator"); - this._method = "SHA"; - } + constructor() { + this.checksumCalculator = Bean("checksumCalculator"); + this._method = "SHA"; + } - /** + /** * sets wizard * @param {SetupWizard} wizard setup wizard * @returns {Checksum} Checksum object */ - wizard(wizard) { - this._wizard = wizard; + wizard(wizard) { + this._wizard = wizard; - return this; - } + return this; + } - /** + /** * sets checksum algorithm * @param {string} algorithm algorithm (e.g. "SHA") * @returns {Checksum} Checksum object */ - method(algorithm) { - this._method = algorithm; + method(algorithm) { + this._method = algorithm; - return this; - } + return this; + } - /** + /** * sets file for which the checksum shall be computed * @param {string} file file for which the checksum shall be computed * @returns {Checksum} Checksum object */ - of(file) { - this._file = file; + of(file) { + this._file = file; - return this; - } + return this; + } - /** + /** * returns calculated checksum * @returns {string} calculated checksum */ - get() { - if (this._wizard) { - var progressBar = this._wizard.progressBar(tr("Checking file consistency...")); - } - - return this.checksumCalculator.calculate(this._file, this._method, function(progressEntity) { - if (progressBar) { - progressBar.accept(progressEntity); - } - }); - } + get() { + if (this._wizard) { + var progressBar = this._wizard.progressBar(tr("Checking file consistency...")); + } + + return this.checksumCalculator.calculate(this._file, this._method, function (progressEntity) { + if (progressBar) { + progressBar.accept(progressEntity); + } + }); + } } From 7ffb42c277e4411a8aa4cd36c9d0202abc3d6d04 Mon Sep 17 00:00:00 2001 From: Marc Arndt Date: Fri, 28 Jun 2019 21:22:43 +0200 Subject: [PATCH 3/3] - review comments - improve JSDoc --- Utils/Functions/Filesystem/Files/script.js | 51 +++++++++++++++------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/Utils/Functions/Filesystem/Files/script.js b/Utils/Functions/Filesystem/Files/script.js index 0b3160ffc4..cd836055c8 100644 --- a/Utils/Functions/Filesystem/Files/script.js +++ b/Utils/Functions/Filesystem/Files/script.js @@ -7,6 +7,7 @@ var fileUtilities = Bean("fileUtilities"); * @param {string} directoryPath directory path * @returns {string[]} list of files and directories */ +// eslint-disable-next-line no-unused-vars function ls(directoryPath) { return fileUtilities.ls(directoryPath); } @@ -17,6 +18,7 @@ function ls(directoryPath) { * @param {string} directoryPath directory path * @returns {void} */ +// eslint-disable-next-line no-unused-vars function mkdir(directoryPath) { fileUtilities.mkdir(directoryPath); } @@ -27,6 +29,7 @@ function mkdir(directoryPath) { * @param {string} filePath file path * @returns {boolean} true if file exists */ +// eslint-disable-next-line no-unused-vars function fileExists(filePath) { return fileUtilities.exists(filePath); } @@ -37,6 +40,7 @@ function fileExists(filePath) { * @param {string} filePath file path * @returns {string} content */ +// eslint-disable-next-line no-unused-vars function cat(filePath) { return fileUtilities.getFileContent(filePath); } @@ -48,6 +52,7 @@ function cat(filePath) { * @param {string} target Target location * @returns {void} */ +// eslint-disable-next-line no-unused-vars function cp(source, target) { return fileUtilities.copy(source, target); } @@ -58,6 +63,7 @@ function cp(source, target) { * @param {string} filePath file path * @returns {number} file size */ +// eslint-disable-next-line no-unused-vars function getFileSize(filePath) { return fileUtilities.getSize(filePath); } @@ -68,6 +74,7 @@ function getFileSize(filePath) { * @param {string} filePath file path * @returns {string} file name */ +// eslint-disable-next-line no-unused-vars function fileName(filePath) { return fileUtilities.getFileName(filePath); } @@ -79,6 +86,7 @@ function fileName(filePath) { * @param {string} link destination * @returns {void} */ +// eslint-disable-next-line no-unused-vars function lns(target, link) { return fileUtilities.createSymbolicLink(link, target); } @@ -89,6 +97,7 @@ function lns(target, link) { * @param {string} filePath file path * @returns {void} */ +// eslint-disable-next-line no-unused-vars function remove(filePath) { return fileUtilities.remove(filePath); } @@ -99,6 +108,7 @@ function remove(filePath) { * @param {string} filePath file path * @returns {void} */ +// eslint-disable-next-line no-unused-vars function touch(filePath) { if (!fileExists(filePath)) { fileUtilities.writeToFile(filePath, ""); @@ -112,6 +122,7 @@ function touch(filePath) { * @param {string} content content which shall be written * @returns {void} */ +// eslint-disable-next-line no-unused-vars function writeToFile(filePath, content) { fileUtilities.writeToFile(filePath, content); } @@ -122,6 +133,7 @@ function writeToFile(filePath, content) { * @param {string} extension file extension * @returns {string} file path of created temporary file */ +// eslint-disable-next-line no-unused-vars function createTempFile(extension) { return fileUtilities.createTmpFile(extension); } @@ -131,6 +143,7 @@ function createTempFile(extension) { * * @returns {string} file path of created temporary directory */ +// eslint-disable-next-line no-unused-vars function createTempDir() { return fileUtilities.createTmpDir(); } @@ -142,6 +155,7 @@ function createTempDir() { * @param {string} permissions file permissions (e.g. "r--r--r--") * @returns {void} */ +// eslint-disable-next-line no-unused-vars function chmod(filePath, permissions) { fileUtilities.chmod(filePath, permissions); } @@ -149,6 +163,7 @@ function chmod(filePath, permissions) { /** * Checksum */ +// eslint-disable-next-line no-unused-vars class Checksum { constructor() { this.checksumCalculator = Bean("checksumCalculator"); @@ -156,10 +171,11 @@ class Checksum { } /** - * sets wizard - * @param {SetupWizard} wizard setup wizard - * @returns {Checksum} Checksum object - */ + * Sets the setup wizard + * + * @param {SetupWizard} wizard The setup wizard + * @returns {Checksum} The Checksum object + */ wizard(wizard) { this._wizard = wizard; @@ -167,10 +183,11 @@ class Checksum { } /** - * sets checksum algorithm - * @param {string} algorithm algorithm (e.g. "SHA") - * @returns {Checksum} Checksum object - */ + * Sets the used checksum algorithm + * + * @param {string} algorithm The used algorithm (e.g. "SHA") + * @returns {Checksum} The Checksum object + */ method(algorithm) { this._method = algorithm; @@ -178,10 +195,11 @@ class Checksum { } /** - * sets file for which the checksum shall be computed - * @param {string} file file for which the checksum shall be computed - * @returns {Checksum} Checksum object - */ + * Sets the file for which the checksum shall be computed + * + * @param {string} file The file for which the checksum shall be computed + * @returns {Checksum} The Checksum object + */ of(file) { this._file = file; @@ -189,15 +207,16 @@ class Checksum { } /** - * returns calculated checksum - * @returns {string} calculated checksum - */ + * Calculates and returns the checksum for the previously set file + * + * @returns {string} The calculated checksum + */ get() { if (this._wizard) { var progressBar = this._wizard.progressBar(tr("Checking file consistency...")); } - return this.checksumCalculator.calculate(this._file, this._method, function (progressEntity) { + return this.checksumCalculator.calculate(this._file, this._method, progressEntity => { if (progressBar) { progressBar.accept(progressEntity); }