summaryrefslogtreecommitdiff
path: root/crashboxd/src/main/scala/io/crashbox/ci/Parser.scala
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2017-04-01 13:21:15 -0700
committerJakob Odersky <jakob@odersky.com>2017-04-01 13:21:15 -0700
commit26aa8adc30a84d983d020e34b488ac22a31cb544 (patch)
tree5e2cee54da5f64011f56a85c4b09bd1add4eacc7 /crashboxd/src/main/scala/io/crashbox/ci/Parser.scala
parent8a4ebe76200a2e570bd959d8780c3c0a0bf71d5c (diff)
downloadcrashbox-ci-26aa8adc30a84d983d020e34b488ac22a31cb544.tar.gz
crashbox-ci-26aa8adc30a84d983d020e34b488ac22a31cb544.tar.bz2
crashbox-ci-26aa8adc30a84d983d020e34b488ac22a31cb544.zip
Add yaml parser and docker executor
Diffstat (limited to 'crashboxd/src/main/scala/io/crashbox/ci/Parser.scala')
-rw-r--r--crashboxd/src/main/scala/io/crashbox/ci/Parser.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/crashboxd/src/main/scala/io/crashbox/ci/Parser.scala b/crashboxd/src/main/scala/io/crashbox/ci/Parser.scala
new file mode 100644
index 0000000..5a58612
--- /dev/null
+++ b/crashboxd/src/main/scala/io/crashbox/ci/Parser.scala
@@ -0,0 +1,44 @@
+package io.crashbox.ci
+
+import io.crashbox.ci.yaml._
+import io.crashbox.ci.yaml.DefaultReaders._
+
+object Parser {
+ sealed trait Result
+ case class Success(buildDef: BuildDef) extends Result
+ case class Failure(error: String) extends Result
+
+ implicit object TaskDefReader extends YamlReader[TaskDef] {
+ def read(value: YamlValue) = {
+ val items = value.convertTo[Map[String, YamlValue]]
+ val image = items
+ .getOrElse("image",
+ throw new YamlFormatException("no image specified"))
+ .convertTo[String]
+ val script = items
+ .getOrElse("script",
+ throw new YamlFormatException("no script specified"))
+ .convertTo[String]
+ TaskDef(DockerEnvironment(image), script)
+ }
+ }
+
+ implicit object BuildDefReader extends YamlReader[BuildDef] {
+ def read(value: YamlValue) = {
+ val items = value.convertTo[Map[String, YamlValue]]
+ val tasks = items
+ .getOrElse("tasks",
+ throw new YamlFormatException("no tasks specified"))
+ .convertTo[Map[String, TaskDef]]
+ BuildDef(tasks.values.toSeq)
+ }
+ }
+
+ def parse(build: String): Result =
+ try {
+ Success(Yaml.parse(build).convertTo[BuildDef])
+ } catch {
+ case ex: YamlFormatException => Failure(ex.toString)
+ }
+
+}