All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.daemon.common.CompileService.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright 2010-2015 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 org.jetbrains.kotlin.cli.common.repl.*
import java.io.File
import java.io.Serializable
import java.rmi.Remote
import java.rmi.RemoteException

interface CompileService : Remote {

    enum class OutputFormat : Serializable {
        PLAIN,
        XML
    }

    enum class TargetPlatform : Serializable {
        JVM,
        JS,
        METADATA
    }

    companion object {
        val NO_SESSION: Int = 0
    }

    sealed class CallResult : Serializable {

        class Good(val result: R) : CallResult() {
            override fun get(): R = result
            override fun equals(other: Any?): Boolean = other is Good<*> && this.result == other.result
            override fun hashCode(): Int = this::class.java.hashCode() + (result?.hashCode() ?: 1)
        }
        class Ok : CallResult() {
            override fun get(): Nothing = throw IllegalStateException("Get is inapplicable to Ok call result")
            override fun equals(other: Any?): Boolean = other is Ok
            override fun hashCode(): Int = this::class.java.hashCode() + 1 // avoiding clash with the hash of class itself
        }
        class Dying : CallResult() {
            override fun get(): Nothing = throw IllegalStateException("Service is dying")
            override fun equals(other: Any?): Boolean = other is Dying
            override fun hashCode(): Int = this::class.java.hashCode() + 1 // see comment to Ok.hashCode
        }
        class Error(val message: String) : CallResult() {
            override fun get(): Nothing = throw Exception(message)
            override fun equals(other: Any?): Boolean = other is Error && this.message == other.message
            override fun hashCode(): Int = this::class.java.hashCode() + message.hashCode()
        }

        val isGood: Boolean get() = this is Good<*>

        abstract fun get(): R
    }

    // TODO: remove!
    @Throws(RemoteException::class)
    fun checkCompilerId(expectedCompilerId: CompilerId): Boolean

    @Throws(RemoteException::class)
    fun getUsedMemory(): CallResult

    @Throws(RemoteException::class)
    fun getDaemonOptions(): CallResult

    @Throws(RemoteException::class)
    fun getDaemonInfo(): CallResult

    @Throws(RemoteException::class)
    fun getDaemonJVMOptions(): CallResult

    @Throws(RemoteException::class)
    fun registerClient(aliveFlagPath: String?): CallResult

    // TODO: consider adding another client alive checking mechanism, e.g. socket/port

    @Throws(RemoteException::class)
    fun getClients(): CallResult>

    @Throws(RemoteException::class)
    fun leaseCompileSession(aliveFlagPath: String?): CallResult

    @Throws(RemoteException::class)
    fun releaseCompileSession(sessionId: Int): CallResult

    @Throws(RemoteException::class)
    fun shutdown(): CallResult

    @Throws(RemoteException::class)
    fun scheduleShutdown(graceful: Boolean): CallResult

    // TODO: consider adding async version of shutdown and release

    @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

    @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,
            compilerArguments: Array,
            compilationOptions: CompilationOptions,
            servicesFacade: CompilerServicesFacadeBase,
            compilationResults: CompilationResults?
    ): CallResult

    @Throws(RemoteException::class)
    fun clearJarCache()

    @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?,
            compilerArguments: Array,
            compilationOptions: CompilationOptions,
            servicesFacade: CompilerServicesFacadeBase,
            templateClasspath: List,
            templateClassName: String
    ): CallResult

    @Throws(RemoteException::class)
    fun replCreateState(sessionId: Int): CallResult

    @Throws(RemoteException::class)
    fun replCheck(
            sessionId: Int,
            replStateId: Int,
            codeLine: ReplCodeLine
    ): CallResult

    @Throws(RemoteException::class)
    fun replCompile(
            sessionId: Int,
            replStateId: Int,
            codeLine: ReplCodeLine
    ): CallResult
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy