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