Adds a scripted test that tests repo override

This commit is contained in:
Eugene Yokota 2016-04-24 14:23:48 -04:00
parent 411e5f6c69
commit 081a9868ce
6 changed files with 38 additions and 7 deletions

View File

@ -35,8 +35,9 @@ env:
- SBT_CMD="scripted tests/*"
- SBT_CMD="scripted project-load/*"
- SBT_CMD="checkBuildScala211"
- SBT_CMD="mavenResolverPluginTest:scripted dependency-management/*1of2 project/transitive-plugins"
- SBT_CMD="repoOverrideTest:scripted dependency-management/*"
- SBT_CMD="mavenResolverPluginTest:scripted dependency-management/*2of2"
- SBT_CMD="mavenResolverPluginTest:scripted dependency-management/*1of2 project/transitive-plugins"
notifications:
email:

View File

@ -500,13 +500,15 @@ def scriptedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask {
(altLocalPublish in interfaceProj).value
(altLocalPublish in compileInterfaceProj).value
doScripted((sbtLaunchJar in bundledLauncherProj).value, (fullClasspath in scriptedSbtProj in Test).value,
(scalaInstance in scriptedSbtProj).value, scriptedSource.value, result, scriptedPrescripted.value)
(scalaInstance in scriptedSbtProj).value, scriptedSource.value, result, scriptedPrescripted.value,
scriptedLaunchOpts.value)
}
def scriptedUnpublishedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask {
val result = scriptedSource(dir => (s: State) => scriptedParser(dir)).parsed
doScripted((sbtLaunchJar in bundledLauncherProj).value, (fullClasspath in scriptedSbtProj in Test).value,
(scalaInstance in scriptedSbtProj).value, scriptedSource.value, result, scriptedPrescripted.value)
(scalaInstance in scriptedSbtProj).value, scriptedSource.value, result, scriptedPrescripted.value,
scriptedLaunchOpts.value)
}
lazy val publishAll = TaskKey[Unit]("publish-all")
@ -531,6 +533,7 @@ def rootSettings = fullDocSettings ++
Transform.conscriptSettings(bundledLauncherProj)
def otherRootSettings = Seq(
Scripted.scriptedPrescripted := { addSbtAlternateResolver _ },
Scripted.scriptedLaunchOpts := List("-XX:MaxPermSize=256M", "-Xmx1G"),
Scripted.scripted <<= scriptedTask,
Scripted.scriptedUnpublished <<= scriptedUnpublishedTask,
Scripted.scriptedSource := (sourceDirectory in sbtProj).value / "sbt-test",
@ -539,6 +542,7 @@ def otherRootSettings = Seq(
},
aggregate in bintrayRelease := false
) ++ inConfig(Scripted.MavenResolverPluginTest)(Seq(
Scripted.scriptedLaunchOpts := List("-XX:MaxPermSize=256M", "-Xmx1G"),
Scripted.scripted <<= scriptedTask,
Scripted.scriptedUnpublished <<= scriptedUnpublishedTask,
Scripted.scriptedPrescripted := { f =>
@ -547,9 +551,17 @@ def otherRootSettings = Seq(
IO.write(inj, "addMavenResolverPlugin")
// sLog.value.info(s"""Injected project/maven.sbt to $f""")
}
addSbtAlternateResolver(f)
}
)) ++ inConfig(Scripted.RepoOverrideTest)(Seq(
Scripted.scriptedPrescripted := { _ => () },
Scripted.scriptedLaunchOpts := {
List("-XX:MaxPermSize=256M", "-Xmx1G", "-Dsbt.override.build.repos=true",
s"""-Dsbt.repository.config=${ Scripted.scriptedSource.value / "repo.config" }""")
},
Scripted.scripted <<= scriptedTask,
Scripted.scriptedUnpublished <<= scriptedUnpublishedTask,
Scripted.scriptedSource := (sourceDirectory in sbtProj).value / "repo-override-test"
))
def addSbtAlternateResolver(scriptedRoot: File) = {

View File

@ -10,8 +10,10 @@ object 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 scriptedLaunchOpts = SettingKey[Seq[String]]("scripted-launch-opts", "options to pass to jvm launching scripted tasks")
lazy val MavenResolverPluginTest = config("mavenResolverPluginTest") extend Compile
lazy val RepoOverrideTest = config("repoOverrideTest") extend Compile
import sbt.complete._
import DefaultParsers._
@ -66,13 +68,14 @@ object Scripted {
launchOpts: Array[String], prescripted: java.util.List[File]): Unit
}
def doScripted(launcher: File, scriptedSbtClasspath: Seq[Attributed[File]], scriptedSbtInstance: ScalaInstance, sourcePath: File, args: Seq[String], prescripted: File => Unit): Unit = {
def doScripted(launcher: File, scriptedSbtClasspath: Seq[Attributed[File]],
scriptedSbtInstance: ScalaInstance, sourcePath: File, args: Seq[String],
prescripted: File => Unit, launchOpts: Seq[String]): 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 bridgeClass = Class.forName("sbt.test.ScriptedRunner", true, loader)
val bridge = bridgeClass.newInstance.asInstanceOf[SbtScriptedRunner]
val launcherVmOptions = Array("-XX:MaxPermSize=256M", "-Xmx1G") // increased after a failure in scripted source-dependencies/macro
try {
// Using java.util.List to encode File => Unit.
val callback = new java.util.AbstractList[File] {
@ -83,7 +86,7 @@ object Scripted {
def get(x: Int): sbt.File = ???
def size(): Int = 0
}
bridge.run(sourcePath, true, args.toArray, launcher, launcherVmOptions, callback)
bridge.run(sourcePath, true, args.toArray, launcher, launchOpts.toArray, callback)
} catch { case ite: java.lang.reflect.InvocationTargetException => throw ite.getCause }
}
}

View File

@ -0,0 +1,11 @@
lazy val check = taskKey[Unit]("")
lazy val root = (project in file(".")).
settings(
autoScalaLibrary := false,
check := {
val ar = appResolvers.value.get
assert(!(ar exists { _.name == "jcenter" }))
assert(!(ar exists { _.name == "public" }))
}
)

View File

@ -0,0 +1 @@
> check

View File

@ -0,0 +1,3 @@
[repositories]
local
typesafe-ivy-releases: https://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]