From 57e7e15d20cbcc0c3d7f7ae53bdfa217d00a47ba Mon Sep 17 00:00:00 2001 From: mikrise2 <56760252+mikrise2@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:59:56 +0100 Subject: [PATCH] [ML4SE-342] External logs support. (#96) --- .../research/tasktracker/config/content/Log.kt | 12 ++++++++++++ .../config/content/PluginInfoConfig.kt | 3 +++ .../tasktracker/tracking/ExternalLogger.kt | 13 +++++++++++++ .../tasktracker/tracking/TrackingService.kt | 18 +++++++++++++++++- .../tasktracker/config/info_default.yaml | 6 +++++- 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/content/Log.kt create mode 100644 ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/ExternalLogger.kt diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/content/Log.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/content/Log.kt new file mode 100644 index 00000000..34519d34 --- /dev/null +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/content/Log.kt @@ -0,0 +1,12 @@ +package org.jetbrains.research.tasktracker.config.content + +import kotlinx.serialization.Serializable + +/** + * Represents a log with associated log paths and a log type. + * + * @param logPaths The list of relative log paths from the project root. + * @param type The log type. By default, it is set to "default". + */ +@Serializable +data class Log(val logPaths: List, val type: String = "default") diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/content/PluginInfoConfig.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/content/PluginInfoConfig.kt index 0d97ab11..22ec7feb 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/content/PluginInfoConfig.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/content/PluginInfoConfig.kt @@ -7,6 +7,9 @@ import java.io.File @Serializable class PluginInfoConfig(val pluginName: String, val pluginDescription: String, val researchId: String) : BaseConfig { + + val logs: List = emptyList() + override val configName: String get() = CONFIG_FILE_PREFIX diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/ExternalLogger.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/ExternalLogger.kt new file mode 100644 index 00000000..ccfe8eb2 --- /dev/null +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/ExternalLogger.kt @@ -0,0 +1,13 @@ +package org.jetbrains.research.tasktracker.tracking + +import org.jetbrains.research.tasktracker.config.content.Log +import java.io.File +import java.nio.file.Path + +class ExternalLogger(private val root: Path, private val log: Log) : Loggable() { + override val logFileType: String = log.type + + override fun getLogFiles(): List = log.logPaths.map { + root.resolve(it).toFile() + }.filter { it.exists() } +} diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TrackingService.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TrackingService.kt index b3639ef8..0c12267d 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TrackingService.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TrackingService.kt @@ -5,14 +5,17 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.Service import com.intellij.openapi.project.Project import kotlinx.coroutines.runBlocking +import org.jetbrains.research.tasktracker.TaskTrackerPlugin import org.jetbrains.research.tasktracker.tracking.activity.ActivityTracker import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorTracker import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowTracker +import kotlin.io.path.Path @Service(Service.Level.PROJECT) class TrackingService : Disposable { private val trackers: MutableList = mutableListOf() + private val logs: MutableList = mutableListOf() fun startTracking(project: Project) { if (trackers.isNotEmpty()) { // Otherwise we can lose data @@ -25,6 +28,16 @@ class TrackingService : Disposable { FileEditorTracker(project) ) ) + project.basePath?.let { path -> + logs.addAll( + TaskTrackerPlugin.mainConfig.pluginInfoConfig?.logs?.map { + ExternalLogger( + Path(path), + it + ) + } ?: emptyList() + ) + } trackers.forEach { it.startTracking() } } @@ -43,8 +56,11 @@ class TrackingService : Disposable { runBlocking { val result = trackers.all { it.send() - } + }.and( + logs.all { it.send() } + ) trackers.clear() + logs.clear() if (result) success.invoke() else failure.invoke() } } diff --git a/ij-plugin/src/main/resources/org/jetbrains/research/tasktracker/config/info_default.yaml b/ij-plugin/src/main/resources/org/jetbrains/research/tasktracker/config/info_default.yaml index eb334fec..ffbd97cf 100644 --- a/ij-plugin/src/main/resources/org/jetbrains/research/tasktracker/config/info_default.yaml +++ b/ij-plugin/src/main/resources/org/jetbrains/research/tasktracker/config/info_default.yaml @@ -1,3 +1,7 @@ pluginName: Refactoring course pluginDescription: "We want to track your progress through the code refactoring course in order to collect data on file changes during the course completion. Please, when you are ready, press the next button." -researchId: "RefactoringCourse" \ No newline at end of file +researchId: "RefactoringCourse" +logs: + - logPaths: + - "eduAssistant.log" + type: "ai" \ No newline at end of file