From e1f746f23cbc1aa967756f656e48a11094b06857 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 24 Sep 2018 14:56:03 +0300 Subject: [PATCH] Resolve "key is not found in bundle" exception from tests in AS Android Studio idea.jar is taken from clion projects and has IdeSpecificFeatures.xml and ProductivityFeaturesRegistry.xml files that mention function that have to be found in ProductivityFeaturesRegistry. Unfortunately, correspondent CLion bundle is not registered in tests, and this causes a lot of tests fail. --- .../kotlin/idea/PluginStartupComponent.java | 6 +++ .../kotlin/idea/testResourceBundle.kt | 9 +++++ .../kotlin/idea/testResourceBundle.kt.as31 | 38 +++++++++++++++++++ .../kotlin/idea/testResourceBundle.kt.as32 | 38 +++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt create mode 100644 idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as31 create mode 100644 idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as32 diff --git a/idea/src/org/jetbrains/kotlin/idea/PluginStartupComponent.java b/idea/src/org/jetbrains/kotlin/idea/PluginStartupComponent.java index ed74e7aa2bb..f5a647bbad1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/PluginStartupComponent.java +++ b/idea/src/org/jetbrains/kotlin/idea/PluginStartupComponent.java @@ -35,6 +35,8 @@ import org.jetbrains.kotlin.utils.PathUtil; import java.io.File; import java.io.IOException; +import static org.jetbrains.kotlin.idea.TestResourceBundleKt.registerAdditionalResourceBundleInTests; + public class PluginStartupComponent implements ApplicationComponent { private static final Logger LOG = Logger.getInstance(PluginStartupComponent.class); @@ -52,6 +54,10 @@ public class PluginStartupComponent implements ApplicationComponent { @Override public void initComponent() { + if (ApplicationManager.getApplication().isUnitTestMode()) { + registerAdditionalResourceBundleInTests(); + } + registerPathVariable(); try { diff --git a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt new file mode 100644 index 00000000000..297d5805e62 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt @@ -0,0 +1,9 @@ +/* + * 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 + +fun registerAdditionalResourceBundleInTests() { +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as31 b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as31 new file mode 100644 index 00000000000..d48f9598c24 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as31 @@ -0,0 +1,38 @@ +/* + * 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. + */ + +@file:Suppress("DEPRECATION") + +package org.jetbrains.kotlin.idea + +import com.intellij.featureStatistics.FeatureStatisticsBundleProvider +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.extensions.Extensions +import java.lang.IllegalStateException + +private const val CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME = "com.jetbrains.cidr.lang.OCFeatureStatisticsBundleProvider" + +fun registerAdditionalResourceBundleInTests() { + if (!ApplicationManager.getApplication().isUnitTestMode) { + return + } + + val isAlreadyRegistered = FeatureStatisticsBundleProvider.EP_NAME.extensions.any { provider -> + provider.javaClass.name == CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME + } + if (isAlreadyRegistered) { + throw IllegalStateException("Remove this registration for the current platform: bundle is already registered.") + } + + val cidrFSBundleProviderClass = try { + Class.forName(CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME) + } catch (_: ClassNotFoundException) { + throw IllegalStateException("Remove this registration for the current platform: class wasn't found.") + } + + val cidrFSBundleProvider = cidrFSBundleProviderClass.newInstance() as FeatureStatisticsBundleProvider + + Extensions.getRootArea().getExtensionPoint(FeatureStatisticsBundleProvider.EP_NAME).registerExtension(cidrFSBundleProvider) +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as32 b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as32 new file mode 100644 index 00000000000..d48f9598c24 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as32 @@ -0,0 +1,38 @@ +/* + * 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. + */ + +@file:Suppress("DEPRECATION") + +package org.jetbrains.kotlin.idea + +import com.intellij.featureStatistics.FeatureStatisticsBundleProvider +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.extensions.Extensions +import java.lang.IllegalStateException + +private const val CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME = "com.jetbrains.cidr.lang.OCFeatureStatisticsBundleProvider" + +fun registerAdditionalResourceBundleInTests() { + if (!ApplicationManager.getApplication().isUnitTestMode) { + return + } + + val isAlreadyRegistered = FeatureStatisticsBundleProvider.EP_NAME.extensions.any { provider -> + provider.javaClass.name == CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME + } + if (isAlreadyRegistered) { + throw IllegalStateException("Remove this registration for the current platform: bundle is already registered.") + } + + val cidrFSBundleProviderClass = try { + Class.forName(CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME) + } catch (_: ClassNotFoundException) { + throw IllegalStateException("Remove this registration for the current platform: class wasn't found.") + } + + val cidrFSBundleProvider = cidrFSBundleProviderClass.newInstance() as FeatureStatisticsBundleProvider + + Extensions.getRootArea().getExtensionPoint(FeatureStatisticsBundleProvider.EP_NAME).registerExtension(cidrFSBundleProvider) +} \ No newline at end of file