diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/TaskTrackerPlugin.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/TaskTrackerPlugin.kt index c8c8f44d..40ed39d0 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/TaskTrackerPlugin.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/TaskTrackerPlugin.kt @@ -1,5 +1,6 @@ package org.jetbrains.research.tasktracker +import com.intellij.openapi.application.runReadAction import com.intellij.openapi.diagnostic.Logger import org.jetbrains.research.tasktracker.config.DefaultConfigsFactory import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig @@ -38,7 +39,7 @@ object TaskTrackerPlugin { DataHandler.LOCAL_FILE -> { val configFolderRoot = props.getProperty(CONFIG_ROOT_PROPERTY_NAME)?.let { File(it) } ?: defaultConfigRoot - MainTaskTrackerConfig.buildConfig(pluginProps, configFolderRoot) + runReadAction { MainTaskTrackerConfig.buildConfig(pluginProps, configFolderRoot) } } DataHandler.SERVER_CONNECTION -> { diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/DefaultConfigsFactory.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/DefaultConfigsFactory.kt index 8bb7a0c4..878244de 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/DefaultConfigsFactory.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/DefaultConfigsFactory.kt @@ -1,5 +1,7 @@ package org.jetbrains.research.tasktracker.config +import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.diagnostic.Logger import org.jetbrains.research.tasktracker.config.agreement.AgreementConfig import org.jetbrains.research.tasktracker.config.content.FinalPageContentConfig @@ -46,8 +48,8 @@ object DefaultConfigsFactory { private fun writeFromResources(configName: String, filePath: String) { val configFile = File(filePath) - DefaultConfigsFactory::class.java.getResource(configName)?.readText()?.let { - configFile.writeText(it) + runReadAction { DefaultConfigsFactory::class.java.getResource(configName)?.readText() }?.let { + runWriteAction { configFile.writeText(it) } } ?: logger.warn("There are no file with name $configName") } } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/properties/PropertiesController.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/properties/PropertiesController.kt index a23a94a4..04f9cd41 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/properties/PropertiesController.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/properties/PropertiesController.kt @@ -1,5 +1,7 @@ package org.jetbrains.research.tasktracker.properties +import com.intellij.openapi.application.runReadAction +import com.intellij.openapi.application.runWriteAction import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig import java.io.File import java.io.FileInputStream @@ -19,10 +21,10 @@ object PropertiesController { fun loadProps() = Properties().also { props -> createPropertiesFile() - FileInputStream(propertiesFile).use { props.load(it) } + runReadAction { FileInputStream(propertiesFile).use { props.load(it) } } } - private fun createPropertiesFile() { + private fun createPropertiesFile() = runWriteAction { defaultConfigRoot.mkdirs() propertiesFile.createNewFile() createDefaultPropertiesFile() diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/BaseLogger.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/BaseLogger.kt index aed91f39..aec18fe8 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/BaseLogger.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/BaseLogger.kt @@ -1,5 +1,7 @@ package org.jetbrains.research.tasktracker.tracking.logger +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.util.io.FileUtil import com.jetbrains.rd.util.AtomicInteger import org.apache.commons.csv.CSVFormat @@ -22,7 +24,9 @@ abstract class BaseLogger { protected fun log(dataToPrint: Iterable<*>) { val logPrinter = getActiveLogPrinter() - logPrinter.csvPrinter.printRecord(dataToPrint) + ApplicationManager.getApplication().invokeLater { + runWriteAction { logPrinter.csvPrinter.printRecord(dataToPrint) } + } } /** @@ -47,19 +51,21 @@ abstract class BaseLogger { val logFile = createLogFile("$logPrinterFilename${atomicInteger.getAndIncrement()}.csv") val fileWriter = OutputStreamWriter(FileOutputStream(logFile), StandardCharsets.UTF_8) val csvPrinter = CSVPrinter(fileWriter, CSVFormat.DEFAULT) - csvPrinter.printRecord(loggedData.headers) + runWriteAction { csvPrinter.printRecord(loggedData.headers) } logPrinters.add(LogPrinter(csvPrinter, fileWriter, logFile)) return logPrinters.last() } - private fun createLogFile(fileName: String): File { + private fun createLogFile(fileName: String): File = runWriteAction { val logFile = File("${MainTaskTrackerConfig.logFilesFolder}/$fileName") FileUtil.createIfDoesntExist(logFile) - return logFile + logFile } - fun getLogFiles(): List = logPrinters.map { - it.csvPrinter.flush() - it.logFile + fun getLogFiles(): List = runWriteAction { + logPrinters.map { + it.csvPrinter.flush() + it.logFile + } } } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogPrinter.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogPrinter.kt index 2b4714bb..bf08431d 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogPrinter.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogPrinter.kt @@ -1,5 +1,6 @@ package org.jetbrains.research.tasktracker.tracking.logger +import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.Document import com.intellij.openapi.fileEditor.FileDocumentManager @@ -41,17 +42,17 @@ class DocumentLogPrinter { logPrinters.last() } - private fun addLogPrinter(project: Project, document: Document): LogPrinter { + private fun addLogPrinter(project: Project, document: Document): LogPrinter = runWriteAction { logger.info("${MainTaskTrackerConfig.PLUGIN_NAME}: init printer") val logFile = createLogFile(document) val fileWriter = OutputStreamWriter(FileOutputStream(logFile), StandardCharsets.UTF_8) val csvPrinter = CSVPrinter(fileWriter, CSVFormat.DEFAULT) csvPrinter.printRecord(DocumentLoggedData(project).headers) logPrinters.add(LogPrinter(csvPrinter, fileWriter, logFile)) - return logPrinters.last() + logPrinters.last() } - private fun createLogFile(document: Document): File { + private fun createLogFile(document: Document): File = runWriteAction { File(MainTaskTrackerConfig.logFilesFolder).mkdirs() val trackedFile = FileDocumentManager.getInstance().getFile(document) logger.info("${MainTaskTrackerConfig.PLUGIN_NAME}: create log file for tracked file ${trackedFile?.name}") @@ -60,7 +61,7 @@ class DocumentLogPrinter { "${trackedFile?.nameWithoutExtension}_${trackedFile.hashCode()}_${document.hashCode()}_$logFilesNumber.csv" val logFile = File("${MainTaskTrackerConfig.logFilesFolder}/$logFileName") FileUtil.createIfDoesntExist(logFile) - return logFile + logFile } /** @@ -76,8 +77,10 @@ class DocumentLogPrinter { /** * We need to flush printers before getting their log files. */ - fun getLogFiles() = logPrinters.map { - it.csvPrinter.flush() - it.logFile + fun getLogFiles() = runWriteAction { + logPrinters.map { + it.csvPrinter.flush() + it.logFile + } } } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogger.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogger.kt index ec5cc545..2b3a7177 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogger.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogger.kt @@ -1,5 +1,6 @@ package org.jetbrains.research.tasktracker.tracking.logger +import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.Document import com.intellij.openapi.project.Project @@ -15,7 +16,7 @@ object DocumentLogger { fun log(project: Project, document: Document) { val docPrinter = myDocumentsToPrinters.getOrPut(document) { DocumentLogPrinter() } val logPrinter = docPrinter.getActiveLogPrinter(project, document) - logPrinter.csvPrinter.printRecord(DocumentLoggedData(project).getData(document)) + runWriteAction { logPrinter.csvPrinter.printRecord(DocumentLoggedData(project).getData(document)) } } fun getDocumentLogPrinter(document: Document): DocumentLogPrinter? = myDocumentsToPrinters[document]