summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandra Dima <alexandra.dima@jetbrains.com>2019-07-22 11:53:28 +0200
committerSamvel Abrahamyan <samvel1024@gmail.com>2019-10-12 14:33:07 +0200
commit5a49a273cf86b58b18395edd05f57c7c209f3fe7 (patch)
tree4a6a752d1550fd4f5bc99a72c29a743de2e0ea5c
parentb5347266ee73d62659d01bdfe2d3444680a98747 (diff)
downloadmill-5a49a273cf86b58b18395edd05f57c7c209f3fe7.tar.gz
mill-5a49a273cf86b58b18395edd05f57c7c209f3fe7.tar.bz2
mill-5a49a273cf86b58b18395edd05f57c7c209f3fe7.zip
Made the variables that count erros and warnings in the compilation reporter atomic, such that their incrementation will be thread safe.
-rw-r--r--contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala23
1 files changed, 12 insertions, 11 deletions
diff --git a/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala b/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala
index 8e537fb8..b4647fed 100644
--- a/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala
+++ b/contrib/bsp/src/mill/contrib/bsp/BspLoggedReporter.scala
@@ -1,6 +1,7 @@
package mill.contrib.bsp
import java.io.File
+import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.{ConcurrentHashMap, ConcurrentMap}
import ch.epfl.scala.bsp4j.{BuildServer, BuildTargetIdentifier, CompileReport, Diagnostic, InverseSourcesParams, ScalaBuildServer, StatusCode, TaskFinishParams, TaskId, TextDocumentIdentifier}
@@ -24,27 +25,27 @@ class BspLoggedReporter(client: bsp.BuildClient,
maxErrors: Int,
logger: ManagedLogger) extends ManagedLoggedReporter(maxErrors, logger) {
- var errors = 0
- var warnings = 0
- var infos = 0
+ var errors = new AtomicInteger(0)
+ var warnings = new AtomicInteger(0)
+ var infos = new AtomicInteger(0)
var diagnosticMap: concurrent.Map[TextDocumentIdentifier, bsp.PublishDiagnosticsParams] =
new ConcurrentHashMap[TextDocumentIdentifier, bsp.PublishDiagnosticsParams]().asScala
override def logError(problem: Problem): Unit = {
client.onBuildPublishDiagnostics(getDiagnostics(problem, targetId, compilationOriginId))
- errors += 1
+ errors.incrementAndGet()
super.logError(problem)
}
override def logInfo(problem: Problem): Unit = {
client.onBuildPublishDiagnostics(getDiagnostics(problem, targetId, compilationOriginId))
- infos += 1
+ infos.incrementAndGet()
super.logInfo(problem)
}
override def logWarning(problem: Problem): Unit = {
client.onBuildPublishDiagnostics(getDiagnostics(problem, targetId, compilationOriginId))
- warnings += 1
+ warnings.incrementAndGet()
super.logWarning(problem)
}
@@ -53,7 +54,7 @@ class BspLoggedReporter(client: bsp.BuildClient,
taskFinishParams.setEventTime(System.currentTimeMillis())
taskFinishParams.setMessage("Finished compiling target: " + targetId.getUri)
taskFinishParams.setDataKind("compile-report")
- val compileReport = new CompileReport(targetId, errors, warnings)
+ val compileReport = new CompileReport(targetId, errors.get, warnings.get)
compilationOriginId match {
case Some(id) => compileReport.setOriginId(id)
case None =>
@@ -84,16 +85,16 @@ class BspLoggedReporter(client: bsp.BuildClient,
}
private[this] def getStatusCode: StatusCode = {
- if (errors > 0) StatusCode.ERROR else StatusCode.OK
+ if (errors.get > 0) StatusCode.ERROR else StatusCode.OK
}
private[this] def appendDiagnostics(textDocument: TextDocumentIdentifier,
currentDiagnostic: Diagnostic): List[Diagnostic] = {
- diagnosticMap.getOrElse(textDocument, new bsp.PublishDiagnosticsParams(
+ diagnosticMap.putIfAbsent(textDocument, new bsp.PublishDiagnosticsParams(
textDocument,
targetId,
- List.empty[Diagnostic].asJava, true)).getDiagnostics.asScala.toList ++
- List(currentDiagnostic)
+ List.empty[Diagnostic].asJava, true))
+ diagnosticMap(textDocument).getDiagnostics.asScala.toList ++ List(currentDiagnostic)
}
private[this] def getSingleDiagnostic(problem: Problem): Diagnostic ={