FUS: extract a method to retrieve project id

This commit is contained in:
Svetlana.Zemlyanskaya
2018-09-27 16:37:46 +02:00
parent ff00602b19
commit d5fb87d805
3 changed files with 12 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
package com.intellij.configurationStore.statistic.eventLog
import com.intellij.internal.statistic.eventLog.FeatureUsageLogger
import com.intellij.internal.statistic.utils.getProjectId
import com.intellij.openapi.components.State
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
@@ -53,7 +54,7 @@ open class FeatureUsageSettingsEventPrinter {
}
val isDefaultProject = project?.isDefault == true
val hash = if (!isDefaultProject) toHash(project?.name) else null
val hash = if (!isDefaultProject) toHash(project) else null
for (accessor in accessors) {
val type = accessor.genericType
@@ -84,9 +85,9 @@ open class FeatureUsageSettingsEventPrinter {
FeatureUsageLogger.logState(groupId, eventId, data)
}
internal fun toHash(projectName: String?): String? {
return projectName?.let {
return projectName.hashCode().toString()
internal fun toHash(project: Project?): String? {
return project?.let {
return getProjectId(project)
}
}
}

View File

@@ -24,9 +24,8 @@ class FeatureUsageSettingsEventsTest {
@Test
fun projectNameToHash() {
val name = "project-name"
val printer = TestFeatureUsageSettingsEventsPrinter()
assertNotNull(printer.toHash(name))
assertNotNull(printer.toHash(projectRule.project))
}
@Test

View File

@@ -19,10 +19,16 @@ import com.intellij.ide.plugins.PluginManager
import com.intellij.ide.plugins.PluginManagerMain
import com.intellij.internal.statistic.beans.UsageDescriptor
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.getProjectCacheFileName
import com.intellij.util.containers.ObjectIntHashMap
import gnu.trove.THashSet
import java.util.*
fun getProjectId(project: Project): String {
return project.getProjectCacheFileName(false, ".").hashCode().toString()
}
fun isDevelopedByJetBrains(pluginId: PluginId?): Boolean {
val plugin = PluginManager.getPlugin(pluginId)
return plugin == null || plugin.isBundled || PluginManagerMain.isDevelopedByJetBrains(plugin.vendor)