16
16
17
17
package org.jetbrains.kotlin.idea
18
18
19
- import com.intellij.ide.plugins.IdeaPluginDescriptor
20
- import com.intellij.ide.plugins.PluginManager
21
- import com.intellij.ide.plugins.PluginManagerMain
22
- import com.intellij.ide.plugins.RepositoryHelper
19
+ import com.intellij.ide.actions.ShowFilePathAction
20
+ import com.intellij.ide.plugins.*
23
21
import com.intellij.ide.util.PropertiesComponent
24
22
import com.intellij.notification.NotificationDisplayType
25
23
import com.intellij.notification.NotificationGroup
@@ -28,9 +26,9 @@ import com.intellij.openapi.Disposable
28
26
import com.intellij.openapi.application.ApplicationInfo
29
27
import com.intellij.openapi.application.ApplicationManager
30
28
import com.intellij.openapi.application.ModalityState
29
+ import com.intellij.openapi.application.PathManager
31
30
import com.intellij.openapi.components.ServiceManager
32
31
import com.intellij.openapi.diagnostic.Logger
33
- import com.intellij.openapi.extensions.PluginId
34
32
import com.intellij.openapi.progress.ProgressIndicator
35
33
import com.intellij.openapi.progress.ProgressManager
36
34
import com.intellij.openapi.progress.Task
@@ -43,14 +41,15 @@ import com.intellij.openapi.vfs.CharsetToolkit
43
41
import com.intellij.util.Alarm
44
42
import com.intellij.util.io.HttpRequests
45
43
import com.intellij.util.text.VersionComparatorUtil
44
+ import java.io.File
46
45
import java.net.URLEncoder
47
46
import java.util.concurrent.TimeUnit
48
47
49
48
sealed class PluginUpdateStatus {
50
49
object LatestVersionInstalled : PluginUpdateStatus()
51
50
52
51
class Update (val newVersion : String ,
53
- val descriptorToInstall : IdeaPluginDescriptor ? ,
52
+ val descriptorToInstall : IdeaPluginDescriptor ,
54
53
val hostToInstallFrom : String? ) : PluginUpdateStatus()
55
54
56
55
class CheckFailed (val message : String ) : PluginUpdateStatus()
@@ -90,19 +89,19 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
90
89
private fun updateCheck (callback : (PluginUpdateStatus ) -> Boolean ) {
91
90
try {
92
91
var (mainRepoUpdateSuccess, latestVersionInRepository) = getPluginVersionFromMainRepository()
93
- var descriptorToInstall: IdeaPluginDescriptor ? = null
92
+ var descriptorToInstall: IdeaPluginDescriptor ? = initPluginDescriptor(latestVersionInRepository)
94
93
var hostToInstallFrom: String? = null
95
94
96
95
for (host in RepositoryHelper .getPluginHosts().filterNotNull()) {
97
96
val plugins = try {
98
97
RepositoryHelper .loadPlugins(host, null )
99
98
}
100
99
catch (e: Exception ) {
101
- LOG .info(" Checking custom plugin reposityory $host failed" , e)
100
+ LOG .info(" Checking custom plugin repository $host failed" , e)
102
101
continue
103
102
}
104
103
105
- val kotlinPlugin = plugins.find { it.pluginId.toString() == " org.jetbrains.kotlin " }
104
+ val kotlinPlugin = plugins.find { it.pluginId == KotlinPluginUtil . KOTLIN_PLUGIN_ID }
106
105
if (kotlinPlugin != null && VersionComparatorUtil .compare(kotlinPlugin.version, latestVersionInRepository) > 0 ) {
107
106
latestVersionInRepository = kotlinPlugin.version
108
107
descriptorToInstall = kotlinPlugin
@@ -116,7 +115,7 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
116
115
recordSuccessfulUpdateCheck()
117
116
if (latestVersionInRepository != null && VersionComparatorUtil .compare(latestVersionInRepository, KotlinPluginUtil .getPluginVersion()) > 0 ) {
118
117
ApplicationManager .getApplication().invokeLater({
119
- callback(PluginUpdateStatus .Update (latestVersionInRepository!! , descriptorToInstall, hostToInstallFrom))
118
+ callback(PluginUpdateStatus .Update (latestVersionInRepository!! , descriptorToInstall!! , hostToInstallFrom))
120
119
}, ModalityState .any())
121
120
}
122
121
else {
@@ -140,6 +139,15 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
140
139
}
141
140
}
142
141
142
+ private fun initPluginDescriptor (newVersion : String? ): IdeaPluginDescriptor ? {
143
+ if (newVersion == null ) return null
144
+ val originalPlugin = PluginManager .getPlugin(KotlinPluginUtil .KOTLIN_PLUGIN_ID )!!
145
+ return PluginNode (KotlinPluginUtil .KOTLIN_PLUGIN_ID ).apply {
146
+ version = newVersion
147
+ name = originalPlugin.name
148
+ description = originalPlugin.description
149
+ }
150
+ }
143
151
144
152
data class RepositoryCheckResult (val success : Boolean , val newVersion : String? )
145
153
@@ -189,20 +197,26 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
189
197
190
198
fun installPluginUpdate (update : PluginUpdateStatus .Update ,
191
199
cancelCallback : () -> Unit = {}) {
192
- val descriptor = update.descriptorToInstall ? : PluginManager .getPlugin( PluginId .getId( " org.jetbrains.kotlin " )) ? : return
200
+ val descriptor = update.descriptorToInstall
193
201
val pluginDownloader = PluginDownloader .createDownloader(descriptor, update.hostToInstallFrom, null )
194
202
ProgressManager .getInstance().run (object : Task .Backgroundable (null , " Downloading plugins" , true ) {
195
203
override fun run (indicator : ProgressIndicator ) {
204
+ var installed = false
196
205
if (pluginDownloader.prepareToInstall(indicator)) {
197
206
val pluginDescriptor = pluginDownloader.descriptor
198
207
if (pluginDescriptor != null ) {
208
+ installed = true
199
209
pluginDownloader.install()
200
210
201
211
ApplicationManager .getApplication().invokeLater {
202
212
PluginManagerMain .notifyPluginsUpdated(null )
203
213
}
204
214
}
205
215
}
216
+
217
+ if (! installed) {
218
+ notifyNotInstalled()
219
+ }
206
220
}
207
221
208
222
override fun onCancel () {
@@ -211,6 +225,23 @@ class KotlinPluginUpdater(val propertiesComponent: PropertiesComponent) : Dispos
211
225
})
212
226
}
213
227
228
+ private fun notifyNotInstalled () {
229
+ ApplicationManager .getApplication().invokeLater {
230
+ val notification = notificationGroup.createNotification(
231
+ " Kotlin" ,
232
+ " Plugin update was not installed. <a href=\" #\" >See the log for more information</a>" ,
233
+ NotificationType .INFORMATION ) { notification, event ->
234
+
235
+ val logFile = File (PathManager .getLogPath(), " idea.log" )
236
+ ShowFilePathAction .openFile(logFile)
237
+
238
+ notification.expire()
239
+ }
240
+
241
+ notification.notify(null )
242
+ }
243
+ }
244
+
214
245
override fun dispose () {
215
246
}
216
247
0 commit comments