<commit_before>/*
 * Copyright (C) 2010 reuillon
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.openmole.plugin.task.scala

import java.io.File
import java.io.PrintWriter
import java.util.logging.Logger
import org.openmole.core.model.data.IPrototype
import org.openmole.core.model.task.IPluginSet
import org.openmole.misc.tools.io.FileUtil.fileOrdering
import org.apache.clerezza.scala.scripting.InterpreterFactory
import org.openmole.core.implementation.data.Context
import org.openmole.core.implementation.data.Variable
import org.openmole.core.implementation.task.PluginSet
import org.openmole.core.model.data.IContext
import org.openmole.plugin.task.code._
import scala.collection.immutable.TreeSet
import scala.collection.mutable.ListBuffer


object ScalaTask {
  
  def apply(
    name: String,
    code: String
  )(implicit plugins: IPluginSet = PluginSet.empty) = {
    val _plugins = plugins
    new CodeTaskBuilder { builder =>
      
      def toTask = 
        new ScalaTask(name, code, builder.imports) { 
          val inputs = builder.inputs
          val outputs = builder.outputs
          val parameters = builder.parameters
          val provided = builder.provided
          val produced = builder.produced
        }
    }
  }
  
}

sealed abstract class ScalaTask(
  val name: String,
  val code: String,
  imports: Iterable[String]
)(implicit val plugins: IPluginSet) extends CodeTask {
  
  @transient lazy val factory = new InterpreterFactory
  
  override def processCode(context: IContext) = {
    val interpreter = factory.createInterpreter(new PrintWriter(System.out))
    context.values.foreach{v => interpreter.bind(v.prototype.name, v.value)}
    interpreter.addImports(imports.toSeq: _*)
    interpreter.interpret(code)
    Context.empty ++ outputs.map{o => new Variable(o.prototype.asInstanceOf[IPrototype[Any]], interpreter.valueOfTerm(o.prototype.name))}
  }
}

<commit_msg>Compilation fix.<commit_after>/*
 * Copyright (C) 2010 reuillon
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.openmole.plugin.task.scala

import java.io.File
import java.io.PrintWriter
import java.util.logging.Logger
import org.openmole.core.model.data.IPrototype
import org.openmole.core.model.task.IPluginSet
import org.openmole.misc.tools.io.FileUtil.fileOrdering
import org.openmole.core.implementation.data.Context
import org.openmole.core.implementation.data.Variable
import org.openmole.core.implementation.task.PluginSet
import org.openmole.core.model.data.IContext
import org.openmole.misc.tools.script.ScalaREPL
import org.openmole.plugin.task.code._

object ScalaTask {
  
  def apply(
    name: String,
    code: String
  )(implicit plugins: IPluginSet = PluginSet.empty) = {
    val _plugins = plugins
    new CodeTaskBuilder { builder =>
      
      def toTask = 
        new ScalaTask(name, code, builder.imports) { 
          val inputs = builder.inputs
          val outputs = builder.outputs
          val parameters = builder.parameters
          val provided = builder.provided
          val produced = builder.produced
        }
    }
  }
  
}

sealed abstract class ScalaTask(
  val name: String,
  val code: String,
  imports: Iterable[String]
)(implicit val plugins: IPluginSet) extends CodeTask {
  
  override def processCode(context: IContext) = {
    val interpreter = new ScalaREPL
    context.values.foreach{v => interpreter.bind(v.prototype.name, v.value)}
    interpreter.addImports(imports.toSeq: _*)
    interpreter.interpret(code)
    Context.empty ++ outputs.map{o => new Variable(o.prototype.asInstanceOf[IPrototype[Any]], interpreter.valueOfTerm(o.prototype.name))}
  }
}


{'fraction_non_alphanumeric': 0.08710730314157487, 'fraction_numerical': 0.002039983680130559, 'mean_word_length': 3.6518026565464896, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '836612', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1409, 'n_words': 427}