diff --git a/plugins/github/resources/META-INF/plugin.xml b/plugins/github/resources/META-INF/plugin.xml
index bb347c1df32a..ae7dc5ba1313 100644
--- a/plugins/github/resources/META-INF/plugin.xml
+++ b/plugins/github/resources/META-INF/plugin.xml
@@ -56,6 +56,23 @@
+
+
+
+
+
+
+
+
+
@@ -65,6 +82,11 @@
+
+
+
diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiRequestExecutorManager.kt b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiRequestExecutorManager.kt
index 04bd3a358203..1b1a23b55280 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiRequestExecutorManager.kt
+++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiRequestExecutorManager.kt
@@ -1,7 +1,6 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.github.api
-import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import org.jetbrains.annotations.CalledInAwt
@@ -18,12 +17,6 @@ import java.awt.Component
class GithubApiRequestExecutorManager : AccountTokenChangedListener {
private val executors = mutableMapOf()
- init {
- ApplicationManager.getApplication().messageBus
- .connect()
- .subscribe(GithubAccountManager.ACCOUNT_TOKEN_CHANGED_TOPIC, this)
- }
-
companion object {
@JvmStatic
fun getInstance(): GithubApiRequestExecutorManager = service()
diff --git a/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubAccountInformationProvider.kt b/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubAccountInformationProvider.kt
index 5efdc7a8911a..95f2adda1a9c 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubAccountInformationProvider.kt
+++ b/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubAccountInformationProvider.kt
@@ -1,8 +1,7 @@
-// Copyright 2000-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 file.
+// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.github.authentication.accounts
import com.google.common.cache.CacheBuilder
-import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.openapi.progress.ProgressIndicator
import org.jetbrains.annotations.CalledInBackground
@@ -22,16 +21,6 @@ class GithubAccountInformationProvider {
.expireAfterAccess(30, TimeUnit.MINUTES)
.build()
- init {
- ApplicationManager.getApplication().messageBus
- .connect()
- .subscribe(GithubAccountManager.ACCOUNT_TOKEN_CHANGED_TOPIC, object : AccountTokenChangedListener {
- override fun tokenChanged(account: GithubAccount) {
- informationCache.invalidate(account)
- }
- })
- }
-
@CalledInBackground
@Throws(IOException::class)
fun getInformation(executor: GithubApiRequestExecutor, indicator: ProgressIndicator, account: GithubAccount): GithubAuthenticatedUser {
@@ -44,4 +33,10 @@ class GithubAccountInformationProvider {
return service()
}
}
+
+ class AccountTokenListener : AccountTokenChangedListener {
+ override fun tokenChanged(account: GithubAccount) {
+ getInstance().informationCache.invalidate(account)
+ }
+ }
}
\ No newline at end of file
diff --git a/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubAccountManager.kt b/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubAccountManager.kt
index b4d4c7243e08..a4e873bb1adf 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubAccountManager.kt
+++ b/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubAccountManager.kt
@@ -1,12 +1,16 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.github.authentication.accounts
-import com.intellij.credentialStore.*
+import com.intellij.credentialStore.CredentialAttributes
+import com.intellij.credentialStore.Credentials
+import com.intellij.credentialStore.PasswordSafeSettingsListener
+import com.intellij.credentialStore.generateServiceName
import com.intellij.ide.passwordSafe.PasswordSafe
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.State
import com.intellij.openapi.components.Storage
+import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.logger
import com.intellij.util.messages.Topic
import org.jetbrains.plugins.github.api.GithubServerPath
@@ -26,18 +30,6 @@ internal class GithubAccountManager : PersistentStateComponent()
+
@JvmStatic
val ACCOUNT_REMOVED_TOPIC = Topic("GITHUB_ACCOUNT_REMOVED", AccountRemovedListener::class.java)
+
@JvmStatic
val ACCOUNT_TOKEN_CHANGED_TOPIC = Topic("GITHUB_ACCOUNT_TOKEN_CHANGED", AccountTokenChangedListener::class.java)
fun createAccount(name: String, server: GithubServerPath) = GithubAccount(name, server)
}
+
+ class PasswordStorageClearedListener : PasswordSafeSettingsListener {
+ override fun credentialStoreCleared() {
+ val publisher = ApplicationManager.getApplication()
+ .messageBus
+ .syncPublisher(ACCOUNT_TOKEN_CHANGED_TOPIC)
+ service().accounts.forEach(publisher::tokenChanged)
+ }
+ }
}
private fun createCredentialAttributes(accountId: String) = CredentialAttributes(createServiceName(accountId))
diff --git a/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubProjectDefaultAccountHolder.kt b/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubProjectDefaultAccountHolder.kt
index 5b6fc97e4ce7..31f72ea5b8ce 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubProjectDefaultAccountHolder.kt
+++ b/plugins/github/src/org/jetbrains/plugins/github/authentication/accounts/GithubProjectDefaultAccountHolder.kt
@@ -1,7 +1,6 @@
-// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.github.authentication.accounts
-import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.components.*
import com.intellij.openapi.project.Project
@@ -16,14 +15,6 @@ import org.jetbrains.plugins.github.util.GithubNotifications
internal class GithubProjectDefaultAccountHolder(private val project: Project) : PersistentStateComponent {
var account: GithubAccount? = null
- init {
- ApplicationManager.getApplication().messageBus.connect(project).subscribe(GithubAccountManager.ACCOUNT_REMOVED_TOPIC, object : AccountRemovedListener {
- override fun accountRemoved(removedAccount: GithubAccount) {
- if (account == removedAccount) account = null
- }
- })
- }
-
override fun getState(): AccountState {
return AccountState().apply { defaultAccountId = account?.id }
}
@@ -40,6 +31,13 @@ internal class GithubProjectDefaultAccountHolder(private val project: Project) :
}
return account
}
+
+ class RemovalListener(private val project: Project) : AccountRemovedListener {
+ override fun accountRemoved(removedAccount: GithubAccount) {
+ val holder = project.service()
+ if (holder.account == removedAccount) holder.account = null
+ }
+ }
}
internal class AccountState {
diff --git a/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubAccountGitAuthenticationFailureManager.kt b/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubAccountGitAuthenticationFailureManager.kt
index 868327110639..215868bf90f3 100644
--- a/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubAccountGitAuthenticationFailureManager.kt
+++ b/plugins/github/src/org/jetbrains/plugins/github/extensions/GithubAccountGitAuthenticationFailureManager.kt
@@ -1,28 +1,23 @@
-// Copyright 2000-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 file.
+// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.github.extensions
-import com.intellij.openapi.application.ApplicationManager
+import com.intellij.openapi.components.service
import org.jetbrains.plugins.github.authentication.accounts.AccountTokenChangedListener
import org.jetbrains.plugins.github.authentication.accounts.GithubAccount
-import org.jetbrains.plugins.github.authentication.accounts.GithubAccountManager
import java.util.concurrent.ConcurrentHashMap
class GithubAccountGitAuthenticationFailureManager {
private val storeMap = ConcurrentHashMap>()
- init {
- ApplicationManager.getApplication().messageBus
- .connect()
- .subscribe(GithubAccountManager.ACCOUNT_TOKEN_CHANGED_TOPIC, object : AccountTokenChangedListener {
- override fun tokenChanged(account: GithubAccount) {
- storeMap.remove(account)
- }
- })
- }
-
fun ignoreAccount(url: String, account: GithubAccount) {
storeMap.compute(account) { _, current -> current?.plus(url) ?: setOf(url) }
}
fun isAccountIgnored(url: String, account: GithubAccount): Boolean = storeMap[account]?.contains(url) ?: false
+
+ class AccountTokenListener : AccountTokenChangedListener {
+ override fun tokenChanged(account: GithubAccount) {
+ service().storeMap.remove(account)
+ }
+ }
}