Adds a scripted test that tests repo override

This commit is contained in:
Eugene Yokota 2016-04-24 14:23:48 -04:00
parent 296758e159
commit ab43ec51d8
6 changed files with 60 additions and 7 deletions

View File

@ -35,6 +35,8 @@ env:
- SBT_CMD="scripted source-dependencies/*3of3"
- SBT_CMD="scripted tests/*"
- SBT_CMD="scripted project-load/*"
- SBT_CMD="checkBuildScala211"
- SBT_CMD="repoOverrideTest:scripted dependency-management/*"
notifications:
email:

View File

@ -202,16 +202,21 @@ lazy val sbtProj = (project in sbtPath).
def scriptedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask {
val result = scriptedSource(dir => (s: State) => Scripted.scriptedParser(dir)).parsed
publishAll.value
// These two projects need to be visible in a repo even if the default
// local repository is hidden, so we publish them to an alternate location and add
// that alternate repo to the running scripted test (in Scripted.scriptedpreScripted).
// (altLocalPublish in interfaceProj).value
// (altLocalPublish in compileInterfaceProj).value
Scripted.doScripted((sbtLaunchJar in bundledLauncherProj).value, (fullClasspath in scriptedSbtProj in Test).value,
(scalaInstance in scriptedSbtProj).value,
scriptedSource.value, scriptedBufferLog.value, result, scriptedPrescripted.value)
scriptedSource.value, scriptedBufferLog.value, result, scriptedPrescripted.value, scriptedLaunchOpts.value)
}
def scriptedUnpublishedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask {
val result = scriptedSource(dir => (s: State) => Scripted.scriptedParser(dir)).parsed
Scripted.doScripted((sbtLaunchJar in bundledLauncherProj).value, (fullClasspath in scriptedSbtProj in Test).value,
(scalaInstance in scriptedSbtProj).value,
scriptedSource.value, scriptedBufferLog.value, result, scriptedPrescripted.value)
scriptedSource.value, scriptedBufferLog.value, result, scriptedPrescripted.value, scriptedLaunchOpts.value)
}
lazy val publishLauncher = TaskKey[Unit]("publish-launcher")
@ -233,11 +238,40 @@ def otherRootSettings = Seq(
scripted <<= scriptedTask,
scriptedUnpublished <<= scriptedUnpublishedTask,
scriptedSource := (sourceDirectory in sbtProj).value / "sbt-test",
// scriptedPrescripted := { addSbtAlternateResolver _ },
scriptedLaunchOpts := List("-XX:MaxPermSize=256M", "-Xmx1G"),
publishAll := {
val _ = (publishLocal).all(ScopeFilter(inAnyProject)).value
},
aggregate in bintrayRelease := false
)
) ++ inConfig(Scripted.RepoOverrideTest)(Seq(
scriptedPrescripted := { _ => () },
scriptedLaunchOpts := {
List("-XX:MaxPermSize=256M", "-Xmx1G", "-Dsbt.override.build.repos=true",
s"""-Dsbt.repository.config=${ scriptedSource.value / "repo.config" }""")
},
scripted <<= scriptedTask,
scriptedUnpublished <<= scriptedUnpublishedTask,
scriptedSource := (sourceDirectory in sbtProj).value / "repo-override-test"
))
// def addSbtAlternateResolver(scriptedRoot: File) = {
// val resolver = scriptedRoot / "project" / "AddResolverPlugin.scala"
// if (!resolver.exists) {
// IO.write(resolver, s"""import sbt._
// |import Keys._
// |
// |object AddResolverPlugin extends AutoPlugin {
// | override def requires = sbt.plugins.JvmPlugin
// | override def trigger = allRequirements
// |
// | override lazy val projectSettings = Seq(resolvers += alternativeLocalResolver)
// | lazy val alternativeLocalResolver = Resolver.file("$altLocalRepoName", file("$altLocalRepoPath"))(Resolver.ivyStylePatterns)
// |}
// |""".stripMargin)
// }
// }
lazy val docProjects: ScopeFilter = ScopeFilter(
inAnyProject -- inProjects(sbtRoot, sbtProj, scriptedSbtProj, scriptedPluginProj),
inConfigurations(Compile)

View File

@ -25,10 +25,12 @@ trait ScriptedKeys {
lazy val scriptedSource = SettingKey[File]("scripted-source")
lazy val scriptedPrescripted = TaskKey[File => Unit]("scripted-prescripted")
lazy val scriptedBufferLog = SettingKey[Boolean]("scripted-buffer-log")
lazy val scriptedLaunchOpts = SettingKey[Seq[String]]("scripted-launch-opts", "options to pass to jvm launching scripted tasks")
}
object Scripted {
lazy val MavenResolverPluginTest = config("mavenResolverPluginTest") extend Compile
lazy val RepoOverrideTest = config("repoOverrideTest") extend Compile
import sbt.complete._
import DefaultParsers._
@ -83,14 +85,14 @@ object Scripted {
launchOpts: Array[String], prescripted: java.util.List[File]): Unit
}
def doScripted(launcher: File, scriptedSbtClasspath: Seq[Attributed[File]], scriptedSbtInstance: ScalaInstance,
sourcePath: File, bufferLog: Boolean, args: Seq[String], prescripted: File => Unit): Unit = {
def doScripted(launcher: File, scriptedSbtClasspath: Seq[Attributed[File]],
scriptedSbtInstance: ScalaInstance, sourcePath: File, bufferLog: Boolean,
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] {
@ -101,7 +103,7 @@ object Scripted {
def get(x: Int): sbt.File = ???
def size(): Int = 0
}
bridge.run(sourcePath, bufferLog, args.toArray, launcher, launcherVmOptions, callback)
bridge.run(sourcePath, bufferLog, 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]