mirror of https://github.com/sbt/sbt.git
Merge pull request #1801 from sbt/wip/aether-resolver-scripted
Run scripted with sbt-maven-resolver
This commit is contained in:
commit
c9875c05b1
|
|
@ -16,6 +16,8 @@ env:
|
|||
- SCRIPTED_TEST="scripted compiler-project/*""
|
||||
- SCRIPTED_TEST="scripted dependency-management/*1of2"
|
||||
- SCRIPTED_TEST="scripted dependency-management/*2of2"
|
||||
- SCRIPTED_TEST="mavenResolverPluginTest:scripted dependency-management/*1of2"
|
||||
- SCRIPTED_TEST="mavenResolverPluginTest:scripted dependency-management/*2of2"
|
||||
- SCRIPTED_TEST="scripted java/*"
|
||||
- SCRIPTED_TEST="scripted package/*"
|
||||
- SCRIPTED_TEST="scripted project/*1of2"
|
||||
|
|
|
|||
30
build.sbt
30
build.sbt
|
|
@ -421,15 +421,17 @@ lazy val mavenResolverPluginProj = (project in file("sbt-maven-resolver")).
|
|||
sbtPlugin := true
|
||||
)
|
||||
|
||||
def scriptedTask: Initialize[InputTask[Unit]] = InputTask(scriptedSource(dir => (s: State) => scriptedParser(dir))) { result =>
|
||||
(proguard in Proguard, fullClasspath in scriptedSbtProj in Test, scalaInstance in scriptedSbtProj, publishAll, scriptedSource, result) map {
|
||||
(launcher, scriptedSbtClasspath, scriptedSbtInstance, _, sourcePath, args) =>
|
||||
doScripted(launcher, scriptedSbtClasspath, scriptedSbtInstance, sourcePath, args)
|
||||
}
|
||||
def scriptedTask: Initialize[InputTask[Unit]] = Def.inputTask {
|
||||
val result = scriptedSource(dir => (s: State) => scriptedParser(dir)).parsed
|
||||
publishAll.value
|
||||
doScripted((proguard in Proguard).value, (fullClasspath in scriptedSbtProj in Test).value,
|
||||
(scalaInstance in scriptedSbtProj).value, scriptedSource.value, result, scriptedPrescripted.value)
|
||||
}
|
||||
|
||||
def scriptedUnpublishedTask: Initialize[InputTask[Unit]] = InputTask(scriptedSource(dir => (s: State) => scriptedParser(dir))) { result =>
|
||||
(proguard in Proguard, fullClasspath in scriptedSbtProj in Test, scalaInstance in scriptedSbtProj, scriptedSource, result) map doScripted
|
||||
def scriptedUnpublishedTask: Initialize[InputTask[Unit]] = Def.inputTask {
|
||||
val result = scriptedSource(dir => (s: State) => scriptedParser(dir)).parsed
|
||||
doScripted((proguard in Proguard).value, (fullClasspath in scriptedSbtProj in Test).value,
|
||||
(scalaInstance in scriptedSbtProj).value, scriptedSource.value, result, scriptedPrescripted.value)
|
||||
}
|
||||
|
||||
lazy val publishAll = TaskKey[Unit]("publish-all")
|
||||
|
|
@ -453,13 +455,25 @@ def rootSettings = releaseSettings ++ fullDocSettings ++ LaunchProguard.settings
|
|||
Util.publishPomSettings ++ otherRootSettings ++ proguardedLauncherSettings ++ Formatting.sbtFilesSettings ++
|
||||
Transform.conscriptSettings(launchProj)
|
||||
def otherRootSettings = Seq(
|
||||
Scripted.scriptedPrescripted := { _ => },
|
||||
Scripted.scripted <<= scriptedTask,
|
||||
Scripted.scriptedUnpublished <<= scriptedUnpublishedTask,
|
||||
Scripted.scriptedSource <<= (sourceDirectory in sbtProj) / "sbt-test",
|
||||
publishAll := {
|
||||
(publishLocal).all(ScopeFilter(inAnyProject)).value
|
||||
}
|
||||
)
|
||||
) ++ inConfig(Scripted.MavenResolverPluginTest)(Seq(
|
||||
Scripted.scripted <<= scriptedTask,
|
||||
Scripted.scriptedUnpublished <<= scriptedUnpublishedTask,
|
||||
Scripted.scriptedPrescripted := { f =>
|
||||
val inj = f / "project" / "maven.sbt"
|
||||
if (!inj.exists) {
|
||||
IO.write(inj, """libraryDependencies += Defaults.sbtPluginExtra("org.scala-sbt" % "sbt-maven-resolver" % sbtVersion.value,
|
||||
|sbtBinaryVersion.value, scalaBinaryVersion.value)""".stripMargin)
|
||||
// sLog.value.info(s"""Injected project/maven.sbt to $f""")
|
||||
}
|
||||
}
|
||||
))
|
||||
lazy val docProjects: ScopeFilter = ScopeFilter(
|
||||
inAnyProject -- inProjects(root, sbtProj, scriptedBaseProj, scriptedSbtProj, scriptedPluginProj),
|
||||
inConfigurations(Compile)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ object Scripted {
|
|||
lazy val scripted = InputKey[Unit]("scripted")
|
||||
lazy val scriptedUnpublished = InputKey[Unit]("scripted-unpublished", "Execute scripted without publishing SBT first. Saves you some time when only your test has changed.")
|
||||
lazy val scriptedSource = SettingKey[File]("scripted-source")
|
||||
lazy val scriptedPrescripted = TaskKey[File => Unit]("scripted-prescripted")
|
||||
|
||||
lazy val MavenResolverPluginTest = config("mavenResolverPluginTest") extend Compile
|
||||
|
||||
import sbt.complete._
|
||||
import DefaultParsers._
|
||||
|
|
@ -55,14 +58,14 @@ object Scripted {
|
|||
(token(Space) ~> (PagedIds | testIdAsGroup)).* map (_.flatten)
|
||||
}
|
||||
|
||||
def doScripted(launcher: File, scriptedSbtClasspath: Seq[Attributed[File]], scriptedSbtInstance: ScalaInstance, sourcePath: File, args: Seq[String]) {
|
||||
def doScripted(launcher: File, scriptedSbtClasspath: Seq[Attributed[File]], scriptedSbtInstance: ScalaInstance, sourcePath: File, args: Seq[String], prescripted: File => Unit) {
|
||||
System.err.println(s"About to run tests: ${args.mkString("\n * ", "\n * ", "\n")}")
|
||||
val noJLine = new classpath.FilteredLoader(scriptedSbtInstance.loader, "jline." :: Nil)
|
||||
val loader = classpath.ClasspathUtilities.toLoader(scriptedSbtClasspath.files, noJLine)
|
||||
val m = ModuleUtilities.getObject("sbt.test.ScriptedTests", loader)
|
||||
val r = m.getClass.getMethod("run", classOf[File], classOf[Boolean], classOf[Array[String]], classOf[File], classOf[Array[String]])
|
||||
val r = m.getClass.getMethod("run", classOf[File], classOf[Boolean], classOf[Array[String]], classOf[File], classOf[Array[String]], classOf[File => Unit])
|
||||
val launcherVmOptions = Array("-XX:MaxPermSize=256M") // increased after a failure in scripted source-dependencies/macro
|
||||
try { r.invoke(m, sourcePath, true: java.lang.Boolean, args.toArray[String], launcher, launcherVmOptions) }
|
||||
try { r.invoke(m, sourcePath, true: java.lang.Boolean, args.toArray[String], launcher, launcherVmOptions, prescripted) }
|
||||
catch { case ite: java.lang.reflect.InvocationTargetException => throw ite.getCause }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,16 @@ object PomRepoTest extends Build
|
|||
def pomIncludeRepository(base: File, prev: MavenRepository => Boolean) = (r: MavenRepository) =>
|
||||
if(base / "repo.none" exists) false else if(base / "repo.all" exists) true else prev(r)
|
||||
|
||||
def addSlash(s: String): String =
|
||||
s match {
|
||||
case s if s endsWith "/" => s
|
||||
case _ => s + "/"
|
||||
}
|
||||
|
||||
def checkPomRepositories(file: File, args: Seq[String], s: TaskStreams)
|
||||
{
|
||||
val repositories = scala.xml.XML.loadFile(file) \\ "repository"
|
||||
val extracted = repositories.map { repo => MavenRepository(repo \ "name" text, repo \ "url" text) }
|
||||
val extracted = repositories.map { repo => MavenRepository(repo \ "name" text, addSlash(repo \ "url" text)) }
|
||||
val expected = args.map(GlobFilter.apply)
|
||||
s.log.info("Extracted: " + extracted.mkString("\n\t", "\n\t", "\n"))
|
||||
s.log.info("Expected: " + args.mkString("\n\t", "\n\t", "\n"))
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
libraryDependencies += Defaults.sbtPluginExtra("org.scala-sbt" % "sbt-maven-resolver" % sbtVersion.value,
|
||||
sbtBinaryVersion.value, scalaBinaryVersion.value)
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
# write the default pom. The only repositories should be Scala Tools Releases and Snapshots
|
||||
> check-pom https://oss.sonatype.org/content/repositories/releases https://oss.sonatype.org/content/repositories/snapshots
|
||||
> check-pom https://oss.sonatype.org/content/repositories/releases/ https://oss.sonatype.org/content/repositories/snapshots/
|
||||
|
||||
# include file:// repositories. The generated repositories section should include the local Maven repository as well
|
||||
$ touch repo.all
|
||||
> check-pom https://oss.sonatype.org/content/repositories/releases https://oss.sonatype.org/content/repositories/snapshots file://*.m2/repository
|
||||
> check-pom https://oss.sonatype.org/content/repositories/releases/ https://oss.sonatype.org/content/repositories/snapshots/ file://*.m2/repository/
|
||||
|
||||
# include file:// repositories. The generated repositories section should include the local Maven repository as well
|
||||
$ delete repo.all
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import xsbt.test.{ CommentHandler, FileCommands, ScriptRunner, TestScriptParser
|
|||
import IO.wrapNull
|
||||
|
||||
final class ScriptedTests(resourceBaseDirectory: File, bufferLog: Boolean, launcher: File, launchOpts: Seq[String]) {
|
||||
import ScriptedTests.emptyCallback
|
||||
private val testResources = new Resources(resourceBaseDirectory)
|
||||
|
||||
val ScriptFilename = "test"
|
||||
|
|
@ -20,7 +21,9 @@ final class ScriptedTests(resourceBaseDirectory: File, bufferLog: Boolean, launc
|
|||
|
||||
def scriptedTest(group: String, name: String, log: xsbti.Logger): Seq[() => Option[String]] =
|
||||
scriptedTest(group, name, Logger.xlog2Log(log))
|
||||
def scriptedTest(group: String, name: String, log: Logger): Seq[() => Option[String]] = {
|
||||
def scriptedTest(group: String, name: String, log: Logger): Seq[() => Option[String]] =
|
||||
scriptedTest(group, name, emptyCallback, log)
|
||||
def scriptedTest(group: String, name: String, prescripted: File => Unit, log: Logger): Seq[() => Option[String]] = {
|
||||
import Path._
|
||||
import GlobFilter._
|
||||
var failed = false
|
||||
|
|
@ -36,14 +39,14 @@ final class ScriptedTests(resourceBaseDirectory: File, bufferLog: Boolean, launc
|
|||
log.info("D " + str + " [DISABLED]")
|
||||
None
|
||||
} else {
|
||||
try { scriptedTest(str, testDirectory, log); None }
|
||||
try { scriptedTest(str, testDirectory, prescripted, log); None }
|
||||
catch { case e: xsbt.test.TestException => Some(str) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private def scriptedTest(label: String, testDirectory: File, log: Logger): Unit =
|
||||
private def scriptedTest(label: String, testDirectory: File, prescripted: File => Unit, log: Logger): Unit =
|
||||
{
|
||||
val buffered = new BufferedLogger(new FullLogger(log))
|
||||
if (bufferLog)
|
||||
|
|
@ -74,6 +77,7 @@ final class ScriptedTests(resourceBaseDirectory: File, bufferLog: Boolean, launc
|
|||
}
|
||||
|
||||
try {
|
||||
prescripted(testDirectory)
|
||||
runTest()
|
||||
buffered.info("+ " + label + pendingString)
|
||||
} catch {
|
||||
|
|
@ -91,6 +95,8 @@ final class ScriptedTests(resourceBaseDirectory: File, bufferLog: Boolean, launc
|
|||
}
|
||||
}
|
||||
object ScriptedTests {
|
||||
val emptyCallback: File => Unit = { _ => () }
|
||||
|
||||
def main(args: Array[String]) {
|
||||
val directory = new File(args(0))
|
||||
val buffer = args(1).toBoolean
|
||||
|
|
@ -100,16 +106,26 @@ object ScriptedTests {
|
|||
val bootProperties = new File(args(5))
|
||||
val tests = args.drop(6)
|
||||
val logger = ConsoleLogger()
|
||||
run(directory, buffer, tests, logger, bootProperties, Array())
|
||||
run(directory, buffer, tests, logger, bootProperties, Array(), emptyCallback)
|
||||
}
|
||||
def run(resourceBaseDirectory: File, bufferLog: Boolean, tests: Array[String], bootProperties: File, launchOpts: Array[String]): Unit =
|
||||
run(resourceBaseDirectory, bufferLog, tests, ConsoleLogger(), bootProperties, launchOpts) //new FullLogger(Logger.xlog2Log(log)))
|
||||
def run(resourceBaseDirectory: File, bufferLog: Boolean, tests: Array[String], bootProperties: File,
|
||||
launchOpts: Array[String]): Unit =
|
||||
run(resourceBaseDirectory, bufferLog, tests, ConsoleLogger(), bootProperties, launchOpts, emptyCallback) //new FullLogger(Logger.xlog2Log(log)))
|
||||
|
||||
def run(resourceBaseDirectory: File, bufferLog: Boolean, tests: Array[String], logger: AbstractLogger, bootProperties: File, launchOpts: Array[String]) {
|
||||
def run(resourceBaseDirectory: File, bufferLog: Boolean, tests: Array[String], bootProperties: File,
|
||||
launchOpts: Array[String], prescripted: File => Unit): Unit =
|
||||
run(resourceBaseDirectory, bufferLog, tests, ConsoleLogger(), bootProperties, launchOpts, prescripted) //new FullLogger(Logger.xlog2Log(log)))
|
||||
|
||||
def run(resourceBaseDirectory: File, bufferLog: Boolean, tests: Array[String], logger: AbstractLogger, bootProperties: File,
|
||||
launchOpts: Array[String]): Unit =
|
||||
run(resourceBaseDirectory, bufferLog, tests, logger, bootProperties, launchOpts, emptyCallback)
|
||||
|
||||
def run(resourceBaseDirectory: File, bufferLog: Boolean, tests: Array[String], logger: AbstractLogger, bootProperties: File,
|
||||
launchOpts: Array[String], prescripted: File => Unit) {
|
||||
val runner = new ScriptedTests(resourceBaseDirectory, bufferLog, bootProperties, launchOpts)
|
||||
val allTests = get(tests, resourceBaseDirectory, logger) flatMap {
|
||||
case ScriptedTest(group, name) =>
|
||||
runner.scriptedTest(group, name, logger)
|
||||
runner.scriptedTest(group, name, prescripted, logger)
|
||||
}
|
||||
runAll(allTests)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue