diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity.java index 558c398f873..cf3b27b8ded 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/messages/CompilerMessageSeverity.java @@ -19,30 +19,12 @@ package org.jetbrains.kotlin.cli.common.messages; import java.util.EnumSet; public enum CompilerMessageSeverity { - ERROR(0), - EXCEPTION(5), - WARNING(10), - INFO(15), - OUTPUT(20), - LOGGING(25); - - private final int value; - - CompilerMessageSeverity(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - static CompilerMessageSeverity fromValue(int value) { - for (CompilerMessageSeverity severity : CompilerMessageSeverity.values()) { - if (severity.value == value) return severity; - } - - return null; - } + ERROR, + EXCEPTION, + WARNING, + INFO, + OUTPUT, + LOGGING; public static final EnumSet ERRORS = EnumSet.of(ERROR, EXCEPTION); public static final EnumSet VERBOSE = EnumSet.of(OUTPUT, LOGGING); diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationOptions.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationOptions.kt index d2bf095373d..ac7da3bc83a 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationOptions.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationOptions.kt @@ -22,7 +22,9 @@ import java.io.Serializable open class CompilationOptions( val compilerMode: CompileService.CompilerMode, val targetPlatform: CompileService.TargetPlatform, - val reportingFilters: List + val reportCategories: Array, + val reportSeverity: Int, + val requestedCompilationResults: Array ) : 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 -) : CompilationOptions(compilerMode, targetPlatform, reportingFilters) { + reportedCategories: Array, + reportedSeverity: Int, + requestedCompilationResults: Array +) : CompilationOptions(compilerMode, targetPlatform, reportedCategories, reportedSeverity, requestedCompilationResults) { companion object { const val serialVersionUID: Long = 0 } diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReportingFilter.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationResultsStorage.kt similarity index 64% rename from compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReportingFilter.kt rename to compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationResultsStorage.kt index 16789ef97e0..405e97d43ef 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReportingFilter.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationResultsStorage.kt @@ -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) : 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) } \ No newline at end of file diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompileService.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompileService.kt index b4c862fe281..43995702e9a 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompileService.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompileService.kt @@ -138,7 +138,8 @@ interface CompileService : Remote { sessionId: Int, compilerArguments: CommonCompilerArguments, compilationOptions: CompilationOptions, - servicesFacade: CompilerServicesFacadeBase + servicesFacade: CompilerServicesFacadeBase, + compilationResultsStorage: CompilationResultsStorage? ): CallResult @Throws(RemoteException::class) diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt index 4206a80f1d3..701ef68cbed 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilerServicesFacadeBase.kt @@ -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) + 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? + } } -interface JpsCompilerServicesFacade : CompilerServicesFacadeBase, CompilerCallbackServicesFacade \ No newline at end of file +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 + } +} diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/IncrementalCompilerServicesFacade.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/IncrementalCompilerServicesFacade.kt new file mode 100644 index 00000000000..02e8026fab0 --- /dev/null +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/IncrementalCompilerServicesFacade.kt @@ -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) + + @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? +} \ No newline at end of file diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/JpsCompilerServicesFacade.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/JpsCompilerServicesFacade.kt new file mode 100644 index 00000000000..b47e58c8a7c --- /dev/null +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/JpsCompilerServicesFacade.kt @@ -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 \ No newline at end of file diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReportCategory.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReportCategory.kt deleted file mode 100644 index 58d840580d5..00000000000 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/ReportCategory.kt +++ /dev/null @@ -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 - } -} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index 334b3892cbf..bb4edcb5710 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -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 { 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 = 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 checkedCompile(compileServiceReporter: CompileServiceReporter, rpcProfiler: Profiler, body: () -> R): R { + private fun 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) } } diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/incremental/RemoteICReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/incremental/RemoteICReporter.kt deleted file mode 100644 index 9e03d1cdf46..00000000000 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/incremental/RemoteICReporter.kt +++ /dev/null @@ -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, 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, val exitCode: String) : Serializable { - companion object { - const val serialVersionUID: Long = 0 - } -} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServiceReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServiceReporter.kt deleted file mode 100644 index 4f7f4c40acb..00000000000 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServiceReporter.kt +++ /dev/null @@ -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) - } -} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt index 39bd6e2f73f..986908cef5a 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/CompileServicesFacadeMessageCollector.kt @@ -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 -} \ No newline at end of file +} diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/DaemonMessageReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/DaemonMessageReporter.kt new file mode 100644 index 00000000000..4cb49f3a7c3 --- /dev/null +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/DaemonMessageReporter.kt @@ -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) { + } +} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/FilteringReporterBase.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/FilteringReporterBase.kt deleted file mode 100644 index a30d9f1ede0..00000000000 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/FilteringReporterBase.kt +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt new file mode 100644 index 00000000000..d0eb108b153 --- /dev/null +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/report/RemoteICReporter.kt @@ -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, 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, + @Suppress("unused") // used in Gradle + val exitCode: String +) : Serializable { + companion object { + const val serialVersionUID: Long = 0 + } +} \ No newline at end of file diff --git a/jps-plugin/jps-plugin.iml b/jps-plugin/jps-plugin.iml index 21a11f39ee9..59e6dad560b 100644 --- a/jps-plugin/jps-plugin.iml +++ b/jps-plugin/jps-plugin.iml @@ -20,5 +20,6 @@ + \ No newline at end of file diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerServicesFacadeImpl.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerServicesFacadeImpl.kt index 71b8337a3fc..b4df5aa4089 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerServicesFacadeImpl.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerServicesFacadeImpl.kt @@ -19,9 +19,7 @@ package org.jetbrains.kotlin.compilerRunner import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.daemon.client.CompilerCallbackServicesFacadeServer -import org.jetbrains.kotlin.daemon.common.JpsCompilerServicesFacade -import org.jetbrains.kotlin.daemon.common.ReportCategory -import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT +import org.jetbrains.kotlin.daemon.common.* import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.progress.CompilationCanceledStatus import java.io.Serializable @@ -34,20 +32,26 @@ internal class JpsCompilerServicesFacadeImpl( port), JpsCompilerServicesFacade { - override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) { - when (category) { + override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) { + val reportCategory = ReportCategory.fromCode(category) + + when (reportCategory) { + ReportCategory.OUTPUT_MESSAGE -> { + env.messageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION) + } ReportCategory.COMPILER_MESSAGE -> { - val compilerMessageSeverity = CompilerMessageSeverity.values().firstOrNull { it.value == severity } - if (compilerMessageSeverity != null) { - val location = attachment as? CompilerMessageLocation ?: CompilerMessageLocation.NO_LOCATION - env.messageCollector.report(compilerMessageSeverity, message!!, location) + val compilerMessageAttachment = attachment as? CompilerMessageAttachment + if (message != null && compilerMessageAttachment != null) { + val originalSeverity = compilerMessageAttachment.severity + val originalLocation = compilerMessageAttachment.location + env.messageCollector.report(originalSeverity, message, originalLocation) } else { reportUnexpected(category, severity, message, attachment) } } ReportCategory.DAEMON_MESSAGE, - ReportCategory.INCREMENTAL_COMPILATION -> { + ReportCategory.IC_MESSAGE -> { if (message != null) { env.messageCollector.report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION) } @@ -61,8 +65,15 @@ internal class JpsCompilerServicesFacadeImpl( } } - private fun reportUnexpected(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) { - env.messageCollector.report(CompilerMessageSeverity.LOGGING, + private fun reportUnexpected(category: Int, severity: Int, message: String?, attachment: Serializable?) { + val compilerMessageSeverity = when (ReportSeverity.fromCode(severity)) { + ReportSeverity.ERROR -> CompilerMessageSeverity.ERROR + ReportSeverity.WARNING -> CompilerMessageSeverity.WARNING + ReportSeverity.INFO -> CompilerMessageSeverity.INFO + else -> CompilerMessageSeverity.LOGGING + } + + env.messageCollector.report(compilerMessageSeverity, "Unexpected message: category=$category; severity=$severity; message='$message'; attachment=$attachment", CompilerMessageLocation.NO_LOCATION) } diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index 2a99aad5190..75c670d28e4 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -28,6 +28,8 @@ import org.jetbrains.kotlin.jps.build.KotlinBuilder import java.io.ByteArrayOutputStream import java.io.File import java.io.PrintStream +import java.io.Serializable +import java.rmi.server.UnicastRemoteObject import java.util.* class JpsKotlinCompilerRunner : KotlinCompilerRunner() { @@ -99,39 +101,30 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { } val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId -> - val options = CompilationOptions(CompileService.CompilerMode.JPS_COMPILER, - targetPlatform, - reportingFilters = getReportingFilters(compilerArgs.verbose)) - daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment)) + val compilerMode = CompileService.CompilerMode.JPS_COMPILER + val verbose = compilerArgs.verbose + val options = CompilationOptions(compilerMode, targetPlatform, reportCategories(verbose), reportSeverity(verbose), requestedCompilationResults = emptyArray()) + daemon.compile(sessionId, compilerArgs, options, JpsCompilerServicesFacadeImpl(environment), null) } return res?.get()?.let { exitCodeFromProcessExitCode(it) } } - private fun getReportingFilters(verbose: Boolean): List { - val result = ArrayList() - - val compilerMessagesSeverities = ArrayList().apply { - add(CompilerMessageSeverity.ERROR.value) - add(CompilerMessageSeverity.EXCEPTION.value) - add(CompilerMessageSeverity.WARNING.value) - add(CompilerMessageSeverity.INFO.value) - add(CompilerMessageSeverity.OUTPUT.value) - - if (verbose) { - add(CompilerMessageSeverity.LOGGING.value) + private fun reportCategories(verbose: Boolean): Array = + if (!verbose) { + arrayOf(ReportCategory.COMPILER_MESSAGE.code) + } + else { + ReportCategory.values().map { it.code }.toTypedArray() } - } - if (verbose) { - result.add(ReportingFilter(ReportCategory.DAEMON_MESSAGE, emptyList())) - } - - val compilerMessagesFilter = ReportingFilter(ReportCategory.COMPILER_MESSAGE, compilerMessagesSeverities) - result.add(compilerMessagesFilter) - - return result - } + private fun reportSeverity(verbose: Boolean): Int = + if (!verbose) { + ReportSeverity.INFO.code + } + else { + ReportSeverity.DEBUG.code + } private fun fallbackCompileStrategy( argsArray: Array, diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilationResultsStorage.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilationResultsStorage.kt new file mode 100644 index 00000000000..5dada1c4b96 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleCompilationResultsStorage.kt @@ -0,0 +1,33 @@ +package org.jetbrains.kotlin.compilerRunner + +import org.gradle.api.Project +import org.jetbrains.kotlin.daemon.common.CompilationResult +import org.jetbrains.kotlin.daemon.common.CompilationResultsStorage +import org.jetbrains.kotlin.daemon.common.SOCKET_ANY_FREE_PORT +import org.jetbrains.kotlin.daemon.report.CompileIterationResult +import org.jetbrains.kotlin.gradle.plugin.kotlinDebug +import org.jetbrains.kotlin.incremental.pathsAsStringRelativeTo +import java.io.Serializable +import java.rmi.RemoteException +import java.rmi.server.UnicastRemoteObject + +internal class GradleCompilationResultsStorage(project: Project): CompilationResultsStorage, UnicastRemoteObject(SOCKET_ANY_FREE_PORT) { + private val log = project.logger + private val projectRootFile = project.rootProject.projectDir + + @Throws(RemoteException::class) + override fun store(compilationResult: Int, value: Serializable) { + if (compilationResult == CompilationResult.IC_COMPILE_ITERATION.code) { + @Suppress("UNCHECKED_CAST") + val compileIterationResult = value as? CompileIterationResult + if (compileIterationResult != null) { + val sourceFiles = compileIterationResult.sourceFiles + if (sourceFiles.any()) { + log.kotlinDebug { "compile iteration: ${sourceFiles.pathsAsStringRelativeTo(projectRootFile)}" } + } + val exitCode = compileIterationResult.exitCode + log.kotlinDebug { "compiler exit code: $exitCode" } + } + } + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt index d8fde7230a8..03e36300205 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleIncrementalCompilerServicesFacadeImpl.kt @@ -6,15 +6,12 @@ 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.* -import org.jetbrains.kotlin.daemon.incremental.CompileIterationResult -import org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity import org.jetbrains.kotlin.daemon.incremental.toDirtyData import org.jetbrains.kotlin.daemon.incremental.toSimpleDirtyData import org.jetbrains.kotlin.gradle.plugin.kotlinDebug import org.jetbrains.kotlin.gradle.plugin.kotlinWarn import org.jetbrains.kotlin.incremental.DirtyData import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifference -import org.jetbrains.kotlin.incremental.pathsAsStringRelativeTo import org.jetbrains.kotlin.resolve.jvm.JvmClassName import java.io.File import java.io.Serializable @@ -28,28 +25,34 @@ internal open class GradleCompilerServicesFacadeImpl( ) : UnicastRemoteObject(port), CompilerServicesFacadeBase, Remote { protected val log: Logger = project.logger - override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) { - when (category) { - ReportCategory.COMPILER_MESSAGE -> { - val compilerSeverity = CompilerMessageSeverity.values().firstOrNull { it.value == severity } + override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) { + val reportCategory = ReportCategory.fromCode(category) - if (compilerSeverity != null && message != null && attachment is CompilerMessageLocation) { - compilerMessageCollector.report(compilerSeverity, message, attachment) + when (reportCategory) { + ReportCategory.COMPILER_MESSAGE -> { + if (message != null && attachment is CompilerMessageAttachment) { + compilerMessageCollector.report(attachment.severity, message, attachment.location) } else { reportUnexpectedMessage(category, severity, message, attachment) } } + ReportCategory.IC_MESSAGE -> { + log.kotlinDebug { "[IC] $message" } + } ReportCategory.DAEMON_MESSAGE -> { log.kotlinDebug { "[DAEMON] $message" } } + ReportCategory.OUTPUT_MESSAGE -> { + compilerMessageCollector.report(CompilerMessageSeverity.OUTPUT, message!!, CompilerMessageLocation.NO_LOCATION) + } else -> { reportUnexpectedMessage(category, severity, message, attachment) } } } - protected fun reportUnexpectedMessage(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) { + protected fun reportUnexpectedMessage(category: Int, severity: Int, message: String?, attachment: Serializable?) { // todo add assert to tests log.kotlinWarn("Received unexpected message from compiler daemon: category=$category, severity=$severity, message='$message', attachment=$attachment") } @@ -62,42 +65,6 @@ internal class GradleIncrementalCompilerServicesFacadeImpl( ) : GradleCompilerServicesFacadeImpl(project, environment.messageCollector, port), IncrementalCompilerServicesFacade { - private val projectRootFile = project.rootProject.projectDir - - override fun report(category: ReportCategory, severity: Int, message: String?, attachment: Serializable?) { - when (category) { - ReportCategory.INCREMENTAL_COMPILATION -> { - val icSeverity = IncrementalCompilationSeverity.values().firstOrNull { it.value == severity } - when (icSeverity) { - IncrementalCompilationSeverity.COMPILED_FILES -> { - @Suppress("UNCHECKED_CAST") - val compileIterationResult = attachment as? CompileIterationResult - if (compileIterationResult == null) { - reportUnexpectedMessage(category, severity, message, attachment) - } - else { - val sourceFiles = compileIterationResult.sourceFiles - if (sourceFiles.any()) { - log.kotlinDebug { "compile iteration: ${sourceFiles.pathsAsStringRelativeTo(projectRootFile)}" } - } - val exitCode = compileIterationResult.exitCode - log.kotlinDebug { "compiler exit code: $exitCode" } - } - } - IncrementalCompilationSeverity.LOGGING -> { - log.kotlinDebug { "[IC] $message" } - } - else -> { - reportUnexpectedMessage(category, severity, message, attachment) - } - } - } - else -> { - super.report(category, severity, message, attachment) - } - } - } - override fun hasAnnotationsFileUpdater(): Boolean = environment.kaptAnnotationsFileUpdater != null diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt index 9198eabeb31..c51acafe9ba 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt @@ -24,16 +24,15 @@ import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.config.Services -import org.jetbrains.kotlin.daemon.client.RemoteOutputStreamServer import org.jetbrains.kotlin.daemon.common.* -import org.jetbrains.kotlin.daemon.incremental.IncrementalCompilationSeverity +import org.jetbrains.kotlin.daemon.common.CompilationResult import org.jetbrains.kotlin.gradle.plugin.ParentLastURLClassLoader import org.jetbrains.kotlin.gradle.plugin.kotlinDebug import org.jetbrains.kotlin.incremental.* -import java.io.* +import java.io.ByteArrayOutputStream +import java.io.File +import java.io.PrintStream import kotlin.concurrent.thread internal const val KOTLIN_COMPILER_EXECUTION_STRATEGY_PROPERTY = "kotlin.compiler.execution.strategy" @@ -162,14 +161,18 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil K2METADATA_COMPILER -> CompileService.TargetPlatform.METADATA else -> throw IllegalArgumentException("Unknown compiler type $compilerClassName") } + + val verbose = environment.compilerArgs.verbose val compilationOptions = CompilationOptions( - reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose), compilerMode = CompileService.CompilerMode.NON_INCREMENTAL_COMPILER, - targetPlatform = targetPlatform) + targetPlatform = targetPlatform, + reportCategories = reportCategories(verbose), + reportSeverity = reportSeverity(verbose), + requestedCompilationResults = emptyArray()) val servicesFacade = GradleCompilerServicesFacadeImpl(project, environment.messageCollector) val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId -> - daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade) + daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade, compilationResultsStorage = null) } val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) } @@ -183,6 +186,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil private fun incrementalCompilationWithDaemon(environment: GradleIncrementalCompilerEnvironment): ExitCode? { val knownChangedFiles = environment.changedFiles as? ChangedFiles.Known + val verbose = environment.compilerArgs.verbose val compilationOptions = IncrementalCompilationOptions( areFileChangesKnown = knownChangedFiles != null, modifiedFiles = knownChangedFiles?.modified, @@ -190,15 +194,16 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil workingDir = environment.workingDir, customCacheVersion = GRADLE_CACHE_VERSION, customCacheVersionFileName = GRADLE_CACHE_VERSION_FILE_NAME, - reportingFilters = getNonIncrementalReportingFilters(environment.compilerArgs.verbose) + - getIncrementalReportingFilters(environment.compilerArgs.verbose), + reportedCategories = reportCategories(verbose), + reportedSeverity = reportSeverity(verbose), + requestedCompilationResults = arrayOf(CompilationResult.IC_COMPILE_ITERATION.code), compilerMode = CompileService.CompilerMode.INCREMENTAL_COMPILER, targetPlatform = CompileService.TargetPlatform.JVM ) val servicesFacade = GradleIncrementalCompilerServicesFacadeImpl(project, environment) val res = withDaemon(environment, retryOnConnectionError = true) { daemon, sessionId -> - daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade) + daemon.compile(sessionId, environment.compilerArgs, compilationOptions, servicesFacade, GradleCompilationResultsStorage(project)) } val exitCode = res?.get()?.let { exitCodeFromProcessExitCode(it) } @@ -209,36 +214,21 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil return exitCode } - private fun getNonIncrementalReportingFilters(verbose: Boolean): List { - val result = ArrayList() - - val compilerMessagesSeverities = ArrayList().apply { - add(CompilerMessageSeverity.ERROR.value) - add(CompilerMessageSeverity.EXCEPTION.value) - add(CompilerMessageSeverity.WARNING.value) - add(CompilerMessageSeverity.INFO.value) - - if (verbose) { - add(CompilerMessageSeverity.OUTPUT.value) - add(CompilerMessageSeverity.LOGGING.value) + private fun reportCategories(verbose: Boolean): Array = + if (!verbose) { + arrayOf(ReportCategory.COMPILER_MESSAGE.code) } - } - - if (verbose) { - result.add(ReportingFilter(ReportCategory.DAEMON_MESSAGE, emptyList())) - } - - val compilerMessagesFilter = ReportingFilter(ReportCategory.COMPILER_MESSAGE, compilerMessagesSeverities) - result.add(compilerMessagesFilter) - - return result - } - - private fun getIncrementalReportingFilters(verbose: Boolean) = - if (verbose) { - listOf(ReportingFilter(ReportCategory.INCREMENTAL_COMPILATION, listOf(IncrementalCompilationSeverity.COMPILED_FILES.value, IncrementalCompilationSeverity.LOGGING.value))) + else { + ReportCategory.values().map { it.code }.toTypedArray() + } + + private fun reportSeverity(verbose: Boolean): Int = + if (!verbose) { + ReportSeverity.INFO.code + } + else { + ReportSeverity.DEBUG.code } - else emptyList() private fun compileOutOfProcess( argsArray: Array,