Refactor messages sending
This commit is contained in:
+7
-3
@@ -22,7 +22,9 @@ import java.io.Serializable
|
||||
open class CompilationOptions(
|
||||
val compilerMode: CompileService.CompilerMode,
|
||||
val targetPlatform: CompileService.TargetPlatform,
|
||||
val reportingFilters: List<ReportingFilter>
|
||||
val reportCategories: Array<Int>,
|
||||
val reportSeverity: Int,
|
||||
val requestedCompilationResults: Array<Int>
|
||||
) : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 0
|
||||
@@ -38,8 +40,10 @@ class IncrementalCompilationOptions(
|
||||
val customCacheVersion: Int,
|
||||
compilerMode: CompileService.CompilerMode,
|
||||
targetPlatform: CompileService.TargetPlatform,
|
||||
reportingFilters: List<ReportingFilter>
|
||||
) : CompilationOptions(compilerMode, targetPlatform, reportingFilters) {
|
||||
reportedCategories: Array<Int>,
|
||||
reportedSeverity: Int,
|
||||
requestedCompilationResults: Array<Int>
|
||||
) : CompilationOptions(compilerMode, targetPlatform, reportedCategories, reportedSeverity, requestedCompilationResults) {
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 0
|
||||
}
|
||||
|
||||
+10
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,12 +17,14 @@
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import java.io.Serializable
|
||||
import java.rmi.Remote
|
||||
import java.rmi.RemoteException
|
||||
|
||||
/**
|
||||
* Allows daemon clients to specify report category and severities for that category that should be reported from daemon
|
||||
*/
|
||||
data class ReportingFilter(val category: ReportCategory, val severities: List<Int>) : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 0
|
||||
}
|
||||
interface CompilationResultsStorage : Remote {
|
||||
@Throws(RemoteException::class)
|
||||
fun store(compilationResult: Int, value: Serializable)
|
||||
}
|
||||
|
||||
enum class CompilationResult(val code: Int) {
|
||||
IC_COMPILE_ITERATION(0)
|
||||
}
|
||||
+2
-1
@@ -138,7 +138,8 @@ interface CompileService : Remote {
|
||||
sessionId: Int,
|
||||
compilerArguments: CommonCompilerArguments,
|
||||
compilationOptions: CompilationOptions,
|
||||
servicesFacade: CompilerServicesFacadeBase
|
||||
servicesFacade: CompilerServicesFacadeBase,
|
||||
compilationResultsStorage: CompilationResultsStorage?
|
||||
): CallResult<Int>
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
|
||||
+36
-21
@@ -16,7 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import java.io.File
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import java.io.Serializable
|
||||
import java.rmi.Remote
|
||||
import java.rmi.RemoteException
|
||||
@@ -26,29 +27,43 @@ interface CompilerServicesFacadeBase : Remote {
|
||||
* Reports different kind of diagnostic messages from compile daemon to compile daemon clients (jps, gradle, ...)
|
||||
*/
|
||||
@Throws(RemoteException::class)
|
||||
fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?)
|
||||
fun report(category: Int, severity: Int, message: String?, attachment: Serializable?)
|
||||
}
|
||||
|
||||
interface IncrementalCompilerServicesFacade : CompilerServicesFacadeBase {
|
||||
// AnnotationFileUpdater
|
||||
@Throws(RemoteException::class)
|
||||
fun hasAnnotationsFileUpdater(): Boolean
|
||||
enum class ReportCategory(val code: Int) {
|
||||
COMPILER_MESSAGE(0),
|
||||
DAEMON_MESSAGE(1),
|
||||
IC_MESSAGE(2),
|
||||
OUTPUT_MESSAGE(3);
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun updateAnnotations(outdatedClassesJvmNames: Iterable<String>)
|
||||
companion object {
|
||||
fun fromCode(code: Int): ReportCategory? =
|
||||
ReportCategory.values().firstOrNull { it.code == code }
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun revert()
|
||||
|
||||
// ChangesRegistry
|
||||
@Throws(RemoteException::class)
|
||||
fun registerChanges(timestamp: Long, dirtyData: SimpleDirtyData)
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun unknownChanges(timestamp: Long)
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun getChanges(artifact: File, sinceTS: Long): Iterable<SimpleDirtyData>?
|
||||
}
|
||||
}
|
||||
|
||||
interface JpsCompilerServicesFacade : CompilerServicesFacadeBase, CompilerCallbackServicesFacade
|
||||
enum class ReportSeverity(val code: Int) {
|
||||
ERROR(0),
|
||||
WARNING(1),
|
||||
INFO(2),
|
||||
DEBUG(3);
|
||||
|
||||
companion object {
|
||||
fun fromCode(code: Int): ReportSeverity? =
|
||||
ReportSeverity.values().firstOrNull { it.code == code }
|
||||
}
|
||||
}
|
||||
|
||||
fun CompilerServicesFacadeBase.report(category: ReportCategory, severity: ReportSeverity, message: String? = null, attachment: Serializable? = null) {
|
||||
report(category.code, severity.code, message, attachment)
|
||||
}
|
||||
|
||||
data class CompilerMessageAttachment(
|
||||
val severity: CompilerMessageSeverity,
|
||||
val location: CompilerMessageLocation
|
||||
) : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
}
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import java.io.File
|
||||
import java.rmi.RemoteException
|
||||
|
||||
interface IncrementalCompilerServicesFacade : CompilerServicesFacadeBase {
|
||||
// AnnotationFileUpdater
|
||||
@Throws(RemoteException::class)
|
||||
fun hasAnnotationsFileUpdater(): Boolean
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun updateAnnotations(outdatedClassesJvmNames: Iterable<String>)
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun revert()
|
||||
|
||||
// ChangesRegistry
|
||||
@Throws(RemoteException::class)
|
||||
fun registerChanges(timestamp: Long, dirtyData: SimpleDirtyData)
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun unknownChanges(timestamp: Long)
|
||||
|
||||
@Throws(RemoteException::class)
|
||||
fun getChanges(artifact: File, sinceTS: Long): Iterable<SimpleDirtyData>?
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
interface JpsCompilerServicesFacade : CompilerServicesFacadeBase, CompilerCallbackServicesFacade
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.common
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
enum class ReportCategory : Serializable {
|
||||
/**
|
||||
* Messages from compiler
|
||||
* For related severities see [org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity]
|
||||
*/
|
||||
COMPILER_MESSAGE,
|
||||
/**
|
||||
* Messages from compile daemon
|
||||
* For related severities see [org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity]
|
||||
*/
|
||||
DAEMON_MESSAGE,
|
||||
/**
|
||||
* For related severities see [org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity]
|
||||
*/
|
||||
INCREMENTAL_COMPILATION;
|
||||
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 0
|
||||
}
|
||||
}
|
||||
@@ -41,15 +41,13 @@ import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
import org.jetbrains.kotlin.daemon.incremental.*
|
||||
import org.jetbrains.kotlin.daemon.report.CompileServiceReporter
|
||||
import org.jetbrains.kotlin.daemon.report.CompileServiceReporterImpl
|
||||
import org.jetbrains.kotlin.daemon.report.CompileServiceReporterStreamAdapter
|
||||
import org.jetbrains.kotlin.daemon.report.CompileServicesFacadeMessageCollector
|
||||
import org.jetbrains.kotlin.daemon.report.*
|
||||
import org.jetbrains.kotlin.incremental.*
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.check
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import java.rmi.NoSuchObjectException
|
||||
@@ -325,10 +323,11 @@ class CompileServiceImpl(
|
||||
sessionId: Int,
|
||||
compilerArguments: CommonCompilerArguments,
|
||||
compilationOptions: CompilationOptions,
|
||||
servicesFacade: CompilerServicesFacadeBase
|
||||
servicesFacade: CompilerServicesFacadeBase,
|
||||
compilationResultsStorage: CompilationResultsStorage?
|
||||
): CompileService.CallResult<Int> {
|
||||
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
|
||||
val serviceReporter = CompileServiceReporterImpl(servicesFacade, compilationOptions)
|
||||
val daemonReporter = DaemonMessageReporter(servicesFacade, compilationOptions)
|
||||
val compilerMode = compilationOptions.compilerMode
|
||||
val targetPlatform = compilationOptions.targetPlatform
|
||||
|
||||
@@ -336,13 +335,13 @@ class CompileServiceImpl(
|
||||
CompileService.CompilerMode.JPS_COMPILER -> {
|
||||
val jpsServicesFacade = servicesFacade as JpsCompilerServicesFacade
|
||||
|
||||
doCompile(sessionId, serviceReporter, tracer = null) { eventManger, profiler ->
|
||||
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
|
||||
val services = createCompileServices(jpsServicesFacade, eventManger, profiler)
|
||||
execCompiler(compilationOptions.targetPlatform, services, compilerArguments, messageCollector)
|
||||
}
|
||||
}
|
||||
CompileService.CompilerMode.NON_INCREMENTAL_COMPILER -> {
|
||||
doCompile(sessionId, serviceReporter, tracer = null) { eventManger, profiler ->
|
||||
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
|
||||
execCompiler(targetPlatform, Services.EMPTY, compilerArguments, messageCollector)
|
||||
}
|
||||
}
|
||||
@@ -356,8 +355,9 @@ class CompileServiceImpl(
|
||||
val gradleIncrementalServicesFacade = servicesFacade as IncrementalCompilerServicesFacade
|
||||
|
||||
withIC {
|
||||
doCompile(sessionId, serviceReporter, tracer = null) { eventManger, profiler ->
|
||||
execIncrementalCompiler(k2jvmArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, messageCollector)
|
||||
doCompile(sessionId, daemonReporter, tracer = null) { eventManger, profiler ->
|
||||
execIncrementalCompiler(k2jvmArgs, gradleIncrementalArgs, gradleIncrementalServicesFacade, compilationResultsStorage!!,
|
||||
messageCollector, daemonReporter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,23 +386,34 @@ class CompileServiceImpl(
|
||||
|
||||
private fun execIncrementalCompiler(
|
||||
k2jvmArgs: K2JVMCompilerArguments,
|
||||
incrementalCompilerArgs: IncrementalCompilationOptions,
|
||||
incrementalCompilationOptions: IncrementalCompilationOptions,
|
||||
servicesFacade: IncrementalCompilerServicesFacade,
|
||||
messageCollector: CompileServicesFacadeMessageCollector
|
||||
compilationResultsStorage: CompilationResultsStorage,
|
||||
compilerMessageCollector: MessageCollector,
|
||||
daemonMessageReporter: DaemonMessageReporter
|
||||
): ExitCode {
|
||||
val reporter = RemoteICReporter(servicesFacade, incrementalCompilerArgs)
|
||||
val reporter = RemoteICReporter(servicesFacade, compilationResultsStorage, incrementalCompilationOptions)
|
||||
val annotationFileUpdater = if (servicesFacade.hasAnnotationsFileUpdater()) RemoteAnnotationsFileUpdater(servicesFacade) else null
|
||||
|
||||
val moduleFile = k2jvmArgs.module?.let(::File)
|
||||
assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.module}" }
|
||||
|
||||
val temporaryMessageCollectorForModuleParsing = FilteringMessageCollector(messageCollector) { it != CompilerMessageSeverity.ERROR }
|
||||
val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.module, temporaryMessageCollectorForModuleParsing)
|
||||
// todo: pass javaSourceRoots and allKotlinFiles using IncrementalCompilationOptions
|
||||
val parsedModule = run {
|
||||
val bytesOut = ByteArrayOutputStream()
|
||||
val printStream = PrintStream(bytesOut)
|
||||
val mc = PrintingMessageCollector(printStream, MessageRenderer.PLAIN_FULL_PATHS, false)
|
||||
val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.module, mc)
|
||||
if (mc.hasErrors()) {
|
||||
daemonMessageReporter.report(ReportSeverity.ERROR, bytesOut.toString("UTF8"))
|
||||
}
|
||||
parsedModule
|
||||
}
|
||||
val javaSourceRoots = parsedModule.modules.flatMapTo(HashSet()) { it.getJavaSourceRoots().map { File(it.path) } }
|
||||
val allKotlinFiles = parsedModule.modules.flatMap { it.getSourceFiles().map(::File) }
|
||||
|
||||
val changedFiles = if (incrementalCompilerArgs.areFileChangesKnown) {
|
||||
ChangedFiles.Known(incrementalCompilerArgs.modifiedFiles!!, incrementalCompilerArgs.deletedFiles!!)
|
||||
val changedFiles = if (incrementalCompilationOptions.areFileChangesKnown) {
|
||||
ChangedFiles.Known(incrementalCompilationOptions.modifiedFiles!!, incrementalCompilationOptions.deletedFiles!!)
|
||||
}
|
||||
else {
|
||||
ChangedFiles.Unknown()
|
||||
@@ -411,13 +422,13 @@ class CompileServiceImpl(
|
||||
val artifactChanges = RemoteArtifactChangesProvider(servicesFacade)
|
||||
val changesRegistry = RemoteChangesRegostry(servicesFacade)
|
||||
|
||||
val workingDir = incrementalCompilerArgs.workingDir
|
||||
val workingDir = incrementalCompilationOptions.workingDir
|
||||
val versions = commonCacheVersions(workingDir) +
|
||||
customCacheVersion(incrementalCompilerArgs.customCacheVersion, incrementalCompilerArgs.customCacheVersionFileName, workingDir, forceEnable = true)
|
||||
customCacheVersion(incrementalCompilationOptions.customCacheVersion, incrementalCompilationOptions.customCacheVersionFileName, workingDir, forceEnable = true)
|
||||
|
||||
return IncrementalJvmCompilerRunner(workingDir, javaSourceRoots, versions, reporter, annotationFileUpdater,
|
||||
artifactChanges, changesRegistry)
|
||||
.compile(allKotlinFiles, k2jvmArgs, messageCollector, { changedFiles })
|
||||
.compile(allKotlinFiles, k2jvmArgs, compilerMessageCollector, { changedFiles })
|
||||
}
|
||||
|
||||
override fun leaseReplSession(
|
||||
@@ -657,7 +668,7 @@ class CompileServiceImpl(
|
||||
val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesStreamProxy, rpcProfiler), REMOTE_STREAM_BUFFER_SIZE))
|
||||
val serviceOutputStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(serviceOutputStreamProxy, rpcProfiler), REMOTE_STREAM_BUFFER_SIZE))
|
||||
try {
|
||||
val compileServiceReporter = CompileServiceReporterStreamAdapter(serviceOutputStream)
|
||||
val compileServiceReporter = DaemonMessageReporterPrintStreamAdapter(serviceOutputStream)
|
||||
if (args.none())
|
||||
throw IllegalArgumentException("Error: empty arguments list.")
|
||||
log.info("Starting compilation with args: " + args.joinToString(" "))
|
||||
@@ -676,7 +687,7 @@ class CompileServiceImpl(
|
||||
}
|
||||
|
||||
private fun doCompile(sessionId: Int,
|
||||
compileServiceReporter: CompileServiceReporter,
|
||||
daemonMessageReporter: DaemonMessageReporter,
|
||||
tracer: RemoteOperationsTracer?,
|
||||
body: (EventManger, Profiler) -> ExitCode): CompileService.CallResult<Int> =
|
||||
ifAlive {
|
||||
@@ -685,7 +696,7 @@ class CompileServiceImpl(
|
||||
val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler()
|
||||
val eventManger = EventMangerImpl()
|
||||
try {
|
||||
val exitCode = checkedCompile(compileServiceReporter, rpcProfiler) {
|
||||
val exitCode = checkedCompile(daemonMessageReporter, rpcProfiler) {
|
||||
body(eventManger, rpcProfiler).code
|
||||
}
|
||||
CompileService.CallResult.Good(exitCode)
|
||||
@@ -709,7 +720,7 @@ class CompileServiceImpl(
|
||||
}
|
||||
|
||||
|
||||
private fun<R> checkedCompile(compileServiceReporter: CompileServiceReporter, rpcProfiler: Profiler, body: () -> R): R {
|
||||
private fun<R> checkedCompile(daemonMessageReporter: DaemonMessageReporter, rpcProfiler: Profiler, body: () -> R): R {
|
||||
try {
|
||||
val profiler = if (daemonOptions.reportPerf) WallAndThreadAndMemoryTotalProfiler(withGC = false) else DummyProfiler()
|
||||
|
||||
@@ -726,14 +737,14 @@ class CompileServiceImpl(
|
||||
val rpc = rpcProfiler.getTotalCounters()
|
||||
|
||||
"PERF: Compile on daemon: ${pc.time.ms()} ms; thread: user ${pc.threadUserTime.ms()} ms, sys ${(pc.threadTime - pc.threadUserTime).ms()} ms; rpc: ${rpc.count} calls, ${rpc.time.ms()} ms, thread ${rpc.threadTime.ms()} ms; memory: ${endMem.kb()} kb (${"%+d".format(pc.memory.kb())} kb)".let {
|
||||
compileServiceReporter.info(it)
|
||||
daemonMessageReporter.report(ReportSeverity.INFO, it)
|
||||
log.info(it)
|
||||
}
|
||||
|
||||
// this will only be reported if if appropriate (e.g. ByClass) profiler is used
|
||||
for ((obj, counters) in rpcProfiler.getCounters()) {
|
||||
"PERF: rpc by $obj: ${counters.count} calls, ${counters.time.ms()} ms, thread ${counters.threadTime.ms()} ms".let {
|
||||
compileServiceReporter.info(it)
|
||||
daemonMessageReporter.report(ReportSeverity.INFO, it)
|
||||
log.info(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.incremental
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.daemon.report.FilteringReporterBase
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationOptions
|
||||
import org.jetbrains.kotlin.daemon.common.IncrementalCompilationServicesFacade
|
||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
||||
import org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity.COMPILED_FILES
|
||||
import org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity.LOGGING
|
||||
import org.jetbrains.kotlin.incremental.ICReporter
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
|
||||
internal class RemoteICReporter(
|
||||
servicesFacade: CompilerServicesFacadeBase,
|
||||
additionalCompilerArgs: CompilationOptions
|
||||
) : FilteringReporterBase(servicesFacade, additionalCompilerArgs, ReportCategory.INCREMENTAL_COMPILATION), ICReporter {
|
||||
override fun report(message: () -> String) {
|
||||
if (shouldReport(LOGGING.value)) {
|
||||
report(LOGGING.value, message())
|
||||
}
|
||||
}
|
||||
|
||||
override fun reportCompileIteration(sourceFiles: Collection<File>, exitCode: ExitCode) {
|
||||
if (shouldReport(COMPILED_FILES.value)) {
|
||||
report(COMPILED_FILES.value, message = null, attachment = CompileIterationResult(sourceFiles, exitCode.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* See [RemoteICReporter]
|
||||
*/
|
||||
enum class IncrementalCompilationSeverity(val value: Int) {
|
||||
COMPILED_FILES(0),
|
||||
LOGGING(10)
|
||||
}
|
||||
|
||||
class CompileIterationResult(val sourceFiles: Iterable<File>, val exitCode: String) : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 0
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.report
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationOptions
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
||||
import org.jetbrains.kotlin.daemon.report.FilteringReporterBase
|
||||
import java.io.PrintStream
|
||||
|
||||
// For messages of about compile daemon
|
||||
internal interface CompileServiceReporter {
|
||||
fun info(message: String) {
|
||||
report(CompilerMessageSeverity.INFO, message)
|
||||
}
|
||||
|
||||
fun report(severity: CompilerMessageSeverity, message: String)
|
||||
}
|
||||
|
||||
internal class CompileServiceReporterStreamAdapter(private val out: PrintStream) : CompileServiceReporter {
|
||||
override fun report(severity: CompilerMessageSeverity, message: String) {
|
||||
out.print("[Kotlin daemon][$severity] $message")
|
||||
}
|
||||
}
|
||||
|
||||
internal class CompileServiceReporterImpl(
|
||||
servicesFacade: CompilerServicesFacadeBase,
|
||||
compilationOptions: CompilationOptions
|
||||
) : FilteringReporterBase(servicesFacade, compilationOptions, ReportCategory.DAEMON_MESSAGE), CompileServiceReporter {
|
||||
|
||||
override fun report(severity: CompilerMessageSeverity, message: String) {
|
||||
report(severity.value, message)
|
||||
}
|
||||
}
|
||||
+20
-7
@@ -19,27 +19,40 @@ package org.jetbrains.kotlin.daemon.report
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationOptions
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
|
||||
internal class CompileServicesFacadeMessageCollector(
|
||||
private val servicesFacade: CompilerServicesFacadeBase,
|
||||
compilationOptions: CompilationOptions
|
||||
) : MessageCollector {
|
||||
private val mySeverity = compilationOptions.reportSeverity
|
||||
private var hasErrors = false
|
||||
private val reportingFilter = compilationOptions.reportingFilters.firstOrNull { it.category == ReportCategory.DAEMON_MESSAGE }
|
||||
|
||||
override fun clear() {
|
||||
hasErrors = false
|
||||
}
|
||||
|
||||
override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageLocation) {
|
||||
if (reportingFilter != null && severity.value !in reportingFilter.severities) return
|
||||
val reportCategory = when (severity) {
|
||||
CompilerMessageSeverity.OUTPUT -> ReportCategory.OUTPUT_MESSAGE
|
||||
else -> ReportCategory.COMPILER_MESSAGE
|
||||
}
|
||||
|
||||
val reportSeverity = when (severity) {
|
||||
CompilerMessageSeverity.ERROR,
|
||||
CompilerMessageSeverity.EXCEPTION -> ReportSeverity.ERROR
|
||||
CompilerMessageSeverity.WARNING -> ReportSeverity.WARNING
|
||||
CompilerMessageSeverity.INFO -> ReportSeverity.INFO
|
||||
CompilerMessageSeverity.LOGGING -> ReportSeverity.DEBUG
|
||||
CompilerMessageSeverity.OUTPUT -> ReportSeverity.ERROR
|
||||
}
|
||||
|
||||
if (reportSeverity.code <= mySeverity) {
|
||||
servicesFacade.report(reportCategory, reportSeverity, message, CompilerMessageAttachment(severity, location))
|
||||
}
|
||||
|
||||
hasErrors = hasErrors || severity == CompilerMessageSeverity.ERROR
|
||||
servicesFacade.report(ReportCategory.DAEMON_MESSAGE, severity.value, message, location)
|
||||
}
|
||||
|
||||
override fun hasErrors(): Boolean = hasErrors
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.report
|
||||
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
import java.io.PrintStream
|
||||
|
||||
internal interface DaemonMessageReporter {
|
||||
fun report(severity: ReportSeverity, message: String)
|
||||
}
|
||||
|
||||
internal fun DaemonMessageReporter(
|
||||
servicesFacade: CompilerServicesFacadeBase,
|
||||
compilationOptions: CompilationOptions
|
||||
): DaemonMessageReporter =
|
||||
if (ReportCategory.DAEMON_MESSAGE.code in compilationOptions.reportCategories) {
|
||||
val mySeverity = ReportSeverity.fromCode(compilationOptions.reportSeverity)!!
|
||||
DaemonMessageReporterImpl(servicesFacade, mySeverity)
|
||||
}
|
||||
else {
|
||||
DummyDaemonMessageReporter
|
||||
}
|
||||
|
||||
internal class DaemonMessageReporterPrintStreamAdapter(private val out: PrintStream): DaemonMessageReporter {
|
||||
override fun report(severity: ReportSeverity, message: String) {
|
||||
out.print("[Kotlin compile daemon][$severity] $message")
|
||||
}
|
||||
}
|
||||
|
||||
private class DaemonMessageReporterImpl(
|
||||
private val servicesFacade: CompilerServicesFacadeBase,
|
||||
private val mySeverity: ReportSeverity
|
||||
): DaemonMessageReporter {
|
||||
override fun report(severity: ReportSeverity, message: String) {
|
||||
if (severity.code <= mySeverity.code) {
|
||||
servicesFacade.report(ReportCategory.DAEMON_MESSAGE.code, severity.code, message, attachment = null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private object DummyDaemonMessageReporter : DaemonMessageReporter {
|
||||
override fun report(severity: ReportSeverity, message: String) {
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.report
|
||||
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationOptions
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
||||
import java.io.Serializable
|
||||
|
||||
internal open class FilteringReporterBase(
|
||||
private val servicesFacade: CompilerServicesFacadeBase,
|
||||
additionalCompilerArgs: CompilationOptions,
|
||||
private val reportCategory: ReportCategory
|
||||
) {
|
||||
private val reportingFilter = additionalCompilerArgs.reportingFilters.firstOrNull { it.category == reportCategory }
|
||||
|
||||
protected fun report(severity: Int, message: String?, attachment: Serializable? = null) {
|
||||
if (shouldReport(severity)) {
|
||||
servicesFacade.report(reportCategory, severity, message, attachment)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun shouldReport(severity: Int): Boolean =
|
||||
reportingFilter == null || severity in reportingFilter.severities
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.daemon.report
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
import org.jetbrains.kotlin.incremental.ICReporter
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
|
||||
internal class RemoteICReporter(
|
||||
private val servicesFacade: CompilerServicesFacadeBase,
|
||||
private val compilationResultsStorage: CompilationResultsStorage,
|
||||
compilationOptions: CompilationOptions
|
||||
) : ICReporter {
|
||||
private val shouldReportMessages = ReportCategory.IC_MESSAGE.code in compilationOptions.reportCategories
|
||||
private val isVerbose = compilationOptions.reportSeverity == ReportSeverity.DEBUG.code
|
||||
private val shouldReportCompileIteration = CompilationResult.IC_COMPILE_ITERATION.code in compilationOptions.requestedCompilationResults
|
||||
|
||||
override fun report(message: () -> String) {
|
||||
if (shouldReportMessages && isVerbose) {
|
||||
servicesFacade.report(ReportCategory.IC_MESSAGE, ReportSeverity.DEBUG, message())
|
||||
}
|
||||
}
|
||||
|
||||
override fun reportCompileIteration(sourceFiles: Collection<File>, exitCode: ExitCode) {
|
||||
if (shouldReportCompileIteration) {
|
||||
compilationResultsStorage.store(CompilationResult.IC_COMPILE_ITERATION.code, CompileIterationResult(sourceFiles, exitCode.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CompileIterationResult(
|
||||
@Suppress("unused") // used in Gradle
|
||||
val sourceFiles: Iterable<File>,
|
||||
@Suppress("unused") // used in Gradle
|
||||
val exitCode: String
|
||||
) : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user