DoNotStorePasswordTest — check project and app components appcode/163.1714
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Wed, 20 Jul 2016 08:54:20 +0000 (10:54 +0200)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Wed, 20 Jul 2016 08:54:20 +0000 (10:54 +0200)
platform/configuration-store-impl/src/ExportSettingsAction.kt
platform/configuration-store-impl/testSrc/DoNotStorePasswordTest.kt

index a2428f71437590b73f2ab2a834c3aa7c1d557a8e..e5ff1d7d0ba7fcb1016101fddf6dcc2bc7cde65d 100644 (file)
@@ -31,6 +31,7 @@ import com.intellij.openapi.application.ApplicationManager
 import com.intellij.openapi.application.PathManager
 import com.intellij.openapi.application.impl.ApplicationImpl
 import com.intellij.openapi.components.*
+import com.intellij.openapi.components.ex.ComponentManagerEx
 import com.intellij.openapi.components.impl.ServiceManagerImpl
 import com.intellij.openapi.components.impl.stores.StateStorageManager
 import com.intellij.openapi.components.impl.stores.StoreUtil
@@ -167,7 +168,7 @@ fun getExportableComponentsMap(onlyExisting: Boolean,
   }
 
   @Suppress("DEPRECATION")
-  ApplicationManager.getApplication().getComponents(ExportableApplicationComponent::class.java).forEach(processor)
+  (ApplicationManager.getApplication() as ComponentManagerEx).getComponentInstancesOfType(ExportableApplicationComponent::class.java).forEach(processor)
   ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent::class.java).forEach(processor)
 
   val configPath = storageManager.expandMacros(ROOT_CONFIG)
index bbeb2e3e7ea49a1909f782e7518ad560f3467a13..7dc929190067696904ebfd95a7c642f51afb856b 100644 (file)
@@ -26,9 +26,39 @@ class DoNotStorePasswordTest {
 
   @Test
   fun printPasswordComponents() {
-    checkPassword(ApplicationManager.getApplication() as ApplicationImpl)
+    val processor = PairProcessor<Class<*>, PluginDescriptor> { aClass, pluginDescriptor ->
+      val stateAnnotation = StoreUtil.getStateSpec(aClass)
+      if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty()) {
+        return@PairProcessor true
+      }
+
+      for (i in aClass.genericInterfaces) {
+        if (checkType(i)) {
+          return@PairProcessor true
+        }
+      }
+
+
+      // public static class Project extends WebServersConfigManagerBaseImpl<WebServersConfigManagerBaseImpl.State> {
+      // so, we check not only PersistentStateComponent
+      checkType(aClass.genericSuperclass)
+
+      true
+    }
+
+    val app = ApplicationManager.getApplication() as ApplicationImpl
+    ServiceManagerImpl.processAllImplementationClasses(app, processor)
     // yes, we don't use default project here to be sure
-    checkPassword(projectRule.project as ComponentManagerImpl)
+    ServiceManagerImpl.processAllImplementationClasses(projectRule.project as ComponentManagerImpl, processor)
+
+    @Suppress("DEPRECATION")
+    for (c in app.getComponentInstancesOfType(PersistentStateComponent::class.java)) {
+      processor.process(c.javaClass, null)
+    }
+    @Suppress("DEPRECATION")
+    for (c in (projectRule.project as ComponentManagerImpl).getComponentInstancesOfType(PersistentStateComponent::class.java)) {
+      processor.process(c.javaClass, null)
+    }
   }
 
   fun isSavePasswordField(name: String) = name.contains("remember", ignoreCase = true) || name.contains("keep", ignoreCase = true) || name.contains("save", ignoreCase = true)
@@ -58,29 +88,6 @@ class DoNotStorePasswordTest {
     }
   }
 
-  private fun checkPassword(componentManager: ComponentManagerImpl) {
-    ServiceManagerImpl.processAllImplementationClasses(componentManager,
-        PairProcessor<Class<*>, PluginDescriptor> { aClass, pluginDescriptor ->
-          val stateAnnotation = StoreUtil.getStateSpec(aClass)
-          if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty()) {
-            return@PairProcessor true
-          }
-
-          for (i in aClass.genericInterfaces) {
-            if (checkType(i)) {
-              return@PairProcessor true
-            }
-          }
-
-
-          // public static class Project extends WebServersConfigManagerBaseImpl<WebServersConfigManagerBaseImpl.State> {
-          // so, we check not only PersistentStateComponent
-          checkType(aClass.genericSuperclass)
-
-          true
-        })
-  }
-
   private fun checkType(type: Type): Boolean {
     if (type !is ParameterizedType || !PersistentStateComponent::class.java.isAssignableFrom(type.rawType as Class<*>)) {
       return false