package jetbrains.buildServer.helm;

import jetbrains.buildServer.RunBuildException;
import jetbrains.buildServer.agent.runner.BuildServiceAdapter;
import jetbrains.buildServer.agent.runner.ProgramCommandLine;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static jetbrains.buildServer.helm.HelmConstants.*;

/**
 * Created by Evgeniy Koshkin (evgeniy.koshkin@jetbrains.com) on 18.10.17.
 */
public class InstallBuildService extends BuildServiceAdapter {
    @NotNull
    @Override
    public ProgramCommandLine makeProgramCommandLine() throws RunBuildException {
        return new ProgramCommandLine() {
            @NotNull
            @Override
            public String getExecutablePath() throws RunBuildException {
                return HELM_EXEC_NAME;
            }

            @NotNull
            @Override
            public String getWorkingDirectory() throws RunBuildException {
                return getRunnerContext().getBuild().getCheckoutDirectory().getAbsolutePath();
            }

            @NotNull
            @Override
            public List<String> getArguments() throws RunBuildException {
                Map<String, String> runnerParameters = getRunnerParameters();
                return Arrays.asList(HELM_INSTALL_COMMAND, StringUtil.emptyIfNull(runnerParameters.get(CHART)), StringUtil.emptyIfNull(runnerParameters.get(ADDITIONAL_FLAGS)));
            }

            @NotNull
            @Override
            public Map<String, String> getEnvironment() throws RunBuildException {
                return getRunnerContext().getBuildParameters().getEnvironmentVariables();
            }
        };
    }
}

@@ -309,22 +309,26 @@
 va.util.
-Arrays
+LinkedList
 ;%0Aimport
@@ -1336,51 +1336,133 @@
     
-return Arrays.asList(HELM_INSTALL_COMMAND, 
+List%3CString%3E result = new LinkedList%3CString%3E();%0A                result.add(HELM_INSTALL_COMMAND);%0A                result.add(
 Stri
@@ -1508,18 +1508,46 @@
 (CHART))
-, 
+);%0A                result.add(
 StringUt
@@ -1599,24 +1599,55 @@
 L_FLAGS)));%0A
+                return result;%0A
             

use linked list for args