<commit_before>package cook.config.runner.buildin

import scala.collection.mutable.HashMap

import java.io.File

import org.apache.tools.ant.DirectoryScanner

import cook.config.runner.EvalException
import cook.config.runner.value._
import cook.util._

/**
 * Buildin function glob.
 *
 * return filelist: ListValue
 *
 * Example:
 *
 * glob(["*.java"])
 */
object Glob extends BuildinFunction("glob", GlobArgsDef()) {

  override def eval(path: String, argsValue: Scope): Value = {
    var l = argsValue("filters")
    if (l.typeName != "List") {
      l = ListValue(l.name, Seq(l))
    }
    val filters = l.toListStr("Buildin function \"glob\" only aceppt string or string list")

    val dirScanner = new DirectoryScanner
    dirScanner.setIncludes(filters.toArray)
    dirScanner.setBasedir(FileUtil(path))
    dirScanner.scan

    val files = dirScanner.getIncludedFiles

    ListValue("glob()", files.map((f) => {
        FileLabelValue("<unknown>", new FileLabel(path, f))
    }))
  }
}

object GlobArgsDef {

  def apply() = new ArgsDef(Seq[String]("filters"), new HashMap[String, Value])
}<commit_msg>glob function add "baseDir" support<commit_after>package cook.config.runner.buildin

import scala.collection.mutable.HashMap

import java.io.File

import org.apache.tools.ant.DirectoryScanner

import cook.config.runner.EvalException
import cook.config.runner.value._
import cook.util._

/**
 * Buildin function glob.
 *
 * return filelist: ListValue
 *
 * Example:
 *
 * glob(["*.java"])
 */
object Glob extends BuildinFunction("glob", GlobArgsDef()) {

  override def eval(path: String, argsValue: Scope): Value = {
    var l = argsValue("filters")
    if (l.typeName != "List") {
      l = ListValue(l.name, Seq(l))
    }
    val filters = l.toListStr("Buildin function \"glob\" only aceppt string or string list")

    val baseDir = argsValue("baseDir")
    val baseDirFile = if (baseDir.isNull) {
      FileUtil(path)
    } else {
      FileUtil(baseDir.toStr)
    }

    val dirScanner = new DirectoryScanner
    dirScanner.setIncludes(filters.toArray)
    dirScanner.setBasedir(baseDirFile)
    dirScanner.scan

    val files = dirScanner.getIncludedFiles

    ListValue("glob()", files.map((f) => {
        FileLabelValue("<unknown>", new FileLabel(path, f))
    }))
  }
}

object GlobArgsDef {

  def apply() = {
    val names = Seq[String]("filters", "baseDir")
    val defaultValues = new HashMap[String, Value]
    defaultValues("baseDir") = NullValue("baseDir")
    new ArgsDef(names, defaultValues)
  }
}
{'fraction_non_alphanumeric': 0.1337025316455696, 'fraction_numerical': 0.0, 'mean_word_length': 3.735955056179775, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4542828', 'n_tokens_mistral': 828, 'n_tokens_neox': 815, 'n_words': 181}