<commit_before>package unityExplorer

import com.intellij.ide.util.treeView.AbstractTreeNode
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.openapi.project.Project
import com.jetbrains.rider.ideaInterop.vfs.VfsWriteOperationsHost
import com.jetbrains.rider.model.RdProjectModelDumpFlags
import com.jetbrains.rider.model.RdProjectModelDumpParams
import com.jetbrains.rider.model.projectModelTasks
import com.jetbrains.rider.plugins.unity.explorer.UnityExplorer
import com.jetbrains.rider.plugins.unity.explorer.UnityExplorerNode
import com.jetbrains.rider.projectView.moveProviders.RiderCutProvider
import com.jetbrains.rider.projectView.moveProviders.RiderPasteProvider
import com.jetbrains.rider.projectView.moveProviders.impl.ActionOrderType
import com.jetbrains.rider.projectView.moveProviders.impl.ProjectModelData
import com.jetbrains.rider.projectView.solution
import com.jetbrains.rider.projectView.views.SolutionViewPaneBase
import com.jetbrains.rider.test.framework.TestProjectModelContext
import com.jetbrains.rider.test.framework.flushQueues
import com.jetbrains.rider.test.framework.frameworkLogger
import com.jetbrains.rider.test.framework.persistAllFilesOnDisk
import com.jetbrains.rider.test.maskCacheFiles
import com.jetbrains.rider.test.scriptingApi.*
import com.jetbrains.rider.util.idea.getComponent
import com.jetbrains.rider.util.idea.syncFromBackend
import java.io.File
import javax.swing.JTree

fun TestProjectModelContext.dump(caption: String, project: Project, tempTestDirectory: File, action: () -> Unit) {

    doActionAndWait(project, action, true)
    val treeDump = dumpUnityExplorerTree(project, tempTestDirectory)

    treeOutput.appendln("===================")
    fileOutput.appendln("===================")
    treeOutput.appendln(caption)
    fileOutput.appendln(caption)
    treeOutput.appendln()
    fileOutput.appendln()
    treeOutput.appendln(treeDump)
    treeOutput.appendln()

    val dumpProjectModelTask = project.solution.projectModelTasks.dumpProjectModel
    val dumpParams = RdProjectModelDumpParams(RdProjectModelDumpFlags.Structure, hideMiscFilesProjectContent)
    val projectModelDump = dumpProjectModelTask.syncFromBackend(dumpParams, project)
    treeOutput.appendln(projectModelDump?.maskCacheFiles())
    treeOutput.appendln()

    dumpFiles(fileOutput, tempTestDirectory, false, this.profile)
}

private fun dumpUnityExplorerTree(project: Project, tempTestDirectory: File) : String {
    val tree = UnityExplorer.getInstance(project).tree
    return dumpExplorerTree(tree)
        .replace(tempTestDirectory.toPath().toUri().toString().replace("file:///", "file://"), "")
}


fun dumpExplorerTree(tree: JTree) : String {
    val dump = dumpTree(tree)
    return dump
        .replace(" Scratches and Consoles", "")
        .replace(SolutionViewPaneBase.TextSeparator, "*")
        .replace(" * no index", "")
        .maskCacheFiles()
        .replace("""(\s+)-Plugins$(\1\s+\S+$)*""".toRegex(RegexOption.MULTILINE), "") + "\n"
}

fun addNewItem(project: Project, path: Array<String>, template: TemplateType, itemName: String) {
    frameworkLogger.info("Start adding new item: '$itemName'")
    val dataContext = createDataContextFor2(project, arrayOf(path))
    changeFileSystem(project) {
        val createdFile = executeNewItemAction(dataContext, template.type, template.group!!, itemName)
        this.affectedFiles.add(createdFile!!.parentFile)
    }
    persistAllFilesOnDisk()
    frameworkLogger.info("New item '$itemName' is added")
}

fun createDataContextFor2(project: Project, paths: Array<Array<String>>): DataContext {
    flushQueues()
    val nodes = paths.map { findReq(it, project) }.toTypedArray()<commit_msg>Fix frontend tests on Mac<commit_after>package unityExplorer

import com.intellij.ide.util.treeView.AbstractTreeNode
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
import com.intellij.openapi.project.Project
import com.jetbrains.rider.ideaInterop.vfs.VfsWriteOperationsHost
import com.jetbrains.rider.model.RdProjectModelDumpFlags
import com.jetbrains.rider.model.RdProjectModelDumpParams
import com.jetbrains.rider.model.projectModelTasks
import com.jetbrains.rider.plugins.unity.explorer.UnityExplorer
import com.jetbrains.rider.plugins.unity.explorer.UnityExplorerNode
import com.jetbrains.rider.projectView.moveProviders.RiderCutProvider
import com.jetbrains.rider.projectView.moveProviders.RiderPasteProvider
import com.jetbrains.rider.projectView.moveProviders.impl.ActionOrderType
import com.jetbrains.rider.projectView.moveProviders.impl.ProjectModelData
import com.jetbrains.rider.projectView.solution
import com.jetbrains.rider.projectView.views.SolutionViewPaneBase
import com.jetbrains.rider.test.framework.TestProjectModelContext
import com.jetbrains.rider.test.framework.flushQueues
import com.jetbrains.rider.test.framework.frameworkLogger
import com.jetbrains.rider.test.framework.persistAllFilesOnDisk
import com.jetbrains.rider.test.maskCacheFiles
import com.jetbrains.rider.test.scriptingApi.*
import com.jetbrains.rider.util.idea.getComponent
import com.jetbrains.rider.util.idea.syncFromBackend
import java.io.File
import javax.swing.JTree

fun TestProjectModelContext.dump(caption: String, project: Project, tempTestDirectory: File, action: () -> Unit) {

    doActionAndWait(project, action, true)
    val treeDump = dumpUnityExplorerTree(project, tempTestDirectory)

    treeOutput.appendln("===================")
    fileOutput.appendln("===================")
    treeOutput.appendln(caption)
    fileOutput.appendln(caption)
    treeOutput.appendln()
    fileOutput.appendln()
    treeOutput.appendln(treeDump)
    treeOutput.appendln()

    val dumpProjectModelTask = project.solution.projectModelTasks.dumpProjectModel
    val dumpParams = RdProjectModelDumpParams(RdProjectModelDumpFlags.Structure, hideMiscFilesProjectContent)
    val projectModelDump = dumpProjectModelTask.syncFromBackend(dumpParams, project)
    treeOutput.appendln(projectModelDump?.maskCacheFiles())
    treeOutput.appendln()

    dumpFiles(fileOutput, tempTestDirectory, false, this.profile)
}

private fun dumpUnityExplorerTree(project: Project, tempTestDirectory: File) : String {
    val tree = UnityExplorer.getInstance(project).tree
    return dumpExplorerTree(tree)
        .replace(tempTestDirectory.toPath().toUri().toString(), "")
        .replace(tempTestDirectory.toPath().toUri().toString().replace("file:///", "file://"), "")
}


fun dumpExplorerTree(tree: JTree) : String {
    val dump = dumpTree(tree)
    return dump
        .replace(" Scratches and Consoles", "")
        .replace(SolutionViewPaneBase.TextSeparator, "*")
        .replace(" * no index", "")
        .maskCacheFiles()
        .replace("""(\s+)-Plugins$(\1\s+\S+$)*""".toRegex(RegexOption.MULTILINE), "") + "\n"
}

fun addNewItem(project: Project, path: Array<String>, template: TemplateType, itemName: String) {
    frameworkLogger.info("Start adding new item: '$itemName'")
    val dataContext = createDataContextFor2(project, arrayOf(path))
    changeFileSystem(project) {
        val createdFile = executeNewItemAction(dataContext, template.type, template.group!!, itemName)
        this.affectedFiles.add(createdFile!!.parentFile)
    }
    persistAllFilesOnDisk()
    frameworkLogger.info("New item '$itemName' is added")
}

fun createDataContextFor2(project: Project, paths: Array<Array<String>>): DataContext {
    flushQueues()
    val nodes = paths.map { findReq(it, project) }.toTypedArray()
{'fraction_non_alphanumeric': 0.11831761006289308, 'fraction_numerical': 0.0007861635220125787, 'mean_word_length': 5.6201214223764095, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '5392232', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2261, 'n_words': 352}