Code cleanup
This commit is contained in:
@@ -271,7 +271,7 @@ public object KotlinCompilerClient {
|
|||||||
}
|
}
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.toList()
|
.toList()
|
||||||
return when (daemons.size()) {
|
return when (daemons.size) {
|
||||||
0 -> null
|
0 -> null
|
||||||
1 -> daemons.first()
|
1 -> daemons.first()
|
||||||
else -> throw IllegalStateException("Multiple daemons serving the same compiler, reset with the cleanup required")
|
else -> throw IllegalStateException("Multiple daemons serving the same compiler, reset with the cleanup required")
|
||||||
|
|||||||
@@ -50,15 +50,19 @@ public object LoopbackNetworkInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// base socket factories by default don't implement equals properly (see e.g. http://stackoverflow.com/questions/21555710/rmi-and-jmx-socket-factories)
|
||||||
|
// so implementing it in derived classes using the fact that they are singletons
|
||||||
|
|
||||||
data class ServerLoopbackSocketFactory : RMIServerSocketFactory, Serializable {
|
class ServerLoopbackSocketFactory : RMIServerSocketFactory, Serializable {
|
||||||
|
override fun equals(other: Any?): Boolean = other === this || super.equals(other)
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun createServerSocket(port: Int): ServerSocket = ServerSocket(port, SERVER_SOCKET_BACKLOG_SIZE, InetAddress.getByName(loopbackInetAddressName))
|
override fun createServerSocket(port: Int): ServerSocket = ServerSocket(port, SERVER_SOCKET_BACKLOG_SIZE, InetAddress.getByName(loopbackInetAddressName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data class ClientLoopbackSocketFactory : RMIClientSocketFactory, Serializable {
|
class ClientLoopbackSocketFactory : RMIClientSocketFactory, Serializable {
|
||||||
|
override fun equals(other: Any?): Boolean = other === this || super.equals(other)
|
||||||
|
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
override fun createSocket(host: String, port: Int): Socket = Socket(InetAddress.getByName(loopbackInetAddressName), port)
|
override fun createSocket(host: String, port: Int): Socket = Socket(InetAddress.getByName(loopbackInetAddressName), port)
|
||||||
|
|||||||
@@ -209,11 +209,4 @@ class CompileServiceImpl(
|
|||||||
if (!alive) throw IllegalStateException("Kotlin Compiler Service is not in alive state")
|
if (!alive) throw IllegalStateException("Kotlin Compiler Service is not in alive state")
|
||||||
body()
|
body()
|
||||||
}
|
}
|
||||||
|
|
||||||
// sometimes used for debugging
|
|
||||||
fun<R> spy(msg: String, body: () -> R): R {
|
|
||||||
val res = body()
|
|
||||||
log.info(msg + " = " + res.toString())
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.rmi.service
|
|
||||||
|
|
||||||
import java.io.FilePermission
|
|
||||||
import java.net.SocketPermission
|
|
||||||
import java.security.CodeSource
|
|
||||||
import java.security.Permission
|
|
||||||
import java.security.PermissionCollection
|
|
||||||
import java.security.Policy
|
|
||||||
import java.util.ArrayList
|
|
||||||
import java.util.Collections
|
|
||||||
import java.util.Enumeration
|
|
||||||
import java.util.PropertyPermission
|
|
||||||
|
|
||||||
|
|
||||||
public class DaemonPolicy(val port: Int) : Policy() {
|
|
||||||
|
|
||||||
private fun createPermissions(): PermissionCollection {
|
|
||||||
val perms = DaemonPermissionCollection()
|
|
||||||
|
|
||||||
val socketPermission = SocketPermission("localhost:$port-", "connect, accept, resolve")
|
|
||||||
val propertyPermission = PropertyPermission("localhost:$port", "read")
|
|
||||||
//val filePermission = FilePermission("<<ALL FILES>>", "read")
|
|
||||||
|
|
||||||
perms.add(socketPermission)
|
|
||||||
perms.add(propertyPermission)
|
|
||||||
//perms.add(filePermission)
|
|
||||||
|
|
||||||
return perms
|
|
||||||
}
|
|
||||||
|
|
||||||
private val perms: PermissionCollection by lazy { createPermissions() }
|
|
||||||
|
|
||||||
override fun getPermissions(codesource: CodeSource?): PermissionCollection {
|
|
||||||
return perms
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class DaemonPermissionCollection : PermissionCollection() {
|
|
||||||
val perms = ArrayList<Permission>()
|
|
||||||
|
|
||||||
override fun add(p: Permission) {
|
|
||||||
perms.add(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun implies(p: Permission): Boolean = perms.any { implies(p) }
|
|
||||||
|
|
||||||
override fun elements(): Enumeration<Permission> = Collections.enumeration(perms)
|
|
||||||
|
|
||||||
override fun isReadOnly(): Boolean = false
|
|
||||||
//
|
|
||||||
// companion object {
|
|
||||||
//
|
|
||||||
// private val serialVersionUID = 614300921365729272L
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public fun setDaemonPpermissions(port: Int) {
|
|
||||||
Policy.setPolicy(DaemonPolicy(port))
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user