Merge pull request #2569 from eed3si9n/wip/mavenrepobug

Fixes Maven Central getting included even with repo override
This commit is contained in:
eugene yokota 2016-04-24 16:53:19 -04:00
commit bc5451438e
8 changed files with 43 additions and 10 deletions

View File

@ -35,8 +35,9 @@ env:
- SBT_CMD="scripted tests/*" - SBT_CMD="scripted tests/*"
- SBT_CMD="scripted project-load/*" - SBT_CMD="scripted project-load/*"
- SBT_CMD="checkBuildScala211" - 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/*2of2"
- SBT_CMD="mavenResolverPluginTest:scripted dependency-management/*1of2 project/transitive-plugins"
notifications: notifications:
email: email:

View File

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

View File

@ -186,7 +186,6 @@ private[sbt] case class SbtChainResolver(
} }
}).reverse.headOption map { }).reverse.headOption map {
case (rmr, resolver) => case (rmr, resolver) =>
Message.warn(s"Choosing $resolver for ${rmr.getId}")
// Now that we know the real latest revision, let's force Ivy to use it // Now that we know the real latest revision, let's force Ivy to use it
val artifactOpt = findFirstArtifactRef(rmr.getDescriptor, dd, data, resolver) val artifactOpt = findFirstArtifactRef(rmr.getDescriptor, dd, data, resolver)
artifactOpt match { artifactOpt match {

View File

@ -1148,12 +1148,15 @@ object Classpaths {
externalResolvers <<= (externalResolvers.task.?, resolvers, appResolvers, useJCenter) { externalResolvers <<= (externalResolvers.task.?, resolvers, appResolvers, useJCenter) {
case (Some(delegated), Seq(), _, _) => delegated case (Some(delegated), Seq(), _, _) => delegated
case (_, rs, Some(ars), uj) => task { ars ++ rs } case (_, rs, Some(ars), uj) => task { ars ++ rs }
case (_, rs, _, uj) => task { Resolver.withDefaultResolvers(rs, uj, true) } case (_, rs, _, uj) => task { Resolver.withDefaultResolvers(rs, uj, mavenCentral = true) }
}, },
appResolvers := { appResolvers := {
val ac = appConfiguration.value val ac = appConfiguration.value
val uj = useJCenter.value val uj = useJCenter.value
appRepositories(ac) map { ars => Resolver.reorganizeAppResolvers(ars, uj, true) } appRepositories(ac) map { ars =>
val useMavenCentral = ars contains DefaultMavenRepository
Resolver.reorganizeAppResolvers(ars, uj, useMavenCentral)
}
}, },
bootResolvers <<= appConfiguration map bootRepositories, bootResolvers <<= appConfiguration map bootRepositories,
fullResolvers <<= (projectResolver, externalResolvers, sbtPlugin, sbtResolver, bootResolvers, overrideBuildResolvers) map { (proj, rs, isPlugin, sbtr, boot, overrideFlag) => fullResolvers <<= (projectResolver, externalResolvers, sbtPlugin, sbtResolver, bootResolvers, overrideBuildResolvers) map { (proj, rs, isPlugin, sbtr, boot, overrideFlag) =>

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 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 scriptedSource = SettingKey[File]("scripted-source")
lazy val scriptedPrescripted = TaskKey[File => Unit]("scripted-prescripted") 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 MavenResolverPluginTest = config("mavenResolverPluginTest") extend Compile
lazy val RepoOverrideTest = config("repoOverrideTest") extend Compile
import sbt.complete._ import sbt.complete._
import DefaultParsers._ import DefaultParsers._
@ -66,13 +68,14 @@ object Scripted {
launchOpts: Array[String], prescripted: java.util.List[File]): Unit 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")}") System.err.println(s"About to run tests: ${args.mkString("\n * ", "\n * ", "\n")}")
val noJLine = new classpath.FilteredLoader(scriptedSbtInstance.loader, "jline." :: Nil) val noJLine = new classpath.FilteredLoader(scriptedSbtInstance.loader, "jline." :: Nil)
val loader = classpath.ClasspathUtilities.toLoader(scriptedSbtClasspath.files, noJLine) val loader = classpath.ClasspathUtilities.toLoader(scriptedSbtClasspath.files, noJLine)
val bridgeClass = Class.forName("sbt.test.ScriptedRunner", true, loader) val bridgeClass = Class.forName("sbt.test.ScriptedRunner", true, loader)
val bridge = bridgeClass.newInstance.asInstanceOf[SbtScriptedRunner] val bridge = bridgeClass.newInstance.asInstanceOf[SbtScriptedRunner]
val launcherVmOptions = Array("-XX:MaxPermSize=256M", "-Xmx1G") // increased after a failure in scripted source-dependencies/macro
try { try {
// Using java.util.List to encode File => Unit. // Using java.util.List to encode File => Unit.
val callback = new java.util.AbstractList[File] { val callback = new java.util.AbstractList[File] {
@ -83,7 +86,7 @@ object Scripted {
def get(x: Int): sbt.File = ??? def get(x: Int): sbt.File = ???
def size(): Int = 0 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 } } 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]