diff --git a/gpii/node_modules/processReporter/src/processesBridge.js b/gpii/node_modules/processReporter/src/processesBridge.js index b4d617994..559e49895 100644 --- a/gpii/node_modules/processReporter/src/processesBridge.js +++ b/gpii/node_modules/processReporter/src/processesBridge.js @@ -74,13 +74,20 @@ 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", args: ["{arguments}.0"] // optional string or numeric identifier of the process } - } + }, + // True if process names are matched with differing case. + ignoreCase: false }); /** @@ -143,9 +150,21 @@ 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. 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. @@ -158,8 +177,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 (aProcInfo.command === commandName) { + var match = aProcInfo.command === commandName || + (that.options.ignoreCase && aProcInfo.command.toLowerCase() === commandNameLower); + + if (match) { matchingProcs.push(aProcInfo); } return matchingProcs; 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 () {