Extracting progress reporter to own class

This commit is contained in:
Igal Tabachnik 2021-09-09 23:26:54 +03:00
parent f209d0093c
commit 2f589b6713
3 changed files with 33 additions and 32 deletions

View File

@ -12,7 +12,6 @@ import java.net.{ URI, URL }
import java.nio.file.{ Paths, Path => NioPath }
import java.util.Optional
import java.util.concurrent.TimeUnit
import lmcoursier.CoursierDependencyResolution
import lmcoursier.definitions.{ Configuration => CConfiguration }
import org.apache.ivy.core.module.descriptor.ModuleDescriptor
@ -47,6 +46,7 @@ import sbt.internal.librarymanagement.mavenint.{
import sbt.internal.librarymanagement.{ CustomHttp => _, _ }
import sbt.internal.nio.{ CheckBuildSources, Globs }
import sbt.internal.server.{
BspCompileProgress,
BspCompileTask,
BuildServerProtocol,
BuildServerReporter,
@ -2353,39 +2353,16 @@ object Defaults extends BuildCommon {
)
}
def onProgress(s: Setup) = {
val p = s.progress.asScala
s.withProgress {
p.collect {
case c: CompileProgress =>
new CompileProgress {
override def startUnit(phase: String, unitPath: String): Unit =
c.startUnit(phase, unitPath)
override def afterEarlyOutput(success: Boolean): Unit =
c.afterEarlyOutput(success)
override def advance(
current: Int,
total: Int,
prevPhase: String,
nextPhase: String
): Boolean = {
val percentage = current * 100 / total
// Report percentages every 5% increments
val shouldReportPercentage = percentage % 5 == 0
if (shouldReportPercentage) {
task.notifyProgress(percentage, total)
}
c.advance(current, total, prevPhase, nextPhase)
}
}
}.asJava
}
val cp: BspCompileProgress = s.progress.asScala
.map(p => new BspCompileProgress(task, Some(p)))
.getOrElse(new BspCompileProgress(task, None))
s.withProgress(cp)
}
val compilers: Compilers = ci.compilers
val setup: Setup = ci.setup
val i = ci.withCompilers(onArgs(compilers)).withSetup(onProgress(setup))
val i = ci
.withCompilers(onArgs(compilers))
.withSetup(onProgress(setup))
try {
val result = incCompiler.compile(i, s.log)
reporter.sendSuccessReport(result.getAnalysis)

View File

@ -0,0 +1,24 @@
package sbt.internal.server
import xsbti.compile.CompileProgress
private[sbt] final class BspCompileProgress(
task: BspCompileTask,
underlying: Option[CompileProgress]
) extends CompileProgress {
override def advance(
current: Int,
total: Int,
prevPhase: String,
nextPhase: String
): Boolean = {
val percentage = current * 100 / total
// Report percentages every 5% increments
val shouldReportPercentage = percentage % 5 == 0
if (shouldReportPercentage) {
task.notifyProgress(percentage, total)
}
underlying.foreach(_.advance(current, total, prevPhase, nextPhase))
true
}
}

View File

@ -26,7 +26,7 @@ object BspCompileTask {
): CompileResult = {
val task = BspCompileTask(targetId, project, config)
try {
task.notifyStart
task.notifyStart()
val result = Retry(compile(task))
task.notifySuccess(result)
result