Sha256: ade6d138e3d3add133f4cb1594f1a3bd17fd66ca45c7e7cd6b95e17823057770

Contents?: true

Size: 1.66 KB

Versions: 68

Compression:

Stored size: 1.66 KB

Contents

import java.io.File

import sbt.Keys._
import sbt._

import scala.io.Source
import scala.util.parsing.json.{JSONArray, JSONObject, JSON}

object XScalaBuild extends Build {

  scalaVersion := "2.11.7"
  name := "xscala"

  val commonSettings = Seq(
    updateOptions := updateOptions.value.withCachedResolution(true),

    (unmanagedSources in Test) <<= (unmanagedSources in Test, sourceManaged in Test) map {
      case (testSources, managedTestDir) =>
        copyTestsAndStripPending(testSources, managedTestDir)
    }
  )

  override def projects: Seq[Project] = {
    fetchProblemNames("config.json").map {
      problemName => Project(problemName, new File(problemName)).settings(commonSettings:_*)
    }
  }

  def copyTestsAndStripPending(tests: Seq[File], managedSourceDir: File): Seq[File] = {
    tests.map { originalTestFile =>
      val filename = originalTestFile.name
      val newTestFile = managedSourceDir / filename
      IO.writeLines(newTestFile, IO.readLines(originalTestFile).filter(_.trim != "pending"))
      newTestFile
    }
  }

  def fetchProblemNames(configJsonFile: String): Seq[String] = {
    val configStr = Source.fromFile(configJsonFile, "UTF-8").getLines().mkString
    val configObj = JSON
      .parseRaw(configStr)
      .map(_.asInstanceOf[JSONObject].obj)
      .getOrElse {
        throw new IllegalArgumentException(s"Could not parse $configJsonFile as JSON")
      }
    configObj
      .get("exercises")
      .map(_.asInstanceOf[JSONArray].list)
      .getOrElse {
        throw new IllegalArgumentException(s"Could not find array 'exercises' in $configJsonFile")
      }
      .collect { case problem: JSONObject => problem.obj("slug").toString }
  }
}

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.0.6.24 tracks/scala/project/Build.scala
trackler-2.0.6.23 tracks/scala/project/Build.scala
trackler-2.0.6.22 tracks/scala/project/Build.scala
trackler-2.0.6.21 tracks/scala/project/Build.scala
trackler-2.0.6.20 tracks/scala/project/Build.scala
trackler-2.0.6.19 tracks/scala/project/Build.scala
trackler-2.0.6.18 tracks/scala/project/Build.scala
trackler-2.0.6.17 tracks/scala/project/Build.scala
trackler-2.0.6.16 tracks/scala/project/Build.scala
trackler-2.0.6.15 tracks/scala/project/Build.scala
trackler-2.0.6.14 tracks/scala/project/Build.scala
trackler-2.0.6.13 tracks/scala/project/Build.scala
trackler-2.0.6.12 tracks/scala/project/Build.scala
trackler-2.0.6.11 tracks/scala/project/Build.scala
trackler-2.0.6.10 tracks/scala/project/Build.scala
trackler-2.0.6.9 tracks/scala/project/Build.scala
trackler-2.0.6.8 tracks/scala/project/Build.scala
trackler-2.0.6.7 tracks/scala/project/Build.scala
trackler-2.0.6.6 tracks/scala/project/Build.scala
trackler-2.0.6.5 tracks/scala/project/Build.scala