Skip to content

Commit

Permalink
Merge pull request #797 from scalacenter/ticket/795
Browse files Browse the repository at this point in the history
Prepare for v1.2.2 release
  • Loading branch information
jvican authored Jan 15, 2019
2 parents 9689c5d + aeeced4 commit 8197a74
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 79 deletions.
33 changes: 22 additions & 11 deletions backend/src/main/scala/bloop/DependencyResolution.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ object DependencyResolution {
Repository,
Resolution
}
import coursier.interop.scalaz._
import scalaz.concurrent.Task

/**
Expand All @@ -46,7 +45,9 @@ object DependencyResolution {
version: String,
logger: Logger,
additionalRepositories: Seq[Repository] = Nil
): Array[AbsolutePath] = {
)(implicit ec: scala.concurrent.ExecutionContext): Array[AbsolutePath] = {
import coursier._
import coursier.util.{Gather, Task}
logger.debug(s"Resolving $organization:$module:$version")(DebugFilter.Compilation)
val org = coursier.Organization(organization)
val moduleName = coursier.ModuleName(module)
Expand All @@ -56,20 +57,30 @@ object DependencyResolution {
val baseRepositories = Seq(
Cache.ivy2Local,
MavenRepository("https://repo1.maven.org/maven2"),
MavenRepository("https://dl.bintray.com/scalacenter/releases"))
MavenRepository("https://dl.bintray.com/scalacenter/releases")
)
baseRepositories ++ additionalRepositories
}
val fetch = Fetch.from(repositories, Cache.fetch())
val resolution = start.process.run(fetch).unsafePerformSync
val errors = resolution.errors
if (errors.isEmpty) {
val localArtifacts: List[Either[FileError, File]] =
Task.gatherUnordered(resolution.artifacts().map(Cache.file(_).run)).unsafePerformSync
localArtifacts.collect { case Right(f) => AbsolutePath(f.toPath) }.toArray
val fetch = Fetch.from(repositories, Cache.fetch[Task]())
val resolution = start.process.run(fetch).unsafeRun()
val localArtifacts: Seq[(Boolean, Either[FileError, File])] = {
Gather[Task]
.gather(resolution.artifacts().map { artifact =>
Cache.file[Task](artifact).run.map(artifact.optional -> _)
})
.unsafeRun()
}

val fileErrors = localArtifacts.collect {
case (isOptional, Left(error)) if !isOptional || !error.notFound => error
}
if (fileErrors.isEmpty) {
localArtifacts.collect { case (_, Right(f)) => AbsolutePath(f.toPath) }.toArray
} else {
val moduleInfo = s"$organization:$module:$version"
val prettyFileErrors = fileErrors.map(_.describe).mkString(System.lineSeparator)
sys.error(
s"Resolution of module $moduleInfo failed with: ${errors.mkString("\n =>", "=> \n", "\n")}"
s"Resolution of module $moduleInfo failed with:${System.lineSeparator}${prettyFileErrors}"
)
}
}
Expand Down
12 changes: 8 additions & 4 deletions backend/src/main/scala/bloop/ScalaInstance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ final class ScalaInstance private (

object ScalaInstance {
import bloop.io.AbsolutePath
import scala.concurrent.ExecutionContext

private[ScalaInstance] final val ScalacCompilerName = "scala-compiler"

Expand All @@ -97,12 +98,13 @@ object ScalaInstance {
scalaVersion: String,
allJars: Seq[AbsolutePath],
logger: Logger
): ScalaInstance = {
)(implicit ec: ExecutionContext): ScalaInstance = {
val jarsKey = allJars.map(_.underlying).sortBy(_.toString).toList
if (allJars.nonEmpty) {
def newInstance = {
logger.debug(s"Cache miss for scala instance ${scalaOrg}:${scalaName}:${scalaVersion}.")(
DebugFilter.Compilation)
DebugFilter.Compilation
)
jarsKey.foreach(p => logger.debug(s" => $p")(DebugFilter.Compilation))
new ScalaInstance(scalaOrg, scalaName, scalaVersion, allJars.map(_.toFile).toArray)
}
Expand All @@ -123,7 +125,7 @@ object ScalaInstance {
scalaName: String,
scalaVersion: String,
logger: Logger
): ScalaInstance = {
)(implicit ec: ExecutionContext): ScalaInstance = {
def resolveInstance: ScalaInstance = {
val allPaths = DependencyResolution.resolve(scalaOrg, scalaName, scalaVersion, logger)
val allJars = allPaths.collect {
Expand Down Expand Up @@ -158,7 +160,9 @@ object ScalaInstance {
* happen to be so strict as to prevent getting the location from the protected
* domain.
*/
def scalaInstanceFromBloop(logger: Logger): Option[ScalaInstance] = {
def scalaInstanceFromBloop(
logger: Logger
)(implicit ec: ExecutionContext): Option[ScalaInstance] = {
lazy val tempDirectory = Files.createTempDirectory("bloop-scala-instance")
implicit val filter = DebugFilter.Compilation
def findLocationForClazz(clazz: Class[_], jarName: String): Option[Path] = {
Expand Down
2 changes: 2 additions & 0 deletions backend/src/test/scala/bloop/ScalaInstanceCachingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters

import scala.concurrent.ExecutionContext.Implicits.global

object ScalaInstanceCachingSpec {
val sameVersionPairs = Array("2.10.6", "2.10.1", "2.11.11", "2.12.0", "2.12.4")
val unsharedVersionPairs =
Expand Down
1 change: 1 addition & 0 deletions backend/src/test/scala/bloop/ScalaInstanceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.junit.experimental.categories.Category
@Category(Array(classOf[FastTests]))
class ScalaInstanceSpec {
@Test def testInstanceFromBloop(): Unit = {
import scala.concurrent.ExecutionContext.Implicits.global
val instance0 = ScalaInstance.scalaInstanceFromBloop(new RecordingLogger())
Assert.assertTrue("Scala instance couldn't be created", instance0.isDefined)
val instance = instance0.get
Expand Down
26 changes: 14 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ val benchmarkBridge = project
releaseEarly := { () },
skip in publish := true,
bloopGenerate in Compile := None,
bloopGenerate in Test := None,
bloopGenerate in Test := None
)

/***************************************************************************************************/
Expand All @@ -42,7 +42,6 @@ val backend = project
Dependencies.scalazConcurrent,
Dependencies.coursier,
Dependencies.coursierCache,
Dependencies.coursierScalaz,
Dependencies.libraryManagement,
Dependencies.configDirectories,
Dependencies.sourcecode,
Expand Down Expand Up @@ -71,7 +70,7 @@ val jsonConfig210 = project
Dependencies.circeCore,
Dependencies.circeGeneric,
compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full),
Dependencies.scalacheck % Test,
Dependencies.scalacheck % Test
)
}
)
Expand All @@ -92,7 +91,7 @@ val jsonConfig211 = project
List(
Dependencies.circeParser,
Dependencies.circeDerivation,
Dependencies.scalacheck % Test,
Dependencies.scalacheck % Test
)
}
)
Expand All @@ -113,7 +112,7 @@ val jsonConfig212 = project
List(
Dependencies.circeParser,
Dependencies.circeDerivation,
Dependencies.scalacheck % Test,
Dependencies.scalacheck % Test
)
}
)
Expand All @@ -126,7 +125,6 @@ lazy val launcher: Project = project
libraryDependencies ++= List(
Dependencies.coursier,
Dependencies.coursierCache,
Dependencies.coursierScalaz,
Dependencies.nuprocess,
Dependencies.ipcsocket,
Dependencies.junit % Test,
Expand Down Expand Up @@ -171,7 +169,7 @@ val benchmarks = project
.enablePlugins(BuildInfoPlugin, JmhPlugin)
.settings(benchmarksSettings(frontend))
.settings(
skip in publish := true,
skip in publish := true
)

val integrations = file("integrations")
Expand Down Expand Up @@ -207,14 +205,16 @@ val gradleBloop211 = project
.settings(BuildDefaults.gradlePluginBuildSettings)
.settings(BuildInfoPlugin.buildInfoScopedSettings(Test))
.settings(scalaVersion := Keys.scalaVersion.in(jsonConfig211).value)
.settings(target := (file("integrations") / "gradle-bloop" / "target" / "gradle-bloop-2.11").getAbsoluteFile)
.settings(
target := (file("integrations") / "gradle-bloop" / "target" / "gradle-bloop-2.11").getAbsoluteFile
)
.settings(
sourceDirectories in Test := Nil,
publishLocal := publishLocal.dependsOn(publishLocal.in(jsonConfig211)).value,
bloopGenerate in Test := None,
test in Test := Def.task {
Keys.streams.value.log.error("Run 'gradleBloopTests/test' instead to test the gradle plugin.")
},
}
)

lazy val gradleBloop212 = project
Expand All @@ -225,7 +225,9 @@ lazy val gradleBloop212 = project
.settings(BuildDefaults.gradlePluginBuildSettings, testSettings)
.settings(BuildInfoPlugin.buildInfoScopedSettings(Test))
.settings(scalaVersion := Keys.scalaVersion.in(jsonConfig212).value)
.settings(target := (file("integrations") / "gradle-bloop" / "target" / "gradle-bloop-2.12").getAbsoluteFile)
.settings(
target := (file("integrations") / "gradle-bloop" / "target" / "gradle-bloop-2.12").getAbsoluteFile
)
.settings(
publishLocal := publishLocal.dependsOn(publishLocal.in(jsonConfig212)).value
)
Expand Down Expand Up @@ -290,7 +292,7 @@ lazy val nativeBridge = project
name := "bloop-native-bridge",
libraryDependencies += Dependencies.scalaNativeTools,
javaOptions in Test ++= jvmOptions,
fork in Test := true,
fork in Test := true
)

/* This project has the only purpose of forcing the resolution of some artifacts that fail spuriously to be fetched. */
Expand Down Expand Up @@ -362,7 +364,7 @@ addCommandAlias(
s"${jsBridge10.id}/$publishLocalCmd",
s"${launcher.id}/$publishLocalCmd",
"createLocalHomebrewFormula",
"createLocalScoopFormula",
"createLocalScoopFormula"
).mkString(";", ";", "")
)

Expand Down
30 changes: 22 additions & 8 deletions frontend/src/main/scala/bloop/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ object Server {

def nailMain(ngContext: NGContext): Unit = {
val server = ngContext.getNGServer
shutDown(server)
import java.util.concurrent.ForkJoinPool

ForkJoinPool
.commonPool()
.submit(new Runnable {
override def run(): Unit = {
server.shutdown(false)
}
})

()
}

private def run(server: NGServer): Unit = {
Expand All @@ -39,22 +49,26 @@ object Server {
aliasManager.addAlias(new Alias("compile", "Compile project(s) in the build.", classOf[Cli]))
aliasManager.addAlias(new Alias("test", "Run project(s)' tests in the build.", classOf[Cli]))
aliasManager.addAlias(
new Alias("run", "Run a main entrypoint for project(s) in the build.", classOf[Cli]))
new Alias("run", "Run a main entrypoint for project(s) in the build.", classOf[Cli])
)
aliasManager.addAlias(new Alias("bsp", "Spawn a build server protocol instance.", classOf[Cli]))
aliasManager.addAlias(
new Alias("console", "Run the console for project(s) in the build.", classOf[Cli]))
new Alias("console", "Run the console for project(s) in the build.", classOf[Cli])
)
aliasManager.addAlias(new Alias("projects", "Show projects in the build.", classOf[Cli]))
aliasManager.addAlias(new Alias("configure", "Configure the bloop server.", classOf[Cli]))
aliasManager.addAlias(new Alias("help", "Show bloop help message.", classOf[Cli]))
aliasManager.addAlias(new Alias("exit", "Kill the bloop server.", classOf[Server]))
aliasManager.addAlias(
new Alias(
"exit",
"Kill the bloop server.",
classOf[Server]
)
)

// Register the default entrypoint in case the user doesn't use the right alias
server.setDefaultNailClass(classOf[Cli])
// Disable nails by class name so that we prevent classloading incorrect aliases
server.setAllowNailsByClassName(false)
}

private def shutDown(server: NGServer): Unit = {
server.shutdown( /* exitVM = */ false)
}
}
1 change: 1 addition & 0 deletions frontend/src/main/scala/bloop/data/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ object Project {
}

def fromConfig(file: Config.File, origin: Origin, logger: Logger): Project = {
import bloop.engine.ExecutionContext.ioScheduler
val project = file.project
val scala = project.`scala`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ abstract class ToolchainCompanion[Toolchain] {
private final val BloopVersion = BuildInfo.version
private final val BloopOrg = BuildInfo.organization
private def resolveJars(artifactName: String, logger: Logger): List[Path] = {
import bloop.engine.ExecutionContext.ioScheduler
logger.debug(s"Resolving platform bridge: $BloopOrg:$artifactName:$BloopVersion")(
DebugFilter.Compilation)
DebugFilter.Compilation
)
val files = DependencyResolution.resolve(BloopOrg, artifactName, BloopVersion, logger)
files.iterator.map(_.underlying).filter(_.toString.endsWith(".jar")).toList
}
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/main/scala/bloop/testing/TestInternals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ object TestInternals {

lazy val filteredLoader = {
val filter = new IncludePackagesFilter(
Set("java.", "javax.", "sun.", "sbt.testing.", "org.scalatools.testing.", "org.xml.sax."))
Set("java.", "javax.", "sun.", "sbt.testing.", "org.scalatools.testing.", "org.xml.sax.")
)
new FilteredLoader(getClass.getClassLoader, filter)
}

Expand Down Expand Up @@ -80,6 +81,7 @@ object TestInternals {
testAgentFiles match {
case Some(paths) => paths
case None =>
import bloop.engine.ExecutionContext.ioScheduler
val paths = DependencyResolution.resolve(sbtOrg, testAgentId, testAgentVersion, logger)
testAgentFiles = Some(paths)
paths
Expand Down Expand Up @@ -213,8 +215,9 @@ object TestInternals {
}
}

def getFingerprints(frameworks: Seq[Framework])
: (Set[PrintInfo[SubclassFingerprint]], Set[PrintInfo[AnnotatedFingerprint]]) = {
def getFingerprints(
frameworks: Seq[Framework]
): (Set[PrintInfo[SubclassFingerprint]], Set[PrintInfo[AnnotatedFingerprint]]) = {
val subclasses = mutable.Set.empty[PrintInfo[SubclassFingerprint]]
val annotated = mutable.Set.empty[PrintInfo[AnnotatedFingerprint]]
for {
Expand Down Expand Up @@ -282,7 +285,8 @@ object TestInternals {
private def defined[T <: Fingerprint](
in: Set[PrintInfo[T]],
names: Set[String],
IsModule: Boolean): Set[PrintInfo[T]] = {
IsModule: Boolean
): Set[PrintInfo[T]] = {
in collect { case info @ (name, IsModule, _, _) if names(name) => info }
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/test/scala/bloop/ClasspathHashingSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ClasspathHashingSpec {
@Test
def detectsMacrosInClasspath(): Unit = {
val logger = new RecordingLogger()
import bloop.engine.ExecutionContext.ioScheduler
val jars = DependencyResolution
.resolve("ch.epfl.scala", "zinc_2.12", "1.2.1+97-636ca091", logger)
.filter(_.syntax.endsWith(".jar"))
Expand Down
Loading

0 comments on commit 8197a74

Please sign in to comment.