<commit_before>package net.virtualvoid.bytecode

import _root_.org.specs._

import _root_.scala.tools.nsc.Settings

object BytecodeStaticSpecs extends Specification {
  import _root_.scala.tools.nsc.reporters._

  val outerClassLoader = getClass.getClassLoader.asInstanceOf[java.net.URLClassLoader]
  val mySettings = new Settings
  
  def asFile(url:java.net.URL):java.io.File =
      new java.io.File(url.toURI)

  def inflateClassPath(jarfile: java.io.File): Seq[java.io.File] =
    jarfile +: new java.util.jar.JarFile(jarfile).getManifest.getMainAttributes.getValue("Class-Path").split("\\s+").map(new java.io.File(_))

  object interpreter extends _root_.scala.tools.nsc.Interpreter(mySettings){
    var writer = new java.io.StringWriter
    var pWriter = newWriter
    def newWriter = new java.io.PrintWriter(writer)
    
    def lastError = writer.toString
    
    object myReporter extends ConsoleReporter(mySettings,null,null){
      override def printMessage(msg: String) { pWriter.print(msg + "\n"); pWriter.flush() }
      override def reset{
        writer = new java.io.StringWriter
        pWriter = newWriter
        super.reset
      }
    }
    override def newCompiler(se:Settings,reporter:Reporter) = {
      se.classpath.value = outerClassLoader.getURLs flatMap(url => inflateClassPath(asFile(url))) map (_.getAbsolutePath) mkString(java.io.File.pathSeparator)
      super.newCompiler(se,myReporter)
    }
  }
  
  import org.specs.matcher.Matcher
  def compilePrefixed(prefix:String,suffix:String) = new Matcher[String]{
    def apply(str: =>String) = 
      {
        interpreter.myReporter.reset
        interpreter.compileString(
          """object Test {
import _root_.net.virtualvoid.bytecode.Bytecode
import Bytecode._
import Bytecode.Instructions._
import Bytecode.Implicits._
"""+prefix+str+suffix+"}")
        (!interpreter.myReporter.hasErrors,"compiled","did not compile with error: "+interpreter.lastError)
      }      
  }<commit_msg>debug output<commit_after>package net.virtualvoid.bytecode

import _root_.org.specs._

import _root_.scala.tools.nsc.Settings

object BytecodeStaticSpecs extends Specification {
  import _root_.scala.tools.nsc.reporters._

  val outerClassLoader = getClass.getClassLoader.asInstanceOf[java.net.URLClassLoader]
  val mySettings = new Settings
  
  def asFile(url:java.net.URL):java.io.File =
      new java.io.File(url.toURI)

  def printClassLoaders(cl: ClassLoader) {
    if (cl != null)
      { 
	val urls = if (cl.isInstanceOf[java.net.URLClassLoader]) cl.asInstanceOf[java.net.URLClassLoader].getURLs.mkString(", ") else ""
        println(cl.toString+": "+urls); 
        
        printClassLoaders(cl.getParent);}
  }
  def inflateClassPath(jarfile: java.io.File): Seq[java.io.File] =
    jarfile +: new java.util.jar.JarFile(jarfile).getManifest.getMainAttributes.getValue("Class-Path").split("\\s+").map(new java.io.File(_))

  object interpreter extends _root_.scala.tools.nsc.Interpreter(mySettings){
    var writer = new java.io.StringWriter
    var pWriter = newWriter
    def newWriter = new java.io.PrintWriter(writer)
    
    def lastError = writer.toString
    
    object myReporter extends ConsoleReporter(mySettings,null,null){
      override def printMessage(msg: String) { pWriter.print(msg + "\n"); pWriter.flush() }
      override def reset{
        writer = new java.io.StringWriter
        pWriter = newWriter
        super.reset
      }
    }
    override def newCompiler(se:Settings,reporter:Reporter) = {
      se.classpath.value = outerClassLoader.getURLs flatMap(url => inflateClassPath(asFile(url))) map (_.getAbsolutePath) mkString(java.io.File.pathSeparator)
      printClassLoaders(outerClassLoader)
      println(se.classpath.value)
      super.newCompiler(se,myReporter)
    }
  }
  
  import org.specs.matcher.Matcher
  def compilePrefixed(prefix:String,suffix:String) = new Matcher[String]{
    def apply(str: =>String) = 
      {
        interpreter.myReporter.reset
        interpreter.compileString(
          """object Test {
import _root_.net.virtualvoid.bytecode.Bytecode
import Bytecode._
import Bytecode.Instructions._
import Bytecode.Implicits._
"""+prefix+str+suffix+"}")
        (!interpreter.myReporter.hasErrors,"compiled","did not compile with error: "+interpreter.lastError)
      }      
  }
{'fraction_non_alphanumeric': 0.11576753878212549, 'fraction_numerical': 0.0, 'mean_word_length': 3.6956521739130435, 'pattern_counts': {'":': 1, '<': 3, '<?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': '1567489', 'n_tokens_mistral': 1371, 'n_tokens_neox': 1361, 'n_words': 234}