<commit_before>package com.prezi.haskell.gradle.tasks

import java.io.File
import java.nio.charset.StandardCharsets
import java.nio.file.Files

import com.prezi.haskell.gradle.model.Sandbox
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

/**
 * Generates the ghc-mod.cradle file containing all the package databases ghc-mod needs to
 * work on the given project.
 */
class GenerateGhcModCradle extends DefaultTask with HaskellProjectSupport with HaskellDependencies {

  private var targetFile_ : Option[File] = None

  def targetFile = targetFile_
  def targetFile_=(value: Option[File]): Unit = {
    targetFile_ = value

    if (value.isDefined) {
      getOutputs.file(value.get)
    }
  }

  @TaskAction
  def run(): Unit = {
    needsConfigurationSet

    if (!targetFile.isDefined) {
      throw new IllegalStateException("targetFile is not specified")
    }

    val cradleFile = generateContent(dependentSandboxes ::: List(sandbox))
    Files.write(targetFile.get.toPath, cradleFile.getBytes(StandardCharsets.UTF_8))
  }

  private def generateContent(sandboxes: List[Sandbox]): String = {
    val content = new StringBuilder()

    for (sandbox <- sandboxes) {
      content.append(sandbox.packageDb.getAbsolutePath)
      content.append('\n')
    }

    content.mkString
  }
}<commit_msg>Java 1.6 compatibility<commit_after>package com.prezi.haskell.gradle.tasks

import java.io.File

import com.prezi.haskell.gradle.model.Sandbox
import org.apache.commons.io.FileUtils
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

/**
 * Generates the ghc-mod.cradle file containing all the package databases ghc-mod needs to
 * work on the given project.
 */
class GenerateGhcModCradle extends DefaultTask with HaskellProjectSupport with HaskellDependencies {

  private var targetFile_ : Option[File] = None

  def targetFile = targetFile_
  def targetFile_=(value: Option[File]): Unit = {
    targetFile_ = value

    if (value.isDefined) {
      getOutputs.file(value.get)
    }
  }

  @TaskAction
  def run(): Unit = {
    needsConfigurationSet

    if (!targetFile.isDefined) {
      throw new IllegalStateException("targetFile is not specified")
    }

    val cradleFile = generateContent(dependentSandboxes ::: List(sandbox))
    FileUtils.writeStringToFile(targetFile.get, cradleFile)
  }

  private def generateContent(sandboxes: List[Sandbox]): String = {
    val content = new StringBuilder()

    for (sandbox <- sandboxes) {
      content.append(sandbox.packageDb.getAbsolutePath)
      content.append('\n')
    }

    content.mkString
  }
}
{'fraction_non_alphanumeric': 0.09746738296239447, 'fraction_numerical': 0.0011511895625479663, 'mean_word_length': 3.872897196261682, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2145379', 'n_tokens_mistral': 843, 'n_tokens_neox': 775, 'n_words': 180}