From 27fd64ed4276f907079f41920fda3c4a6d530b2a Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 12 Apr 2019 15:07:54 +0300 Subject: [PATCH] Enable registration of CIDR bundle to prevent test failure in AS 3.5 (KT-26337) --- .../kotlin/idea/testResourceBundle.kt.as32 | 1 - .../kotlin/idea/testResourceBundle.kt.as33 | 1 - .../kotlin/idea/testResourceBundle.kt.as34 | 1 - .../kotlin/idea/testResourceBundle.kt.as35 | 39 +++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as35 diff --git a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as32 b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as32 index ce452fb7f93..f053236f81d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as32 +++ b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as32 @@ -15,7 +15,6 @@ import java.lang.IllegalStateException private const val CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME = "com.jetbrains.cidr.lang.OCFeatureStatisticsBundleProvider" // Remove the function, when there's no dependency to cidr during running Kotlin tests. -// BUNCH: as33 fun registerAdditionalResourceBundleInTests() { if (!ApplicationManager.getApplication().isUnitTestMode) { return diff --git a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as33 b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as33 index ffc87550944..a6f976d9f78 100644 --- a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as33 +++ b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as33 @@ -15,7 +15,6 @@ import java.lang.IllegalStateException private const val CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME = "com.jetbrains.cidr.lang.OCFeatureStatisticsBundleProvider" // Remove the function, when there's no dependency to cidr during running Kotlin tests. -// BUNCH: as33 fun registerAdditionalResourceBundleInTests() { if (!ApplicationManager.getApplication().isUnitTestMode) { return diff --git a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as34 b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as34 index ffc87550944..a6f976d9f78 100644 --- a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as34 +++ b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as34 @@ -15,7 +15,6 @@ import java.lang.IllegalStateException private const val CIDR_FEATURE_STATISTICS_PROVIDER_FQNAME = "com.jetbrains.cidr.lang.OCFeatureStatisticsBundleProvider" // Remove the function, when there's no dependency to cidr during running Kotlin tests. -// BUNCH: as33 fun registerAdditionalResourceBundleInTests() { if (!ApplicationManager.getApplication().isUnitTestMode) { return diff --git a/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as35 b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as35 new file mode 100644 index 00000000000..a6f976d9f78 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/testResourceBundle.kt.as35 @@ -0,0 +1,39 @@ +/* + * 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" + +// Remove the function, when there's no dependency to cidr during running Kotlin tests. +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) { + return + } + + val cidrFSBundleProvider = cidrFSBundleProviderClass.newInstance() as FeatureStatisticsBundleProvider + + Extensions.getRootArea().getExtensionPoint(FeatureStatisticsBundleProvider.EP_NAME).registerExtension(cidrFSBundleProvider) +} \ No newline at end of file