<commit_before>package org.jetbrains.plugins.scala.testingSupport.scalaTest


import _root_.java.io.File
import _root_.scala.collection.mutable.ArrayBuffer
import com.intellij.execution._
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.{ProgramRunner, ExecutionEnvironment}
import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil
import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView
import com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm
import com.intellij.execution.testframework.TestConsoleProperties
import com.intellij.execution.ui.ConsoleView
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.{JDOMExternalizer, JDOMExternalizable}
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.{JavaPsiFacade, PsiManager, PsiClass}
import com.intellij.util.PathUtil
import jdom.Element
import _root_.scala.collection.mutable.HashSet
import com.intellij.openapi.module.{ModuleUtil, ModuleManager, Module}
import com.intellij.openapi.options.SettingsEditor
import config.{ScalaConfigUtils, ScalaSDK}

import com.intellij.execution.configurations._
import _root_.java.util.Arrays
import com.intellij.facet.FacetManager
import com.intellij.openapi.vfs.{JarFileSystem, VirtualFile}

import com.intellij.openapi.projectRoots.JavaSdkType
import lang.psi.api.ScalaFile
import com.intellij.execution.filters.TextConsoleBuilderFactory


import com.intellij.vcsUtil.VcsUtil
import com.intellij.openapi.roots.{OrderRootType, ModuleRootManager}
import lang.psi.api.toplevel.typedef.ScTypeDefinition
import script.ScalaScriptRunConfiguration

/**
 * User: <NAME>
 * Date: 22.02.2009
 */

class ScalaTestRunConfiguration(val project: Project, val configurationFactory: ConfigurationFactory, val name: String)
        extends ModuleBasedConfiguration[RunConfigurationModule](name, new RunConfigurationModule(project), configurationFactory) {
  val SCALA_HOME = "-Dscala.home="
  val CLASSPATH = "-Denv.classpath=\"%CLASSPATH%\""
  val EMACS = "-Denv.emacs=\"%EMACS%\""
  val MAIN_CLASS = "org.scalatest.tools.Runner"
  val SUITE_PATH = "org.scalatest.Suite"
  val REPORTER = "org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestReporter"
  private var testClassPath = ""
  private var testArgs = ""
  private var javaOptions = ""

  def getTestClassPath = testClassPath
  def getTestArgs = testArgs
  def getJavaOptions = javaOptions
  def setTestClassPath(s: String): Unit = testClassPath = s
  def setTestArgs(s: String): Unit = testArgs = s
  def setJavaOptions(s: String): Unit = javaOptions = s

  def apply(configuration: ScalaTestRunConfigurationForm) {
    setTestClassPath(configuration.getTestClassPath)
    setJavaOptions(configuration.getJavaOptions)
    setTestArgs(configuration.getTestArgs)
  }

  def getClazz(path: String): PsiClass = {
    val facade = JavaPsiFacade.getInstance(project)
    facade.findClass(path, GlobalSearchScope.allScope(project))
  }

  def getState(executor: Executor, env: ExecutionEnvironment): RunProfileState = {
    def classNotFoundError {
      throw new ExecutionException("Test class not found.")
    }
    var clazz: PsiClass = null
    var suiteClass: PsiClass = null
    try {
      clazz = getClazz(testClassPath)
      suiteClass = getClazz(SUITE_PATH)
    }
    catch {
      case e => classNotFoundError
    }
    if (clazz == null) classNotFoundError
    if (suiteClass == null)
      throw new ExecutionException("ScalaTest not specified.")
    if (!clazz.isInheritor(suiteClass, true)) throw new ExecutionException("Not found suite class.")

    val module = getModule
    if (module == null) throw new ExecutionException("Module is not specified")
    val scalaSdkPath = getScalaInstallPath
    if (scalaSdkPath == "") throw new ExecutionException("Scala SDK is not specified")
    val rootManager = ModuleRootManager.getInstance(module);
    val sdk = rootManager.getSdk();
    if (sdk == null || !(sdk.getSdkType.isInstanceOf[JavaSdkType])) {
      throw CantRunException.noJdkForModule(module);
    }
    val sdkType = sdk.getSdkType

    val state = new JavaCommandLineState(env) {
      protected override def createJavaParameters: JavaParameters = {
        val params = new JavaParameters();

        params.setJdk(sdk)

        params.setCharset(null)
        params.getVMParametersList.addParametersString(getJavaOptions)
        //params.getVMParametersList.addParametersString("-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5009")
        val list = new java.util.ArrayList[String]
        val dir: VirtualFile = VcsUtil.getVirtualFile(scalaSdkPath + File.separator + "lib")
        for (child <- dir.getChildren) {
          params.getClassPath.add(child)
        }
        params.getClassPath.add(getClassPath(module))
        val rtJarPath = PathUtil.getJarPathForClass(classOf[ScalaTestReporter])
        params.getClassPath.add(rtJarPath)
        params.setMainClass(MAIN_CLASS)

        params.getProgramParametersList.add("-s")
        params.getProgramParametersList.add(testClassPath)
        params.getProgramParametersList.add("-rYZTFGUPBISAR")
        params.getProgramParametersList.add(REPORTER)<commit_msg>hack to use ScalaTestReporter without scalatest.jar<commit_after>package org.jetbrains.plugins.scala.testingSupport.scalaTest


import _root_.java.io.File
import _root_.scala.collection.mutable.ArrayBuffer
import com.intellij.execution._
import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.runners.{ProgramRunner, ExecutionEnvironment}
import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties
import com.intellij.execution.testframework.sm.SMTestRunnerConnectionUtil
import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView
import com.intellij.execution.testframework.sm.runner.ui.SMTestRunnerResultsForm
import com.intellij.execution.testframework.TestConsoleProperties
import com.intellij.execution.ui.ConsoleView
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.{JDOMExternalizer, JDOMExternalizable}
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.{JavaPsiFacade, PsiManager, PsiClass}
import com.intellij.util.PathUtil
import jdom.Element
import _root_.scala.collection.mutable.HashSet
import com.intellij.openapi.module.{ModuleUtil, ModuleManager, Module}
import com.intellij.openapi.options.SettingsEditor
import config.{ScalaConfigUtils, ScalaSDK}

import com.intellij.execution.configurations._
import _root_.java.util.Arrays
import com.intellij.facet.FacetManager
import com.intellij.openapi.vfs.{JarFileSystem, VirtualFile}

import com.intellij.openapi.projectRoots.JavaSdkType
import lang.psi.api.ScalaFile
import com.intellij.execution.filters.TextConsoleBuilderFactory


import com.intellij.vcsUtil.VcsUtil
import com.intellij.openapi.roots.{OrderRootType, ModuleRootManager}
import lang.psi.api.toplevel.typedef.ScTypeDefinition
import script.ScalaScriptRunConfiguration

/**
 * User: <NAME>
 * Date: 22.02.2009
 */

class ScalaTestRunConfiguration(val project: Project, val configurationFactory: ConfigurationFactory, val name: String)
        extends ModuleBasedConfiguration[RunConfigurationModule](name, new RunConfigurationModule(project), configurationFactory) {
  val SCALA_HOME = "-Dscala.home="
  val CLASSPATH = "-Denv.classpath=\"%CLASSPATH%\""
  val EMACS = "-Denv.emacs=\"%EMACS%\""
  val MAIN_CLASS = "org.scalatest.tools.Runner"
  val SUITE_PATH = "org.scalatest.Suite"
  val REPORTER = "org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestReporter"
  private var testClassPath = ""
  private var testArgs = ""
  private var javaOptions = ""

  def getTestClassPath = testClassPath
  def getTestArgs = testArgs
  def getJavaOptions = javaOptions
  def setTestClassPath(s: String): Unit = testClassPath = s
  def setTestArgs(s: String): Unit = testArgs = s
  def setJavaOptions(s: String): Unit = javaOptions = s

  def apply(configuration: ScalaTestRunConfigurationForm) {
    setTestClassPath(configuration.getTestClassPath)
    setJavaOptions(configuration.getJavaOptions)
    setTestArgs(configuration.getTestArgs)
  }

  def getClazz(path: String): PsiClass = {
    val facade = JavaPsiFacade.getInstance(project)
    facade.findClass(path, GlobalSearchScope.allScope(project))
  }

  def getState(executor: Executor, env: ExecutionEnvironment): RunProfileState = {
    def classNotFoundError {
      throw new ExecutionException("Test class not found.")
    }
    var clazz: PsiClass = null
    var suiteClass: PsiClass = null
    try {
      clazz = getClazz(testClassPath)
      suiteClass = getClazz(SUITE_PATH)
    }
    catch {
      case e => classNotFoundError
    }
    if (clazz == null) classNotFoundError
    if (suiteClass == null)
      throw new ExecutionException("ScalaTest not specified.")
    if (!clazz.isInheritor(suiteClass, true)) throw new ExecutionException("Not found suite class.")

    val module = getModule
    if (module == null) throw new ExecutionException("Module is not specified")
    val scalaSdkPath = getScalaInstallPath
    if (scalaSdkPath == "") throw new ExecutionException("Scala SDK is not specified")
    val rootManager = ModuleRootManager.getInstance(module);
    val sdk = rootManager.getSdk();
    if (sdk == null || !(sdk.getSdkType.isInstanceOf[JavaSdkType])) {
      throw CantRunException.noJdkForModule(module);
    }
    val sdkType = sdk.getSdkType

    val state = new JavaCommandLineState(env) {
      protected override def createJavaParameters: JavaParameters = {
        val params = new JavaParameters();

        params.setJdk(sdk)

        params.setCharset(null)
        params.getVMParametersList.addParametersString(getJavaOptions)
        //params.getVMParametersList.addParametersString("-Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5009")
        val list = new java.util.ArrayList[String]
        val dir: VirtualFile = VcsUtil.getVirtualFile(scalaSdkPath + File.separator + "lib")
        for (child <- dir.getChildren) {
          params.getClassPath.add(child)
        }
        params.getClassPath.add(getClassPath(module))
        val jarPathForClass = PathUtil.getJarPathForClass(classOf[ScalaTestRunConfiguration])
        val virtFile = VcsUtil.getVirtualFile(jarPathForClass)
        if (virtFile.getExtension != "jar") { //so it's debug mode, we can free use ScalaTestReporter class
          val rtJarPath = PathUtil.getJarPathForClass(classOf[ScalaTestReporter])
          params.getClassPath.add(rtJarPath)
        } else { //so we must to find jar
          val rtJarPath = jarPathForClass.substring(0, jarPathForClass.lastIndexOf(File.separator)) + "runners.jar"
          params.getClassPath.add(rtJarPath)
        }

        params.setMainClass(MAIN_CLASS)

        params.getProgramParametersList.add("-s")
        params.getProgramParametersList.add(testClassPath)
        params.getProgramParametersList.add("-rYZTFGUPBISAR")
        params.getProgramParametersList.add(REPORTER)
{'fraction_non_alphanumeric': 0.09421898588047242, 'fraction_numerical': 0.0022200515051949204, 'mean_word_length': 4.664989939637827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4944732', 'n_tokens_mistral': 3465, 'n_tokens_neox': 3381, 'n_words': 632}