diff --git a/project/Scripted.scala b/project/Scripted.scala index e77749d63..2b4276a8d 100644 --- a/project/Scripted.scala +++ b/project/Scripted.scala @@ -17,8 +17,10 @@ object LocalScriptedPlugin extends AutoPlugin { trait ScriptedKeys { val publishAll = taskKey[Unit]("") val publishLocalBinAll = taskKey[Unit]("") - val scriptedUnpublished = inputKey[Unit]("Execute scripted without publishing sbt first. " + - "Saves you some time when only your test has changed") + val scriptedUnpublished = inputKey[Unit]( + "Execute scripted without publishing sbt first. " + + "Saves you some time when only your test has changed" + ) val scriptedSource = settingKey[File]("") val scriptedPrescripted = taskKey[File => Unit]("") } @@ -107,33 +109,48 @@ object Scripted { // Interface to cross class loader type SbtScriptedRunner = { def runInParallel( - resourceBaseDirectory: File, - bufferLog: Boolean, - tests: Array[String], - bootProperties: File, - launchOpts: Array[String], - prescripted: java.util.List[File], + resourceBaseDirectory: File, + bufferLog: Boolean, + tests: Array[String], + bootProperties: File, + launchOpts: Array[String], + prescripted: java.util.List[File], + instances: Int ): Unit } - val bridge = bridgeClass.getDeclaredConstructor().newInstance().asInstanceOf[SbtScriptedRunner] - + val initLoader = Thread.currentThread.getContextClassLoader try { - // Using java.util.List to encode File => Unit. - val callback = new java.util.AbstractList[File] { - override def add(x: File): Boolean = { prescripted(x); false } - def get(x: Int): sbt.File = ??? - def size(): Int = 0 - } - import scala.language.reflectiveCalls - bridge.runInParallel( - sourcePath, - bufferLog, - args.toArray, - launcher, - launchOpts.toArray, - callback, - ) - } catch { case ite: InvocationTargetException => throw ite.getCause } + Thread.currentThread.setContextClassLoader(loader) + val bridge = + bridgeClass.getDeclaredConstructor().newInstance().asInstanceOf[SbtScriptedRunner] + try { + // Using java.util.List to encode File => Unit. + val callback = new java.util.AbstractList[File] { + override def add(x: File): Boolean = { prescripted(x); false } + def get(x: Int): sbt.File = ??? + def size(): Int = 0 + } + val instances: Int = (System.getProperty("sbt.scripted.parallel.instances") match { + case null => 1 + case i => scala.util.Try(i.toInt).getOrElse(1) + }) match { + case i if i > 0 => i + case _ => 1 + } + import scala.language.reflectiveCalls + bridge.runInParallel( + sourcePath, + bufferLog, + args.toArray, + launcher, + launchOpts.toArray, + callback, + instances + ) + } catch { case ite: InvocationTargetException => throw ite.getCause } + } finally { + Thread.currentThread.setContextClassLoader(initLoader) + } } } diff --git a/sbt/src/sbt-test/dependency-management/cached-resolution-classifier/test b/sbt/src/sbt-test/dependency-management/cached-resolution-classifier/test index ccff5f24b..55cfc0713 100644 --- a/sbt/src/sbt-test/dependency-management/cached-resolution-classifier/test +++ b/sbt/src/sbt-test/dependency-management/cached-resolution-classifier/test @@ -1,5 +1,3 @@ -> debug - > a/update > a/updateClassifiers diff --git a/sbt/src/sbt-test/dependency-management/cached-resolution-conflicts/test b/sbt/src/sbt-test/dependency-management/cached-resolution-conflicts/test index 8e266c833..1a1446f96 100644 --- a/sbt/src/sbt-test/dependency-management/cached-resolution-conflicts/test +++ b/sbt/src/sbt-test/dependency-management/cached-resolution-conflicts/test @@ -1,4 +1,3 @@ > y1/publishLocal > y2/publishLocal -> debug > check diff --git a/sbt/src/sbt-test/dependency-management/cached-resolution-interproj/test b/sbt/src/sbt-test/dependency-management/cached-resolution-interproj/test index f3d872ac0..15886c51a 100644 --- a/sbt/src/sbt-test/dependency-management/cached-resolution-interproj/test +++ b/sbt/src/sbt-test/dependency-management/cached-resolution-interproj/test @@ -1,4 +1,2 @@ -> debug - > check diff --git a/sbt/src/sbt-test/dependency-management/exclude-transitive/test b/sbt/src/sbt-test/dependency-management/exclude-transitive/test index bf78e6c17..6204908fb 100644 --- a/sbt/src/sbt-test/dependency-management/exclude-transitive/test +++ b/sbt/src/sbt-test/dependency-management/exclude-transitive/test @@ -1,4 +1,3 @@ -> debug # load the project definition with transitive dependencies enabled # and check that they are not downloaded #$ pause diff --git a/sbt/src/sbt-test/dependency-management/ivy-settings-a/test b/sbt/src/sbt-test/dependency-management/ivy-settings-a/test index a8347e838..d7b5b2289 100644 --- a/sbt/src/sbt-test/dependency-management/ivy-settings-a/test +++ b/sbt/src/sbt-test/dependency-management/ivy-settings-a/test @@ -1,4 +1,3 @@ -> debug > update # works because scalaVersion is the same as sbtScalaVersion > compile diff --git a/sbt/src/sbt-test/dependency-management/mvn-local/disabled b/sbt/src/sbt-test/dependency-management/mvn-local/disabled index e6f5381a9..b7eb9f51f 100644 --- a/sbt/src/sbt-test/dependency-management/mvn-local/disabled +++ b/sbt/src/sbt-test/dependency-management/mvn-local/disabled @@ -19,7 +19,6 @@ $ copy-file changes/mainB1.scala main/B.scala -> main/compile $ copy-file changes/libA.scala library/A.scala -> debug > library/publishM2 # should succeed even without 'update' because Ivy should use the jar from the origin and not copy it to its cache > main/compile diff --git a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala index 91373e1d0..8375bf835 100644 --- a/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala +++ b/scripted-sbt-redux/src/main/scala/sbt/scriptedtest/ScriptedTests.scala @@ -125,7 +125,10 @@ final class ScriptedTests( if (labelsAndDirs.isEmpty) List() else { val totalSize = labelsAndDirs.size - val batchSize = totalSize / sbtInstances + val batchSize = totalSize / sbtInstances match { + case 0 => 1 + case s => s + } val (launcherBasedTests, runFromSourceBasedTests) = labelsAndDirs.partition { case (testName, _) =>