Skip to content

Commit

Permalink
FindBugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Oct 18, 2018
1 parent 4e964bf commit c957dca
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/main/java/hudson/tasks/Ant.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.kohsuke.stapler.QueryParameter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.remoting.VirtualChannel;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -395,22 +396,27 @@ public void buildEnvVars(EnvVars env) {
* Gets the executable path of this Ant on the given target system.
*/
public String getExecutable(Launcher launcher) throws IOException, InterruptedException {
return launcher.getChannel().call(new MasterToSlaveCallable<String,IOException>() {
private static final long serialVersionUID = 906341330603832653L;
public String call() throws IOException {
File exe = getExeFile();
if(exe.exists())
return exe.getPath();
return null;
}
});
VirtualChannel channel = launcher.getChannel();
if (channel == null) {
throw new IOException("offline?");
}
return channel.call(new GetExecutable(getHome()));
}

private File getExeFile() {
String execName = Functions.isWindows() ? "ant.bat" : "ant";
String home = Util.replaceMacro(getHome(), EnvVars.masterEnvVars);

return new File(home,"bin/"+execName);
private static class GetExecutable extends MasterToSlaveCallable<String, IOException> {
private static final long serialVersionUID = 906341330603832653L;
private final String rawHome;
GetExecutable(String rawHome) {
this.rawHome = rawHome;
}
@Override public String call() throws IOException {
String execName = Functions.isWindows() ? "ant.bat" : "ant";
String home = Util.replaceMacro(rawHome, EnvVars.masterEnvVars);
File exe = new File(home, "bin/" + execName);
if (exe.exists()) {
return exe.getPath();
}
return null;
}
}

/**
Expand Down

0 comments on commit c957dca

Please sign in to comment.