From 9d7801bb26673d733366c70670888e61f614a31b Mon Sep 17 00:00:00 2001 From: ste Date: Thu, 15 Mar 2018 13:25:47 +0000 Subject: [PATCH 1/4] GPII-2578: Made findProcessesByCommand case-insensitive for Windows. --- .../processReporter/src/processesBridge.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/gpii/node_modules/processReporter/src/processesBridge.js b/gpii/node_modules/processReporter/src/processesBridge.js index b4d617994..04511fc4c 100644 --- a/gpii/node_modules/processReporter/src/processesBridge.js +++ b/gpii/node_modules/processReporter/src/processesBridge.js @@ -16,6 +16,7 @@ https://github.com/gpii/universal/LICENSE.txt var fluid = fluid || require("infusion"); var gpii = fluid.registerNamespace("gpii"); +var os = require("os"); fluid.defaults("gpii.processes", { gradeNames: ["fluid.component", "fluid.contextAware"], @@ -145,7 +146,7 @@ gpii.processes.findProcessByPid = function (that, pid, procArray) { /** * Return a list of process information objects that match the given - * command name. Return san empty array if not matching name is found. + * command name. Returns an empty array if not matching name is found. * * @param that {Component} - an instance of a processes component. * @param commandName {String} - the name of the processe to inspect. @@ -159,7 +160,7 @@ gpii.processes.findProcessesByCommand = function (that, commandName, procArray) procArray = that.getProcessList(commandName); } return fluid.accumulate(procArray, function (aProcInfo, matchingProcs) { - if (aProcInfo.command === commandName) { + if (gpii.processes.compareProcessNames(aProcInfo.command, commandName)) { matchingProcs.push(aProcInfo); } return matchingProcs; @@ -265,3 +266,18 @@ gpii.processes.initProcInfoNotRunning = function (that, command) { gpii.processes.getProcessList = function (/* identifier */) { return []; }; + +var compare = (os.platform() === "win32") + ? (new Intl.Collator(undefined, {sensitivity:"base"})).compare + : Object.is; + +/** + * Compares the names of two processes, returning a boolean indicating whether or not they are equal according to + * the case-sensitivity rules of the OS. + * + * @param processA {String} Name of a process. + * @param processB {String} Name of another process. + */ +gpii.processes.compareProcessNames = function (processA, processB) { + return !compare(processA, processB); +}; From 483167796eb4fee8f242ac63fdbbd50aa28f1729 Mon Sep 17 00:00:00 2001 From: ste Date: Tue, 20 Mar 2018 11:38:57 +0000 Subject: [PATCH 2/4] GPII-2578: Implemented the os detection the right way --- .../processReporter/src/processesBridge.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/gpii/node_modules/processReporter/src/processesBridge.js b/gpii/node_modules/processReporter/src/processesBridge.js index 04511fc4c..0d395c071 100644 --- a/gpii/node_modules/processReporter/src/processesBridge.js +++ b/gpii/node_modules/processReporter/src/processesBridge.js @@ -16,7 +16,6 @@ https://github.com/gpii/universal/LICENSE.txt var fluid = fluid || require("infusion"); var gpii = fluid.registerNamespace("gpii"); -var os = require("os"); fluid.defaults("gpii.processes", { gradeNames: ["fluid.component", "fluid.contextAware"], @@ -80,6 +79,11 @@ fluid.defaults("gpii.processes", { funcName: "gpii.processes.getProcessList", args: ["{arguments}.0"] // optional string or numeric identifier of the process + }, + compareProcessNames: { + funcName: "gpii.processes.compareProcessNames", + args: ["{arguments}.0", "{arguments}.1"] + // process name A, process name B } } }); @@ -160,7 +164,7 @@ gpii.processes.findProcessesByCommand = function (that, commandName, procArray) procArray = that.getProcessList(commandName); } return fluid.accumulate(procArray, function (aProcInfo, matchingProcs) { - if (gpii.processes.compareProcessNames(aProcInfo.command, commandName)) { + if (that.compareProcessNames(aProcInfo.command, commandName)) { matchingProcs.push(aProcInfo); } return matchingProcs; @@ -267,17 +271,12 @@ gpii.processes.getProcessList = function (/* identifier */) { return []; }; -var compare = (os.platform() === "win32") - ? (new Intl.Collator(undefined, {sensitivity:"base"})).compare - : Object.is; - /** - * Compares the names of two processes, returning a boolean indicating whether or not they are equal according to - * the case-sensitivity rules of the OS. + * Compares the names of two processes, returning a boolean indicating whether or not they are equal. * * @param processA {String} Name of a process. * @param processB {String} Name of another process. */ gpii.processes.compareProcessNames = function (processA, processB) { - return !compare(processA, processB); + return processA === processB; }; From 65a563e0e94995757f72c1e31be5250434b7a47a Mon Sep 17 00:00:00 2001 From: ste Date: Mon, 26 Mar 2018 16:36:36 +0100 Subject: [PATCH 3/4] GPII-2578: Moved case-insensitive process match into universal --- .../processReporter/src/processesBridge.js | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/gpii/node_modules/processReporter/src/processesBridge.js b/gpii/node_modules/processReporter/src/processesBridge.js index 0d395c071..727087d5e 100644 --- a/gpii/node_modules/processReporter/src/processesBridge.js +++ b/gpii/node_modules/processReporter/src/processesBridge.js @@ -79,13 +79,10 @@ fluid.defaults("gpii.processes", { funcName: "gpii.processes.getProcessList", args: ["{arguments}.0"] // optional string or numeric identifier of the process - }, - compareProcessNames: { - funcName: "gpii.processes.compareProcessNames", - args: ["{arguments}.0", "{arguments}.1"] - // process name A, process name B } - } + }, + // True if process names are matched with differing case. + ignoreCase: false }); /** @@ -163,8 +160,12 @@ gpii.processes.findProcessesByCommand = function (that, commandName, procArray) if (!procArray) { procArray = that.getProcessList(commandName); } + var commandNameLower = that.options.ignoreCase && commandName.toLowerCase(); return fluid.accumulate(procArray, function (aProcInfo, matchingProcs) { - if (that.compareProcessNames(aProcInfo.command, commandName)) { + var match = aProcInfo.command === commandName || + (that.options.ignoreCase && aProcInfo.command.toLowerCase() === commandNameLower); + + if (match) { matchingProcs.push(aProcInfo); } return matchingProcs; @@ -270,13 +271,3 @@ gpii.processes.initProcInfoNotRunning = function (that, command) { gpii.processes.getProcessList = function (/* identifier */) { return []; }; - -/** - * Compares the names of two processes, returning a boolean indicating whether or not they are equal. - * - * @param processA {String} Name of a process. - * @param processB {String} Name of another process. - */ -gpii.processes.compareProcessNames = function (processA, processB) { - return processA === processB; -}; From 4fc0d71e84e483324d4c1a36330e6518a2a9024e Mon Sep 17 00:00:00 2001 From: ste Date: Mon, 26 Mar 2018 16:41:19 +0100 Subject: [PATCH 4/4] GPII-2578: Implemented getProcessPath() --- .../processReporter/src/processesBridge.js | 17 +++++++++++++++++ .../test/web/js/ProcessesBridgeTests.js | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/gpii/node_modules/processReporter/src/processesBridge.js b/gpii/node_modules/processReporter/src/processesBridge.js index 727087d5e..559e49895 100644 --- a/gpii/node_modules/processReporter/src/processesBridge.js +++ b/gpii/node_modules/processReporter/src/processesBridge.js @@ -74,6 +74,11 @@ fluid.defaults("gpii.processes", { args: ["{that}", "{arguments}.0"] // command name (string) }, + getProcessPath: { + funcName: "gpii.processes.getProcessPath", + args: ["{that}", "{arguments}.0"] + // command name (string) + }, // Context aware invokers. getProcessList : { funcName: "gpii.processes.getProcessList", @@ -145,6 +150,18 @@ gpii.processes.findProcessByPid = function (that, pid, procArray) { }, null); }; +/** + * Return the path of a running process. + * + * @param that {Component} - an instance of a processes component. + * @param pid {Number} - the process id of the process. + * @return {String} - The full path of the process, or null if there's no matching process. + */ +gpii.processes.getProcessPath = function (that, pid) { + var proc = that.findProcessByPid(pid); + return proc && proc.fullPath; +}; + /** * Return a list of process information objects that match the given * command name. Returns an empty array if not matching name is found. diff --git a/gpii/node_modules/processReporter/test/web/js/ProcessesBridgeTests.js b/gpii/node_modules/processReporter/test/web/js/ProcessesBridgeTests.js index 5ed148dd2..8dd0b95d4 100644 --- a/gpii/node_modules/processReporter/test/web/js/ProcessesBridgeTests.js +++ b/gpii/node_modules/processReporter/test/web/js/ProcessesBridgeTests.js @@ -187,6 +187,25 @@ gpii.tests.processes.runTests = function () { } ); + jqUnit.test( + "Test getProcessPath() with non-running process id", + function () { + jqUnit.assertNull( + "Path of negative process id value", processesBridge.getProcessPath(-1) + ); + } + ); + + jqUnit.test( + "Test getProcessPath() against mock node process object.", + function () { + var fullPath = processesBridge.getProcessPath(processesBridge.mockNode.pid); + + jqUnit.assertEquals("Node process fullPath", + processesBridge.mockNode.fullPath, fullPath); + } + ); + jqUnit.test( "Test findProcessesByCmd()/findFirstProcessByCmd()", function () {