Build KotlinNativeABICompatibilityChecker notifications in a separate function
Issue #KT-34814
This commit is contained in:
+27
-21
@@ -60,8 +60,31 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec
|
|||||||
return
|
return
|
||||||
|
|
||||||
val librariesToNotify = getLibrariesToNotifyAbout()
|
val librariesToNotify = getLibrariesToNotifyAbout()
|
||||||
|
val notifications = prepareNotifications(librariesToNotify)
|
||||||
|
|
||||||
|
notifications.forEach { it.notify(project) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getLibrariesToNotifyAbout(): Map<String, NativeLibraryInfo> = synchronized(this) {
|
||||||
|
val incompatibleLibraries = getModuleInfosFromIdeaModel(project).asSequence()
|
||||||
|
.filterIsInstance<NativeLibraryInfo>()
|
||||||
|
.filter { it.safeAbiVersion != KotlinAbiVersion.CURRENT }
|
||||||
|
.associateBy { it.libraryRoot }
|
||||||
|
|
||||||
|
val newEntries = if (cachedIncompatibleLibraries.isNotEmpty())
|
||||||
|
incompatibleLibraries.filterKeys { it !in cachedIncompatibleLibraries }
|
||||||
|
else
|
||||||
|
incompatibleLibraries
|
||||||
|
|
||||||
|
cachedIncompatibleLibraries.clear()
|
||||||
|
cachedIncompatibleLibraries.addAll(incompatibleLibraries.keys)
|
||||||
|
|
||||||
|
return newEntries
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun prepareNotifications(librariesToNotify: Map<String, NativeLibraryInfo>): List<Notification> {
|
||||||
if (librariesToNotify.isEmpty())
|
if (librariesToNotify.isEmpty())
|
||||||
return
|
return emptyList()
|
||||||
|
|
||||||
val librariesByGroups = HashMap<Pair<LibraryGroup, Boolean>, MutableList<Pair<String, String>>>()
|
val librariesByGroups = HashMap<Pair<LibraryGroup, Boolean>, MutableList<Pair<String, String>>>()
|
||||||
librariesToNotify.forEach { (libraryRoot, libraryInfo) ->
|
librariesToNotify.forEach { (libraryRoot, libraryInfo) ->
|
||||||
@@ -70,12 +93,12 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec
|
|||||||
librariesByGroups.computeIfAbsent(libraryGroup to isOldAbi) { mutableListOf() } += libraryName to libraryRoot
|
librariesByGroups.computeIfAbsent(libraryGroup to isOldAbi) { mutableListOf() } += libraryName to libraryRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
librariesByGroups.keys.sortedWith(
|
return librariesByGroups.keys.sortedWith(
|
||||||
compareBy(
|
compareBy(
|
||||||
{ (libraryGroup, _) -> libraryGroup },
|
{ (libraryGroup, _) -> libraryGroup },
|
||||||
{ (_, isOldAbi) -> isOldAbi }
|
{ (_, isOldAbi) -> isOldAbi }
|
||||||
)
|
)
|
||||||
).forEach { key ->
|
).map { key ->
|
||||||
|
|
||||||
val (libraryGroup, isOldAbi) = key
|
val (libraryGroup, isOldAbi) = key
|
||||||
val libraries =
|
val libraries =
|
||||||
@@ -154,27 +177,10 @@ class KotlinNativeABICompatibilityChecker(private val project: Project) : Projec
|
|||||||
StringUtilRt.convertLineSeparators(message, "<br/>"),
|
StringUtilRt.convertLineSeparators(message, "<br/>"),
|
||||||
NotificationType.ERROR,
|
NotificationType.ERROR,
|
||||||
null
|
null
|
||||||
).notify(project)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getLibrariesToNotifyAbout(): Map<String, NativeLibraryInfo> = synchronized(this) {
|
|
||||||
val incompatibleLibraries = getModuleInfosFromIdeaModel(project).asSequence()
|
|
||||||
.filterIsInstance<NativeLibraryInfo>()
|
|
||||||
.filter { it.safeAbiVersion != KotlinAbiVersion.CURRENT }
|
|
||||||
.associateBy { it.libraryRoot }
|
|
||||||
|
|
||||||
val newEntries = if (cachedIncompatibleLibraries.isNotEmpty())
|
|
||||||
incompatibleLibraries.filterKeys { it !in cachedIncompatibleLibraries }
|
|
||||||
else
|
|
||||||
incompatibleLibraries
|
|
||||||
|
|
||||||
cachedIncompatibleLibraries.clear()
|
|
||||||
cachedIncompatibleLibraries.addAll(incompatibleLibraries.keys)
|
|
||||||
|
|
||||||
return newEntries
|
|
||||||
}
|
|
||||||
|
|
||||||
// returns pair of library name and library group
|
// returns pair of library name and library group
|
||||||
private fun parseIDELibraryName(libraryInfo: NativeLibraryInfo): Pair<String, LibraryGroup> {
|
private fun parseIDELibraryName(libraryInfo: NativeLibraryInfo): Pair<String, LibraryGroup> {
|
||||||
val ideLibraryName = libraryInfo.library.name?.takeIf(String::isNotEmpty)
|
val ideLibraryName = libraryInfo.library.name?.takeIf(String::isNotEmpty)
|
||||||
|
|||||||
Reference in New Issue
Block a user