Skip to content

Commit

Permalink
[ML4SE-342] External logs support. (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikrise2 authored Jan 31, 2024
1 parent e52724c commit 57e7e15
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<String>, val type: String = "default")
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import java.io.File

@Serializable
class PluginInfoConfig(val pluginName: String, val pluginDescription: String, val researchId: String) : BaseConfig {

val logs: List<Log> = emptyList()

override val configName: String
get() = CONFIG_FILE_PREFIX

Expand Down
Original file line number Diff line number Diff line change
@@ -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<File> = log.logPaths.map {
root.resolve(it).toFile()
}.filter { it.exists() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BaseTracker> = mutableListOf()
private val logs: MutableList<Loggable> = mutableListOf()

fun startTracking(project: Project) {
if (trackers.isNotEmpty()) { // Otherwise we can lose data
Expand All @@ -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() }
}

Expand All @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
researchId: "RefactoringCourse"
logs:
- logPaths:
- "eduAssistant.log"
type: "ai"

0 comments on commit 57e7e15

Please sign in to comment.