-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
frontend/src/main/scala/bloop/engine/caches/ExpressionCompilerCache.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package bloop.engine.caches | ||
|
||
import bloop.DependencyResolution | ||
import bloop.ExpressionCompilerCacheLock | ||
import bloop.io.AbsolutePath | ||
import bloop.io.Paths | ||
import bloop.logging.Logger | ||
import ch.epfl.scala.debugadapter.BuildInfo | ||
import sbt.internal.inc.BloopComponentCompiler | ||
import sbt.internal.inc.BloopComponentManager | ||
import sbt.internal.inc.IfMissing | ||
|
||
import scala.util.Failure | ||
import scala.util.Success | ||
import scala.util.Try | ||
|
||
object ExpressionCompilerCache { | ||
import ch.epfl.scala.debugadapter.BuildInfo._ | ||
|
||
private val cacheDirectory = Paths.getCacheDirectory(expressionCompilerName) | ||
private val provider = BloopComponentCompiler.getComponentProvider(cacheDirectory) | ||
private val manager = | ||
new BloopComponentManager(ExpressionCompilerCacheLock, provider, secondaryCacheDir = None) | ||
|
||
def fetch( | ||
scalaVersion: String, | ||
logger: Logger | ||
): Either[String, AbsolutePath] = { | ||
val module = s"${expressionCompilerName}_$scalaVersion" | ||
val expressionCompilerId = s"$expressionCompilerOrganization.$module.$expressionCompilerVersion" | ||
|
||
def attemptResolution(): Either[String, AbsolutePath] = { | ||
import bloop.engine.ExecutionContext.ioScheduler | ||
val artifact = DependencyResolution.Artifact( | ||
expressionCompilerOrganization, | ||
module, | ||
expressionCompilerVersion | ||
) | ||
DependencyResolution.resolveWithErrors(List(artifact), logger)(ioScheduler) match { | ||
case Left(error) => Left(error.getMessage()) | ||
case Right(paths) => | ||
paths | ||
.find(_.syntax.contains(module)) | ||
.toRight(s"Missing $module in resolved jars ${paths.map(_.syntax).mkString(",")}") | ||
} | ||
} | ||
|
||
Try(manager.file(expressionCompilerId)(IfMissing.Fail)) match { | ||
case Success(pluginPath) => Right(AbsolutePath(pluginPath)) | ||
case Failure(exception) => | ||
val resolution = attemptResolution() | ||
resolution.foreach(jar => manager.define(expressionCompilerId, Seq(jar.toFile))) | ||
resolution | ||
} | ||
} | ||
} |