Files
sbt/compile/interface/ScaladocInterface.scala
T
Mark Harrah a76d75bca6 more flexible scalac logging
the custom scalac Reporter now delegates to an instance of
  an sbt interface called xsbti.Reporter
handling compilation logging is now mainly done on the sbt-side of the
  compiler interface
the xsbti.Reporter interface provides access to richer information
  about errors and warnings, including source file, line, and offset
xsbti.Reporter can be implemented by users to get access to
  detailed information without needing to parse the logging output
the CompileFailed exception that is thrown when compilation fails now
  includes an array of the problems, providing detailed
  error and warning information that can, for example, be consumed
  by doing a mapFailure on 'compile' and using 'Compile.allProblems'
2010-10-23 16:34:22 -04:00

68 lines
1.8 KiB
Scala

/* sbt -- Simple Build Tool
* Copyright 2008, 2009 Mark Harrah
*/
package xsbt
import xsbti.Logger
import Log.debug
class ScaladocInterface
{
def run(args: Array[String], log: Logger, delegate: xsbti.Reporter) = (new Runner(args, log, delegate)).run
}
private class Runner(args: Array[String], log: Logger, delegate: xsbti.Reporter)
{
import scala.tools.nsc.{doc, Global, reporters}
import reporters.Reporter
val docSettings: doc.Settings = new doc.Settings(Log.settingsError(log))
val command = Command(args.toList, docSettings)
val reporter = DelegatingReporter(docSettings, delegate)
def noErrors = !reporter.hasErrors && command.ok
import forScope._
def run()
{
debug(log, "Calling Scaladoc with arguments:\n\t" + args.mkString("\n\t"))
if(noErrors)
{
import doc._ // 2.8 trunk and Beta1-RC4 have doc.DocFactory. For other Scala versions, the next line creates forScope.DocFactory
val processor = new DocFactory(reporter, docSettings)
processor.document(command.files)
}
reporter.printSummary()
if(!noErrors) throw new InterfaceCompileFailed(args, reporter.problems, "Scaladoc generation failed")
}
object forScope
{
class DocFactory(reporter: Reporter, docSettings: doc.Settings) // 2.7 compatibility
{
object compiler extends Global(command.settings, reporter)
{
override def onlyPresentation = true
class DefaultDocDriver // 2.8 source compatibility
{
assert(false)
def process(units: Iterator[CompilationUnit]) = error("for 2.8 compatibility only")
}
}
def document(ignore: Seq[String])
{
import compiler._
val run = new Run
run compile command.files
val generator =
{
import doc._
new DefaultDocDriver
{
lazy val global: compiler.type = compiler
lazy val settings = docSettings
}
}
generator.process(run.units)
}
}
}
}