diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt index 5ce0040f02b..39b60311c88 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.daemon.client import org.jetbrains.kotlin.cli.common.CompilerSystemProperties import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.daemon.common.* import org.jetbrains.kotlin.incremental.components.LookupTracker @@ -144,48 +145,6 @@ object KotlinCompilerClient { compilerService.releaseCompileSession(sessionId) } - @Suppress("DEPRECATION") - @Deprecated("Use other compile method", ReplaceWith("compile")) - fun compile(compilerService: CompileService, - sessionId: Int, - targetPlatform: CompileService.TargetPlatform, - args: Array, - out: OutputStream, - port: Int = SOCKET_ANY_FREE_PORT, - operationsTracer: RemoteOperationsTracer? = null - ): Int { - val outStrm = RemoteOutputStreamServer(out, port = port) - return compilerService.remoteCompile(sessionId, targetPlatform, args, CompilerCallbackServicesFacadeServer(port = port), outStrm, CompileService.OutputFormat.PLAIN, outStrm, operationsTracer).get() - } - - - @Suppress("DEPRECATION") - @Deprecated("Use non-deprecated compile method", ReplaceWith("compile")) - fun incrementalCompile(compileService: CompileService, - sessionId: Int, - targetPlatform: CompileService.TargetPlatform, - args: Array, - callbackServices: CompilationServices, - compilerOut: OutputStream, - daemonOut: OutputStream, - port: Int = SOCKET_ANY_FREE_PORT, - profiler: Profiler = DummyProfiler(), - operationsTracer: RemoteOperationsTracer? = null - ): Int = profiler.withMeasure(this) { - compileService.remoteIncrementalCompile( - sessionId, - targetPlatform, - args, - CompilerCallbackServicesFacadeServer(incrementalCompilationComponents = callbackServices.incrementalCompilationComponents, - lookupTracker = callbackServices.lookupTracker, - compilationCanceledStatus = callbackServices.compilationCanceledStatus, - port = port), - RemoteOutputStreamServer(compilerOut, port), - CompileService.OutputFormat.XML, - RemoteOutputStreamServer(daemonOut, port), - operationsTracer).get() - } - fun compile(compilerService: CompileService, sessionId: Int, targetPlatform: CompileService.TargetPlatform, @@ -274,14 +233,42 @@ object KotlinCompilerClient { } else -> { println("Executing daemon compilation with args: " + filteredArgs.joinToString(" ")) - val outStrm = RemoteOutputStreamServer(System.out) - val servicesFacade = CompilerCallbackServicesFacadeServer() + val messageCollector = object : MessageCollector { + var hasErrors = false + override fun clear() {} + + override fun report(severity: CompilerMessageSeverity, message: String, location: CompilerMessageSourceLocation?) { + if (severity.isError) { + hasErrors = true + } + println("${severity.name}\t${location?.path ?: ""}:${location?.line ?: ""} \t$message") + } + + override fun hasErrors() = hasErrors + } + + val outputsCollector = { x: File, y: List -> println("$x $y") } + val servicesFacade = BasicCompilerServicesWithResultsFacadeServer(messageCollector, outputsCollector) try { val memBefore = daemon.getUsedMemory().get() / 1024 val startTime = System.nanoTime() - @Suppress("DEPRECATION") - val res = daemon.remoteCompile(CompileService.NO_SESSION, CompileService.TargetPlatform.JVM, filteredArgs.toList().toTypedArray(), servicesFacade, outStrm, CompileService.OutputFormat.PLAIN, outStrm, null) + val compilationOptions = CompilationOptions( + CompilerMode.NON_INCREMENTAL_COMPILER, + CompileService.TargetPlatform.JVM, + arrayOf(ReportCategory.COMPILER_MESSAGE.code, ReportCategory.DAEMON_MESSAGE.code, ReportCategory.EXCEPTION.code, ReportCategory.OUTPUT_MESSAGE.code), + ReportSeverity.INFO.code, + emptyArray() + ) + + + val res = daemon.compile( + CompileService.NO_SESSION, + filteredArgs.toList().toTypedArray(), + compilationOptions, + servicesFacade, + null + ) val endTime = System.nanoTime() println("Compilation ${if (res.isGood) "succeeded" else "failed"}, result code: ${res.get()}") @@ -292,7 +279,6 @@ object KotlinCompilerClient { finally { // forcing RMI to unregister all objects and stop UnicastRemoteObject.unexportObject(servicesFacade, true) - UnicastRemoteObject.unexportObject(outStrm, true) } } } 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 daf5a39062f..3d7cf601faf 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 @@ -115,36 +115,6 @@ interface CompileService : Remote { @Throws(RemoteException::class) fun scheduleShutdown(graceful: Boolean): CallResult - // TODO: consider adding async version of shutdown and release - - @Suppress("DEPRECATION") - @Deprecated("The usages should be replaced with `compile` method", ReplaceWith("compile")) - @Throws(RemoteException::class) - fun remoteCompile( - sessionId: Int, - targetPlatform: TargetPlatform, - args: Array, - servicesFacade: CompilerCallbackServicesFacade, - compilerOutputStream: RemoteOutputStream, - outputFormat: OutputFormat, - serviceOutputStream: RemoteOutputStream, - operationsTracer: RemoteOperationsTracer? - ): CallResult - - @Suppress("DEPRECATION") - @Deprecated("The usages should be replaced with `compile` method", ReplaceWith("compile")) - @Throws(RemoteException::class) - fun remoteIncrementalCompile( - sessionId: Int, - targetPlatform: TargetPlatform, - args: Array, - servicesFacade: CompilerCallbackServicesFacade, - compilerOutputStream: RemoteOutputStream, - compilerOutputFormat: OutputFormat, - serviceOutputStream: RemoteOutputStream, - operationsTracer: RemoteOperationsTracer? - ): CallResult - @Throws(RemoteException::class) fun compile( sessionId: Int, @@ -163,50 +133,9 @@ interface CompileService : Remote { @Throws(RemoteException::class) fun clearJarCache() - @Suppress("DEPRECATION") - @Deprecated("The usages should be replaced with other `leaseReplSession` method", ReplaceWith("leaseReplSession")) - @Throws(RemoteException::class) - fun leaseReplSession( - aliveFlagPath: String?, - targetPlatform: CompileService.TargetPlatform, - servicesFacade: CompilerCallbackServicesFacade, - templateClasspath: List, - templateClassName: String, - scriptArgs: Array?, - scriptArgsTypes: Array>?, - compilerMessagesOutputStream: RemoteOutputStream, - evalOutputStream: RemoteOutputStream?, - evalErrorStream: RemoteOutputStream?, - evalInputStream: RemoteInputStream?, - operationsTracer: RemoteOperationsTracer? - ): CallResult - @Throws(RemoteException::class) fun releaseReplSession(sessionId: Int): CallResult - @Deprecated("The usages should be replaced with `replCheck` method", ReplaceWith("replCheck")) - @Throws(RemoteException::class) - fun remoteReplLineCheck( - sessionId: Int, - codeLine: ReplCodeLine - ): CallResult - - @Deprecated("The usages should be replaced with `replCompile` method", ReplaceWith("replCompile")) - @Throws(RemoteException::class) - fun remoteReplLineCompile( - sessionId: Int, - codeLine: ReplCodeLine, - history: List? - ): CallResult - - @Deprecated("Evaluation on daemon is not supported") - @Throws(RemoteException::class) - fun remoteReplLineEval( - sessionId: Int, - codeLine: ReplCodeLine, - history: List? - ): CallResult - @Throws(RemoteException::class) fun leaseReplSession( aliveFlagPath: String?, diff --git a/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt b/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt index 22b41198b1e..a1e2f66e611 100644 --- a/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt +++ b/compiler/daemon/daemon-tests/test/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt @@ -723,51 +723,6 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { } } - fun testDaemonCallbackConnectionProblems() { - withFlagFile(getTestName(true), ".alive") { flagFile -> - val daemonOptions = makeTestDaemonOptions(getTestName(true)) - - withLogFile("kotlin-daemon-test") { logFile -> - val daemonJVMOptions = makeTestDaemonJvmOptions(logFile) - - val daemon = KotlinCompilerClient.connectToCompileService(compilerId, flagFile, daemonJVMOptions, daemonOptions, DaemonReportingTargets(out = System.err), autostart = true) - assertNotNull("failed to connect daemon", daemon) - daemon?.registerClient(flagFile.absolutePath) - - val file = File(testTempDir, "largeKotlinFile.kt") - file.writeText(generateLargeKotlinFile(10)) - val jar = File(testTempDir, "largeKotlinFile.jar").absolutePath - - var callbackServices: CompilerCallbackServicesFacadeServer? = null - callbackServices = CompilerCallbackServicesFacadeServer(compilationCanceledStatus = object : CompilationCanceledStatus { - override fun checkCanceled() { - thread { - Thread.sleep(10) - UnicastRemoteObject.unexportObject(callbackServices, true) - } - } - }, port = SOCKET_ANY_FREE_PORT) - val strm = ByteArrayOutputStream() - @Suppress("DEPRECATION") - val code = daemon!!.remoteCompile(CompileService.NO_SESSION, - CompileService.TargetPlatform.JVM, - arrayOf("-include-runtime", file.absolutePath, "-d", jar), - callbackServices, - RemoteOutputStreamServer(strm, SOCKET_ANY_FREE_PORT), - CompileService.OutputFormat.XML, - RemoteOutputStreamServer(strm, SOCKET_ANY_FREE_PORT), - null).get() - - TestCase.assertEquals(0, code) - - val compilerOutput = strm.toString() - assertTrue("Expecting cancellation message in:\n$compilerOutput", compilerOutput.contains("Compilation was canceled")) - logFile.assertLogContainsSequence("error communicating with host, assuming compilation canceled") - - } - } - } - fun testDaemonReplScriptingNotInClasspathError() { withDaemon(compilerId) { daemon -> var repl: KotlinRemoteReplCompilerClient? = null diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index 5211327d9cf..04020c46aca 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -736,58 +736,6 @@ class CompileServiceImpl( CompileService.CallResult.Good(res) } - @Suppress("OverridingDeprecatedMember", "DEPRECATION", "OVERRIDE_DEPRECATION") - override fun remoteCompile( - sessionId: Int, - targetPlatform: CompileService.TargetPlatform, - args: Array, - servicesFacade: CompilerCallbackServicesFacade, - compilerOutputStream: RemoteOutputStream, - outputFormat: CompileService.OutputFormat, - serviceOutputStream: RemoteOutputStream, - operationsTracer: RemoteOperationsTracer? - ): CompileService.CallResult = - doCompile(sessionId, args, compilerOutputStream, serviceOutputStream, operationsTracer) { printStream, eventManager, profiler -> - when (outputFormat) { - CompileService.OutputFormat.PLAIN -> compiler[targetPlatform].exec(printStream, *args) - CompileService.OutputFormat.XML -> compiler[targetPlatform].execAndOutputXml( - printStream, - createCompileServices( - servicesFacade, - eventManager, - profiler - ), - *args - ) - } - } - - @Suppress("OverridingDeprecatedMember", "DEPRECATION", "OVERRIDE_DEPRECATION") - override fun remoteIncrementalCompile( - sessionId: Int, - targetPlatform: CompileService.TargetPlatform, - args: Array, - servicesFacade: CompilerCallbackServicesFacade, - compilerOutputStream: RemoteOutputStream, - compilerOutputFormat: CompileService.OutputFormat, - serviceOutputStream: RemoteOutputStream, - operationsTracer: RemoteOperationsTracer? - ): CompileService.CallResult = - doCompile(sessionId, args, compilerOutputStream, serviceOutputStream, operationsTracer) { printStream, eventManager, profiler -> - when (compilerOutputFormat) { - CompileService.OutputFormat.PLAIN -> throw NotImplementedError("Only XML output is supported in remote incremental compilation") - CompileService.OutputFormat.XML -> compiler[targetPlatform].execAndOutputXml( - printStream, - createCompileServices( - servicesFacade, - eventManager, - profiler - ), - *args - ) - } - } - override fun classesFqNamesByFiles( sessionId: Int, sourceFiles: Set ): CompileService.CallResult> = @@ -819,54 +767,9 @@ class CompileServiceImpl( } - @Deprecated("The usages should be replaced with other `leaseReplSession` method", ReplaceWith("leaseReplSession")) - override fun leaseReplSession( - aliveFlagPath: String?, - targetPlatform: CompileService.TargetPlatform, - @Suppress("DEPRECATION") servicesFacade: CompilerCallbackServicesFacade, - templateClasspath: List, - templateClassName: String, - scriptArgs: Array?, - scriptArgsTypes: Array>?, - compilerMessagesOutputStream: RemoteOutputStream, - evalOutputStream: RemoteOutputStream?, - evalErrorStream: RemoteOutputStream?, - evalInputStream: RemoteInputStream?, - operationsTracer: RemoteOperationsTracer? - ): CompileService.CallResult = ifAlive(minAliveness = Aliveness.Alive) { - if (targetPlatform != CompileService.TargetPlatform.JVM) - CompileService.CallResult.Error("Sorry, only JVM target platform is supported now") - else { - val disposable = Disposer.newDisposable() - val compilerMessagesStream = PrintStream( - BufferedOutputStream( - RemoteOutputStreamClient(compilerMessagesOutputStream, DummyProfiler()), - REMOTE_STREAM_BUFFER_SIZE - ) - ) - val messageCollector = KeepFirstErrorMessageCollector(compilerMessagesStream) - val repl = KotlinJvmReplService( - disposable, port, compilerId, templateClasspath, templateClassName, - messageCollector, operationsTracer - ) - val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable)) - - CompileService.CallResult.Good(sessionId) - } - } - // TODO: add more checks (e.g. is it a repl session) override fun releaseReplSession(sessionId: Int): CompileService.CallResult = releaseCompileSession(sessionId) - @Suppress("OverridingDeprecatedMember", "OVERRIDE_DEPRECATION") - override fun remoteReplLineCheck(sessionId: Int, codeLine: ReplCodeLine): CompileService.CallResult = - ifAlive(minAliveness = Aliveness.Alive) { - withValidRepl(sessionId) { - @Suppress("DEPRECATION") - CompileService.CallResult.Good(check(codeLine)) - } - } - private fun createCompileServices( @Suppress("DEPRECATION") facade: CompilerCallbackServicesFacade, eventManager: EventManager, @@ -904,29 +807,6 @@ class CompileServiceImpl( return builder.build() } - @Suppress("OverridingDeprecatedMember", "OVERRIDE_DEPRECATION") - override fun remoteReplLineCompile( - sessionId: Int, - codeLine: ReplCodeLine, - history: List? - ): CompileService.CallResult = - ifAlive(minAliveness = Aliveness.Alive) { - withValidRepl(sessionId) { - @Suppress("DEPRECATION") - CompileService.CallResult.Good(compile(codeLine, history)) - } - } - - @Suppress("OverridingDeprecatedMember", "OVERRIDE_DEPRECATION") - override fun remoteReplLineEval( - sessionId: Int, - codeLine: ReplCodeLine, - history: List? - ): CompileService.CallResult = - ifAlive(minAliveness = Aliveness.Alive) { - CompileService.CallResult.Error("Eval on daemon is not supported") - } - override fun leaseReplSession( aliveFlagPath: String?, compilerArguments: Array, @@ -1171,50 +1051,6 @@ class CompileServiceImpl( return true } - // todo: remove after remoteIncrementalCompile is removed - private fun doCompile( - sessionId: Int, - args: Array, - compilerMessagesStreamProxy: RemoteOutputStream, - serviceOutputStreamProxy: RemoteOutputStream, - operationsTracer: RemoteOperationsTracer?, - body: (PrintStream, EventManager, Profiler) -> ExitCode - ): CompileService.CallResult = - ifAlive { - withValidClientOrSessionProxy(sessionId) { - operationsTracer?.before("compile") - val rpcProfiler = if (daemonOptions.reportPerf) WallAndThreadTotalProfiler() else DummyProfiler() - val eventManger = EventManagerImpl() - 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 = DaemonMessageReporterPrintStreamAdapter(serviceOutputStream) - if (args.none()) - throw IllegalArgumentException("Error: empty arguments list.") - log.info("Starting compilation with args: " + args.joinToString(" ")) - val exitCode = checkedCompile(compileServiceReporter, rpcProfiler) { - body(compilerMessagesStream, eventManger, rpcProfiler).code - } - CompileService.CallResult.Good(exitCode) - } finally { - serviceOutputStream.flush() - compilerMessagesStream.flush() - eventManger.fireCompilationFinished() - operationsTracer?.after("compile") - } - } - } - init { // assuming logicaly synchronized try {