UnsupportedAbiVersionNotificationPanelProvider: cleanup code
This commit is contained in:
+87
-73
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -81,73 +81,83 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
|
|||||||
val isPluginOldForAllRoots = badVersionedRoots.all { it.supportedVersion < it.version }
|
val isPluginOldForAllRoots = badVersionedRoots.all { it.supportedVersion < it.version }
|
||||||
val isPluginNewForAllRoots = badVersionedRoots.all { it.supportedVersion > it.version }
|
val isPluginNewForAllRoots = badVersionedRoots.all { it.supportedVersion > it.version }
|
||||||
|
|
||||||
if (!badRuntimeLibraries.isEmpty()) {
|
when {
|
||||||
val badRootsInRuntimeLibraries = findBadRootsInRuntimeLibraries(badRuntimeLibraries, badVersionedRoots)
|
badRuntimeLibraries.isNotEmpty() -> {
|
||||||
val otherBadRootsCount = badVersionedRoots.size - badRootsInRuntimeLibraries.size
|
val badRootsInRuntimeLibraries = findBadRootsInRuntimeLibraries(badRuntimeLibraries, badVersionedRoots)
|
||||||
|
val otherBadRootsCount = badVersionedRoots.size - badRootsInRuntimeLibraries.size
|
||||||
|
|
||||||
val text = MessageFormat.format("<html><b>{0,choice,0#|1#|1<Some }Kotlin runtime librar{0,choice,0#|1#y|1<ies}</b>" +
|
val text = MessageFormat.format(
|
||||||
"{1,choice,0#|1# and one other jar|1< and {1} other jars} " +
|
"<html><b>{0,choice,0#|1#|1<Some }Kotlin runtime librar{0,choice,0#|1#y|1<ies}</b>" +
|
||||||
"{1,choice,0#has|0<have} an unsupported binary format.</html>",
|
"{1,choice,0#|1# and one other jar|1< and {1} other jars} " +
|
||||||
badRuntimeLibraries.size,
|
"{1,choice,0#has|0<have} an unsupported binary format.</html>",
|
||||||
otherBadRootsCount)
|
badRuntimeLibraries.size,
|
||||||
|
otherBadRootsCount
|
||||||
|
)
|
||||||
|
|
||||||
answer.setText(text)
|
answer.setText(text)
|
||||||
|
|
||||||
if (isPluginOldForAllRoots) {
|
if (isPluginOldForAllRoots) {
|
||||||
|
createUpdatePluginLink(answer)
|
||||||
|
}
|
||||||
|
|
||||||
|
val isPluginOldForAllRuntimeLibraries = badRootsInRuntimeLibraries.all { it.supportedVersion < it.version }
|
||||||
|
val isPluginNewForAllRuntimeLibraries = badRootsInRuntimeLibraries.all { it.supportedVersion > it.version }
|
||||||
|
|
||||||
|
val updateAction = when {
|
||||||
|
isPluginNewForAllRuntimeLibraries -> "Update"
|
||||||
|
isPluginOldForAllRuntimeLibraries -> "Downgrade"
|
||||||
|
else -> "Replace"
|
||||||
|
}
|
||||||
|
|
||||||
|
val actionLabelText = MessageFormat.format(
|
||||||
|
"$updateAction {0,choice,0#|1#|1<all }Kotlin runtime librar{0,choice,0#|1#y|1<ies} ",
|
||||||
|
badRuntimeLibraries.size
|
||||||
|
)
|
||||||
|
answer.createActionLabel(actionLabelText) {
|
||||||
|
ApplicationManager.getApplication().invokeLater {
|
||||||
|
updateLibraries(project, badRuntimeLibraries)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
badVersionedRoots.size == 1 -> {
|
||||||
|
val badVersionedRoot = badVersionedRoots.first()
|
||||||
|
val presentableName = badVersionedRoot.file.presentableName
|
||||||
|
|
||||||
|
when {
|
||||||
|
isPluginOldForAllRoots -> {
|
||||||
|
answer.setText("<html>Kotlin library <b>'$presentableName'</b> was compiled with a newer Kotlin compiler and can't be read. Please update Kotlin plugin.</html>")
|
||||||
|
createUpdatePluginLink(answer)
|
||||||
|
}
|
||||||
|
|
||||||
|
isPluginNewForAllRoots ->
|
||||||
|
answer.setText("<html>Kotlin library <b>'$presentableName'</b> has outdated binary format and can't be read by current plugin. Please update the library.</html>")
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
throw IllegalStateException("Bad root with compatible version found: $badVersionedRoot")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
answer.createActionLabel("Go to $presentableName") { navigateToLibraryRoot(project, badVersionedRoot.file) }
|
||||||
|
}
|
||||||
|
|
||||||
|
isPluginOldForAllRoots -> {
|
||||||
|
answer.setText(
|
||||||
|
"Some Kotlin libraries attached to this project were compiled with a newer Kotlin compiler and can't be read. " +
|
||||||
|
"Please update Kotlin plugin."
|
||||||
|
)
|
||||||
createUpdatePluginLink(answer)
|
createUpdatePluginLink(answer)
|
||||||
}
|
}
|
||||||
|
|
||||||
val isPluginOldForAllRuntimeLibraries = badRootsInRuntimeLibraries.all { it.supportedVersion < it.version }
|
isPluginNewForAllRoots ->
|
||||||
val isPluginNewForAllRuntimeLibraries = badRootsInRuntimeLibraries.all { it.supportedVersion > it.version }
|
answer.setText(
|
||||||
|
"Some Kotlin libraries attached to this project have outdated binary format and can't be read by current plugin. " +
|
||||||
|
"Please update found libraries."
|
||||||
|
)
|
||||||
|
|
||||||
val updateAction = when {
|
else ->
|
||||||
isPluginNewForAllRuntimeLibraries -> "Update"
|
answer.setText("Some Kotlin libraries attached to this project have unsupported binary format. Please update the libraries or the plugin.")
|
||||||
isPluginOldForAllRuntimeLibraries -> "Downgrade"
|
|
||||||
else -> "Replace"
|
|
||||||
}
|
|
||||||
|
|
||||||
val actionLabelText = MessageFormat.format("$updateAction {0,choice,0#|1#|1<all }Kotlin runtime librar{0,choice,0#|1#y|1<ies} ", badRuntimeLibraries.size)
|
|
||||||
answer.createActionLabel(actionLabelText) {
|
|
||||||
ApplicationManager.getApplication().invokeLater {
|
|
||||||
updateLibraries(project, badRuntimeLibraries)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (badVersionedRoots.size == 1) {
|
|
||||||
val badVersionedRoot = badVersionedRoots.first()
|
|
||||||
val presentableName = badVersionedRoot.file.presentableName
|
|
||||||
|
|
||||||
when {
|
|
||||||
isPluginOldForAllRoots -> {
|
|
||||||
answer.setText("<html>Kotlin library <b>'$presentableName'</b> was compiled with a newer Kotlin compiler and can't be read. Please update Kotlin plugin.</html>")
|
|
||||||
createUpdatePluginLink(answer)
|
|
||||||
}
|
|
||||||
|
|
||||||
isPluginNewForAllRoots ->
|
|
||||||
answer.setText("<html>Kotlin library <b>'$presentableName'</b> has outdated binary format and can't be read by current plugin. Please update the library.</html>")
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
throw IllegalStateException("Bad root with compatible version found: $badVersionedRoot")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
answer.createActionLabel("Go to " + presentableName) { navigateToLibraryRoot(project, badVersionedRoot.file) }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
when {
|
|
||||||
isPluginOldForAllRoots -> {
|
|
||||||
answer.setText("Some Kotlin libraries attached to this project were compiled with a newer Kotlin compiler and can't be read. " +
|
|
||||||
"Please update Kotlin plugin.")
|
|
||||||
createUpdatePluginLink(answer)
|
|
||||||
}
|
|
||||||
|
|
||||||
isPluginNewForAllRoots ->
|
|
||||||
answer.setText("Some Kotlin libraries attached to this project have outdated binary format and can't be read by current plugin. " +
|
|
||||||
"Please update found libraries.")
|
|
||||||
|
|
||||||
else ->
|
|
||||||
answer.setText("Some Kotlin libraries attached to this project have unsupported binary format. Please update the libraries or the plugin.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createShowPathsActionLabel(module, answer, "Details")
|
createShowPathsActionLabel(module, answer, "Details")
|
||||||
@@ -157,16 +167,21 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
|
|||||||
|
|
||||||
private fun createShowPathsActionLabel(module: Module, answer: EditorNotificationPanel, labelText: String) {
|
private fun createShowPathsActionLabel(module: Module, answer: EditorNotificationPanel, labelText: String) {
|
||||||
answer.createComponentActionLabel(labelText) { label ->
|
answer.createComponentActionLabel(labelText) { label ->
|
||||||
DumbService.getInstance(project).tryRunReadActionInSmartMode({
|
val task = {
|
||||||
val badRoots = collectBadRoots(module)
|
val badRoots = collectBadRoots(module)
|
||||||
assert(!badRoots.isEmpty()) { "This action should only be called when bad roots are present" }
|
assert(!badRoots.isEmpty()) { "This action should only be called when bad roots are present" }
|
||||||
|
|
||||||
val listPopupModel = LibraryRootsPopupModel("Unsupported format, plugin version: " + KotlinPluginUtil.getPluginVersion(), project, badRoots)
|
val listPopupModel = LibraryRootsPopupModel(
|
||||||
|
"Unsupported format, plugin version: " + KotlinPluginUtil.getPluginVersion(),
|
||||||
|
project,
|
||||||
|
badRoots
|
||||||
|
)
|
||||||
val popup = JBPopupFactory.getInstance().createListPopup(listPopupModel)
|
val popup = JBPopupFactory.getInstance().createListPopup(listPopupModel)
|
||||||
popup.showUnderneathOf(label)
|
popup.showUnderneathOf(label)
|
||||||
|
|
||||||
null
|
null
|
||||||
}, "Can't show all paths during index update")
|
}
|
||||||
|
DumbService.getInstance(project).tryRunReadActionInSmartMode(task, "Can't show all paths during index update")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,11 +222,9 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
|
|||||||
val module = ModuleUtilCore.findModuleForFile(file, project) ?: return null
|
val module = ModuleUtilCore.findModuleForFile(file, project) ?: return null
|
||||||
|
|
||||||
return checkAndCreate(module)
|
return checkAndCreate(module)
|
||||||
}
|
} catch (e: ProcessCanceledException) {
|
||||||
catch (e: ProcessCanceledException) {
|
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
} catch (e: IndexNotReadyException) {
|
||||||
catch (e: IndexNotReadyException) {
|
|
||||||
DumbService.getInstance(project).runWhenSmart(updateNotifications)
|
DumbService.getInstance(project).runWhenSmart(updateNotifications)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,8 +246,9 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun findBadRootsInRuntimeLibraries(
|
private fun findBadRootsInRuntimeLibraries(
|
||||||
badRuntimeLibraries: List<Library>,
|
badRuntimeLibraries: List<Library>,
|
||||||
badVersionedRoots: Collection<BinaryVersionedFile<BinaryVersion>>): ArrayList<BinaryVersionedFile<BinaryVersion>> {
|
badVersionedRoots: Collection<BinaryVersionedFile<BinaryVersion>>
|
||||||
|
): ArrayList<BinaryVersionedFile<BinaryVersion>> {
|
||||||
val badRootsInLibraries = ArrayList<BinaryVersionedFile<BinaryVersion>>()
|
val badRootsInLibraries = ArrayList<BinaryVersionedFile<BinaryVersion>>()
|
||||||
|
|
||||||
fun addToBadRoots(file: VirtualFile?) {
|
fun addToBadRoots(file: VirtualFile?) {
|
||||||
@@ -256,9 +270,9 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class LibraryRootsPopupModel(
|
private class LibraryRootsPopupModel(
|
||||||
title: String,
|
title: String,
|
||||||
private val project: Project,
|
private val project: Project,
|
||||||
roots: Collection<BinaryVersionedFile<BinaryVersion>>
|
roots: Collection<BinaryVersionedFile<BinaryVersion>>
|
||||||
) : BaseListPopupStep<BinaryVersionedFile<BinaryVersion>>(title, *roots.toTypedArray()) {
|
) : BaseListPopupStep<BinaryVersionedFile<BinaryVersion>>(title, *roots.toTypedArray()) {
|
||||||
|
|
||||||
override fun getTextFor(root: BinaryVersionedFile<BinaryVersion>): String {
|
override fun getTextFor(root: BinaryVersionedFile<BinaryVersion>): String {
|
||||||
@@ -290,7 +304,7 @@ class UnsupportedAbiVersionNotificationPanelProvider(private val project: Projec
|
|||||||
val label = JLabel(text)
|
val label = JLabel(text)
|
||||||
myLinksPanel.add(label)
|
myLinksPanel.add(label)
|
||||||
|
|
||||||
val successLink = createActionLabel(successLinkText, { })
|
val successLink = createActionLabel(successLinkText) { }
|
||||||
successLink.isVisible = false
|
successLink.isVisible = false
|
||||||
|
|
||||||
// Several notification panels can be created almost instantly but we want to postpone deferred checks until
|
// Several notification panels can be created almost instantly but we want to postpone deferred checks until
|
||||||
|
|||||||
Reference in New Issue
Block a user