mirror of https://github.com/sbt/sbt.git
Extracting progress reporter to own class
This commit is contained in:
parent
f209d0093c
commit
2f589b6713
|
|
@ -12,7 +12,6 @@ import java.net.{ URI, URL }
|
||||||
import java.nio.file.{ Paths, Path => NioPath }
|
import java.nio.file.{ Paths, Path => NioPath }
|
||||||
import java.util.Optional
|
import java.util.Optional
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
import lmcoursier.CoursierDependencyResolution
|
import lmcoursier.CoursierDependencyResolution
|
||||||
import lmcoursier.definitions.{ Configuration => CConfiguration }
|
import lmcoursier.definitions.{ Configuration => CConfiguration }
|
||||||
import org.apache.ivy.core.module.descriptor.ModuleDescriptor
|
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.librarymanagement.{ CustomHttp => _, _ }
|
||||||
import sbt.internal.nio.{ CheckBuildSources, Globs }
|
import sbt.internal.nio.{ CheckBuildSources, Globs }
|
||||||
import sbt.internal.server.{
|
import sbt.internal.server.{
|
||||||
|
BspCompileProgress,
|
||||||
BspCompileTask,
|
BspCompileTask,
|
||||||
BuildServerProtocol,
|
BuildServerProtocol,
|
||||||
BuildServerReporter,
|
BuildServerReporter,
|
||||||
|
|
@ -2353,39 +2353,16 @@ object Defaults extends BuildCommon {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
def onProgress(s: Setup) = {
|
def onProgress(s: Setup) = {
|
||||||
val p = s.progress.asScala
|
val cp: BspCompileProgress = s.progress.asScala
|
||||||
s.withProgress {
|
.map(p => new BspCompileProgress(task, Some(p)))
|
||||||
p.collect {
|
.getOrElse(new BspCompileProgress(task, None))
|
||||||
case c: CompileProgress =>
|
s.withProgress(cp)
|
||||||
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 compilers: Compilers = ci.compilers
|
val compilers: Compilers = ci.compilers
|
||||||
val setup: Setup = ci.setup
|
val setup: Setup = ci.setup
|
||||||
val i = ci.withCompilers(onArgs(compilers)).withSetup(onProgress(setup))
|
val i = ci
|
||||||
|
.withCompilers(onArgs(compilers))
|
||||||
|
.withSetup(onProgress(setup))
|
||||||
try {
|
try {
|
||||||
val result = incCompiler.compile(i, s.log)
|
val result = incCompiler.compile(i, s.log)
|
||||||
reporter.sendSuccessReport(result.getAnalysis)
|
reporter.sendSuccessReport(result.getAnalysis)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -26,7 +26,7 @@ object BspCompileTask {
|
||||||
): CompileResult = {
|
): CompileResult = {
|
||||||
val task = BspCompileTask(targetId, project, config)
|
val task = BspCompileTask(targetId, project, config)
|
||||||
try {
|
try {
|
||||||
task.notifyStart
|
task.notifyStart()
|
||||||
val result = Retry(compile(task))
|
val result = Retry(compile(task))
|
||||||
task.notifySuccess(result)
|
task.notifySuccess(result)
|
||||||
result
|
result
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue