diff options
author | Alexandra Dima <alexandra.dima@jetbrains.com> | 2019-07-24 14:03:48 +0200 |
---|---|---|
committer | Samvel Abrahamyan <samvel1024@gmail.com> | 2019-10-12 14:33:11 +0200 |
commit | 0b4bcbbfabe06d549d95efb427e75356287398fb (patch) | |
tree | 38496e9791f508276b58fdcf8aef46ffe1a5d971 /contrib/bsp/src | |
parent | fca29d647f2ae0b71c5b66b3ea4462987e08c911 (diff) | |
download | mill-0b4bcbbfabe06d549d95efb427e75356287398fb.tar.gz mill-0b4bcbbfabe06d549d95efb427e75356287398fb.tar.bz2 mill-0b4bcbbfabe06d549d95efb427e75356287398fb.zip |
Changed the clean cache method to usethe clean command form mill's MainModule rather than start the clean command as a separate subprocess. Removed dead code comment and added show message notifications to the MillBspLogger.
Diffstat (limited to 'contrib/bsp/src')
-rw-r--r-- | contrib/bsp/src/mill/contrib/bsp/MillBspLogger.scala | 21 | ||||
-rw-r--r-- | contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala | 36 |
2 files changed, 33 insertions, 24 deletions
diff --git a/contrib/bsp/src/mill/contrib/bsp/MillBspLogger.scala b/contrib/bsp/src/mill/contrib/bsp/MillBspLogger.scala index 811c898c..195d9aab 100644 --- a/contrib/bsp/src/mill/contrib/bsp/MillBspLogger.scala +++ b/contrib/bsp/src/mill/contrib/bsp/MillBspLogger.scala @@ -1,9 +1,7 @@ package mill.contrib.bsp -import java.io.{InputStream, PrintStream} - -import ch.epfl.scala.bsp4j.{BuildClient, TaskId, TaskProgressParams} -import mill.api.{BspContext, Logger} +import ch.epfl.scala.bsp4j._ +import mill.api.Logger import mill.util.ProxyLogger class MillBspLogger(client: BuildClient, taskId: Int, logger: Logger) extends ProxyLogger(logger) { @@ -24,4 +22,19 @@ class MillBspLogger(client: BuildClient, taskId: Int, logger: Logger) extends Pr } } + override def error(s: String): Unit = { + super.error(s) + client.onBuildShowMessage(new ShowMessageParams(MessageType.ERROR, s)) + } + + override def info(s: String): Unit = { + super.info(s) + client.onBuildShowMessage(new ShowMessageParams(MessageType.INFORMATION, s)) + } + + override def debug(s: String): Unit = { + super.debug(s) + client.onBuildShowMessage(new ShowMessageParams(MessageType.LOG, s)) + } + } diff --git a/contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala b/contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala index b5ebf83e..f34571e4 100644 --- a/contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala +++ b/contrib/bsp/src/mill/contrib/bsp/MillBuildServer.scala @@ -20,6 +20,7 @@ import scala.collection.JavaConverters._ import mill.modules.Jvm import mill.util.Ctx import mill.define.{Discover, ExternalModule} +import mill.main.MainModule import sbt.internal.util.{ConsoleOut, MainAppender, ManagedLogger} import sbt.util.LogExchange @@ -393,30 +394,25 @@ class MillBuildServer(evaluator: Evaluator, var cleaned = true for (targetId <- cleanCacheParams.getTargets.asScala) { val module = targetIdToModule(targetId) - val cleanCommand = List("java", - s"-DMILL_CLASSPATH=${System.getProperty("MILL_CLASSPATH")}", - s"-DMILL_VERSION=${System.getProperty("MILL_VERSION")}", - "-Djna.nosys=true", "-cp", - System.getProperty("MILL_CLASSPATH"), - "mill.MillMain", "clean", - s"${module.millModuleSegments.render}.compile") - val process = Runtime.getRuntime.exec(cleanCommand.mkString(" ")) - - val processIn = process.getInputStream - val processErr = process.getErrorStream - - val errMessage = Source.fromInputStream(processErr).getLines().mkString("\n") - val message = Source.fromInputStream(processIn).getLines().mkString("\n") - msg += s"Cleaning cache for target ${targetId} produced the following message: ${message}, ${errMessage}" - if (msg.contains("failed")) { + val mainModule = new MainModule { + override implicit def millDiscover: Discover[_] = { + Discover[this.type] + } + } + val cleanCommand = mainModule.clean(millEvaluator, List(s"${module.millModuleSegments.render}.compile"):_*) + val cleanResult = millEvaluator.evaluate( + Strict.Agg(cleanCommand), + logger = new MillBspLogger(client, cleanCommand.hashCode, millEvaluator.log) + ) + if (cleanResult.failing.keyCount > 0) { cleaned = false + msg += s" Target ${module.millModuleSegments.render} could not be cleaned." } - process.waitFor() } - new CleanCacheResult(msg, cleaned) + new CleanCacheResult(msg, cleaned) + } + handleExceptions[String, CleanCacheResult]((in) => getCleanCacheResult, "") } - handleExceptions[String, CleanCacheResult]((in) => getCleanCacheResult, "") - } override def buildTargetScalacOptions(scalacOptionsParams: ScalacOptionsParams): CompletableFuture[ScalacOptionsResult] = { |