<commit_before>package org.jetbrains.plugins.scala
package debugger

import java.io.File
import javax.swing.SwingUtilities

import com.intellij.ProjectTopics
import com.intellij.compiler.CompilerTestUtil
import com.intellij.compiler.server.BuildManager
import com.intellij.openapi.compiler.{CompileContext, CompileStatusNotification, CompilerManager, CompilerMessageCategory}
import com.intellij.openapi.projectRoots._
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl
import com.intellij.openapi.roots._
import com.intellij.openapi.vfs._
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.testFramework.{PsiTestUtil, VfsTestUtil}
import com.intellij.util.concurrency.Semaphore
import com.intellij.util.ui.UIUtil
import junit.framework.Assert
import org.jetbrains.plugins.scala.base.ScalaLibraryLoader
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.SyntheticClasses

import scala.collection.mutable.ListBuffer

/**
 * Nikolay.Tropin
 * 2/26/14
 */
abstract class ScalaCompilerTestBase extends CompileServerTestBase with ScalaVersion {

  override def setUp(): Unit = {
    VfsRootAccess.SHOULD_PERFORM_ACCESS_CHECK = false

    super.setUp()
    myProject.getMessageBus.connect(myTestRootDisposable).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter {
      override def rootsChanged(event: ModuleRootEvent) {
        forceFSRescan()
      }
    })
    CompilerTestUtil.enableExternalCompiler()

    addRoots()
    DebuggerTestUtil.setCompileServerSettings()
    DebuggerTestUtil.forceJdk8ForBuildProcess()

    getProject.save()
  }

  protected def addRoots() {
    inWriteAction {
      val srcRoot = getBaseDir.findChild("src").toOption.getOrElse(
        getBaseDir.createChildDirectory(this, "src")
      )
      PsiTestUtil.addSourceRoot(getModule, srcRoot, false)
      val output = getBaseDir.findChild("out").toOption.getOrElse(
        getBaseDir.createChildDirectory(this, "out")
      )
      CompilerProjectExtension.getInstance(getProject).setCompilerOutputUrl(output.getUrl)
    }
  }

  protected def addScalaSdk(loadReflect: Boolean = true) {
    ScalaLoader.loadScala()
    val cl = SyntheticClasses.get(getProject)
    if (!cl.isClassesRegistered) cl.registerClasses()

    ScalaLibraryLoader.addScalaSdk(myModule, scalaSdkVersion, loadReflect)
  }

  override protected def getTestProjectJdk: Sdk = {
    val jdkTable = JavaAwareProjectJdkTableImpl.getInstanceEx
    if (scalaVersion.startsWith("2.12")) {
      DebuggerTestUtil.findJdk8()
    }
    else {
      jdkTable.getInternalJdk
    }
  }

  protected def forceFSRescan() = BuildManager.getInstance.clearState(myProject)

  protected override def tearDown() {
    CompilerTestUtil.disableExternalCompiler(myProject)

    super.tearDown()
  }

  protected def make(): List[String] = {
    val semaphore: Semaphore = new Semaphore
    semaphore.down()
    val callback = new ErrorReportingCallback(semaphore)
    UIUtil.invokeAndWaitIfNeeded(new Runnable {
      def run() {
        try {
          CompilerTestUtil.saveApplicationSettings()
          val ioFile: File = VfsUtilCore.virtualToIoFile(myModule.getModuleFile)
          if (!ioFile.exists) {
            getProject.save()
            assert(ioFile.exists, "File does not exist: " + ioFile.getPath)<commit_msg>radical solution to compiler tests failing due to broken internal jdk paths<commit_after>package org.jetbrains.plugins.scala
package debugger

import java.io.File
import javax.swing.SwingUtilities

import com.intellij.ProjectTopics
import com.intellij.compiler.CompilerTestUtil
import com.intellij.compiler.server.BuildManager
import com.intellij.openapi.compiler.{CompileContext, CompileStatusNotification, CompilerManager, CompilerMessageCategory}
import com.intellij.openapi.projectRoots._
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl
import com.intellij.openapi.roots._
import com.intellij.openapi.vfs._
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.testFramework.{PsiTestUtil, VfsTestUtil}
import com.intellij.util.concurrency.Semaphore
import com.intellij.util.ui.UIUtil
import junit.framework.Assert
import org.jetbrains.plugins.scala.base.ScalaLibraryLoader
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.synthetic.SyntheticClasses

import scala.collection.mutable.ListBuffer

/**
 * Nikolay.Tropin
 * 2/26/14
 */
abstract class ScalaCompilerTestBase extends CompileServerTestBase with ScalaVersion {

  override def setUp(): Unit = {
    VfsRootAccess.SHOULD_PERFORM_ACCESS_CHECK = false

    super.setUp()
    myProject.getMessageBus.connect(myTestRootDisposable).subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter {
      override def rootsChanged(event: ModuleRootEvent) {
        forceFSRescan()
      }
    })
    CompilerTestUtil.enableExternalCompiler()

    addRoots()
    DebuggerTestUtil.setCompileServerSettings()
    DebuggerTestUtil.forceJdk8ForBuildProcess()

    getProject.save()
  }

  protected def addRoots() {
    inWriteAction {
      val srcRoot = getBaseDir.findChild("src").toOption.getOrElse(
        getBaseDir.createChildDirectory(this, "src")
      )
      PsiTestUtil.addSourceRoot(getModule, srcRoot, false)
      val output = getBaseDir.findChild("out").toOption.getOrElse(
        getBaseDir.createChildDirectory(this, "out")
      )
      CompilerProjectExtension.getInstance(getProject).setCompilerOutputUrl(output.getUrl)
    }
  }

  protected def addScalaSdk(loadReflect: Boolean = true) {
    ScalaLoader.loadScala()
    val cl = SyntheticClasses.get(getProject)
    if (!cl.isClassesRegistered) cl.registerClasses()

    ScalaLibraryLoader.addScalaSdk(myModule, scalaSdkVersion, loadReflect)
  }

  override protected def getTestProjectJdk: Sdk = {
//    val jdkTable = JavaAwareProjectJdkTableImpl.getInstanceEx
//    if (scalaVersion.startsWith("2.12")) {
//      DebuggerTestUtil.findJdk8()
//    }
//    else {
//      jdkTable.getInternalJdk
//    }
      DebuggerTestUtil.findJdk8()
  }

  protected def forceFSRescan() = BuildManager.getInstance.clearState(myProject)

  protected override def tearDown() {
    CompilerTestUtil.disableExternalCompiler(myProject)

    super.tearDown()
  }

  protected def make(): List[String] = {
    val semaphore: Semaphore = new Semaphore
    semaphore.down()
    val callback = new ErrorReportingCallback(semaphore)
    UIUtil.invokeAndWaitIfNeeded(new Runnable {
      def run() {
        try {
          CompilerTestUtil.saveApplicationSettings()
          val ioFile: File = VfsUtilCore.virtualToIoFile(myModule.getModuleFile)
          if (!ioFile.exists) {
            getProject.save()
            assert(ioFile.exists, "File does not exist: " + ioFile.getPath)
{'fraction_non_alphanumeric': 0.09123981373690337, 'fraction_numerical': 0.0030558789289871946, 'mean_word_length': 4.254587155963303, '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': '5326556', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2103, 'n_words': 339}