Fixing run filename compatibility with windows, improving diagnostics, some minor tweaks

This commit is contained in:
Ilya Chernikov
2015-09-11 15:30:17 +02:00
parent 0e067290af
commit 8b970cd186
3 changed files with 26 additions and 17 deletions
@@ -30,6 +30,7 @@ import java.rmi.registry.Registry
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import java.util.jar.Manifest import java.util.jar.Manifest
import java.util.logging.Level
import java.util.logging.LogManager import java.util.logging.LogManager
import java.util.logging.Logger import java.util.logging.Logger
import kotlin.concurrent.timer import kotlin.concurrent.timer
@@ -120,11 +121,13 @@ public object CompileDaemon {
val runFileDir = File(if (daemonOptions.runFilesPath.isBlank()) COMPILE_DAEMON_DEFAULT_RUN_DIR_PATH else daemonOptions.runFilesPath) val runFileDir = File(if (daemonOptions.runFilesPath.isBlank()) COMPILE_DAEMON_DEFAULT_RUN_DIR_PATH else daemonOptions.runFilesPath)
runFileDir.mkdirs() runFileDir.mkdirs()
val runFile = File(runFileDir, val runFile = File(runFileDir,
makeRunFilenameString(timestamp = "%tFT%<tT.%<tLZ".format(Calendar.getInstance(TimeZone.getTimeZone("Z"))), makeRunFilenameString(timestamp = "%tFT%<tH-%<tM-%<tS.%<tLZ".format(Calendar.getInstance(TimeZone.getTimeZone("Z"))),
digest = compilerId.compilerClasspath.map { File(it).absolutePath }.distinctStringsDigest(), digest = compilerId.compilerClasspath.map { File(it).absolutePath }.distinctStringsDigest(),
port = port.toString())) port = port.toString()))
if (!runFile.createNewFile()) { try {
throw IllegalStateException("Unable to create run file '${runFile.absolutePath}'") if (!runFile.createNewFile()) throw Exception("createNewFile returned false")
} catch (e: Exception) {
throw IllegalStateException("Unable to create run file '${runFile.absolutePath}'", e)
} }
runFile.deleteOnExit() runFile.deleteOnExit()
@@ -159,26 +162,31 @@ public object CompileDaemon {
// stopping daemon if any shutdown condition is met // stopping daemon if any shutdown condition is met
timer(initialDelay = DAEMON_PERIODIC_CHECK_INTERVAL_MS, period = DAEMON_PERIODIC_CHECK_INTERVAL_MS) { timer(initialDelay = DAEMON_PERIODIC_CHECK_INTERVAL_MS, period = DAEMON_PERIODIC_CHECK_INTERVAL_MS) {
try {
val idleSeconds = nowSeconds() - compilerService.lastUsedSeconds val idleSeconds = nowSeconds() - compilerService.lastUsedSeconds
if (shutdownCondition({ !runFile.exists() }, "Run file removed, shutting down") || if (shutdownCondition({ !runFile.exists() }, "Run file removed, shutting down") ||
shutdownCondition({ daemonOptions.autoshutdownIdleSeconds != COMPILE_DAEMON_TIMEOUT_INFINITE_S && idleSeconds > daemonOptions.autoshutdownIdleSeconds}, shutdownCondition({ daemonOptions.autoshutdownIdleSeconds != COMPILE_DAEMON_TIMEOUT_INFINITE_S && idleSeconds > daemonOptions.autoshutdownIdleSeconds },
"Idle timeout exceeded ${daemonOptions.autoshutdownIdleSeconds}s, shutting down") || "Idle timeout exceeded ${daemonOptions.autoshutdownIdleSeconds}s, shutting down") ||
shutdownCondition({ daemonOptions.clientAliveFlagPath?.let { !File(it).exists() } ?: false }, shutdownCondition({ daemonOptions.clientAliveFlagPath?.let { !File(it).exists() } ?: false },
"Client alive flag ${daemonOptions.clientAliveFlagPath} removed, shutting down")) "Client alive flag ${daemonOptions.clientAliveFlagPath} removed, shutting down")) {
{
cancel() cancel()
compilerService.shutdown() compilerService.shutdown()
} }
} }
catch (e: Exception) {
System.err.println("Exception in timer thread: " + e.getMessage())
e.printStackTrace(System.err)
}
}
} }
catch (e: Exception) { catch (e: Exception) {
System.err.println("Exception: " + e.getMessage()) System.err.println("Exception: " + e.getMessage())
log.info("Exception" + e.getMessage()) e.printStackTrace(System.err)
log.info(e.toString()) // repeating it to log for the cases when stderr is not redirected yet
log.log(Level.INFO, "Exception: ", e)
// TODO consider exiting without throwing // TODO consider exiting without throwing
throw e throw e
} }
} }
val random = Random() val random = Random()
@@ -33,7 +33,7 @@ public class KotlinBuildProcessParametersProvider(private val compilerWorkspaceS
kotlinPluginStartupComponent.aliveFlagPath.let { kotlinPluginStartupComponent.aliveFlagPath.let {
if (!it.isBlank()) { if (!it.isBlank()) {
// TODO: consider taking the property name from compiler/rmi-interface (check whether dependency will be not too heavy) // TODO: consider taking the property name from compiler/rmi-interface (check whether dependency will be not too heavy)
res.add("-Dkotlin.daemon.client.alive.path=$it") res.add("-Dkotlin.daemon.client.alive.path=\"$it\"")
} }
} }
return res return res
@@ -112,7 +112,8 @@ public class SimpleKotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
public fun testThreeModulesNoReexportWithDaemon() { public fun testThreeModulesNoReexportWithDaemon() {
System.setProperty(COMPILE_DAEMON_ENABLED_PROPERTY,"") System.setProperty(COMPILE_DAEMON_ENABLED_PROPERTY,"")
System.setProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "") System.setProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY, "")
val flagFile = File.createTempFile("kotlin-jps-tests-", "-is-running"); // spaces in the name to test proper file name handling
val flagFile = File.createTempFile("kotlin-jps - tests-", "-is-running");
try { try {
System.setProperty(COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY, flagFile.absolutePath) System.setProperty(COMPILE_DAEMON_CLIENT_ALIVE_PATH_PROPERTY, flagFile.absolutePath)
testThreeModulesNoReexport() testThreeModulesNoReexport()