Skip to content

Commit c957dca

Browse files
committed
FindBugs
1 parent 4e964bf commit c957dca

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/main/java/hudson/tasks/Ant.java

+21-15
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.kohsuke.stapler.QueryParameter;
5959

6060
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
61+
import hudson.remoting.VirtualChannel;
6162

6263
import java.io.File;
6364
import java.io.IOException;
@@ -395,22 +396,27 @@ public void buildEnvVars(EnvVars env) {
395396
* Gets the executable path of this Ant on the given target system.
396397
*/
397398
public String getExecutable(Launcher launcher) throws IOException, InterruptedException {
398-
return launcher.getChannel().call(new MasterToSlaveCallable<String,IOException>() {
399-
private static final long serialVersionUID = 906341330603832653L;
400-
public String call() throws IOException {
401-
File exe = getExeFile();
402-
if(exe.exists())
403-
return exe.getPath();
404-
return null;
405-
}
406-
});
399+
VirtualChannel channel = launcher.getChannel();
400+
if (channel == null) {
401+
throw new IOException("offline?");
402+
}
403+
return channel.call(new GetExecutable(getHome()));
407404
}
408-
409-
private File getExeFile() {
410-
String execName = Functions.isWindows() ? "ant.bat" : "ant";
411-
String home = Util.replaceMacro(getHome(), EnvVars.masterEnvVars);
412-
413-
return new File(home,"bin/"+execName);
405+
private static class GetExecutable extends MasterToSlaveCallable<String, IOException> {
406+
private static final long serialVersionUID = 906341330603832653L;
407+
private final String rawHome;
408+
GetExecutable(String rawHome) {
409+
this.rawHome = rawHome;
410+
}
411+
@Override public String call() throws IOException {
412+
String execName = Functions.isWindows() ? "ant.bat" : "ant";
413+
String home = Util.replaceMacro(rawHome, EnvVars.masterEnvVars);
414+
File exe = new File(home, "bin/" + execName);
415+
if (exe.exists()) {
416+
return exe.getPath();
417+
}
418+
return null;
419+
}
414420
}
415421

416422
/**

0 commit comments

Comments
 (0)