Permalink
Browse files

Add support for properly merging user and sbt configs.

  • Loading branch information...
1 parent b3db492 commit b523ee1d1bad03e62e02046a517db4294f8b380e @aemoncannon aemoncannon committed Mar 7, 2012
Showing with 49 additions and 12 deletions.
  1. +1 −1 README.md
  2. +48 −11 src/main/scala/org/ensime/sbt/EnsimeCommand.scala
View
@@ -10,7 +10,7 @@ __For use with ensime 0.9.0+__
## How to Install
-Add the following to your `~/.sbt/plugins/build.sbt`:
+Add the following to your `~/.sbt/plugins.sbt`:
resolvers += "Scala-Tools Maven2 Snapshots Repository" at "http://scala-tools.org/repo-snapshots"
@@ -60,7 +60,7 @@ object EnsimeCommand {
val initX = Project extract state
- val projs = initX.structure.allProjects.map{
+ val projs:List[Map[KeywordAtom,SExp]] = initX.structure.allProjects.map{
proj =>
import Compat._
@@ -110,16 +110,52 @@ object EnsimeCommand {
val extras = optSetting(ensimeConfig).getOrElse(SExpList(List[SExp]()))
logger(s).info(" User configuration = " + 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()),
- key(":compile-deps") -> SExp(compileDeps.map(SExp.apply)),
- key(":runtime-deps") -> SExp(runtimeDeps.map(SExp.apply)),
- key(":test-deps") -> SExp(testDeps.map(SExp.apply)),
- key(":source-roots") -> SExp(sourceRoots.map(SExp.apply)),
- key(":target") -> target.map(SExp.apply).getOrElse(NilAtom()))
- }
+
+ def merge(user:Option[SExp], sbt:Option[SExp]):SExp = {
+ (user, sbt) match{
+ case (Some(s1:SExp),None) => s1
+ case (None,Some(s2:SExp)) => s2
+ case (Some(SExpList(items1)), Some(SExpList(items2))) => SExpList(items1 ++ items2)
+ case (Some(s1:SExp),Some(s2:SExp)) => s2
+ case _ => NilAtom()
+ }
+ }
+
+ val xtras = extras.toKeywordMap
+ Map[KeywordAtom,SExp](
+
+ key(":name") -> merge(
+ xtras.get(key(":name")),
+ name.map(SExp.apply)),
+
+ key(":package") -> merge(
+ xtras.get(key(":package")),
+ org.map(SExp.apply)),
+
+ key(":version") -> merge(
+ xtras.get(key(":version")),
+ projectVersion.map(SExp.apply)),
+
+ key(":compile-deps") -> merge(
+ xtras.get(key(":compile-deps")),
+ Some(SExp(compileDeps.map(SExp.apply)))),
+
+ key(":runtime-deps") -> merge(
+ xtras.get(key(":runtime-deps")),
+ Some(SExp(runtimeDeps.map(SExp.apply)))),
+
+ key(":test-deps") -> merge(
+ xtras.get(key(":test-deps")),
+ Some(SExp(testDeps.map(SExp.apply)))),
+
+ key(":source-roots") -> merge(
+ xtras.get(key(":source-roots")),
+ Some(SExp(sourceRoots.map(SExp.apply)))),
+
+ key(":target") -> merge(
+ xtras.get(key(":target")),
+ target.map(SExp.apply)))
+ }.toList
val result = SExp(Map(
key(":subprojects") -> SExp(projs.map{p => SExp(p)})
@@ -136,3 +172,4 @@ object EnsimeCommand {
}
}
}
+

0 comments on commit b523ee1

Please sign in to comment.