Allow to leave decline reason empty but demand verifier name
This commit is contained in:
@@ -48,7 +48,7 @@ sealed class PluginUpdateStatus {
|
||||
|
||||
class CheckFailed(val message: String, val detail: String? = null) : PluginUpdateStatus()
|
||||
|
||||
class Unverified(val message: String, val updateStatus: Update) : PluginUpdateStatus()
|
||||
class Unverified(val verifierName: String, val reason: String?, val updateStatus: Update) : PluginUpdateStatus()
|
||||
|
||||
fun mergeWith(other: PluginUpdateStatus): PluginUpdateStatus {
|
||||
if (other is Update) {
|
||||
|
||||
@@ -159,7 +159,10 @@ class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.N
|
||||
|
||||
is PluginUpdateStatus.Unverified -> {
|
||||
val version = pluginUpdateStatus.updateStatus.pluginDescriptor.version
|
||||
form.setUpdateStatus("A new version $version is found. ${pluginUpdateStatus.message}", false)
|
||||
val generalLine = "A new version $version is found but it's not verified by ${pluginUpdateStatus.verifierName}."
|
||||
val reasonLine = pluginUpdateStatus.reason ?: ""
|
||||
val message = "<html>$generalLine<br/>$reasonLine</html>"
|
||||
form.setUpdateStatus(message, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.ide.IdeBundle
|
||||
import com.intellij.openapi.options.Configurable
|
||||
import com.intellij.openapi.options.SearchableConfigurable
|
||||
import com.intellij.openapi.updateSettings.impl.UpdateSettings
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUpdater
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
||||
import org.jetbrains.kotlin.idea.PluginUpdateStatus
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.ConfigurePluginUpdatesForm
|
||||
import javax.swing.JComponent
|
||||
|
||||
class KotlinUpdatesSettingsConfigurable : SearchableConfigurable, Configurable.NoScroll {
|
||||
companion object {
|
||||
const val ID = "preferences.language.Kotlin"
|
||||
|
||||
private fun saveSelectedChannel(channel: Int) {
|
||||
val hosts = UpdateSettings.getInstance().storedPluginHosts
|
||||
hosts.removeIf {
|
||||
it.startsWith("https://plugins.jetbrains.com/plugins/") &&
|
||||
(it.endsWith("/6954") || it.endsWith(KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString))
|
||||
}
|
||||
when (channel) {
|
||||
EAPChannels.EAP_1_3.uiIndex -> hosts.add(EAPChannels.EAP_1_3.url)
|
||||
EAPChannels.EAP_1_2.uiIndex -> hosts.add(EAPChannels.EAP_1_2.url)
|
||||
}
|
||||
}
|
||||
|
||||
enum class EAPChannels(val url: String, val uiIndex: Int) {
|
||||
EAP_1_2("https://plugins.jetbrains.com/plugins/eap-1.2/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 1),
|
||||
EAP_1_3("https://plugins.jetbrains.com/plugins/eap-next/${KotlinPluginUtil.KOTLIN_PLUGIN_ID.idString}", 2);
|
||||
|
||||
private val hasChannel: Boolean get() = url in UpdateSettings.getInstance().pluginHosts
|
||||
|
||||
fun indexIfAvailable() = if (hasChannel) uiIndex else null
|
||||
}
|
||||
}
|
||||
|
||||
private val form = ConfigurePluginUpdatesForm()
|
||||
private var update: PluginUpdateStatus.Update? = null
|
||||
|
||||
private var savedChannel = -1
|
||||
|
||||
private var versionForInstallation: String? = null
|
||||
|
||||
private var installedVersion: String? = null
|
||||
private var installingStatus: String? = null
|
||||
|
||||
override fun getId(): String = ID
|
||||
|
||||
override fun getDisplayName(): String = "Kotlin Updates"
|
||||
|
||||
override fun isModified() = false
|
||||
|
||||
override fun apply() {
|
||||
// Selected channel is now saved automatically
|
||||
}
|
||||
|
||||
private fun setInstalledVersion(installedVersion: String?, installingStatus: String?) {
|
||||
this.installedVersion = installedVersion
|
||||
this.installingStatus = installingStatus
|
||||
}
|
||||
|
||||
override fun createComponent(): JComponent? {
|
||||
form.updateCheckProgressIcon.suspend()
|
||||
form.updateCheckProgressIcon.setPaintPassiveIcon(false)
|
||||
|
||||
form.reCheckButton.addActionListener {
|
||||
checkForUpdates()
|
||||
}
|
||||
|
||||
form.installButton.isVisible = false
|
||||
form.installButton.addActionListener {
|
||||
update?.let {
|
||||
form.hideInstallButton()
|
||||
|
||||
setInstalledVersion(it.pluginDescriptor.version, "Installing...")
|
||||
|
||||
form.installStatusLabel.text = installingStatus
|
||||
|
||||
KotlinPluginUpdater.getInstance().installPluginUpdate(
|
||||
it,
|
||||
successCallback = {
|
||||
setInstalledVersion(it.pluginDescriptor.version, IdeBundle.message("plugin.manager.installed.tooltip"))
|
||||
if (versionForInstallation == it.pluginDescriptor.version) {
|
||||
form.installStatusLabel.text = installingStatus
|
||||
}
|
||||
},
|
||||
cancelCallback = {
|
||||
if (versionForInstallation == it.pluginDescriptor.version) {
|
||||
form.installStatusLabel.text = ""
|
||||
form.showInstallButton()
|
||||
|
||||
setInstalledVersion(null, null)
|
||||
}
|
||||
},
|
||||
errorCallback = {
|
||||
if (versionForInstallation == it.pluginDescriptor.version) {
|
||||
form.installStatusLabel.text = "Installation failed"
|
||||
form.showInstallButton()
|
||||
setInstalledVersion(null, null)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
savedChannel = EAPChannels.EAP_1_3.indexIfAvailable() ?: EAPChannels.EAP_1_2.indexIfAvailable() ?: 0
|
||||
form.channelCombo.selectedIndex = savedChannel
|
||||
|
||||
form.channelCombo.addActionListener {
|
||||
val newChannel = form.channelCombo.selectedIndex
|
||||
if (newChannel != savedChannel) {
|
||||
savedChannel = newChannel
|
||||
checkForUpdates()
|
||||
}
|
||||
}
|
||||
|
||||
checkForUpdates()
|
||||
|
||||
return form.mainPanel
|
||||
}
|
||||
|
||||
private fun checkForUpdates() {
|
||||
saveChannelSettings()
|
||||
form.updateCheckProgressIcon.resume()
|
||||
form.resetUpdateStatus()
|
||||
KotlinPluginUpdater.getInstance().runUpdateCheck{ pluginUpdateStatus ->
|
||||
// Need this to show something is happening when check is very fast
|
||||
Thread.sleep(30)
|
||||
form.updateCheckProgressIcon.suspend()
|
||||
|
||||
when (pluginUpdateStatus) {
|
||||
PluginUpdateStatus.LatestVersionInstalled -> {
|
||||
form.setUpdateStatus(
|
||||
"You have the latest version of the plugin (${KotlinPluginUtil.getPluginVersion()}) installed.",
|
||||
false
|
||||
)
|
||||
}
|
||||
|
||||
is PluginUpdateStatus.Update -> {
|
||||
update = pluginUpdateStatus
|
||||
versionForInstallation = update?.pluginDescriptor?.version
|
||||
form.setUpdateStatus("A new version ${pluginUpdateStatus.pluginDescriptor.version} is available", true)
|
||||
if (installedVersion != null && installedVersion == versionForInstallation) {
|
||||
// Installation of the plugin has been started or finished
|
||||
form.hideInstallButton()
|
||||
form.installStatusLabel.text = installingStatus
|
||||
}
|
||||
}
|
||||
|
||||
is PluginUpdateStatus.CheckFailed ->
|
||||
form.setUpdateStatus("Update check failed: ${pluginUpdateStatus.message}", false)
|
||||
|
||||
is PluginUpdateStatus.Unverified -> {
|
||||
val version = pluginUpdateStatus.updateStatus.pluginDescriptor.version
|
||||
val message = "<html>A new version $version is found, but unverified:<br/> ${pluginUpdateStatus.message}</html>"
|
||||
form.setUpdateStatus(message, false)
|
||||
}
|
||||
}
|
||||
|
||||
false // do not auto-retry update check
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveChannelSettings() {
|
||||
saveSelectedChannel(form.channelCombo.selectedIndex)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,18 +7,19 @@ package org.jetbrains.kotlin.idea.update
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import org.intellij.lang.annotations.Language
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
import javax.xml.bind.JAXBContext
|
||||
import javax.xml.bind.annotation.*
|
||||
import com.intellij.ide.plugins.PluginNode
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import java.io.IOException
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
import javax.xml.bind.JAXBContext
|
||||
import javax.xml.bind.JAXBException
|
||||
import javax.xml.bind.annotation.*
|
||||
|
||||
class GooglePluginUpdateVerifier : PluginUpdateVerifier() {
|
||||
override val verifierName: String
|
||||
get() = "Android Studio"
|
||||
|
||||
// Verifies if a plugin can be installed in Android Studio 3.2+.
|
||||
// Currently used only by KotlinPluginUpdater.
|
||||
@@ -36,9 +37,12 @@ class GooglePluginUpdateVerifier : PluginUpdateVerifier() {
|
||||
val pluginCompatibility = unmarshaller.unmarshal(stream) as PluginCompatibility
|
||||
|
||||
val release = getRelease(pluginCompatibility) ?: return PluginVerifyResult.decline("no verified versions for this build")
|
||||
return if (release.plugins().any { KOTLIN_PLUGIN_ID == it.id && version == it.version }) PluginVerifyResult.accept()
|
||||
else PluginVerifyResult.decline("version to be verified")
|
||||
} catch (e : Exception) {
|
||||
|
||||
return if (release.plugins().any { KOTLIN_PLUGIN_ID == it.id && version == it.version })
|
||||
PluginVerifyResult.accept()
|
||||
else
|
||||
PluginVerifyResult.decline("version to be verified")
|
||||
} catch (e: Exception) {
|
||||
LOG.error("Exception when verifying plugin ${pluginDescriptor.pluginId.idString} version $version", e)
|
||||
return when (e) {
|
||||
is MalformedURLException, is IOException ->
|
||||
@@ -49,7 +53,7 @@ class GooglePluginUpdateVerifier : PluginUpdateVerifier() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getRelease(pluginCompatibility: PluginCompatibility) : StudioRelease? {
|
||||
private fun getRelease(pluginCompatibility: PluginCompatibility): StudioRelease? {
|
||||
for (studioRelease in pluginCompatibility.releases()) {
|
||||
if (buildInRange(studioRelease.name, studioRelease.sinceBuild, studioRelease.untilBuild)) {
|
||||
return studioRelease
|
||||
|
||||
@@ -9,6 +9,8 @@ import com.intellij.ide.plugins.IdeaPluginDescriptor
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
|
||||
abstract class PluginUpdateVerifier {
|
||||
abstract val verifierName: String
|
||||
|
||||
/**
|
||||
* @param pluginDescriptor
|
||||
* @return null means verifier is not responsible for the given plugin descriptor.
|
||||
|
||||
@@ -15,7 +15,8 @@ class PluginVerifyResult {
|
||||
var declineMessage: String? = null
|
||||
|
||||
companion object {
|
||||
fun decline(reason: String): PluginVerifyResult = PluginVerifyResult().apply {
|
||||
@JvmOverloads
|
||||
fun decline(reason: String? = null): PluginVerifyResult = PluginVerifyResult().apply {
|
||||
declineMessage = reason
|
||||
verified = false
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.update
|
||||
|
||||
import org.jetbrains.kotlin.idea.PluginUpdateStatus
|
||||
|
||||
// Do an additional verification with PluginUpdateVerifier. Enabled only in AS 32.
|
||||
// Do an additional verification with PluginUpdateVerifier. Enabled only in AS 3.2+
|
||||
fun verify(updateStatus: PluginUpdateStatus.Update): PluginUpdateStatus {
|
||||
return updateStatus
|
||||
}
|
||||
@@ -8,24 +8,20 @@ package org.jetbrains.kotlin.idea.update
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor
|
||||
import org.jetbrains.kotlin.idea.PluginUpdateStatus
|
||||
|
||||
// Do an additional verification with PluginUpdateVerifier. Enabled only in AS 32.
|
||||
// Do an additional verification with PluginUpdateVerifier. Enabled only in AS 3.2+
|
||||
fun verify(updateStatus: PluginUpdateStatus.Update): PluginUpdateStatus {
|
||||
val pluginDescriptor: IdeaPluginDescriptor = updateStatus.pluginDescriptor
|
||||
val pluginVerifiers = PluginUpdateVerifier.EP_NAME.extensions
|
||||
|
||||
val declineMessage = pluginVerifiers.asSequence()
|
||||
.map { verifier ->
|
||||
val verifyResult = verifier.verify(pluginDescriptor)
|
||||
if (verifyResult != null && !verifyResult.verified) {
|
||||
verifyResult.declineMessage
|
||||
} else {
|
||||
null
|
||||
}
|
||||
for (pluginVerifier in pluginVerifiers) {
|
||||
val verifyResult = pluginVerifier.verify(pluginDescriptor) ?: continue
|
||||
if (!verifyResult.verified) {
|
||||
return PluginUpdateStatus.Unverified(
|
||||
pluginVerifier.verifierName,
|
||||
verifyResult.declineMessage,
|
||||
updateStatus
|
||||
)
|
||||
}
|
||||
.firstOrNull { reason -> reason != null }
|
||||
|
||||
if (declineMessage != null) {
|
||||
return PluginUpdateStatus.Unverified(declineMessage, updateStatus)
|
||||
}
|
||||
|
||||
return updateStatus
|
||||
|
||||
Reference in New Issue
Block a user