mirror of https://github.com/sbt/sbt.git
drop more migrated pending items
This commit is contained in:
parent
defd1ee0d4
commit
aba1dd96c9
|
|
@ -20,62 +20,6 @@ import scala.collection.mutable.ListBuffer
|
|||
* options, and configuration. */
|
||||
abstract class BasicScalaProject extends ScalaProject with BasicDependencyProject with ScalaPaths
|
||||
{
|
||||
/** The explicitly specified class to be run by the 'run' action.
|
||||
* See http://code.google.com/p/simple-build-tool/wiki/RunningProjectCode for details.*/
|
||||
def mainClass: Option[String] = None
|
||||
/** Gets the main class to use. This is used by package and run to determine which main
|
||||
* class to run or include as the Main-Class attribute.
|
||||
* If `mainClass` is explicitly specified, it is used. Otherwise, the main class is selected from
|
||||
* the classes with a main method as automatically detected by the analyzer plugin.
|
||||
* `promptIfMultipleChoices` controls the behavior when multiple main classes are detected.
|
||||
* If true, it prompts the user to select which main class to use. If false, it prints a warning
|
||||
* and returns no main class.*/
|
||||
def getMainClass(promptIfMultipleChoices: Boolean): Option[String] =
|
||||
getMainClass(promptIfMultipleChoices, mainCompileConditional, mainClass)
|
||||
def getMainClass(promptIfMultipleChoices: Boolean, compileConditional: CompileConditional, explicit: Option[String]): Option[String] =
|
||||
explicit orElse
|
||||
{
|
||||
val applications = compileConditional.analysis.allApplications.toList
|
||||
impl.SelectMainClass(promptIfMultipleChoices, applications) orElse
|
||||
{
|
||||
if(!promptIfMultipleChoices && !applications.isEmpty)
|
||||
warnMultipleMainClasses(log)
|
||||
None
|
||||
}
|
||||
}
|
||||
def testMainClass: Option[String] = None
|
||||
def getTestMainClass(promptIfMultipleChoices: Boolean): Option[String] =
|
||||
getMainClass(promptIfMultipleChoices, testCompileConditional, testMainClass)
|
||||
|
||||
/** Specifies the value of the `Class-Path` attribute in the manifest of the main jar. */
|
||||
def manifestClassPath: Option[String] = None
|
||||
def dependencies = info.dependencies ++ subProjects.values.toList
|
||||
|
||||
lazy val mainCompileConditional = new CompileConditional(mainCompileConfiguration, buildCompiler)
|
||||
lazy val testCompileConditional = new CompileConditional(testCompileConfiguration, buildCompiler)
|
||||
|
||||
def compileOrder = CompileOrder.Mixed
|
||||
|
||||
/** The main artifact produced by this project. To redefine the main artifact, override `defaultMainArtifact`
|
||||
* Additional artifacts are defined by `val`s of type `Artifact`.*/
|
||||
lazy val mainArtifact = defaultMainArtifact
|
||||
/** Defines the default main Artifact assigned to `mainArtifact`. By default, this is a jar file with name given
|
||||
* by `artifactID`.*/
|
||||
protected def defaultMainArtifact = Artifact(artifactID, "jar", "jar")
|
||||
|
||||
import Project._
|
||||
|
||||
/** The options provided to the 'compile' action to pass to the Scala compiler.*/
|
||||
def compileOptions: Seq[CompileOption] = Deprecation :: Nil
|
||||
/** The options provided to the 'console' action to pass to the Scala interpreter.*/
|
||||
def consoleOptions: Seq[CompileOption] = compileOptions
|
||||
/** The options provided to the 'compile' action to pass to the Java compiler. */
|
||||
def javaCompileOptions: Seq[JavaCompileOption] = Nil
|
||||
/** The options provided to the 'test-compile' action, defaulting to those for the 'compile' action.*/
|
||||
def testCompileOptions: Seq[CompileOption] = compileOptions
|
||||
/** The options provided to the 'test-compile' action to pass to the Java compiler. */
|
||||
def testJavaCompileOptions: Seq[JavaCompileOption] = javaCompileOptions
|
||||
|
||||
/** The options provided to the 'doc' and 'docTest' actions.*/
|
||||
def documentOptions: Seq[ScaladocOption] =
|
||||
documentTitle(name + " " + version + " API") ::
|
||||
|
|
@ -87,15 +31,6 @@ abstract class BasicScalaProject extends ScalaProject with BasicDependencyProjec
|
|||
TestListeners(testListeners) ::
|
||||
TestFilter(includeTest) ::
|
||||
Nil
|
||||
/** The options provided to the clean action. You can add files to be removed and files to be preserved here.*/
|
||||
def cleanOptions: Seq[CleanOption] =
|
||||
ClearAnalysis(mainCompileConditional.analysis) ::
|
||||
ClearAnalysis(testCompileConditional.analysis) ::
|
||||
historyPath.map(history => Preserve(history)).toList
|
||||
|
||||
def packageOptions: Seq[PackageOption] =
|
||||
manifestClassPath.map(cp => ManifestAttributes( (Attributes.Name.CLASS_PATH, cp) )).toList :::
|
||||
getMainClass(false).map(MainClass(_)).toList
|
||||
|
||||
private def succeededTestPath = testAnalysisPath / "succeeded-tests"
|
||||
protected final def quickOptions(failedOnly: Boolean) =
|
||||
|
|
@ -105,179 +40,6 @@ abstract class BasicScalaProject extends ScalaProject with BasicDependencyProjec
|
|||
TestFilter(new impl.TestQuickFilter(analysis, failedOnly, path, log)) :: TestListeners(new impl.TestStatusReporter(path, log) :: Nil) :: Nil
|
||||
}
|
||||
|
||||
def consoleInit = ""
|
||||
|
||||
protected def includeTest(test: String): Boolean = true
|
||||
|
||||
/** This is called to create the initial directories when a user makes a new project from
|
||||
* sbt.*/
|
||||
override final def initializeDirectories()
|
||||
{
|
||||
FileUtilities.createDirectories(directoriesToCreate, log) match
|
||||
{
|
||||
case Some(errorMessage) => log.error("Could not initialize directory structure: " + errorMessage)
|
||||
case None => log.success("Successfully initialized directory structure.")
|
||||
}
|
||||
}
|
||||
import Configurations._
|
||||
/** The managed configuration to use when determining the classpath for a Scala interpreter session.*/
|
||||
def consoleConfiguration = Test
|
||||
|
||||
/** A PathFinder that provides the classpath to pass to scaladoc. It is the same as the compile classpath
|
||||
* by default. */
|
||||
def docClasspath = compileClasspath
|
||||
/** A PathFinder that provides the classpath to pass to the compiler.*/
|
||||
def compileClasspath = fullClasspath(Compile) +++ optionalClasspath +++ providedClasspath
|
||||
/** A PathFinder that provides the classpath to use when unit testing.*/
|
||||
def testClasspath = fullClasspath(Test) +++ optionalClasspath +++ providedClasspath
|
||||
/** A PathFinder that provides the classpath to use when running the class specified by 'getMainClass'.*/
|
||||
def runClasspath = fullClasspath(Runtime) +++ optionalClasspath +++ providedClasspath
|
||||
/** A PathFinder that provides the classpath to use for a Scala interpreter session.*/
|
||||
def consoleClasspath = fullClasspath(consoleConfiguration) +++ optionalClasspath +++ providedClasspath
|
||||
/** A PathFinder that corresponds to Maven's optional scope. It includes any managed libraries in the
|
||||
* 'optional' configuration for this project only.*/
|
||||
def optionalClasspath = managedClasspath(Optional)
|
||||
/** A PathFinder that corresponds to Maven's provided scope. It includes any managed libraries in the
|
||||
* 'provided' configuration for this project only.*/
|
||||
def providedClasspath = managedClasspath(Provided)
|
||||
/** A PathFinder that contains the jars that should be included in a comprehensive package. This is
|
||||
* by default the 'runtime' classpath excluding the 'provided' classpath.*/
|
||||
def publicClasspath = runClasspath --- providedClasspath
|
||||
|
||||
/** This returns the unmanaged classpath for only this project for the given configuration. It by
|
||||
* default includes the main compiled classes for this project and the libraries in this project's
|
||||
* unmanaged library directory (lib) and the managed directory for the specified configuration. It
|
||||
* also adds the resource directories appropriate to the configuration.
|
||||
* The Provided and Optional configurations are treated specially; they are empty
|
||||
* by default.*/
|
||||
def fullUnmanagedClasspath(config: Configuration) =
|
||||
{
|
||||
config match
|
||||
{
|
||||
case CompilerPlugin => unmanagedClasspath
|
||||
case Runtime => runUnmanagedClasspath
|
||||
case Test => testUnmanagedClasspath
|
||||
case Provided | Optional => Path.emptyPathFinder
|
||||
case _ => mainUnmanagedClasspath
|
||||
}
|
||||
}
|
||||
/** The unmanaged base classpath. By default, the unmanaged classpaths for test and run include this classpath. */
|
||||
protected def mainUnmanagedClasspath = mainCompilePath +++ mainResourcesOutputPath +++ unmanagedClasspath
|
||||
/** The unmanaged classpath for the run configuration. By default, it includes the base classpath returned by
|
||||
* `mainUnmanagedClasspath`.*/
|
||||
protected def runUnmanagedClasspath = mainUnmanagedClasspath +++ mainDependencies.scalaCompiler
|
||||
/** The unmanaged classpath for the test configuration. By default, it includes the run classpath, which includes the base
|
||||
* classpath returned by `mainUnmanagedClasspath`.*/
|
||||
protected def testUnmanagedClasspath = testCompilePath +++ testResourcesOutputPath +++ testDependencies.scalaCompiler +++ runUnmanagedClasspath
|
||||
|
||||
/** An analysis of the jar dependencies of the main Scala sources. It is only valid after main source compilation.
|
||||
* See the LibraryDependencies class for details. */
|
||||
final def mainDependencies = new LibraryDependencies(this, mainCompileConditional)
|
||||
/** An analysis of the jar dependencies of the test Scala sources. It is only valid after test source compilation.
|
||||
* See the LibraryDependencies class for details. */
|
||||
final def testDependencies = new LibraryDependencies(this, testCompileConditional)
|
||||
|
||||
/** The list of test frameworks to use for testing. Note that adding frameworks to this list
|
||||
* for an active project currently requires an explicit 'clean' to properly update the set of tests to
|
||||
* run*/
|
||||
def testFrameworks: Seq[TestFramework] =
|
||||
{
|
||||
import TestFrameworks.{JUnit, ScalaCheck, ScalaTest, Specs, ScalaCheckCompat, ScalaTestCompat, SpecsCompat}
|
||||
ScalaCheck :: Specs :: ScalaTest :: ScalaCheckCompat :: ScalaTestCompat :: SpecsCompat :: JUnit :: Nil
|
||||
}
|
||||
/** The list of listeners for testing. */
|
||||
def testListeners: Seq[TestReportListener] = TestLogger(log) :: Nil
|
||||
|
||||
def mainLabel = "main"
|
||||
def testLabel = "test"
|
||||
|
||||
def mainCompileConfiguration: CompileConfiguration = new MainCompileConfig
|
||||
def testCompileConfiguration: CompileConfiguration = new TestCompileConfig
|
||||
abstract class BaseCompileConfig extends CompileConfiguration
|
||||
{
|
||||
def log = BasicScalaProject.this.log
|
||||
def projectPath = info.projectPath
|
||||
def baseCompileOptions: Seq[CompileOption]
|
||||
def options = optionsAsString(baseCompileOptions.filter(!_.isInstanceOf[MaxCompileErrors]))
|
||||
def maxErrors = maximumErrors(baseCompileOptions)
|
||||
def compileOrder = BasicScalaProject.this.compileOrder
|
||||
protected def getFingerprints(frameworks: Seq[TestFramework]): Fingerprints =
|
||||
{
|
||||
import org.scalatools.testing.{SubclassFingerprint, AnnotatedFingerprint}
|
||||
val (loader, tempDir) = TestFramework.createTestLoader(classpath.get, buildScalaInstance)
|
||||
xsbt.FileUtilities.delete(tempDir.asFile)
|
||||
val annotations = new ListBuffer[String]
|
||||
val superclasses = new ListBuffer[String]
|
||||
frameworks flatMap { _.create(loader, log) } flatMap(TestFramework.getTests) foreach {
|
||||
case s: SubclassFingerprint => superclasses += s.superClassName
|
||||
case a: AnnotatedFingerprint => annotations += a.annotationName
|
||||
case _ => ()
|
||||
}
|
||||
Fingerprints(superclasses.toList, annotations.toList)
|
||||
}
|
||||
}
|
||||
class MainCompileConfig extends BaseCompileConfig
|
||||
{
|
||||
def baseCompileOptions = compileOptions
|
||||
def label = mainLabel
|
||||
def sourceRoots = mainSourceRoots
|
||||
def sources = mainSources
|
||||
def outputDirectory = mainCompilePath
|
||||
def classpath = compileClasspath
|
||||
def analysisPath = mainAnalysisPath
|
||||
def fingerprints = Fingerprints(Nil, Nil)
|
||||
def javaOptions = javaOptionsAsString(javaCompileOptions)
|
||||
}
|
||||
class TestCompileConfig extends BaseCompileConfig
|
||||
{
|
||||
def baseCompileOptions = testCompileOptions
|
||||
def label = testLabel
|
||||
def sourceRoots = testSourceRoots
|
||||
def sources = testSources
|
||||
def outputDirectory = testCompilePath
|
||||
def classpath = testClasspath
|
||||
def analysisPath = testAnalysisPath
|
||||
def fingerprints = getFingerprints(testFrameworks)
|
||||
def javaOptions = javaOptionsAsString(testJavaCompileOptions)
|
||||
}
|
||||
|
||||
/** Configures forking the compiler and runner. Use ForkScalaCompiler, ForkScalaRun or mix together.*/
|
||||
def fork: Option[ForkScala] = None
|
||||
def forkRun: Option[ForkScala] = forkRun(None, Nil)
|
||||
def forkRun(workingDirectory: File): Option[ForkScala] = forkRun(Some(workingDirectory), Nil)
|
||||
def forkRun(jvmOptions: Seq[String]): Option[ForkScala] = forkRun(None, jvmOptions)
|
||||
def forkRun(workingDirectory0: Option[File], jvmOptions: Seq[String]): Option[ForkScala] =
|
||||
{
|
||||
val si = buildScalaInstance
|
||||
Some(new ForkScalaRun {
|
||||
override def scalaJars = si.libraryJar :: si.compilerJar :: Nil
|
||||
override def workingDirectory: Option[File] = workingDirectory0
|
||||
override def runJVMOptions: Seq[String] = jvmOptions
|
||||
})
|
||||
}
|
||||
private def doCompile(conditional: CompileConditional) = conditional.run
|
||||
implicit def defaultRunner: ScalaRun =
|
||||
{
|
||||
fork match
|
||||
{
|
||||
case Some(fr: ForkScalaRun) => new ForkRun(fr)
|
||||
case _ => new Run(buildScalaInstance)
|
||||
}
|
||||
}
|
||||
|
||||
def basicConsoleTask = consoleTask(consoleClasspath, consoleOptions, consoleInit)
|
||||
|
||||
protected def runTask(mainClass: String): MethodTask = task { args => runTask(Some(mainClass), runClasspath, args) dependsOn(compile, copyResources) }
|
||||
|
||||
protected def compileAction = task { doCompile(mainCompileConditional) } describedAs MainCompileDescription
|
||||
protected def testCompileAction = task { doCompile(testCompileConditional) } dependsOn compile describedAs TestCompileDescription
|
||||
protected def cleanAction = cleanTask(outputPath, cleanOptions) describedAs CleanDescription
|
||||
protected def testRunAction = task { args => runTask(getTestMainClass(true), testClasspath, args) dependsOn(testCompile, copyResources) } describedAs TestRunDescription
|
||||
protected def runAction = task { args => runTask(getMainClass(true), runClasspath, args) dependsOn(compile, copyResources) } describedAs RunDescription
|
||||
protected def consoleQuickAction = basicConsoleTask describedAs ConsoleQuickDescription
|
||||
protected def consoleAction = basicConsoleTask.dependsOn(testCompile, copyResources, copyTestResources) describedAs ConsoleDescription
|
||||
protected def docAction = scaladocTask(mainLabel, mainSources, mainDocPath, docClasspath, documentOptions).dependsOn(compile) describedAs DocDescription
|
||||
protected def docTestAction = scaladocTask(testLabel, testSources, testDocPath, docClasspath, documentOptions).dependsOn(testCompile) describedAs TestDocDescription
|
||||
|
||||
protected def testAction = defaultTestTask(testOptions)
|
||||
protected def testOnlyAction = testOnlyTask(testOptions)
|
||||
|
|
@ -289,74 +51,15 @@ abstract class BasicScalaProject extends ScalaProject with BasicDependencyProjec
|
|||
protected def defaultTestTask(testOptions: => Seq[TestOption]) =
|
||||
testTask(testFrameworks, testClasspath, testCompileConditional.analysis, testOptions).dependsOn(testCompile, copyResources, copyTestResources) describedAs TestDescription
|
||||
|
||||
override def packageToPublishActions: Seq[ManagedTask] = `package` :: Nil
|
||||
|
||||
protected def packageAction = packageTask(packagePaths, jarPath, packageOptions).dependsOn(compile) describedAs PackageDescription
|
||||
protected def packageTestAction = packageTask(packageTestPaths, packageTestJar).dependsOn(testCompile) describedAs TestPackageDescription
|
||||
protected def packageDocsAction = packageTask(mainDocPath ###, packageDocsJar, Recursive).dependsOn(doc) describedAs DocPackageDescription
|
||||
protected def packageSrcAction = packageTask(packageSourcePaths, packageSrcJar) describedAs SourcePackageDescription
|
||||
protected def packageTestSrcAction = packageTask(packageTestSourcePaths, packageTestSrcJar) describedAs TestSourcePackageDescription
|
||||
protected def packageProjectAction = zipTask(packageProjectPaths, packageProjectZip) describedAs ProjectPackageDescription
|
||||
|
||||
protected def docAllAction = (doc && docTest) describedAs DocAllDescription
|
||||
protected def packageAllAction = task { None} dependsOn(`package`, packageTest, packageSrc, packageTestSrc, packageDocs) describedAs PackageAllDescription
|
||||
protected def graphSourcesAction = graphSourcesTask(graphSourcesPath, mainSourceRoots, mainCompileConditional.analysis).dependsOn(compile)
|
||||
protected def graphPackagesAction = graphPackagesTask(graphPackagesPath, mainSourceRoots, mainCompileConditional.analysis).dependsOn(compile)
|
||||
protected def incrementVersionAction = task { incrementVersionNumber(); None } describedAs IncrementVersionDescription
|
||||
protected def releaseAction = (test && packageAll && incrementVersion) describedAs ReleaseDescription
|
||||
|
||||
protected def copyResourcesAction = syncPathsTask(mainResources, mainResourcesOutputPath) describedAs CopyResourcesDescription
|
||||
protected def copyTestResourcesAction = syncPathsTask(testResources, testResourcesOutputPath) describedAs CopyTestResourcesDescription
|
||||
|
||||
lazy val compile = compileAction
|
||||
lazy val testCompile = testCompileAction
|
||||
lazy val clean = cleanAction
|
||||
lazy val run = runAction
|
||||
lazy val consoleQuick = consoleQuickAction
|
||||
lazy val console = consoleAction
|
||||
lazy val doc = docAction
|
||||
lazy val docTest = docTestAction
|
||||
lazy val test = testAction
|
||||
lazy val testRun = testRunAction
|
||||
lazy val `package` = packageAction
|
||||
lazy val packageTest = packageTestAction
|
||||
lazy val packageDocs = packageDocsAction
|
||||
lazy val packageSrc = packageSrcAction
|
||||
lazy val packageTestSrc = packageTestSrcAction
|
||||
lazy val packageProject = packageProjectAction
|
||||
lazy val docAll = docAllAction
|
||||
lazy val packageAll = packageAllAction
|
||||
lazy val graphSrc = graphSourcesAction
|
||||
lazy val graphPkg = graphPackagesAction
|
||||
lazy val incrementVersion = incrementVersionAction
|
||||
lazy val release = releaseAction
|
||||
lazy val copyResources = copyResourcesAction
|
||||
lazy val copyTestResources = copyTestResourcesAction
|
||||
|
||||
lazy val testQuick = testQuickAction
|
||||
lazy val testFailed = testFailedAction
|
||||
lazy val testOnly = testOnlyAction
|
||||
|
||||
lazy val javap = javapTask(runClasspath, mainCompileConditional, mainCompilePath)
|
||||
lazy val testJavap = javapTask(testClasspath, testCompileConditional, testCompilePath)
|
||||
|
||||
def jarsOfProjectDependencies = Path.lazyPathFinder {
|
||||
topologicalSort.dropRight(1) flatMap { p =>
|
||||
p match
|
||||
{
|
||||
case bpp: BasicScalaPaths => List(bpp.jarPath)
|
||||
case _ => Nil
|
||||
}
|
||||
}
|
||||
}
|
||||
override def deliverScalaDependencies: Iterable[ModuleID] =
|
||||
{
|
||||
val snapshot = mainDependencies.snapshot
|
||||
mapScalaModule(snapshot.scalaLibrary, ScalaArtifacts.LibraryID) ++
|
||||
mapScalaModule(snapshot.scalaCompiler, ScalaArtifacts.CompilerID)
|
||||
}
|
||||
override def watchPaths = mainSources +++ testSources +++ mainResources +++ testResources
|
||||
private def mapScalaModule(in: Iterable[File], id: String) = in.map(jar => ModuleID(ScalaArtifacts.Organization, id, buildScalaVersion) from(jar.toURI.toURL.toString))
|
||||
}
|
||||
abstract class BasicWebScalaProject extends BasicScalaProject with WebScalaProject with WebScalaPaths
|
||||
{ p =>
|
||||
|
|
@ -512,48 +215,3 @@ object BasicWebScalaProject
|
|||
val JettyReloadDescription =
|
||||
"Forces a reload of a web application running in a Jetty server started by 'jetty-run'. Does nothing if Jetty is not running."
|
||||
}
|
||||
/** Analyzes the dependencies of a project after compilation. All methods except `snapshot` return a
|
||||
* `PathFinder`. The underlying calculations are repeated for each call to PathFinder.get. */
|
||||
final class LibraryDependencies(project: Project, conditional: CompileConditional) extends NotNull
|
||||
{
|
||||
/** Library jars located in unmanaged or managed dependency paths.*/
|
||||
def libraries: PathFinder = Path.finder(snapshot.libraries)
|
||||
/** Library jars located outside of the project.*/
|
||||
def external: PathFinder = Path.finder(snapshot.external)
|
||||
/** The Scala library jar.*/
|
||||
def scalaLibrary: PathFinder = Path.finder(snapshot.scalaLibrary)
|
||||
/** The Scala compiler jar.*/
|
||||
def scalaCompiler: PathFinder = Path.finder(snapshot.scalaCompiler)
|
||||
/** All jar dependencies.*/
|
||||
def all: PathFinder = Path.finder(snapshot.all)
|
||||
/** The Scala library and compiler jars.*/
|
||||
def scalaJars: PathFinder = Path.finder(snapshot.scalaJars)
|
||||
|
||||
/** Returns an object that has all analyzed dependency information frozen at the time of this method call. */
|
||||
def snapshot = new Dependencies
|
||||
|
||||
private def rootProjectDirectory = project.rootProject.info.projectPath
|
||||
|
||||
final class Dependencies
|
||||
{
|
||||
import LibraryDependencies._
|
||||
val all = conditional.analysis.allExternals.filter(ClasspathUtilities.isArchive).map(_.getAbsoluteFile)
|
||||
private[this] val (internal, externalAll) = all.toList.partition(jar => Path.relativize(rootProjectDirectory, jar).isDefined)
|
||||
private[this] val (bootScalaJars, librariesNoScala) = internal.partition(isScalaJar)
|
||||
private[this] val (externalScalaJars, externalNoScala) = externalAll.partition(isScalaJar)
|
||||
val scalaJars = externalScalaJars ::: bootScalaJars
|
||||
val (scalaLibrary, scalaCompiler) = scalaJars.partition(isScalaLibraryJar)
|
||||
def external = externalNoScala
|
||||
def libraries = librariesNoScala
|
||||
}
|
||||
}
|
||||
private object LibraryDependencies
|
||||
{
|
||||
private def ScalaLibraryPrefix = ScalaArtifacts.LibraryID
|
||||
private def ScalaCompilerPrefix = ScalaArtifacts.CompilerID
|
||||
private def ScalaJarPrefixes = List(ScalaCompilerPrefix, ScalaLibraryPrefix)
|
||||
private def isScalaJar(file: File) = ClasspathUtilities.isArchive(file) && ScalaJarPrefixes.exists(isNamed(file))
|
||||
private def isScalaLibraryJar(file: File) = isNamed(file)(ScalaLibraryPrefix)
|
||||
private def isNamed(file: File)(name: String) = file.getName.startsWith(name)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,132 +8,6 @@ import java.io.File
|
|||
import java.util.jar.{Attributes, Manifest}
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
trait Cleanable extends Project
|
||||
{
|
||||
trait CleanOption extends ActionOption
|
||||
case class ClearAnalysis(analysis: TaskAnalysis[_, _, _]) extends CleanOption
|
||||
case class Preserve(paths: PathFinder) extends CleanOption
|
||||
|
||||
def cleanTask(paths: PathFinder, options: CleanOption*): Task =
|
||||
cleanTask(paths, options)
|
||||
def cleanTask(paths: PathFinder, options: => Seq[CleanOption]): Task =
|
||||
task
|
||||
{
|
||||
val cleanOptions = options
|
||||
val preservePaths = for(Preserve(preservePaths) <- cleanOptions; toPreserve <- preservePaths.get) yield toPreserve
|
||||
Control.thread(FileUtilities.preserve(preservePaths, log))
|
||||
{ preserved =>
|
||||
val pathClean = FileUtilities.clean(paths.get, log)
|
||||
for(ClearAnalysis(analysis) <- cleanOptions)
|
||||
{
|
||||
analysis.clear()
|
||||
analysis.save()
|
||||
}
|
||||
val restored = preserved.restore(log)
|
||||
pathClean orElse restored
|
||||
}
|
||||
}
|
||||
|
||||
lazy val cleanPlugins = cleanTask(info.pluginsOutputPath +++ info.pluginsManagedSourcePath +++ info.pluginsManagedDependencyPath)
|
||||
}
|
||||
trait SimpleScalaProject extends ExecProject with Cleanable
|
||||
{
|
||||
def errorTask(message: String) = task{ Some(message) }
|
||||
|
||||
case class CompileOption(val asString: String) extends ActionOption
|
||||
case class JavaCompileOption(val asString: String) extends ActionOption
|
||||
|
||||
def compileOptions(asString: String*): Seq[CompileOption] = asString.map(CompileOption.apply)
|
||||
def javaCompileOptions(asString: String*): Seq[JavaCompileOption] = asString.map(JavaCompileOption.apply)
|
||||
|
||||
val Deprecation = CompileOption(CompileOptions.Deprecation)
|
||||
val ExplainTypes = CompileOption("-explaintypes")
|
||||
val Optimize = CompileOption("-optimise")
|
||||
def Optimise = Optimize
|
||||
val Verbose = CompileOption(CompileOptions.Verbose)
|
||||
val Unchecked = CompileOption(CompileOptions.Unchecked)
|
||||
val DisableWarnings = CompileOption("-nowarn")
|
||||
def target(target: Target.Value) = CompileOption("-target:" + target)
|
||||
object Target extends Enumeration
|
||||
{
|
||||
val Java1_5 = Value("jvm-1.5")
|
||||
val Java1_4 = Value("jvm-1.4")
|
||||
val Msil = Value("msil")
|
||||
}
|
||||
}
|
||||
trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProject with Exec
|
||||
{
|
||||
import ScalaProject._
|
||||
|
||||
final case class MaxCompileErrors(val value: Int) extends CompileOption("") with ScaladocOption { def asList = Nil }
|
||||
trait PackageOption extends ActionOption
|
||||
trait TestOption extends ActionOption
|
||||
|
||||
final case class TestSetup(setup: ClassLoader => Unit) extends TestOption
|
||||
object TestSetup {
|
||||
def apply(setup: () => Unit) = new TestSetup(_ => setup())
|
||||
}
|
||||
final case class TestCleanup(cleanup: ClassLoader => Unit) extends TestOption
|
||||
object TestCleanup {
|
||||
def apply(setup: () => Unit) = new TestCleanup(_ => setup())
|
||||
}
|
||||
case class ExcludeTests(tests: Iterable[String]) extends TestOption
|
||||
case class TestListeners(listeners: Iterable[TestReportListener]) extends TestOption
|
||||
case class TestFilter(filterTest: String => Boolean) extends TestOption
|
||||
|
||||
// args for all frameworks
|
||||
def TestArgument(args: String*): TestArgument = TestArgument(None, args.toList)
|
||||
// args for a particular test framework
|
||||
def TestArgument(tf: TestFramework, args: String*): TestArgument = TestArgument(Some(tf), args.toList)
|
||||
|
||||
// None means apply to all, Some(tf) means apply to a particular framework only.
|
||||
case class TestArgument(framework: Option[TestFramework], args: List[String]) extends TestOption
|
||||
|
||||
case class JarManifest(m: Manifest) extends PackageOption
|
||||
{
|
||||
assert(m != null)
|
||||
}
|
||||
case class MainClass(mainClassName: String) extends PackageOption
|
||||
case class ManifestAttributes(attributes: (Attributes.Name, String)*) extends PackageOption
|
||||
case object Recursive extends PackageOption
|
||||
def ManifestAttributes(attributes: (String, String)*): ManifestAttributes =
|
||||
{
|
||||
val converted = for( (name,value) <- attributes ) yield (new Attributes.Name(name), value)
|
||||
new ManifestAttributes(converted : _*)
|
||||
}
|
||||
|
||||
|
||||
trait ScaladocOption extends ActionOption
|
||||
{
|
||||
def asList: List[String]
|
||||
}
|
||||
case class SimpleDocOption(optionValue: String) extends ScaladocOption
|
||||
{
|
||||
def asList = List(optionValue)
|
||||
}
|
||||
case class CompoundDocOption(label: String, value: String) extends ScaladocOption
|
||||
{
|
||||
def asList = List(label, value)
|
||||
}
|
||||
val LinkSource = SimpleDocOption("-linksource")
|
||||
val NoComment = SimpleDocOption("-nocomment")
|
||||
def access(access: Access.Value) = SimpleDocOption("-access:" + access)
|
||||
def documentBottom(bottomText: String) = CompoundDocOption("-bottom", bottomText)
|
||||
def documentCharset(charset: String) = CompoundDocOption("-charset", charset)
|
||||
def documentTitle(title: String) = CompoundDocOption(if(isScala27) "-doctitle" else "-doc-title", title)
|
||||
def documentFooter(footerText: String) = CompoundDocOption("-footer", footerText)
|
||||
def documentHeader(headerText: String) = CompoundDocOption("-header", headerText)
|
||||
def stylesheetFile(path: Path) = CompoundDocOption("-stylesheetfile", path.asFile.getAbsolutePath)
|
||||
def documentTop(topText: String) = CompoundDocOption("-top", topText)
|
||||
def windowTitle(title: String) = CompoundDocOption("-windowtitle", title)
|
||||
|
||||
object Access extends Enumeration
|
||||
{
|
||||
val Public = Value("public")
|
||||
val Default = Value("protected")
|
||||
val Private = Value("private")
|
||||
}
|
||||
|
||||
def javapTask(classpath: PathFinder, conditional: => CompileConditional, compilePath: Path) =
|
||||
task { args =>
|
||||
val cp = classpath +++ Path.fromFile(FileUtilities.scalaLibraryJar) +++ Path.fromFile(FileUtilities.scalaCompilerJar)
|
||||
|
|
@ -145,24 +19,6 @@ trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProje
|
|||
classes.map(_.replace(java.io.File.separatorChar, '.').toList.dropRight(".class".length).mkString).toSeq
|
||||
}
|
||||
|
||||
def consoleTask(classpath: PathFinder): Task = consoleTask(classpath, Nil, "")
|
||||
def consoleTask(classpath: PathFinder, options: => Seq[CompileOption], initialCommands: => String): Task =
|
||||
interactiveTask {
|
||||
(new Console(buildCompiler))(classpath.get, options.map(_.asString), initialCommands, log)
|
||||
}
|
||||
|
||||
def runTask(mainClass: => Option[String], classpath: PathFinder, options: String*)(implicit runner: ScalaRun): Task =
|
||||
runTask(mainClass, classpath, options)
|
||||
def runTask(mainClass: => Option[String], classpath: PathFinder, options: => Seq[String])(implicit runner: ScalaRun): Task =
|
||||
task
|
||||
{
|
||||
mainClass match
|
||||
{
|
||||
case Some(main) => runner.run(main, classpath.get, options, log)
|
||||
case None => Some("No main class specified.")
|
||||
}
|
||||
}
|
||||
|
||||
def syncPathsTask(sources: PathFinder, destinationDirectory: Path): Task =
|
||||
task { FileUtilities.syncPaths(sources, destinationDirectory, log) }
|
||||
def syncTask(sourceDirectory: Path, destinationDirectory: Path): Task =
|
||||
|
|
@ -170,157 +26,16 @@ trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProje
|
|||
def copyTask(sources: PathFinder, destinationDirectory: Path): Task =
|
||||
task { FileUtilities.copy(sources.get, destinationDirectory, log).left.toOption }
|
||||
|
||||
def testTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, options: TestOption*): Task =
|
||||
testTask(frameworks, classpath, analysis, options)
|
||||
def testTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, options: => Seq[TestOption]): Task =
|
||||
{
|
||||
def rawWork =
|
||||
{
|
||||
val (begin, work, end) = testTasks(frameworks, classpath, analysis, options)
|
||||
val beginTasks = begin.map(toTask).toSeq // test setup tasks
|
||||
val workTasks = work.map(w => toTask(w) dependsOn(beginTasks : _*)) // the actual tests
|
||||
val endTasks = end.map(toTask).toSeq // tasks that perform test cleanup and are run regardless of success of tests
|
||||
val endTask = task { None} named("test-cleanup") dependsOn(endTasks : _*)
|
||||
val rootTask = task { None} named("test-complete") dependsOn(workTasks.toSeq : _*) // the task that depends on all test subtasks
|
||||
SubWork[Project#Task](rootTask, endTask)
|
||||
}
|
||||
def errorTask(e: TestSetupException) = task { Some(e.getMessage) } named("test-setup")
|
||||
def work =
|
||||
try { rawWork }
|
||||
catch { case e: TestSetupException => SubWork[Project#Task](errorTask(e)) }
|
||||
new CompoundTask(work)
|
||||
}
|
||||
private def toTask(testTask: NamedTestTask) = task(testTask.run()) named(testTask.name)
|
||||
|
||||
def graphSourcesTask(outputDirectory: Path, roots: PathFinder, analysis: => CompileAnalysis): Task =
|
||||
task { DotGraph.sources(analysis, outputDirectory, roots.get, log) }
|
||||
def graphPackagesTask(outputDirectory: Path, roots: PathFinder, analysis: => CompileAnalysis): Task =
|
||||
task { DotGraph.packages(analysis, outputDirectory, roots.get, log) }
|
||||
def scaladocTask(label: String, sources: PathFinder, outputDirectory: Path, classpath: PathFinder, options: ScaladocOption*): Task =
|
||||
scaladocTask(label, sources, outputDirectory, classpath, options)
|
||||
def scaladocTask(label: String, sources: PathFinder, outputDirectory: Path, classpath: PathFinder, options: => Seq[ScaladocOption]): Task =
|
||||
fileTask(outputDirectory / "index.html" from sources)
|
||||
{
|
||||
val optionsLocal = options
|
||||
val maxErrors = maximumErrors(optionsLocal)
|
||||
(new Scaladoc(maxErrors, buildCompiler))(label, sources.get, classpath.get, outputDirectory, optionsLocal.flatMap(_.asList), log)
|
||||
}
|
||||
|
||||
def packageTask(sources: PathFinder, outputDirectory: Path, jarName: => String, options: PackageOption*): Task =
|
||||
packageTask(sources, outputDirectory / jarName, options)
|
||||
def packageTask(sources: PathFinder, outputDirectory: Path, jarName: => String, options: => Seq[PackageOption]): Task =
|
||||
packageTask(sources: PathFinder, outputDirectory / jarName, options)
|
||||
def packageTask(sources: PathFinder, jarPath: => Path, options: PackageOption*): Task =
|
||||
packageTask(sources, jarPath, options)
|
||||
def packageTask(sources: PathFinder, jarPath: => Path, options: => Seq[PackageOption]): Task =
|
||||
fileTask("package", jarPath from sources)
|
||||
{
|
||||
import wrap.{MutableMapWrapper,Wrappers}
|
||||
/** Copies the mappings in a2 to a1, mutating a1. */
|
||||
def mergeAttributes(a1: Attributes, a2: Attributes)
|
||||
{
|
||||
for( (key, value) <- Wrappers.toList(a2))
|
||||
a1.put(key, value)
|
||||
}
|
||||
|
||||
val manifest = new Manifest
|
||||
var recursive = false
|
||||
for(option <- options)
|
||||
{
|
||||
option match
|
||||
{
|
||||
case JarManifest(mergeManifest) =>
|
||||
{
|
||||
mergeAttributes(manifest.getMainAttributes, mergeManifest.getMainAttributes)
|
||||
val entryMap = new MutableMapWrapper(manifest.getEntries)
|
||||
for((key, value) <- Wrappers.toList(mergeManifest.getEntries))
|
||||
{
|
||||
entryMap.get(key) match
|
||||
{
|
||||
case Some(attributes) => mergeAttributes(attributes, value)
|
||||
case None => entryMap += (key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
case Recursive => recursive = true
|
||||
case MainClass(mainClassName) =>
|
||||
manifest.getMainAttributes.put(Attributes.Name.MAIN_CLASS, mainClassName)
|
||||
case ManifestAttributes(attributes @ _*) =>
|
||||
val main = manifest.getMainAttributes
|
||||
for( (name, value) <- attributes)
|
||||
main.put(name, value)
|
||||
case _ => log.warn("Ignored unknown package option " + option)
|
||||
}
|
||||
}
|
||||
val jarPathLocal = jarPath
|
||||
FileUtilities.clean(jarPathLocal :: Nil, log) orElse
|
||||
FileUtilities.jar(sources.get, jarPathLocal, manifest, recursive, log)
|
||||
}
|
||||
def zipTask(sources: PathFinder, outputDirectory: Path, zipName: => String): Task =
|
||||
zipTask(sources, outputDirectory / zipName)
|
||||
def zipTask(sources: PathFinder, zipPath: => Path): Task =
|
||||
fileTask("zip", zipPath from sources) { FileUtilities.zip(sources.get, zipPath, false, log) }
|
||||
def incrementVersionNumber()
|
||||
{
|
||||
projectVersion.get match
|
||||
{
|
||||
case Some(v: BasicVersion) =>
|
||||
{
|
||||
val newVersion = incrementImpl(v)
|
||||
log.info("Changing version to " + newVersion)
|
||||
projectVersion() = newVersion
|
||||
}
|
||||
case a => ()
|
||||
}
|
||||
}
|
||||
protected def incrementImpl(v: BasicVersion): Version = v.incrementMicro
|
||||
protected def testTasks(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, options: => Seq[TestOption]) =
|
||||
{
|
||||
import scala.collection.mutable.HashSet
|
||||
import scala.collection.mutable.Map
|
||||
|
||||
val testFilters = new ListBuffer[String => Boolean]
|
||||
val excludeTestsSet = new HashSet[String]
|
||||
val setup, cleanup = new ListBuffer[ClassLoader => Unit]
|
||||
val testListeners = new ListBuffer[TestReportListener]
|
||||
val testArgsByFramework = Map[TestFramework, ListBuffer[String]]()
|
||||
def frameworkArgs(framework: TestFramework): ListBuffer[String] =
|
||||
testArgsByFramework.getOrElseUpdate(framework, new ListBuffer[String])
|
||||
|
||||
for(option <- options)
|
||||
{
|
||||
option match
|
||||
{
|
||||
case TestFilter(include) => testFilters += include
|
||||
case ExcludeTests(exclude) => excludeTestsSet ++= exclude
|
||||
case TestListeners(listeners) => testListeners ++= listeners
|
||||
case TestSetup(setupFunction) => setup += setupFunction
|
||||
case TestCleanup(cleanupFunction) => cleanup += cleanupFunction
|
||||
/**
|
||||
* There are two cases here.
|
||||
* The first handles TestArguments in the project file, which
|
||||
* might have a TestFramework specified.
|
||||
* The second handles arguments to be applied to all test frameworks.
|
||||
* -- arguments from the project file that didnt have a framework specified
|
||||
* -- command line arguments (ex: test-only someClass -- someArg)
|
||||
* (currently, command line args must be passed to all frameworks)
|
||||
*/
|
||||
case TestArgument(Some(framework), args) => frameworkArgs(framework) ++= args
|
||||
case TestArgument(None, args) => frameworks.foreach { framework => frameworkArgs(framework) ++= args.toList }
|
||||
}
|
||||
}
|
||||
|
||||
if(excludeTestsSet.size > 0 && log.atLevel(Level.Debug))
|
||||
{
|
||||
log.debug("Excluding tests: ")
|
||||
excludeTestsSet.foreach(test => log.debug("\t" + test))
|
||||
}
|
||||
def includeTest(test: TestDefinition) = !excludeTestsSet.contains(test.name) && testFilters.forall(filter => filter(test.name))
|
||||
val tests = HashSet.empty[TestDefinition] ++ analysis.allTests.map(_.toDefinition).filter(includeTest)
|
||||
TestFramework.testTasks(frameworks, classpath.get, buildScalaInstance, tests.toSeq, log,
|
||||
testListeners.readOnly, false, setup.readOnly, cleanup.readOnly, testArgsByFramework)
|
||||
}
|
||||
private def flatten[T](i: Iterable[Iterable[T]]) = i.flatMap(x => x)
|
||||
|
||||
protected def testQuickMethod(testAnalysis: CompileAnalysis, options: => Seq[TestOption])(toRun: (Seq[TestOption]) => Task) = {
|
||||
def analysis = Set() ++ testAnalysis.allTests.map(_.className)
|
||||
|
|
@ -328,9 +43,6 @@ trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProje
|
|||
toRun(TestArgument(args:_*) :: TestFilter(includeFunction) :: options.toList)
|
||||
}
|
||||
}
|
||||
|
||||
protected final def maximumErrors[T <: ActionOption](options: Seq[T]) =
|
||||
(for( MaxCompileErrors(maxErrors) <- options) yield maxErrors).firstOption.getOrElse(DefaultMaximumCompileErrors)
|
||||
}
|
||||
|
||||
trait WebScalaProject extends ScalaProject
|
||||
|
|
|
|||
Loading…
Reference in New Issue