<commit_before>package scala.tools.eclipse
package testsetup

import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.JavaCore
import org.eclipse.core.runtime.FileLocator
import org.eclipse.core.runtime.Platform
import java.io.{ ByteArrayInputStream, File, IOException, InputStream }
import org.eclipse.core.resources.{ IContainer, IFile, IFolder, IProject, IProjectDescription, ResourcesPlugin }
import org.eclipse.core.runtime.{ IPath, Path }
import scala.tools.eclipse.util.OSGiUtils
import scala.tools.nsc.util.SourceFile
import scala.collection.mutable
import scala.util.matching.Regex

/** Utility functions for setting up test projects.
 *  
 *  @author <NAME>
 */
object SDTTestUtils {
  
  lazy val sourceWorkspaceLoc = {
    val bundle= Platform.getBundle("org.scala-ide.sdt.core.tests")
    OSGiUtils.pathInBundle(bundle, File.separatorChar + "test-workspace").get
  }
  
  lazy val workspace = ResourcesPlugin.getWorkspace

  /** Setup the project in the target workspace. The 'name' project should
   *  exist in the source workspace.
   */
  def setupProject(name: String): ScalaProject = {
    val wspaceLoc = workspace.getRoot.getLocation
    val src = new File(sourceWorkspaceLoc.toFile().getAbsolutePath + File.separatorChar + name)
    val dst = new File(wspaceLoc.toFile().getAbsolutePath + File.separatorChar + name)
    println("copying %s to %s".format(src, dst))
    FileUtils.copyDirectory(src, dst)
    val project = workspace.getRoot.getProject(name)
    project.create(null)
    project.open(null)
    JavaCore.create(project)
    ScalaPlugin.plugin.getScalaProject(project)
  }<commit_msg>Put the workspace copy inside a workspace runnable, to be safer w.r.t.  concurrent modifications. Should fix a class of spurious failures  in the nightly.<commit_after>package scala.tools.eclipse
package testsetup

import org.eclipse.jdt.core.IJavaProject
import org.eclipse.jdt.core.JavaCore
import org.eclipse.core.runtime.FileLocator
import org.eclipse.core.runtime.Platform
import java.io.{ ByteArrayInputStream, File, IOException, InputStream }
import org.eclipse.core.resources.{ IContainer, IFile, IFolder, IProject, IProjectDescription, ResourcesPlugin }
import org.eclipse.core.runtime.{ IPath, Path }
import scala.tools.eclipse.util.{ OSGiUtils, EclipseUtils }
import scala.tools.nsc.util.SourceFile
import scala.collection.mutable
import scala.util.matching.Regex
import org.eclipse.core.runtime.NullProgressMonitor

/** Utility functions for setting up test projects.
 *  
 *  @author <NAME>
 */
object SDTTestUtils {
  
  lazy val sourceWorkspaceLoc = {
    val bundle= Platform.getBundle("org.scala-ide.sdt.core.tests")
    OSGiUtils.pathInBundle(bundle, File.separatorChar + "test-workspace").get
  }
  
  lazy val workspace = ResourcesPlugin.getWorkspace

  /** Setup the project in the target workspace. The 'name' project should
   *  exist in the source workspace.
   */
  def setupProject(name: String): ScalaProject = {
    EclipseUtils.workspaceRunnableIn(workspace) { monitor =>
      val wspaceLoc = workspace.getRoot.getLocation
      val src = new File(sourceWorkspaceLoc.toFile().getAbsolutePath + File.separatorChar + name)
      val dst = new File(wspaceLoc.toFile().getAbsolutePath + File.separatorChar + name)
      println("copying %s to %s".format(src, dst))
      FileUtils.copyDirectory(src, dst)
      val project = workspace.getRoot.getProject(name)
      project.create(null)
      project.open(null)
      JavaCore.create(project)
    }
    ScalaPlugin.plugin.getScalaProject(workspace.getRoot.getProject(name))
  }
{'fraction_non_alphanumeric': 0.10097629009762901, 'fraction_numerical': 0.0, 'mean_word_length': 4.400602409638554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '1092649', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1064, 'n_words': 251}