From f54c07f748c24753d574f4edd7eb6344e705586b Mon Sep 17 00:00:00 2001 From: colin-harms Date: Tue, 4 Dec 2018 10:07:00 -0600 Subject: [PATCH] Add windows detection when executing `arc` (#270) --- .../phabricator/tasks/ApplyPatchTask.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/uber/jenkins/phabricator/tasks/ApplyPatchTask.java b/src/main/java/com/uber/jenkins/phabricator/tasks/ApplyPatchTask.java index 1b0d6153..e5390eeb 100644 --- a/src/main/java/com/uber/jenkins/phabricator/tasks/ApplyPatchTask.java +++ b/src/main/java/com/uber/jenkins/phabricator/tasks/ApplyPatchTask.java @@ -24,6 +24,8 @@ 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; @@ -31,6 +33,7 @@ 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"; @@ -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; @@ -78,7 +81,6 @@ public ApplyPatchTask( this.diffID = diffID; this.conduitUrl = conduitUrl; this.conduitToken = conduitToken; - this.createCommit = createCommit; this.skipForcedClean = skipForcedClean; this.createBranch = createBranch; @@ -212,6 +214,26 @@ private int launch(List 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 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} */