mirror of https://github.com/sbt/sbt.git
allow discovery on both modules/classes, not just one or the other
This commit is contained in:
parent
fe224479bc
commit
1ee5af39d6
|
|
@ -34,7 +34,7 @@ object Build
|
|||
{
|
||||
val buildDir = base / "project" / "build"
|
||||
val sources = (buildDir * "*.scala") +++ (buildDir / "src" / "main" / "scala" ** "*.scala")
|
||||
source(Nil, sources.get.toSeq, Some(buildDir / "target" asFile), false, auto, name, configuration, allowMultiple)
|
||||
source(Nil, sources.get.toSeq, Some(buildDir / "target" asFile), None, auto, name, configuration, allowMultiple)
|
||||
}
|
||||
|
||||
def binary(classpath: Seq[File], module: Boolean, name: String, parent: ClassLoader, allowMultiple: Boolean): Seq[Any] =
|
||||
|
|
@ -44,7 +44,7 @@ object Build
|
|||
else
|
||||
{
|
||||
val names = if(allowMultiple) name.split(",").toSeq else Seq(name)
|
||||
binaries(classpath, module, names, parent)
|
||||
binaries(classpath, names.map(n => ToLoad(n,module)), parent)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,38 +69,40 @@ object Build
|
|||
val agg = new AggressiveCompile(cacheDirectory)
|
||||
agg(compiler, javac, sources, compileClasspath, outputDirectory, Nil, options)(log)
|
||||
}
|
||||
def source(classpath: Seq[File], sources: Seq[File], output: Option[File], module: Boolean, auto: Auto.Value, name: String, configuration: xsbti.AppConfiguration, allowMultiple: Boolean = false): Seq[Any] =
|
||||
def source(classpath: Seq[File], sources: Seq[File], output: Option[File], module: Option[Boolean], auto: Auto.Value, name: String, configuration: xsbti.AppConfiguration, allowMultiple: Boolean = false): Seq[Any] =
|
||||
{
|
||||
val conf = new Compile(classpath, sources, output, Nil, configuration)
|
||||
val analysis = compile(conf)
|
||||
val discovered = discover(analysis, module, auto, name)
|
||||
binaries(conf.projectClasspath, module, check(discovered, allowMultiple), loader(configuration))
|
||||
binaries(conf.projectClasspath, check(discovered, allowMultiple), loader(configuration))
|
||||
}
|
||||
def discover(analysis: inc.Analysis, module: Boolean, auto: Auto.Value, name: String): Seq[String] =
|
||||
def discover(analysis: inc.Analysis, module: Option[Boolean], auto: Auto.Value, name: String): Seq[ToLoad] =
|
||||
{
|
||||
import Auto.{Annotation, Explicit, Subclass}
|
||||
auto match {
|
||||
case Explicit => if(name.isEmpty) error("No name specified to load explicitly.") else Seq(name)
|
||||
case Explicit => if(name.isEmpty) error("No name specified to load explicitly.") else Seq(new ToLoad(name))
|
||||
case Subclass => discover(analysis, module, new inc.Discovery(Set(name), Set.empty))
|
||||
case Annotation => discover(analysis, module, new inc.Discovery(Set.empty, Set(name)))
|
||||
}
|
||||
}
|
||||
def discover(analysis: inc.Analysis, command: DiscoverCommand): Seq[String] =
|
||||
def discover(analysis: inc.Analysis, command: DiscoverCommand): Seq[ToLoad] =
|
||||
discover(analysis, command.module, command.discovery)
|
||||
|
||||
def discover(analysis: inc.Analysis, module: Boolean, discovery: inc.Discovery): Seq[String] =
|
||||
def discover(analysis: inc.Analysis, module: Option[Boolean], discovery: inc.Discovery): Seq[ToLoad] =
|
||||
{
|
||||
for(src <- analysis.apis.internal.values.toSeq;
|
||||
(df, found) <- discovery(src.definitions) if !found.isEmpty && found.isModule == module)
|
||||
(df, found) <- discovery(src.definitions) if !found.isEmpty && moduleMatches(found.isModule, module))
|
||||
yield
|
||||
df.name
|
||||
new ToLoad(df.name, found.isModule)
|
||||
}
|
||||
def moduleMatches(isModule: Boolean, expected: Option[Boolean]): Boolean =
|
||||
expected.isEmpty || (Some(isModule) == expected)
|
||||
|
||||
def binaries(classpath: Seq[File], module: Boolean, names: Seq[String], parent: ClassLoader): Seq[Any] =
|
||||
loadBinaries(names, module, toLoader(classpath, parent))
|
||||
def binaries(classpath: Seq[File], toLoad: Seq[ToLoad], parent: ClassLoader): Seq[Any] =
|
||||
loadBinaries(toLoad, toLoader(classpath, parent))
|
||||
|
||||
def loadBinaries(names: Seq[String], module: Boolean, loader: ClassLoader): Seq[Any] =
|
||||
for(name <- names if !name.isEmpty) yield
|
||||
def loadBinaries(toLoad: Seq[ToLoad], loader: ClassLoader): Seq[Any] =
|
||||
for(ToLoad(name, module) <- toLoad if !name.isEmpty) yield
|
||||
loadBinary(name, module, loader)
|
||||
|
||||
def loadBinary(name: String, module: Boolean, loader: ClassLoader): Any =
|
||||
|
|
@ -112,7 +114,7 @@ object Build
|
|||
clazz.newInstance
|
||||
}
|
||||
|
||||
def check(discovered: Seq[String], allowMultiple: Boolean): Seq[String] =
|
||||
def check[T](discovered: Seq[T], allowMultiple: Boolean): Seq[T] =
|
||||
discovered match
|
||||
{
|
||||
case Seq() => error("No project found")
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import java.io.File
|
|||
|
||||
sealed trait LoadCommand
|
||||
final case class BinaryLoad(classpath: Seq[File], module: Boolean, name: String) extends LoadCommand
|
||||
final case class SourceLoad(classpath: Seq[File], sourcepath: Seq[File], output: Option[File], module: Boolean, auto: Auto.Value, name: String) extends LoadCommand
|
||||
final case class SourceLoad(classpath: Seq[File], sourcepath: Seq[File], output: Option[File], module: Option[Boolean], auto: Auto.Value, name: String) extends LoadCommand
|
||||
final case class ProjectLoad(base: File, auto: Auto.Value, name: String) extends LoadCommand
|
||||
|
||||
object Auto extends Enumeration
|
||||
|
|
@ -17,4 +17,10 @@ object Auto extends Enumeration
|
|||
}
|
||||
|
||||
final case class CompileCommand(classpath: Seq[File], sources: Seq[File], output: Option[File], options: Seq[String])
|
||||
final case class DiscoverCommand(module: Boolean, discovery: inc.Discovery)
|
||||
final case class DiscoverCommand(module: Option[Boolean], discovery: inc.Discovery)
|
||||
|
||||
final case class ToLoad(name: String, isModule: Boolean = false)
|
||||
{
|
||||
override def toString = tpe + " " + name
|
||||
def tpe = if(isModule) "object" else "class"
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ The command has the following syntax:
|
|||
if(!srcs.isEmpty)
|
||||
SourceLoad(cp, srcs, output(args), mod, auto(args), nme)
|
||||
else if(!cp.isEmpty)
|
||||
BinaryLoad(cp, mod, nme)
|
||||
BinaryLoad(cp, mod.getOrElse(false), nme)
|
||||
else
|
||||
ProjectLoad(proj, auto(args), nme)
|
||||
}
|
||||
|
|
@ -83,11 +83,11 @@ The command has the following syntax:
|
|||
case Some(x) => error("Illegal auto argument '" + x + "'")
|
||||
}
|
||||
|
||||
def module(args: Seq[String]): Boolean =
|
||||
getArg(args, "module") match {
|
||||
case None | Some("false") => false
|
||||
case Some("true") => true
|
||||
case Some(x) => error("Expected boolean, got '" + x + "'")
|
||||
def module(args: Seq[String]): Option[Boolean] =
|
||||
getArg(args, "module") map {
|
||||
case "false" => false
|
||||
case "true" => true
|
||||
case x => error("Expected boolean, got '" + x + "'")
|
||||
}
|
||||
|
||||
def names(label: String, args: Seq[String]): Set[String] =
|
||||
|
|
|
|||
Loading…
Reference in New Issue