in src/main/kotlin/com/jetbrains/plugin/jtreg/util/JTRegLibUtils.kt [303:322]
fun updateJTRegLibrary(project: Project, oldJTRegDir: String?, newJTRegDir: String?): Library {
val libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(project)
val tableModel = libraryTable.modifiableModel
val library = tableModel.getLibraryByName("jtreg-libs") ?: tableModel.createLibrary("jtreg-libs")
val libraryModel = library.modifiableModel
val oldDir = "file://${oldJTRegDir}${File.separator}lib"
if (!oldJTRegDir.isNullOrBlank() && libraryModel.isJarDirectory(oldDir, OrderRootType.CLASSES)) {
libraryModel.removeRoot(oldDir, OrderRootType.CLASSES)
}
val newDir = "file://${newJTRegDir}${File.separator}lib"
if (!newJTRegDir.isNullOrBlank() && !libraryModel.isJarDirectory(newDir, OrderRootType.CLASSES)) {
libraryModel.addJarDirectory(newDir, true)
}
ApplicationManager.getApplication().runWriteAction {
libraryModel.commit()
tableModel.commit()
}
return library
}