package org.jenkinsci.plugins.p4.build;

import hudson.FilePath;
import hudson.model.Computer;
import hudson.model.Node;
import jenkins.model.Jenkins;

public class NodeHelper {

	private static final String UNKNOWN_NODE_NAME = "unknown";
	private static final String MASTER_NODE_NAME = "master";

	private NodeHelper() {
	}

	public static String getNodeName(FilePath path) {
		Node node = workspaceToNode(path);
		String nodeName = nameOf(node);
		return nodeName.isEmpty() ? MASTER_NODE_NAME : nodeName;
	}

	private static String nameOf(Node node) {
		return node == null ? UNKNOWN_NODE_NAME : node.getNodeName();
	}

	/**
	 * Helper: find the Remote/Local Computer used for build
	 *
	 * @param workspace Jenkins workspace on build node
	 */
	private static Computer workspaceToComputer(FilePath workspace) {
		if (workspace != null) {
			return workspace.toComputer();
		}
		return null;
	}

	/**
	 * Helper: find the Node for slave build or return current instance.
	 *
	 * @param workspace Jenkins workspace on build node
	 */
	public static Node workspaceToNode(FilePath workspace) {
		Computer computer = workspaceToComputer(workspace);
		if (computer != null) {
			return computer.getNode();
		}
		return Jenkins.getInstance();
	}
}

@@ -319,16 +319,150 @@
 ) %7B%0A%09%7D%0A%0A
+%09/**%0A%09 * Helper: find the node name used for the build%0A%09 *%0A%09 * @param path Jenkins workspace on build node%0A%09 * @return Node name%0A%09 */%0A
 %09public 
@@ -504,16 +504,16 @@
 path) %7B%0A
-
 %09%09Node n
@@ -865,24 +865,45 @@
  build node%0A
+%09 * @return Computer%0A
 %09 */%0A%09privat
@@ -1121,24 +1121,24 @@
 stance.%0A%09 *%0A
-
 %09 * @param w
@@ -1178,16 +1178,33 @@
 ld node%0A
+%09 * @return Node%0A
 %09 */%0A%09pu

Fix javadoc bugs.