// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root.

package com.microsoft.alm.plugin.external.utils;

import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class ProcessHelper {
    public static Process startProcess(final String workingDirectory, final List<String> arguments) throws IOException {
        final ProcessBuilder pb = new ProcessBuilder(arguments);

        // Disable any telemetry that the tool may initiate
        pb.environment().put("TF_NOTELEMETRY", "TRUE");
        pb.environment().put("TF_ADDITIONAL_JAVA_ARGS", "-Duser.country=US -Duser.language=en");

        if (StringUtils.isNotEmpty(workingDirectory)) {
            pb.directory(new File(workingDirectory));
        }
        return pb.start();
    }
}

@@ -711,16 +711,98 @@
 ge=en%22);
+%0A        pb.environment().put(%22PATH%22, getPatchedPathWithCurrentJavaBinLocation());
 %0A%0A      
@@ -947,11 +947,330 @@
 );%0A    %7D
+%0A%0A    private static String getPatchedPathWithCurrentJavaBinLocation() %7B%0A        String currentJavaHome = System.getProperty(%22java.home%22);%0A        String originPathVariable = System.getenv(%22PATH%22);%0A        return originPathVariable + File.pathSeparator + currentJavaHome + File.separator + %22bin%22 + File.separator;%0A    %7D
 %0A%7D%0A

Use current Java to run TF client. #126