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

package com.microsoft.tfs.tests

import com.jetbrains.rd.util.info
import com.microsoft.tfs.Logging
import org.junit.Assert
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

private val logger = Logging.getLogger("ClassicClientUtilsKt")

private fun executeClient(directory: Path, vararg arguments: String) {
    logger.info { "Running tf with arguments: [${arguments.joinToString(",")}]" }
    val loginArgument = "-login:${IntegrationTestUtils.user},${IntegrationTestUtils.pass}"
    val process = ProcessBuilder(IntegrationTestUtils.tfExe, loginArgument, *arguments)
        .directory(directory.toFile())
        .redirectOutput(ProcessBuilder.Redirect.INHERIT)
        .redirectError(ProcessBuilder.Redirect.INHERIT)
        .start()
    val exitCode = process.waitFor()
    Assert.assertEquals(0, exitCode)
}

private fun tfCreateWorkspace(workspacePath: Path, name: String) {
    val collectionUrl = IntegrationTestUtils.serverUrl
    executeClient(workspacePath, "workspace", "-new", "-collection:$collectionUrl", name)
}

private fun tfDeleteWorkspace(workspacePath: Path, workspaceName: String) {
    executeClient(workspacePath, "workspace", "-delete", workspaceName)
}

private fun tfCreateMapping(workspacePath: Path, workspaceName: String, serverPath: String, localPath: Path) {<commit_msg>Fix classic client environment in tests (#330)<commit_after>// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root.

package com.microsoft.tfs.tests

import com.jetbrains.rd.util.info
import com.microsoft.tfs.Logging
import org.junit.Assert
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths

private val logger = Logging.getLogger("ClassicClientUtilsKt")

private fun executeClient(directory: Path, vararg arguments: String) {
    logger.info { "Running tf with arguments: [${arguments.joinToString(",")}]" }
    val loginArgument = "-login:${IntegrationTestUtils.user},${IntegrationTestUtils.pass}"
    val process = ProcessBuilder(IntegrationTestUtils.tfExe, loginArgument, *arguments)
        .directory(directory.toFile())
        .apply {
            environment().also {
                it["TF_NOTELEMETRY"] = "TRUE"
                it["TF_ADDITIONAL_JAVA_ARGS"] = "-Duser.country=US -Duser.language=en"
                it["TF_USE_KEYCHAIN"] = "FALSE" // will be stuck on com.microsoft.tfs.jni.internal.keychain.NativeKeychain.nativeFindInternetPassword on macOS otherwise
            }
        }
        .inheritIO()
        .start()
    val exitCode = process.waitFor()
    Assert.assertEquals(0, exitCode)
}

private fun tfCreateWorkspace(workspacePath: Path, name: String) {
    val collectionUrl = IntegrationTestUtils.serverUrl
    executeClient(workspacePath, "workspace", "-new", "-collection:$collectionUrl", name)
}

private fun tfDeleteWorkspace(workspacePath: Path, workspaceName: String) {
    executeClient(workspacePath, "workspace", "-delete", workspaceName)
}

private fun tfCreateMapping(workspacePath: Path, workspaceName: String, serverPath: String, localPath: Path) {
{'fraction_non_alphanumeric': 0.1134621281815394, 'fraction_numerical': 0.0015332720024532351, 'mean_word_length': 4.482352941176471, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5938647', 'n_tokens_mistral': 936, 'n_tokens_neox': 918, 'n_words': 222}