From 65bc0fb146bfcdfe9af441bde27d8571fc7f563e Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sat, 28 Jun 2014 05:21:24 -0700 Subject: [PATCH] Added a convenience method. Reference: https://trello.com/c/doFFMdUm/46-filepath-getcomputer --- core/src/main/java/hudson/FilePath.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 1c9fdc2a65..75a9ae1c64 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -30,6 +30,7 @@ import com.jcraft.jzlib.GZIPOutputStream; import hudson.Launcher.LocalLauncher; import hudson.Launcher.RemoteLauncher; import hudson.model.AbstractProject; +import hudson.model.Computer; import hudson.model.Item; import hudson.model.TaskListener; import hudson.org.apache.tools.tar.TarInputStream; @@ -69,6 +70,7 @@ import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipFile; import org.kohsuke.stapler.Stapler; +import javax.annotation.CheckForNull; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileFilter; @@ -1056,6 +1058,22 @@ public final class FilePath implements Serializable { return VirtualFile.forFilePath(this); } + /** + * If this {@link FilePath} represents a file on a particular {@link Computer}, return it. + * Otherwise null. + */ + public @CheckForNull Computer toComputer() { + Jenkins j = Jenkins.getInstance(); + if (j != null) { + for (Computer c : j.getComputers()) { + if (getChannel()==c.getChannel()) { + return c; + } + } + } + return null; + } + /** * Creates this directory. */ -- GitLab