Permalink
Browse files

Add support for specifying extra options

  • Loading branch information...
1 parent 01e6f0d commit e25c95cb7f25d51f5cd77aa9c96ff5f64543bc16 @aemoncannon aemoncannon committed Dec 21, 2011
@@ -1,6 +1,7 @@
package org.ensime.sbt
import util._
import util.SExp._
+import Plugin.Settings._
object EnsimeCommand {
import java.io.{File => JavaFile}
@@ -11,10 +12,6 @@ object EnsimeCommand {
import net.liftweb.json.Printer._
import net.liftweb.json.JsonDSL._
- val ensimeConfig = SettingKey[Map[KeywordAtom,SExp]]("ensime-config")
-
- val settings = Seq(ensimeConfig)
-
val ensimeCommand = "ensime"
val ensimeBrief = (ensimeCommand + " dump <project> <outputFile>",
"Dump project for <project> information to <outputFile>.")
@@ -46,7 +43,7 @@ object EnsimeCommand {
val projRef = ProjectRef(proj.base, proj.id)
val x = Extracted(buildStruct,session,projRef)
- logInfo(proj.id + "...")
+ logInfo("Extracting " + proj.id + "...")
def evaluateTask[T](taskKey: sbt.Project.ScopedKey[sbt.Task[T]]):Option[(State, Result[T])] =
EvaluateTask(buildStruct, taskKey, s, projRef)
@@ -62,7 +59,10 @@ object EnsimeCommand {
def taskFiles(key:TaskKey[Classpath]):List[String] = {
val cp = evaluateTask(key) match {
case Some((s,Value(deps))) => deps
- case _ => logErrorAndFail("Failed to obtain classpath for: " + key)
+ case _ => {
+ logger(s).error("Failed to obtain classpath for: " + key)
+ List()
+ }
}
cp.map{ att => (att.data).getAbsolutePath }.toList
}
@@ -101,7 +101,10 @@ object EnsimeCommand {
val target = optSetting(classDirectory in Compile).map(_.getCanonicalPath)
- reqSetting(ensimeConfig,"Setting ensime-config not defined!") ++ Map[KeywordAtom,SExp](
+ val extras = optSetting(ensimeConfig).getOrElse(SExpList(List[SExp]()))
+ logger(s).info(" ensime-config := " + extras.toReadableString)
+
+ extras.toKeywordMap ++ Map[KeywordAtom,SExp](
key(":name") -> name.map(SExp.apply).getOrElse(NilAtom()),
key(":package") -> org.map(SExp.apply).getOrElse(NilAtom()),
key(":version") -> projectVersion.map(SExp.apply).getOrElse(NilAtom()),
@@ -113,8 +116,7 @@ object EnsimeCommand {
}
val result = SExp(Map(
- key(":use-sbt") -> SExp(true),
- key(":sbt-subprojects") -> SExp(projs.map{p => SExp(p)})
+ key(":subprojects") -> SExp(projs.map{p => SExp(p)})
)).toPPReadableString
val file = rest.headOption.getOrElse(".ensime")
@@ -1,13 +0,0 @@
-package org.ensime.sbt
-import sbt._
-import Keys._
-import util.{KeywordAtom, SExp}
-
-object EnsimePlugin extends sbt.Plugin {
-
- override lazy val settings = Seq(
- Keys.commands += EnsimeCommand.ensime,
- EnsimeCommand.ensimeConfig := Map[KeywordAtom,SExp]()
- )
-
-}
@@ -0,0 +1,16 @@
+package org.ensime.sbt
+import sbt._
+import Keys._
+import util.{SExpList}
+
+object Plugin extends sbt.Plugin {
+
+ override lazy val settings = Seq(
+ Keys.commands += EnsimeCommand.ensime
+ )
+
+ object Settings{
+ val ensimeConfig = SettingKey[SExpList]("ensime-config")
+ }
+
+}
@@ -52,11 +52,11 @@ case class SExpList(items: Iterable[SExp]) extends SExp with Iterable[SExp] {
def toKeywordMap(): Map[KeywordAtom, SExp] = {
var m = Map[KeywordAtom, SExp]()
- items.sliding(2, 2).foreach {
- case (key: KeywordAtom) ::(sexp: SExp) :: rest => {
+ items.toList.sliding(2, 2).foreach {
+ case (key: KeywordAtom) :: (sexp: SExp) :: rest => {
m += (key -> sexp)
}
- case _ => {}
+ case other => {}
}
m
}
@@ -121,18 +121,18 @@ object SExp extends RegexParsers {
import scala.util.matching.Regex
- lazy val string = regexGroups("""\"((?:[^\"\\]|\\.)*)\"""".r) ^^ { m =>
+ private lazy val string = regexGroups("""\"((?:[^\"\\]|\\.)*)\"""".r) ^^ { m =>
StringAtom(m.group(1).replace("\\\\", "\\"))
}
- lazy val sym = regex("[a-zA-Z][a-zA-Z0-9-:]*".r) ^^ { s =>
+ private lazy val symbol = regex("[a-zA-Z][a-zA-Z0-9-:]*".r) ^^ { s =>
if(s == "nil") NilAtom()
else if(s == "t") TruthAtom()
else SymbolAtom(s)
}
- lazy val keyword = regex(":[a-zA-Z][a-zA-Z0-9-:]*".r) ^^ KeywordAtom
- lazy val number = regex("-?[0-9]+".r) ^^ { s => IntAtom(s.toInt) }
- lazy val list = literal("(") ~> rep(expr) <~ literal(")") ^^ SExpList.apply
- lazy val expr: Parser[SExp] = list | keyword | string | number | sym
+ private lazy val keyword = regex(":[a-zA-Z][a-zA-Z0-9-:]*".r) ^^ KeywordAtom
+ private lazy val number = regex("-?[0-9]+".r) ^^ { s => IntAtom(s.toInt) }
+ private lazy val list = literal("(") ~> rep(expr) <~ literal(")") ^^ SExpList.apply
+ private lazy val expr: Parser[SExp] = list | keyword | string | number | symbol
def read(r: input.Reader[Char]): SExp = {
val result: ParseResult[SExp] = expr(r)
@@ -171,13 +171,9 @@ object SExp extends RegexParsers {
def apply(b: Boolean): BooleanAtom = boolToSExp(b)
- def apply(items: SExp*): SExpList = {
- SExpList(items)
- }
+ def apply(items: SExp*): SExpList = sexp(items)
- def apply(items: Iterable[SExp]): SExpList = {
- SExpList(items)
- }
+ def apply(items: Iterable[SExp]): SExpList = sexp(items)
def apply(map: Map[KeywordAtom, SExp]): SExpList = {
val buf = scala.collection.mutable.ListBuffer[SExp]()
@@ -210,6 +206,18 @@ object SExp extends RegexParsers {
KeywordAtom(str)
}
+ def sym(str: String): SymbolAtom = {
+ SymbolAtom(str)
+ }
+
+ def sexp(items: Iterable[SExp]): SExpList = {
+ SExpList(items)
+ }
+
+ def sexp(items: SExp*): SExpList = {
+ SExpList(items)
+ }
+
implicit def intToSExp(value: Int): IntAtom = {
IntAtom(value)
}

0 comments on commit e25c95c

Please sign in to comment.