Skip to content

Instantly share code, notes, and snippets.

@kornysietsma
Created August 12, 2011 06:30
Show Gist options
  • Save kornysietsma/1141574 to your computer and use it in GitHub Desktop.
Save kornysietsma/1141574 to your computer and use it in GitHub Desktop.
sbt sample 3
sealed trait Aggregation
final object Aggregation
{
def apply(dependencies: Seq[ProjectReference], transitive: Boolean = true): Aggregation
= new Explicit(dependencies, transitive)
implicit def fromBoolean(b: Boolean): Aggregation = if(b) Enabled else Disabled
val Enabled = new Implicit(true)
val Disabled = new Implicit(false)
final case class Implicit(enabled: Boolean) extends Aggregation
final class Explicit(val dependencies: Seq[ProjectReference], val transitive: Boolean)
extends Aggregation
final case class KeyValue[+T](key: ScopedKey[_], value: T)
def getTasks[T](key: ScopedKey[T], structure: BuildStructure, transitive: Boolean):
Seq[KeyValue[T]] =
getTasks0(key, structure, transitive, new mutable.HashMap[(ScopedKey[_], Boolean),
Seq[KeyValue[T]]])
private type Memo[T] = mutable.Map[(ScopedKey[_], Boolean),
Seq[KeyValue[T]]]
private[this] def getTasks0[T](key: ScopedKey[T], structure: BuildStructure,
transitive: Boolean, memo: Memo[T]): Seq[KeyValue[T]] =
memo.getOrElseUpdate( (key, transitive), {
val task = structure.data.get(key.scope, key.key).toList.map(t => KeyValue(key,t))
if(transitive) aggregateDeps(key, structure, memo) ++ task else task
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment