/*
 * Copyright (c) 2012-2013, CloudBees, Inc., SOASTA, Inc.
 * All Rights Reserved.
 */
package com.soasta.jenkins;

import hudson.FilePath;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.tools.DownloadFromUrlInstaller;
import hudson.tools.ToolInstallation;
import hudson.tools.ToolInstaller;
import hudson.util.VersionNumber;

import java.io.IOException;
import java.net.URL;

/**
 * @author Kohsuke Kawaguchi
 */
public class SCommandInstaller extends DownloadFromUrlInstaller {
    private final CloudTestServer server;
    private final VersionNumber buildNumber;

    private SCommandInstaller(CloudTestServer server, VersionNumber buildNumber) {
        super("cloudtest-scommand-"+buildNumber);
        this.server = server;
        this.buildNumber = buildNumber;
    }

    public SCommandInstaller(CloudTestServer server) throws IOException {
        this(server,server.getBuildNumber());
    }

    @Override
    public Installable getInstallable() throws IOException {
        Installable i = new Installable();
        i.url = new URL(server.getUrl(),"downloads/scommand/scommand.zip").toExternalForm();
        i.id = id;
        i.name = buildNumber.toString();
        return i;
    }

    /**
     * We implement {@link ToolInstaller} just so that we can reuse its installation code.
     * And because of this, we collapse {@link ToolInstallation} and {@link ToolInstaller}.
     */
    public FilePath performInstallation(Node node, TaskListener log) throws IOException, InterruptedException {
        return super.performInstallation(
                new FakeInstallation(id), node, log);
    }

    public FilePath scommand(Node node, TaskListener log) throws IOException, InterruptedException {
        return performInstallation(node,log).child("bin/scommand");
    }

    // this is internal use only
    // @Extension
    public static final class DescriptorImpl extends DownloadFromUrlInstaller.DescriptorImpl<MakeAppTouchTestableInstaller> {
        public String getDisplayName() {
            return "Install CloudTest Command-Line Client";
        }
    }
}

@@ -1746,22 +1746,39 @@
         
-return
+FilePath scommandHome =
  perform
@@ -1799,16 +1799,263 @@
 ode,log)
+;%0A        String os = (String)node.toComputer().getSystemProperties().get(%22os.name%22);%0A        if (os != null && os.startsWith(%22Windows%22)) %7B%0A            return scommandHome.child(%22bin/scommand.bat%22);%0A        %7D else %7B%0A            return scommandHome
 .child(%22
@@ -2066,24 +2066,34 @@
 scommand%22);%0A
+        %7D%0A
     %7D%0A%0A    /

Fix JENKINS-17986 ("Play Composition" build step does not work on Windows slaves).