diff --git a/platform/platform-tests/testSrc/com/intellij/internal/statistics/serialization/SerializationHelperTest.kt b/platform/platform-tests/testSrc/com/intellij/internal/statistics/serialization/SerializationHelperTest.kt index 2a12b7d4e8a0..d81bc4cbf551 100644 --- a/platform/platform-tests/testSrc/com/intellij/internal/statistics/serialization/SerializationHelperTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/internal/statistics/serialization/SerializationHelperTest.kt @@ -71,14 +71,14 @@ internal class SerializationHelperTest : BasePlatformTestCase() { val groupDescriptor = GroupDescriptor("testId", "counter", 1, setOf(eventSchemeDescriptor, eventSchemeDescriptor), "classNameTest", "recorderTest", "pluginIdTest") val serializationText = SerializationHelper.serialize(groupDescriptor) - val realText = File(getTestDataRoot()+ "SerializationGroupDescriptor.json").readText(Charsets.UTF_8) + val realText = File(getTestDataRoot() + "SerializationGroupDescriptor.json").readText(Charsets.UTF_8) Assertions.assertEquals(realText, serializationText) } @org.junit.Test fun testDeserializationGroupDescriptor() { - val groupDescriptor = File(getTestDataRoot()+ "SerializationGroupDescriptor.json").readText(Charsets.UTF_8) + val groupDescriptor = File(getTestDataRoot() + "SerializationGroupDescriptor.json").readText(Charsets.UTF_8) val deserializationObject = SerializationHelper.deserialize(groupDescriptor, GroupDescriptor::class.java) val serializationText = SerializationHelper.serialize(deserializationObject) @@ -90,14 +90,15 @@ internal class SerializationHelperTest : BasePlatformTestCase() { fun testSerializationFeatureUsageData() { val data = FeatureUsageData("FUS") data.addData("durationMs", 1) - data.addData("version","unknown") + data.addData("version", "unknown") data.addData("file_path", "testData/Serialization.json") val serializationText = SerializationHelper.serializeToSingleLine(data.build()) - val realText = File(getTestDataRoot()+ "SerializationFeatureUsageData.json").readText(Charsets.UTF_8) + val realText = File(getTestDataRoot() + "SerializationFeatureUsageData.json").readText(Charsets.UTF_8) Assertions.assertEquals(realText, serializationText) } + @Test fun testSerializationEventLogExternalSettings() { val eventLogMajorVersionBorders = EventLogMajorVersionBorders() @@ -164,7 +165,7 @@ internal class SerializationHelperTest : BasePlatformTestCase() { eventGroupRemoteDescriptor.versions?.add(EventGroupRemoteDescriptors.GroupVersionRange("1", "2")) eventGroupRemoteDescriptors.groups.add(eventGroupRemoteDescriptor) - val serializationText = StringWriter(1024) + val serializationText = StringWriter(1024) SerializationHelper.serialize(serializationText, eventGroupRemoteDescriptors) val realText = File(getTestDataRoot() + "SerializationEventGroupRemoteDescriptors.json").readText(Charsets.UTF_8) @@ -247,6 +248,7 @@ internal class SerializationHelperTest : BasePlatformTestCase() { Assertions.assertEquals(eventsScheme, serializationText) } + @Test fun testSerializationEventsSchemeArray() { val filedDescriptor = FieldDescriptor("plugin", setOf("{util#class_name}", "{util#plugin}"), FieldDataType.ARRAY) diff --git a/platform/statistics/config/src/com/intellij/internal/statistic/config/SerializationHelper.kt b/platform/statistics/config/src/com/intellij/internal/statistic/config/SerializationHelper.kt index caa16ba8d2bc..7bac6dc27251 100644 --- a/platform/statistics/config/src/com/intellij/internal/statistic/config/SerializationHelper.kt +++ b/platform/statistics/config/src/com/intellij/internal/statistic/config/SerializationHelper.kt @@ -18,7 +18,6 @@ import java.io.Writer object SerializationHelper { private val SERIALIZATION_TO_WRITER_MAPPER: JsonMapper by lazy { val printer: DefaultPrettyPrinter = CustomPrettyPrinter() - printer.indentArraysWith(DefaultIndenter()) JsonMapper .builder() @@ -31,7 +30,6 @@ object SerializationHelper { private val SERIALIZATION_MAPPER: JsonMapper by lazy { val printer: DefaultPrettyPrinter = CustomPrettyPrinter() - printer.indentArraysWith(DefaultIndenter()) JsonMapper .builder() @@ -125,6 +123,11 @@ object SerializationHelper { } class CustomPrettyPrinter : DefaultPrettyPrinter { + init { + _objectIndenter = DefaultIndenter(" ", "\n") + _arrayIndenter = DefaultIndenter(" ", "\n") + } + constructor() : super() constructor(base: DefaultPrettyPrinter?) : super(base) diff --git a/platform/statistics/devkit/src/com/intellij/internal/statistic/devkit/actions/scheme/EventsTestSchemeGroupConfiguration.kt b/platform/statistics/devkit/src/com/intellij/internal/statistic/devkit/actions/scheme/EventsTestSchemeGroupConfiguration.kt index a0d8ae424721..7f3ac1fa742e 100644 --- a/platform/statistics/devkit/src/com/intellij/internal/statistic/devkit/actions/scheme/EventsTestSchemeGroupConfiguration.kt +++ b/platform/statistics/devkit/src/com/intellij/internal/statistic/devkit/actions/scheme/EventsTestSchemeGroupConfiguration.kt @@ -247,43 +247,6 @@ class EventsTestSchemeGroupConfiguration(private val project: Project, return validateTestSchemeGroup(project, currentGroup, groupIdTextField, tempFile) } - private fun createEventsScheme(generatedScheme: List): HashMap { - val eventsScheme = HashMap() - for (group in generatedScheme) { - val validationRules = createValidationRules(group) - if (validationRules != null) { - eventsScheme[group.id] = SerializationHelper.serialize(validationRules) - } - } - return eventsScheme - } - - private fun createValidationRules(group: GroupDescriptor): EventGroupRemoteDescriptors.GroupRemoteRule? { - val eventIds = hashSetOf() - val eventData = hashMapOf>() - val events = group.schema - for (event in events) { - eventIds.add(event.event) - for (dataField in event.fields) { - val validationRule = dataField.value - val validationRules = eventData[dataField.path] - if (validationRules == null) { - eventData[dataField.path] = validationRule.toHashSet() - } - else { - validationRules.addAll(validationRule) - } - } - } - - if (eventIds.isEmpty() && eventData.isEmpty()) return null - - val rules = EventGroupRemoteDescriptors.GroupRemoteRule() - rules.event_id = eventIds - rules.event_data = eventData - return rules - } - companion object { private val LOG = logger() @@ -335,6 +298,43 @@ class EventsTestSchemeGroupConfiguration(private val project: Project, } } + internal fun createEventsScheme(generatedScheme: List): HashMap { + val eventsScheme = HashMap() + for (group in generatedScheme) { + val validationRules = createValidationRules(group) + if (validationRules != null) { + eventsScheme[group.id] = SerializationHelper.serialize(validationRules) + } + } + return eventsScheme + } + + private fun createValidationRules(group: GroupDescriptor): EventGroupRemoteDescriptors.GroupRemoteRule? { + val eventIds = hashSetOf() + val eventData = hashMapOf>() + val events = group.schema + for (event in events) { + eventIds.add(event.event) + for (dataField in event.fields) { + val validationRule = dataField.value + val validationRules = eventData[dataField.path] + if (validationRules == null) { + eventData[dataField.path] = validationRule.toHashSet() + } + else { + validationRules.addAll(validationRule) + } + } + } + + if (eventIds.isEmpty() && eventData.isEmpty()) return null + + val rules = EventGroupRemoteDescriptors.GroupRemoteRule() + rules.event_id = eventIds + rules.event_data = eventData + return rules + } + private fun isValidJson(customRules: String): Boolean { try { val mapper = ObjectMapper() diff --git a/platform/statistics/devkit/testSrc/com/intellij/internal/statistic/actions/devkit/scheme/EventsTestSchemeGroupConfigurationTest.kt b/platform/statistics/devkit/testSrc/com/intellij/internal/statistic/actions/devkit/scheme/EventsTestSchemeGroupConfigurationTest.kt index 8ccd5a256ea1..ba5fc015ddd2 100644 --- a/platform/statistics/devkit/testSrc/com/intellij/internal/statistic/actions/devkit/scheme/EventsTestSchemeGroupConfigurationTest.kt +++ b/platform/statistics/devkit/testSrc/com/intellij/internal/statistic/actions/devkit/scheme/EventsTestSchemeGroupConfigurationTest.kt @@ -3,6 +3,10 @@ package com.intellij.internal.statistic.actions.devkit.scheme import com.intellij.internal.statistic.StatisticsBundle import com.intellij.internal.statistic.devkit.actions.scheme.EventsTestSchemeGroupConfiguration +import com.intellij.internal.statistic.eventLog.events.scheme.EventDescriptor +import com.intellij.internal.statistic.eventLog.events.scheme.FieldDescriptor +import com.intellij.internal.statistic.eventLog.events.scheme.GroupDescriptor +import com.intellij.openapi.util.text.StringUtil import com.intellij.testFramework.UsefulTestCase import com.intellij.testFramework.fixtures.BasePlatformTestCase import com.jetbrains.fus.reporting.model.metadata.EventGroupRemoteDescriptors @@ -16,6 +20,17 @@ class EventsTestSchemeGroupConfigurationTest : BasePlatformTestCase() { System.setProperty("fus.internal.test.mode", "true") } + fun testEventsSchemeSeparators() { + val fieldDescriptor = FieldDescriptor("plugin", setOf("{util#class_name}", "{util#plugin}")) + val eventDescriptor = EventDescriptor("testEvent", setOf(fieldDescriptor)) + val groupDescriptor = GroupDescriptor("testId", "counter", 1, setOf(eventDescriptor), + "classNameTest", "recorderTest", "pluginIdTest") + + val scheme = EventsTestSchemeGroupConfiguration.createEventsScheme(listOf(groupDescriptor)) + + scheme["testId"]?.let { StringUtil.assertValidSeparators(it) } + } + fun testNotValidJson() { val rules = """ {