mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FUS: extract plugin info methods into separate file
This commit is contained in:
+4
-3
@@ -10,7 +10,7 @@ import com.intellij.internal.statistic.eventLog.FeatureUsageLogger;
|
||||
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
|
||||
import com.intellij.internal.statistic.service.fus.collectors.FUSUsageContext;
|
||||
import com.intellij.internal.statistic.utils.PluginInfo;
|
||||
import com.intellij.internal.statistic.utils.StatisticsUtilKt;
|
||||
import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.RoamingType;
|
||||
@@ -34,6 +34,7 @@ public class ActionsCollectorImpl extends ActionsCollector implements Persistent
|
||||
private static final String DEFAULT_ID = "third.party.plugin.action";
|
||||
|
||||
private static final HashMap<String, String> ourPrefixesBlackList = new HashMap<>();
|
||||
|
||||
static {
|
||||
ourPrefixesBlackList.put("RemoteTool_", "Remote External Tool");
|
||||
ourPrefixesBlackList.put("Tool_", "External Tool");
|
||||
@@ -50,13 +51,13 @@ public class ActionsCollectorImpl extends ActionsCollector implements Persistent
|
||||
boolean isContextMenu = event != null && event.isFromContextMenu();
|
||||
final String place = event != null ? event.getPlace() : "";
|
||||
|
||||
final PluginInfo info = StatisticsUtilKt.getPluginInfo(context);
|
||||
final PluginInfo info = PluginInfoDetectorKt.getPluginInfo(context);
|
||||
final FeatureUsageDataBuilder builder = new FeatureUsageDataBuilder().
|
||||
addFeatureContext(FUSUsageContext.OS_CONTEXT).
|
||||
addPluginInfo(info).
|
||||
addData("context_menu", isContextMenu);
|
||||
|
||||
final boolean isDevelopedByJB = info.getType().isDevelopedByJetBrains();
|
||||
final boolean isDevelopedByJB = info.isDevelopedByJetBrains();
|
||||
if (isContextMenu && isDevelopedByJB) {
|
||||
builder.addPlace(place);
|
||||
}
|
||||
|
||||
+6
-4
@@ -11,7 +11,7 @@ import com.intellij.internal.statistic.eventLog.FeatureUsageLogger;
|
||||
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
|
||||
import com.intellij.internal.statistic.service.fus.collectors.FUSUsageContext;
|
||||
import com.intellij.internal.statistic.utils.PluginInfo;
|
||||
import com.intellij.internal.statistic.utils.StatisticsUtilKt;
|
||||
import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -49,9 +49,10 @@ public class IntentionsCollector implements PersistentStateComponent<IntentionsC
|
||||
|
||||
private static final List<String> PREFIXES_TO_STRIP = Arrays.asList("com.intellij.codeInsight.",
|
||||
"com.intellij.");
|
||||
|
||||
public void record(@NotNull IntentionAction action, @NotNull Language language) {
|
||||
final Class<?> clazz = getOriginalHandlerClass(action);
|
||||
final PluginInfo info = StatisticsUtilKt.getPluginInfo(clazz);
|
||||
final PluginInfo info = PluginInfoDetectorKt.getPluginInfo(clazz);
|
||||
|
||||
final Map<String, Object> data = new FeatureUsageDataBuilder().
|
||||
addFeatureContext(FUSUsageContext.OS_CONTEXT).
|
||||
@@ -59,7 +60,7 @@ public class IntentionsCollector implements PersistentStateComponent<IntentionsC
|
||||
addLanguage(language).
|
||||
createData();
|
||||
|
||||
final String id = info.getType().isSafeToReport() ? toReportedId(clazz) : DEFAULT_ID;
|
||||
final String id = info.isSafeToReport() ? toReportedId(clazz) : DEFAULT_ID;
|
||||
FeatureUsageLogger.INSTANCE.log(GROUP, id, data);
|
||||
}
|
||||
|
||||
@@ -71,7 +72,8 @@ public class IntentionsCollector implements PersistentStateComponent<IntentionsC
|
||||
if (delegate != action) {
|
||||
return getOriginalHandlerClass(delegate);
|
||||
}
|
||||
} else if (action instanceof QuickFixWrapper) {
|
||||
}
|
||||
else if (action instanceof QuickFixWrapper) {
|
||||
LocalQuickFix fix = ((QuickFixWrapper)action).getFix();
|
||||
if (fix != action) {
|
||||
handler = fix;
|
||||
|
||||
+10
-8
@@ -7,7 +7,7 @@ import com.intellij.internal.statistic.eventLog.FeatureUsageGroup;
|
||||
import com.intellij.internal.statistic.eventLog.FeatureUsageLogger;
|
||||
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
|
||||
import com.intellij.internal.statistic.utils.PluginInfo;
|
||||
import com.intellij.internal.statistic.utils.StatisticsUtilKt;
|
||||
import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.impl.ActionMenu;
|
||||
@@ -45,6 +45,7 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
private static final String GENERATED_ON_RUNTIME_ITEM = "generated.on.runtime";
|
||||
|
||||
private State myState = new State();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public State getState() {
|
||||
@@ -57,8 +58,8 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
|
||||
public void record(@NotNull AnAction action) {
|
||||
try {
|
||||
final PluginInfo info = StatisticsUtilKt.getPluginInfo(action.getClass());
|
||||
if (!info.getType().isDevelopedByJetBrains()) {
|
||||
final PluginInfo info = PluginInfoDetectorKt.getPluginInfo(action.getClass());
|
||||
if (!info.isDevelopedByJetBrains()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,8 +87,9 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
if (ranges.length == 0) throw new IllegalArgumentException("Constrains are empty");
|
||||
if (value < ranges[0]) return Pair.create(null, ranges[0]);
|
||||
for (int i = 1; i < ranges.length; i++) {
|
||||
if (ranges[i] <= ranges[i - 1])
|
||||
if (ranges[i] <= ranges[i - 1]) {
|
||||
throw new IllegalArgumentException("Constrains are unsorted");
|
||||
}
|
||||
|
||||
if (value < ranges[i]) {
|
||||
return Pair.create(ranges[i - 1], ranges[i]);
|
||||
@@ -98,8 +100,7 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected static String findBucket(long value, Function<? super Long, String> valueConverter, long...ranges) {
|
||||
protected static String findBucket(long value, Function<? super Long, String> valueConverter, long... ranges) {
|
||||
double[] dRanges = new double[ranges.length];
|
||||
for (int i = 0; i < dRanges.length; i++) {
|
||||
dRanges[i] = ranges[i];
|
||||
@@ -107,7 +108,7 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
return findBucket((double)value, (d) -> valueConverter.apply(d.longValue()), dRanges);
|
||||
}
|
||||
|
||||
protected static String findBucket(double value, Function<? super Double, String> valueConverter, double...ranges) {
|
||||
protected static String findBucket(double value, Function<? super Double, String> valueConverter, double... ranges) {
|
||||
for (double range : ranges) {
|
||||
if (range == value) {
|
||||
return valueConverter.apply(value);
|
||||
@@ -134,6 +135,7 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
}
|
||||
|
||||
private static final HashMap<String, String> ourBlackList = new HashMap<>();
|
||||
|
||||
static {
|
||||
ourBlackList.put("com.intellij.ide.ReopenProjectAction", "Reopen Project");
|
||||
ourBlackList.put("com.intellij.openapi.wm.impl.ProjectWindowAction", "Switch Project");
|
||||
@@ -163,7 +165,7 @@ public class MainMenuCollector implements PersistentStateComponent<MainMenuColle
|
||||
Object src = e.getSource();
|
||||
ArrayList<String> items = new ArrayList<>();
|
||||
while (src instanceof MenuItem) {
|
||||
items.add (0, ((MenuItem)src).getLabel());
|
||||
items.add(0, ((MenuItem)src).getLabel());
|
||||
src = ((MenuItem)src).getParent();
|
||||
}
|
||||
if (items.size() > 1) {
|
||||
|
||||
+3
-3
@@ -8,7 +8,7 @@ import com.intellij.internal.statistic.eventLog.FeatureUsageLogger;
|
||||
import com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent;
|
||||
import com.intellij.internal.statistic.service.fus.collectors.FUSUsageContext;
|
||||
import com.intellij.internal.statistic.utils.PluginInfo;
|
||||
import com.intellij.internal.statistic.utils.StatisticsUtilKt;
|
||||
import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.ActionWithDelegate;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
@@ -52,9 +52,9 @@ public class ToolbarClicksCollector implements PersistentStateComponent<ToolbarC
|
||||
}
|
||||
|
||||
public static void record(@NotNull AnAction action, String place) {
|
||||
final PluginInfo info = StatisticsUtilKt.getPluginInfo(action.getClass());
|
||||
final PluginInfo info = PluginInfoDetectorKt.getPluginInfo(action.getClass());
|
||||
|
||||
final boolean isDevelopedByJB = info.getType().isDevelopedByJetBrains();
|
||||
final boolean isDevelopedByJB = info.isDevelopedByJetBrains();
|
||||
final String key = isDevelopedByJB ? toReportedId(action) : DEFAULT_ID;
|
||||
|
||||
final FeatureUsageDataBuilder builder = new FeatureUsageDataBuilder().addPluginInfo(info);
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
// 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.utils
|
||||
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.ide.plugins.PluginManagerMain
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
|
||||
/**
|
||||
* Returns if this code is coming from IntelliJ platform, a plugin created by JetBrains (bundled or not) or from official repository,
|
||||
* so API from it may be reported
|
||||
*/
|
||||
fun getPluginInfo(clazz: Class<*>): PluginInfo {
|
||||
val pluginId = PluginManagerCore.getPluginByClassName(clazz.name) ?: return PluginInfo(PluginType.PLATFORM, null)
|
||||
return getPluginInfoById(pluginId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this code is coming from IntelliJ platform, a plugin created by JetBrains (bundled or not) or from official repository,
|
||||
* so API from it may be reported
|
||||
*/
|
||||
fun getPluginInfoById(pluginId: PluginId?): PluginInfo {
|
||||
if (pluginId == null) return PluginInfo(PluginType.UNKNOWN, null)
|
||||
|
||||
return getPluginInfoByDescriptor(PluginManager.getPlugin(pluginId))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this code is coming from IntelliJ platform, a plugin created by JetBrains (bundled or not) or from official repository,
|
||||
* so API from it may be reported
|
||||
*/
|
||||
fun getPluginInfoByDescriptor(plugin: IdeaPluginDescriptor?): PluginInfo {
|
||||
if (plugin == null) return PluginInfo(PluginType.UNKNOWN, null)
|
||||
|
||||
val id = plugin.pluginId.idString
|
||||
if (PluginManagerMain.isDevelopedByJetBrains(plugin)) {
|
||||
return if (plugin.isBundled) {
|
||||
PluginInfo(PluginType.JB_BUNDLED, id)
|
||||
}
|
||||
else {
|
||||
PluginInfo(PluginType.JB_NOT_BUNDLED, id)
|
||||
}
|
||||
}
|
||||
|
||||
// only plugins installed from some repository (not bundled and not provided via classpath in development IDE instance -
|
||||
// they are also considered bundled) would be reported
|
||||
val listed = !plugin.isBundled && isSafeToReport(id)
|
||||
return if (listed) {
|
||||
PluginInfo(PluginType.LISTED, id)
|
||||
}
|
||||
else {
|
||||
PluginInfo(PluginType.NOT_LISTED, null)
|
||||
}
|
||||
}
|
||||
|
||||
enum class PluginType {
|
||||
PLATFORM, JB_BUNDLED, JB_NOT_BUNDLED, LISTED, NOT_LISTED, UNKNOWN;
|
||||
|
||||
fun isPlatformOrJBBundled(): Boolean {
|
||||
return this == PLATFORM || this == JB_BUNDLED
|
||||
}
|
||||
|
||||
fun isDevelopedByJetBrains(): Boolean {
|
||||
return isPlatformOrJBBundled() || this == JB_NOT_BUNDLED
|
||||
}
|
||||
|
||||
fun isSafeToReport(): Boolean {
|
||||
return isDevelopedByJetBrains() || this == LISTED
|
||||
}
|
||||
}
|
||||
|
||||
class PluginInfo(val type: PluginType, val id: String?) {
|
||||
|
||||
fun isDevelopedByJetBrains(): Boolean {
|
||||
return type.isDevelopedByJetBrains()
|
||||
}
|
||||
|
||||
fun isSafeToReport(): Boolean {
|
||||
return type.isSafeToReport()
|
||||
}
|
||||
}
|
||||
@@ -286,49 +286,6 @@ fun getPluginType(clazz: Class<*>): PluginType {
|
||||
return if (listed) PluginType.LISTED else PluginType.NOT_LISTED
|
||||
}
|
||||
|
||||
fun getPluginInfo(clazz: Class<*>): PluginInfo {
|
||||
val pluginId = PluginManagerCore.getPluginByClassName(clazz.name) ?: return PluginInfo(PluginType.PLATFORM, null)
|
||||
val plugin = PluginManager.getPlugin(pluginId) ?: return PluginInfo(PluginType.UNKNOWN, null)
|
||||
|
||||
val id = plugin.pluginId.idString
|
||||
if (PluginManagerMain.isDevelopedByJetBrains(plugin)) {
|
||||
return if (plugin.isBundled) {
|
||||
PluginInfo(PluginType.JB_BUNDLED, id)
|
||||
}
|
||||
else {
|
||||
PluginInfo(PluginType.JB_NOT_BUNDLED, id)
|
||||
}
|
||||
}
|
||||
|
||||
// only plugins installed from some repository (not bundled and not provided via classpath in development IDE instance -
|
||||
// they are also considered bundled) would be reported
|
||||
val listed = !plugin.isBundled && isSafeToReport(pluginId.idString)
|
||||
return if (listed) {
|
||||
PluginInfo(PluginType.LISTED, id)
|
||||
}
|
||||
else {
|
||||
PluginInfo(PluginType.NOT_LISTED, null)
|
||||
}
|
||||
}
|
||||
|
||||
enum class PluginType {
|
||||
PLATFORM, JB_BUNDLED, JB_NOT_BUNDLED, LISTED, NOT_LISTED, UNKNOWN;
|
||||
|
||||
fun isPlatformOrJBBundled(): Boolean {
|
||||
return this == PLATFORM || this == JB_BUNDLED
|
||||
}
|
||||
|
||||
fun isDevelopedByJetBrains(): Boolean {
|
||||
return isPlatformOrJBBundled() || this == JB_NOT_BUNDLED
|
||||
}
|
||||
|
||||
fun isSafeToReport(): Boolean {
|
||||
return isDevelopedByJetBrains() || this == LISTED;
|
||||
}
|
||||
}
|
||||
|
||||
class PluginInfo(val type: PluginType, val id: String?)
|
||||
|
||||
private class DelayModificationTracker internal constructor(delay: Long, unit: TimeUnit) : ModificationTracker {
|
||||
|
||||
private val myStamp = System.currentTimeMillis()
|
||||
|
||||
Reference in New Issue
Block a user