// 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.plugins;

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.internal.statistic.beans.MetricEvent;
import com.intellij.internal.statistic.beans.MetricEventFactoryKt;
import com.intellij.internal.statistic.eventLog.FeatureUsageData;
import com.intellij.internal.statistic.service.fus.collectors.ApplicationUsagesCollector;
import com.intellij.internal.statistic.utils.PluginInfo;
import com.intellij.internal.statistic.utils.PluginInfoDetectorKt;
import com.intellij.openapi.extensions.PluginId;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;

import java.util.Set;

final class PluginsUsagesCollector extends ApplicationUsagesCollector {
  @Override
  @NotNull
  public String getGroupId() {
    return "plugins";
  }

  @Override
  @NotNull
  public Set<MetricEvent> getMetrics() {
    Set<MetricEvent> result = new THashSet<>();
    for (PluginId id : PluginManagerCore.disabledPlugins()) {
      IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(id);
      if (plugin == null) {
        continue;
      }

      PluginInfo info = PluginInfoDetectorKt.getPluginInfoByDescriptor(plugin);
      FeatureUsageData data = new FeatureUsageData().addPluginInfo(info);
      result.add(MetricEventFactoryKt.newMetric("disabled.plugin", data));
    }

    for (IdeaPluginDescriptor descriptor : PluginManagerCore.getLoadedPlugins()) {
      if (!descriptor.isBundled()) {
        continue;
      }

      PluginInfo info = PluginInfoDetectorKt.getPluginInfoByDescriptor(descriptor);
      FeatureUsageData data = new FeatureUsageData().addPluginInfo(info);
      result.add(MetricEventFactoryKt.newMetric("enabled.not.bundled.plugin", data));
    }
    return result;
  }
}
@@ -1004,16 +1004,75 @@
 %22;%0A  %7D%0A%0A
+  @Override%0A  public int getVersion() %7B%0A    return 2;%0A  %7D%0A%0A
   @Overr
@@ -1078,32 +1078,32 @@
 ride%0A  @NotNull%0A
-
   public Set%3CMet
@@ -1241,132 +1241,8 @@
 ) %7B%0A
-      IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(id);%0A      if (plugin == null) %7B%0A        continue;%0A      %7D%0A%0A
     
@@ -1301,25 +1301,13 @@
 foBy
-Descriptor(plugin
+Id(id
 );%0A 
@@ -1554,16 +1554,42 @@
     if (
+descriptor.isEnabled() && 
 !descrip
@@ -1613,33 +1613,8 @@
 %7B%0A  
-      continue;%0A      %7D%0A%0A
     
@@ -1691,32 +1691,34 @@
 criptor);%0A      
+ 
+ 
 FeatureUsageData
@@ -1761,32 +1761,34 @@
 uginInfo(info);%0A
+  
       result.add
@@ -1853,24 +1853,32 @@
 n%22, data));%0A
+      %7D%0A
     %7D%0A    re

fix reporting enabled plugins