mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-323916 set '\n' as line separator in jackson pretty printer
GitOrigin-RevId: 97fdde2759272dcca607276b63f09d21babe735d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f289a3925f
commit
ff8154d658
+7
-5
@@ -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)
|
||||
|
||||
+5
-2
@@ -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)
|
||||
|
||||
|
||||
+37
-37
@@ -247,43 +247,6 @@ class EventsTestSchemeGroupConfiguration(private val project: Project,
|
||||
return validateTestSchemeGroup(project, currentGroup, groupIdTextField, tempFile)
|
||||
}
|
||||
|
||||
private fun createEventsScheme(generatedScheme: List<GroupDescriptor>): HashMap<String, String> {
|
||||
val eventsScheme = HashMap<String, String>()
|
||||
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<String>()
|
||||
val eventData = hashMapOf<String, MutableSet<String>>()
|
||||
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<EventsTestSchemeGroupConfiguration>()
|
||||
|
||||
@@ -335,6 +298,43 @@ class EventsTestSchemeGroupConfiguration(private val project: Project,
|
||||
}
|
||||
}
|
||||
|
||||
internal fun createEventsScheme(generatedScheme: List<GroupDescriptor>): HashMap<String, String> {
|
||||
val eventsScheme = HashMap<String, String>()
|
||||
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<String>()
|
||||
val eventData = hashMapOf<String, MutableSet<String>>()
|
||||
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()
|
||||
|
||||
+15
@@ -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 = """
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user