FUS: implement util validator for plugin id and lang (FUS-394, FUS-395)

GitOrigin-RevId: 73915ac23a990c075a858bf88276f1a66f2d858e
This commit is contained in:
Svetlana.Zemlyanskaya
2019-05-21 13:21:24 +03:00
committed by intellij-monorepo-bot
parent 567c8c7167
commit f7b26dca7a
4 changed files with 62 additions and 5 deletions
@@ -0,0 +1,27 @@
// 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.collectors.fus;
import com.intellij.internal.statistic.eventLog.validator.ValidationResultType;
import com.intellij.internal.statistic.eventLog.validator.rules.EventContext;
import com.intellij.internal.statistic.eventLog.validator.rules.impl.CustomUtilsWhiteListRule;
import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
import com.intellij.lang.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class LangCustomRuleValidator extends CustomUtilsWhiteListRule {
@Override
public boolean acceptRuleId(@Nullable String ruleId) {
return "lang".equals(ruleId);
}
@NotNull
@Override
protected ValidationResultType doValidate(@NotNull String data, @NotNull EventContext context) {
if (data.equals("third.party")) return ValidationResultType.ACCEPTED;
final Language language = Language.findLanguageByID(data);
return language != null && PluginInfoDetectorKt.getPluginInfo(language.getClass()).isSafeToReport() ?
ValidationResultType.ACCEPTED : ValidationResultType.REJECTED;
}
}
@@ -0,0 +1,21 @@
// 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.collectors.fus;
import com.intellij.internal.statistic.eventLog.validator.ValidationResultType;
import com.intellij.internal.statistic.eventLog.validator.rules.EventContext;
import com.intellij.internal.statistic.eventLog.validator.rules.impl.CustomUtilsWhiteListRule;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PluginIdRuleValidator extends CustomUtilsWhiteListRule {
@Override
public boolean acceptRuleId(@Nullable String ruleId) {
return "plugin".equals(ruleId);
}
@NotNull
@Override
protected ValidationResultType doValidate(@NotNull String data, @NotNull EventContext context) {
return isPluginFromPluginRepository(data) ? ValidationResultType.ACCEPTED : ValidationResultType.REJECTED;
}
}
@@ -21,12 +21,19 @@ public abstract class CustomUtilsWhiteListRule extends PerformanceCareRule imple
protected static ValidationResultType acceptWhenReportedByJetbrainsPlugin(@NotNull EventContext context) {
if ("PLATFORM".equals(context.eventData.get("plugin_type"))) return ValidationResultType.ACCEPTED;
Object plugin = context.eventData.get("plugin");
if (plugin != null) {
PluginId pluginId = PluginId.findId(plugin.toString());
if (pluginId != null && PluginInfoDetectorKt.getPluginInfoById(pluginId).isDevelopedByJetBrains()) {
return ValidationResultType.ACCEPTED;
}
if (plugin != null && isPluginDevelopedByJB(plugin.toString())) {
return ValidationResultType.ACCEPTED;
}
return ValidationResultType.REJECTED;
}
protected static boolean isPluginDevelopedByJB(@NotNull String plugin) {
final PluginId pluginId = PluginId.findId(plugin);
return pluginId != null && PluginInfoDetectorKt.getPluginInfoById(pluginId).isDevelopedByJetBrains();
}
protected static boolean isPluginFromPluginRepository(@NotNull String plugin) {
final PluginId pluginId = PluginId.findId(plugin);
return pluginId != null && PluginInfoDetectorKt.getPluginInfoById(pluginId).isSafeToReport();
}
}
@@ -922,6 +922,8 @@
<statistics.validation.customUtilsWhiteListRule implementation="com.intellij.internal.statistic.collectors.fus.actions.persistence.ActionRuleValidator" />
<statistics.validation.customUtilsWhiteListRule implementation="com.intellij.internal.statistic.eventLog.validator.rules.impl.TestModeValidationRule" />
<statistics.validation.customUtilsWhiteListRule implementation="com.intellij.internal.statistic.collectors.fus.ClassNameRuleValidator" />
<statistics.validation.customUtilsWhiteListRule implementation="com.intellij.internal.statistic.collectors.fus.LangCustomRuleValidator" />
<statistics.validation.customUtilsWhiteListRule implementation="com.intellij.internal.statistic.collectors.fus.PluginIdRuleValidator" />
<statistics.validation.customUtilsWhiteListRule implementation="com.intellij.execution.impl.statistics.AbstractRunConfigurationTypeUsagesCollector$RunConfigurationUtilValidator" />
<statistics.projectUsagesCollector implementation="com.intellij.codeInsight.daemon.impl.tooltips.TooltipActionUsagesCollector"/>