Skip to content

Commit

Permalink
Add windows detection when executing arc (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-harms authored and kageiit committed Dec 4, 2018
1 parent e239ad4 commit f54c07f
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import com.uber.jenkins.phabricator.LauncherFactory;
import com.uber.jenkins.phabricator.conduit.ArcanistClient;
import com.uber.jenkins.phabricator.utils.Logger;
import hudson.model.Computer;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ApplyPatchTask extends Task {
private static final String DEFAULT_GIT_PATH = "git";
Expand Down Expand Up @@ -65,7 +68,7 @@ public ApplyPatchTask(
boolean patchWithForceFlag, String scmType) {
super(logger);

this.arcPath = arcPath;
this.arcPath = isWindows() ? arcPath + ".bat" : arcPath;
this.gitPath = DEFAULT_GIT_PATH;
this.hgPath = DEFAULT_HG_PATH;

Expand All @@ -78,7 +81,6 @@ public ApplyPatchTask(
this.diffID = diffID;
this.conduitUrl = conduitUrl;
this.conduitToken = conduitToken;

this.createCommit = createCommit;
this.skipForcedClean = skipForcedClean;
this.createBranch = createBranch;
Expand Down Expand Up @@ -212,6 +214,26 @@ private int launch(List<String> cmds) throws IOException, InterruptedException {
return starter.launch().cmds(cmds).stdout(logStream).join();
}

/**
* @return true if the current executor is on Windows
*/
private boolean isWindows() {
try {
Computer remoteComputer = Computer.currentComputer();
if (remoteComputer != null) {
Map<Object, Object> remoteProperties = remoteComputer.getSystemProperties();
if (remoteProperties.containsKey("os.name")) {
return StringUtils.startsWithIgnoreCase(remoteProperties.get("os.name").toString(), "Windows");
}
}
} catch (IOException e) {
info("IOException attempting to determine whether the OS is Windows.\n" + e.getMessage());
} catch (InterruptedException e) {
info("InterruptedException attempting to determine whether the OS is Windows.\n" + e.getMessage());
}
return false;
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit f54c07f

Please sign in to comment.