in src/main/kotlin/com/jetbrains/plugin/jtreg/listeners/FileHandlers.kt [34:75]
fun processFileOpened(project: Project, rootManager: TestRootManager, testInfo: TestInfo) {
ApplicationManager.getApplication().executeOnPooledThread {
val file = testInfo.file
if (!file.exists()) return@executeOnPooledThread
val isJtreg = runReadAction { JTRegLibUtils.isJTRegTestData(project, file) }
val isTestNg = runReadAction { JTRegLibUtils.isTestNGTestData(project, file) }
val isJUnit = runReadAction { JTRegLibUtils.isJUnitTestData(project, file) }
if (isJtreg || isTestNg || isJUnit) {
val testRoots = runReadAction { JTRegLibUtils.getTestRoots(project, file) }
val rootModel = runReadAction { rootManager.rootModel(testInfo, project) }
rootModel?.use {
if (testInfo.roots != testRoots) {
rootModel.removeSourceFolders(testInfo.roots)
testInfo.roots = testRoots.toMutableList()
if (testRoots.isNotEmpty()) {
rootModel.addSourceFolders(testRoots)
}
}
if (isTestNg || isJUnit) {
val settings = ApplicationManager.getApplication().getService(JTRegService::class.java)
val libDir = settings.jtregHomeDirectory
val library = JTRegLibUtils.createJTRegLibrary(project, libDir)
testInfo.jtregLib = library
rootModel.addLibrary(library)
} else if (testInfo.jtregLib != null) {
rootModel.removeLibrary(testInfo.jtregLib!!)
testInfo.jtregLib = null
}
}
} else {
val rootModel = runReadAction { rootManager.rootModel(testInfo, project) }
rootModel?.use {
rootModel.removeSourceFolders(testInfo.roots)
testInfo.roots = mutableListOf()
testInfo.jtregLib?.let {
rootModel.removeLibrary(it)
testInfo.jtregLib = null
}
}
}
}
}