From d38e14815537f0bc16ae13cd880669339ba0d16f Mon Sep 17 00:00:00 2001 From: "Svetlana.Zemlyanskaya" Date: Thu, 1 Aug 2019 18:10:12 +0200 Subject: [PATCH] FUS: load global enums and regexps in test whitelist GitOrigin-RevId: 4e8a18189804dac180beedda28a28c1b8268f2b4 --- .../EventLogTestWhitelistPersistence.java | 2 +- .../whitelist/WhitelistTestGroupStorage.java | 52 +++++++++++++++++-- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/validator/persistence/EventLogTestWhitelistPersistence.java b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/validator/persistence/EventLogTestWhitelistPersistence.java index ec0c096411bf..8fbd688941f9 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/validator/persistence/EventLogTestWhitelistPersistence.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/validator/persistence/EventLogTestWhitelistPersistence.java @@ -86,7 +86,7 @@ public class EventLogTestWhitelistPersistence extends BaseEventLogWhitelistPersi } @NotNull - public static WLGroups loadTestWhitelist(@NotNull EventLogTestWhitelistPersistence persistence) { + public static WLGroups loadTestWhitelist(@NotNull BaseEventLogWhitelistPersistence persistence) { final String existing = persistence.getCachedWhitelist(); if (StringUtil.isNotEmpty(existing)) { final WLGroups loaded = FUStatisticsWhiteListGroupsService.parseWhiteListContent(existing); diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/whitelist/WhitelistTestGroupStorage.java b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/whitelist/WhitelistTestGroupStorage.java index c5fb389b016e..50b52fe8705b 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/whitelist/WhitelistTestGroupStorage.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/eventLog/whitelist/WhitelistTestGroupStorage.java @@ -1,9 +1,13 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.internal.statistic.eventLog.whitelist; +import com.intellij.internal.statistic.eventLog.EventLogConfiguration; import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogTestWhitelistPersistence; +import com.intellij.internal.statistic.eventLog.validator.persistence.EventLogWhitelistPersistence; import com.intellij.internal.statistic.eventLog.validator.rules.beans.WhiteListGroupRules; -import com.intellij.internal.statistic.service.fus.FUStatisticsWhiteListGroupsService; +import com.intellij.internal.statistic.service.fus.FUStatisticsWhiteListGroupsService.WLGroups; +import com.intellij.internal.statistic.service.fus.FUStatisticsWhiteListGroupsService.WLRule; +import com.intellij.openapi.util.BuildNumber; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,6 +15,7 @@ import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.Map; import java.util.concurrent.ConcurrentMap; +import java.util.stream.Collectors; public class WhitelistTestGroupStorage extends BaseWhitelistStorage { private static final ConcurrentMap ourTestInstances = ContainerUtil.newConcurrentMap(); @@ -20,6 +25,8 @@ public class WhitelistTestGroupStorage extends BaseWhitelistStorage { @NotNull private final EventLogTestWhitelistPersistence myTestWhitelistPersistence; @NotNull + private final EventLogWhitelistPersistence myWhitelistPersistence; + @NotNull private final String myRecorderId; public static WhitelistTestGroupStorage getInstance(@NotNull String recorderId) { @@ -31,6 +38,7 @@ public class WhitelistTestGroupStorage extends BaseWhitelistStorage { private WhitelistTestGroupStorage(@NotNull String recorderId) { myTestWhitelistPersistence = new EventLogTestWhitelistPersistence(recorderId); + myWhitelistPersistence = new EventLogWhitelistPersistence(recorderId); updateValidators(); myRecorderId = recorderId; } @@ -49,15 +57,51 @@ public class WhitelistTestGroupStorage extends BaseWhitelistStorage { synchronized (myLock) { eventsValidators.clear(); isWhiteListInitialized.set(false); - FUStatisticsWhiteListGroupsService.WLGroups groups = - EventLogTestWhitelistPersistence.loadTestWhitelist(myTestWhitelistPersistence); - final Map result = createValidators(groups); + final WLGroups productionGroups = EventLogTestWhitelistPersistence.loadTestWhitelist(myWhitelistPersistence); + final WLGroups testGroups = EventLogTestWhitelistPersistence.loadTestWhitelist(myTestWhitelistPersistence); + final Map result = createValidators(testGroups, productionGroups); eventsValidators.putAll(result); isWhiteListInitialized.set(true); } } + @NotNull + protected Map createValidators(@NotNull WLGroups groups, @NotNull WLGroups productionGroups) { + final WLRule rules = merge(groups.rules, productionGroups.rules); + final BuildNumber buildNumber = BuildNumber.fromString(EventLogConfiguration.INSTANCE.getBuild()); + return groups.groups.stream(). + filter(group -> group.accepts(buildNumber)). + collect(Collectors.toMap(group -> group.id, group -> createRules(group, rules))); + } + + @Nullable + private static WLRule merge(@Nullable WLRule testRules, @Nullable WLRule productionTestRules) { + if (testRules == null) return productionTestRules; + if (productionTestRules == null) return testRules; + + final WLRule rule = new WLRule(); + copyRules(rule, productionTestRules); + copyRules(rule, testRules); + return rule; + } + + private static void copyRules(@NotNull WLRule to, @NotNull WLRule from) { + if (to.enums == null) { + to.enums = ContainerUtil.newHashMap(); + } + if (to.regexps == null) { + to.regexps = ContainerUtil.newHashMap(); + } + + if (from.enums != null) { + to.enums.putAll(from.enums); + } + if (from.regexps != null) { + to.regexps.putAll(from.regexps); + } + } + public void addGroupWithCustomRules(@NotNull String groupId, @NotNull String rules) throws IOException { EventLogTestWhitelistPersistence.addGroupWithCustomRules(myRecorderId, groupId, rules); updateValidators();