mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
usages statistics refactored + fixed tests
This commit is contained in:
+7
-7
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraries.impl;
|
||||
|
||||
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
|
||||
import com.intellij.internal.statistic.UsagesCollector;
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
@@ -34,12 +35,13 @@ import java.util.*;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class LibraryUsageCollector extends UsagesCollector {
|
||||
public class LibraryUsageCollector extends AbstractApplicationUsagesCollector {
|
||||
|
||||
@NonNls private static final String GROUP_ID = "libraries";
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
|
||||
public Set<UsageDescriptor> getProjectUsages(@Nullable Project project) {
|
||||
if (project == null) return Collections.emptySet();
|
||||
|
||||
final Set<LibraryKind<?>> usedKinds = new HashSet<LibraryKind<?>>();
|
||||
@@ -56,15 +58,13 @@ public class LibraryUsageCollector extends UsagesCollector {
|
||||
|
||||
final HashSet<UsageDescriptor> usageDescriptors = new HashSet<UsageDescriptor>();
|
||||
for (LibraryKind<?> kind : usedKinds) {
|
||||
final GroupDescriptor group = GroupDescriptor.create(GROUP_ID);
|
||||
usageDescriptors.add(new UsageDescriptor(group, kind.getKindId(), 1));
|
||||
usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
|
||||
}
|
||||
return usageDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getGroupId() {
|
||||
return GROUP_ID;
|
||||
}
|
||||
public GroupDescriptor getGroupId() {
|
||||
return GroupDescriptor.create(GROUP_ID); }
|
||||
}
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.facet.impl.statistics;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class FrameworkStatisticsPersistence {
|
||||
private Map<String, Set<UsageDescriptor>> myFrameworks = new HashMap<String, Set<UsageDescriptor>>();
|
||||
|
||||
public FrameworkStatisticsPersistence() {
|
||||
}
|
||||
|
||||
public void persistFrameworks(@NotNull Project project, @NotNull Set<UsageDescriptor> frameworks) {
|
||||
myFrameworks.put(project.getName(), frameworks);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Set<UsageDescriptor>> getFrameworks() {
|
||||
return myFrameworks;
|
||||
}
|
||||
|
||||
}
|
||||
-146
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.facet.impl.statistics;
|
||||
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ProjectManagerListener;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@State(
|
||||
name = "FrameworkUsages",
|
||||
storages = {
|
||||
@Storage(
|
||||
id = "frameworks",
|
||||
file = "$APP_CONFIG$/framework.usages.xml"
|
||||
)}
|
||||
)
|
||||
public class FrameworkStatisticsPersistenceComponent extends FrameworkStatisticsPersistence
|
||||
implements ApplicationComponent, PersistentStateComponent<Element> {
|
||||
private static final String TOKENIZER = ",";
|
||||
|
||||
@NonNls private static final String PROJECT_TAG = "project";
|
||||
@NonNls private static final String PROJECT_ID_ATTR = "id";
|
||||
@NonNls private static final String FRAMEWORKS_ATTR = "frameworks";
|
||||
|
||||
public FrameworkStatisticsPersistenceComponent() {
|
||||
}
|
||||
|
||||
public static FrameworkStatisticsPersistenceComponent getInstance() {
|
||||
return ApplicationManager.getApplication().getComponent(FrameworkStatisticsPersistenceComponent.class);
|
||||
}
|
||||
|
||||
public void loadState(final Element element) {
|
||||
List projectsList = element.getChildren(PROJECT_TAG);
|
||||
for (Object project : projectsList) {
|
||||
Element projectElement = (Element)project;
|
||||
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
|
||||
String frameworks = projectElement.getAttributeValue(FRAMEWORKS_ATTR);
|
||||
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
|
||||
Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>();
|
||||
for (String key : StringUtil.split(frameworks, TOKENIZER)) {
|
||||
frameworkDescriptors.add(new UsageDescriptor(FrameworkUsagesCollector.getGroupDescriptor(), key, 1));
|
||||
}
|
||||
getFrameworks().put(projectId, frameworkDescriptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
|
||||
for (Map.Entry<String, Set<UsageDescriptor>> frameworks : getFrameworks().entrySet()) {
|
||||
Element projectElement = new Element(PROJECT_TAG);
|
||||
projectElement.setAttribute(PROJECT_ID_ATTR, frameworks.getKey());
|
||||
projectElement.setAttribute(FRAMEWORKS_ATTR, joinUsages(frameworks.getValue()));
|
||||
|
||||
element.addContent(projectElement);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
|
||||
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
|
||||
@Override
|
||||
public String fun(UsageDescriptor usageDescriptor) {
|
||||
return usageDescriptor.getKey();
|
||||
}
|
||||
}, TOKENIZER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNls
|
||||
public File[] getExportFiles() {
|
||||
return new File[]{PathManager.getOptionsFile("framework.usages")};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPresentableName() {
|
||||
return "Framework Usages";
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
return "FrameworkStatisticsPersistenceComponent";
|
||||
}
|
||||
|
||||
public void initComponent() {
|
||||
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
|
||||
@Override
|
||||
public void projectOpened(Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCloseProject(Project project) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosed(Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosing(Project project) {
|
||||
if (project != null) {
|
||||
FrameworkUsagesCollector.persistProjectUsages(project);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void disposeComponent() {
|
||||
}
|
||||
}
|
||||
+6
-59
@@ -17,84 +17,31 @@ package com.intellij.facet.impl.statistics;
|
||||
|
||||
import com.intellij.facet.Facet;
|
||||
import com.intellij.facet.FacetManager;
|
||||
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.internal.statistic.UsagesCollector;
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FrameworkUsagesCollector extends UsagesCollector {
|
||||
public class FrameworkUsagesCollector extends AbstractApplicationUsagesCollector {
|
||||
public static final String GROUP_ID = "frameworks";
|
||||
|
||||
public static void persistProjectUsages(@NotNull Project project) {
|
||||
persistProjectUsages(project, getProjectUsages(project));
|
||||
}
|
||||
|
||||
public static void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
|
||||
persistProjectUsages(project, usages, FrameworkStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
public static void persistProjectUsages(@NotNull Project project,
|
||||
@NotNull Set<UsageDescriptor> usages,
|
||||
@NotNull FrameworkStatisticsPersistence persistence) {
|
||||
persistence.persistFrameworks(project, usages);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getApplicationUsages() {
|
||||
return getApplicationUsages(FrameworkStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getApplicationUsages(@NotNull final FrameworkStatisticsPersistence persistence) {
|
||||
final Map<String, Integer> facets = new HashMap<String, Integer>();
|
||||
|
||||
for (Set<UsageDescriptor> frameworks : persistence.getFrameworks().values()) {
|
||||
for (UsageDescriptor framework : frameworks) {
|
||||
final String key = framework.getKey();
|
||||
final Integer count = facets.get(key);
|
||||
facets.put(key, count == null ? 1 : count.intValue() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return ContainerUtil.map2Set(facets.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(Map.Entry<String, Integer> facet) {
|
||||
return new UsageDescriptor(getGroupDescriptor(), facet.getKey(), facet.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getGroupId() {
|
||||
return GROUP_ID;
|
||||
}
|
||||
|
||||
public static GroupDescriptor getGroupDescriptor() {
|
||||
public GroupDescriptor getGroupId() {
|
||||
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
|
||||
if (project != null) {
|
||||
persistProjectUsages(project, getProjectUsages(project));
|
||||
}
|
||||
|
||||
return getApplicationUsages();
|
||||
}
|
||||
|
||||
public static Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
|
||||
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
|
||||
final Set<String> facets = new HashSet<String>();
|
||||
for (Module module : ModuleManager.getInstance(project).getModules()) {
|
||||
for (Facet facet : FacetManager.getInstance(module).getAllFacets()) {
|
||||
@@ -105,7 +52,7 @@ public class FrameworkUsagesCollector extends UsagesCollector {
|
||||
return ContainerUtil.map2Set(facets, new Function<String, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(String facet) {
|
||||
return new UsageDescriptor(getGroupDescriptor(), facet, 1);
|
||||
return new UsageDescriptor(facet, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+3
-4
@@ -29,8 +29,8 @@ public class FeaturesUsageCollector extends UsagesCollector {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getGroupId() {
|
||||
return "productivity";
|
||||
public GroupDescriptor getGroupId() {
|
||||
return GroupDescriptor.create("productivity", GroupDescriptor.LOWER_PRIORITY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -44,8 +44,7 @@ public class FeaturesUsageCollector extends UsagesCollector {
|
||||
for (String featureId : registry.getFeatureIds()) {
|
||||
final FeatureDescriptor featureDescriptor = registry.getFeatureDescriptor(featureId);
|
||||
if (featureDescriptor != null) {
|
||||
usages.add(new UsageDescriptor(
|
||||
GroupDescriptor.create(getGroupId(), GroupDescriptor.LOWER_PRIORITY), featureId, featureDescriptor.getUsageCount()));
|
||||
usages.add(new UsageDescriptor(featureId, featureDescriptor.getUsageCount()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ public class PluginsUsagesCollector extends UsagesCollector {
|
||||
private static final String GROUP_ID = "disabled-plugins";
|
||||
|
||||
@NotNull
|
||||
public String getGroupId() {
|
||||
return GROUP_ID;
|
||||
public GroupDescriptor getGroupId() {
|
||||
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -39,7 +39,7 @@ public class PluginsUsagesCollector extends UsagesCollector {
|
||||
return ContainerUtil.map2Set(PluginManager.getDisabledPlugins(), new Function<String, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(String descriptor) {
|
||||
return new UsageDescriptor(GroupDescriptor.create(getGroupId(), GroupDescriptor.HIGHER_PRIORITY), descriptor, 1);
|
||||
return new UsageDescriptor(descriptor, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.internal.statistic;
|
||||
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistence;
|
||||
import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractApplicationUsagesCollector extends UsagesCollector {
|
||||
public void persistProjectUsages(@NotNull Project project) {
|
||||
persistProjectUsages(project, getProjectUsages(project));
|
||||
}
|
||||
|
||||
public void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
|
||||
persistProjectUsages(project, usages, ApplicationStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
public void persistProjectUsages(@NotNull Project project,
|
||||
@NotNull Set<UsageDescriptor> usages,
|
||||
@NotNull ApplicationStatisticsPersistence persistence) {
|
||||
persistence.persistFrameworks(getGroupId(), project, usages);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getApplicationUsages() {
|
||||
return getApplicationUsages(ApplicationStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getApplicationUsages(@NotNull final ApplicationStatisticsPersistence persistence) {
|
||||
final Map<String, Integer> facets = new HashMap<String, Integer>();
|
||||
|
||||
for (Set<UsageDescriptor> frameworks : persistence.getApplicationData(getGroupId()).values()) {
|
||||
for (UsageDescriptor framework : frameworks) {
|
||||
final String key = framework.getKey();
|
||||
final Integer count = facets.get(key);
|
||||
facets.put(key, count == null ? 1 : count.intValue() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return ContainerUtil.map2Set(facets.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(Map.Entry<String, Integer> facet) {
|
||||
return new UsageDescriptor(facet.getKey(), facet.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
|
||||
if (project != null) {
|
||||
persistProjectUsages(project, getProjectUsages(project));
|
||||
}
|
||||
|
||||
return getApplicationUsages();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract Set<UsageDescriptor> getProjectUsages(@NotNull Project project);
|
||||
}
|
||||
+178
-147
@@ -30,7 +30,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.text.DateFormatUtil;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -38,173 +38,204 @@ import java.util.*;
|
||||
|
||||
public class StatisticsUploadAssistant {
|
||||
|
||||
public String getData() {
|
||||
return getData(Collections.<String>emptySet());
|
||||
}
|
||||
public String getData() {
|
||||
return getData(Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
public static boolean showNotification() {
|
||||
return UsageStatisticsPersistenceComponent.getInstance().isShowNotification();
|
||||
}
|
||||
public static boolean showNotification() {
|
||||
return UsageStatisticsPersistenceComponent.getInstance().isShowNotification();
|
||||
}
|
||||
|
||||
public static boolean isTimeToSend() {
|
||||
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
|
||||
public static boolean isTimeToSend() {
|
||||
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
|
||||
|
||||
return isTimeToSend(UsageStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
return isTimeToSend(UsageStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
public static boolean isTimeToSend(UsageStatisticsPersistenceComponent settings) {
|
||||
final long timeDelta = System.currentTimeMillis() - settings.getLastTimeSent();
|
||||
public static boolean isTimeToSend(UsageStatisticsPersistenceComponent settings) {
|
||||
final long timeDelta = System.currentTimeMillis() - settings.getLastTimeSent();
|
||||
|
||||
return Math.abs(timeDelta) > settings.getPeriod().getMillis();
|
||||
}
|
||||
return Math.abs(timeDelta) > settings.getPeriod().getMillis();
|
||||
}
|
||||
|
||||
public static boolean isSendAllowed() {
|
||||
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
|
||||
public static boolean isSendAllowed() {
|
||||
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
|
||||
|
||||
return isSendAllowed(UsageStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
return isSendAllowed(UsageStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
public static boolean isSendAllowed(final SentUsagesPersistence settings) {
|
||||
return settings != null && settings.isAllowed();
|
||||
}
|
||||
public static boolean isSendAllowed(final SentUsagesPersistence settings) {
|
||||
return settings != null && settings.isAllowed();
|
||||
}
|
||||
|
||||
public static String getData(@NotNull Set<String> disabledGroups) {
|
||||
return getStringPatch(disabledGroups, ProjectManager.getInstance().getOpenProjects());
|
||||
}
|
||||
public static String getData(@NotNull Set<String> disabledGroups) {
|
||||
return getStringPatch(disabledGroups, ProjectManager.getInstance().getOpenProjects());
|
||||
}
|
||||
|
||||
public static void persistSentPatch(@NotNull String patchStr) {
|
||||
persistSentPatch(patchStr, UsageStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
public static void persistSentPatch(@NotNull String patchStr) {
|
||||
persistSentPatch(patchStr, UsageStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
public static void persistSentPatch(@NotNull String patchStr, @NotNull SentUsagesPersistence persistenceComponent) {
|
||||
Set<PatchedUsage> patchedUsages =
|
||||
ContainerUtil.map2Set(ConvertUsagesUtil.convertString(patchStr), new Function<UsageDescriptor, PatchedUsage>() {
|
||||
@Override
|
||||
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
|
||||
return new PatchedUsage(usageDescriptor);
|
||||
public static void persistSentPatch(@NotNull String patchStr, @NotNull SentUsagesPersistence persistenceComponent) {
|
||||
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = mapToPatchedUsagesMap(ConvertUsagesUtil.convertString(patchStr));
|
||||
|
||||
if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@NotNull Set<String> disabledGroups, Project... project) {
|
||||
return getStringPatch(disabledGroups, project, UsageStatisticsPersistenceComponent.getInstance(), 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@NotNull Set<String> disabledGroups,
|
||||
@NotNull Project[] projects,
|
||||
@NotNull SentUsagesPersistence usagesPersistence,
|
||||
int maxSize) {
|
||||
final Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = getPatchedUsages(disabledGroups, projects, usagesPersistence);
|
||||
|
||||
return getStringPatch(patchedUsages, maxSize);
|
||||
}
|
||||
|
||||
public static String getStringPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages, int maxSize) {
|
||||
if (patchedUsages.size() == 0) return "";
|
||||
|
||||
String patchStr = ConvertUsagesUtil.convertUsages(patchedUsages);
|
||||
if (maxSize > 0 && patchStr.getBytes().length > maxSize) {
|
||||
patchStr = ConvertUsagesUtil.cutPatchString(patchStr, maxSize);
|
||||
}
|
||||
});
|
||||
|
||||
if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@NotNull Set<String> disabledGroups, Project... project) {
|
||||
return getStringPatch(disabledGroups, project, UsageStatisticsPersistenceComponent.getInstance(), 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@NotNull Set<String> disabledGroups,
|
||||
@NotNull Project[] projects,
|
||||
@NotNull SentUsagesPersistence usagesPersistence,
|
||||
int maxSize) {
|
||||
final Set<PatchedUsage> patchedUsages = getPatchedUsages(disabledGroups, projects, usagesPersistence);
|
||||
|
||||
return getStringPatch(patchedUsages, maxSize);
|
||||
}
|
||||
|
||||
public static String getStringPatch(@NotNull Set<PatchedUsage> patchedUsages, int maxSize) {
|
||||
if (patchedUsages.size() == 0) return "";
|
||||
|
||||
String patchStr = ConvertUsagesUtil.convertUsages(patchedUsages);
|
||||
if (maxSize > 0 && patchStr.getBytes().length > maxSize) {
|
||||
patchStr = ConvertUsagesUtil.cutPatchString(patchStr, maxSize);
|
||||
return patchStr;
|
||||
}
|
||||
|
||||
return patchStr;
|
||||
}
|
||||
@NotNull
|
||||
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull Set<String> disabledGroups,
|
||||
@NotNull Project[] projects,
|
||||
@NotNull SentUsagesPersistence usagesPersistence) {
|
||||
Map<GroupDescriptor, Set<PatchedUsage>> usages = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
|
||||
|
||||
@NotNull
|
||||
public static Set<PatchedUsage> getPatchedUsages(@NotNull Set<String> disabledGroups,
|
||||
@NotNull Project[] projects,
|
||||
@NotNull SentUsagesPersistence usagesPersistence) {
|
||||
Set<PatchedUsage> usages = new HashSet<PatchedUsage>();
|
||||
for (Project project : projects) {
|
||||
final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages = getAllUsages(project, disabledGroups);
|
||||
final Map<GroupDescriptor, Set<UsageDescriptor>> sentUsages = filterDisabled(disabledGroups, usagesPersistence.getSentUsages());
|
||||
|
||||
for (Project project : projects) {
|
||||
final Set<UsageDescriptor> allUsages = getAllUsages(project, disabledGroups);
|
||||
final Set<UsageDescriptor> sentUsages = filterDisabled(disabledGroups, usagesPersistence.getSentUsages());
|
||||
|
||||
usages.addAll(getPatchedUsages(allUsages, sentUsages));
|
||||
}
|
||||
return usages;
|
||||
}
|
||||
|
||||
private static Set<UsageDescriptor> filterDisabled(@NotNull Set<String> disabledGroups, @NotNull Set<UsageDescriptor> usages) {
|
||||
Set<UsageDescriptor> filtered = new HashSet<UsageDescriptor>();
|
||||
|
||||
for (UsageDescriptor usage : usages) {
|
||||
if (!disabledGroups.contains(usage.getGroup().getId())) {
|
||||
filtered.add(usage);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<PatchedUsage> getPatchedUsages(@NotNull final Set<UsageDescriptor> allUsages,
|
||||
@NotNull SentUsagesPersistence usagesPersistence) {
|
||||
return getPatchedUsages(allUsages, usagesPersistence.getSentUsages());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<PatchedUsage> getPatchedUsages(@NotNull final Set<UsageDescriptor> allUsages, final Set<UsageDescriptor> sentUsages) {
|
||||
final Set<PatchedUsage> patchedUsages = ContainerUtil.map2Set(allUsages, new Function<UsageDescriptor, PatchedUsage>() {
|
||||
@Override
|
||||
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
|
||||
return new PatchedUsage(usageDescriptor);
|
||||
}
|
||||
});
|
||||
|
||||
for (UsageDescriptor sentUsage : sentUsages) {
|
||||
final PatchedUsage descriptor = findDescriptor(patchedUsages, Pair.create(sentUsage.getGroup(), sentUsage.getKey()));
|
||||
if (descriptor == null) {
|
||||
patchedUsages.add(new PatchedUsage(sentUsage.getGroup(), sentUsage.getKey(), -sentUsage.getValue()));
|
||||
}
|
||||
else {
|
||||
descriptor.subValue(sentUsage.getValue());
|
||||
}
|
||||
usages.putAll(getPatchedUsages(allUsages, sentUsages));
|
||||
}
|
||||
return usages;
|
||||
}
|
||||
|
||||
return packCollection(patchedUsages, new Condition<PatchedUsage>() {
|
||||
@Override
|
||||
public boolean value(PatchedUsage patchedUsage) {
|
||||
return patchedUsage.getDelta() != 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
@NotNull
|
||||
private static Map<GroupDescriptor, Set<UsageDescriptor>> filterDisabled(@NotNull Set<String> disabledGroups, @NotNull Map<GroupDescriptor, Set<UsageDescriptor>> usages) {
|
||||
Map<GroupDescriptor, Set<UsageDescriptor>> filtered = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
|
||||
|
||||
@NotNull
|
||||
private static <T> Set<T> packCollection(@NotNull Collection<T> set, @NotNull Condition<T> condition) {
|
||||
final Set<T> result = new LinkedHashSet<T>();
|
||||
for (T t : set) {
|
||||
if (condition.value(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> usage : usages.entrySet()) {
|
||||
if (!disabledGroups.contains(usage.getKey().getId())) {
|
||||
filtered.put(usage.getKey(), usage.getValue());
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T extends UsageDescriptor> T findDescriptor(@NotNull Set<T> descriptors,
|
||||
@NotNull final Pair<GroupDescriptor, String> id) {
|
||||
return ContainerUtil.find(descriptors, new Condition<T>() {
|
||||
@Override
|
||||
public boolean value(T t) {
|
||||
return id.getFirst().equals(t.getGroup()) && id.getSecond().equals(t.getKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<UsageDescriptor> getAllUsages(@Nullable Project project, @NotNull Set<String> disabledGroups) {
|
||||
final Set<UsageDescriptor> usageDescriptors = new TreeSet<UsageDescriptor>();
|
||||
|
||||
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
|
||||
if (!disabledGroups.contains(usagesCollector.getGroupId())) {
|
||||
usageDescriptors.addAll(usagesCollector.getUsages(project));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages,
|
||||
@NotNull SentUsagesPersistence usagesPersistence) {
|
||||
return getPatchedUsages(allUsages, usagesPersistence.getSentUsages());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages, final Map<GroupDescriptor, Set<UsageDescriptor>> sentUsageMap) {
|
||||
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = mapToPatchedUsagesMap(allUsages);
|
||||
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> sentUsageEntry : sentUsageMap.entrySet()) {
|
||||
final GroupDescriptor sentUsageGroupDescriptor = sentUsageEntry.getKey();
|
||||
|
||||
final Set<UsageDescriptor> sentUsages = sentUsageEntry.getValue();
|
||||
|
||||
for (UsageDescriptor sentUsage : sentUsages) {
|
||||
final PatchedUsage descriptor = findDescriptor(patchedUsages, Pair.create(sentUsageGroupDescriptor, sentUsage.getKey()));
|
||||
if (descriptor == null) {
|
||||
if (!patchedUsages.containsKey(sentUsageGroupDescriptor)) {
|
||||
patchedUsages.put(sentUsageGroupDescriptor, new HashSet<PatchedUsage>());
|
||||
}
|
||||
patchedUsages.get(sentUsageGroupDescriptor).add(new PatchedUsage(sentUsage.getKey(), -sentUsage.getValue()));
|
||||
} else {
|
||||
descriptor.subValue(sentUsage.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return packCollection(patchedUsages, new Condition<PatchedUsage>() {
|
||||
@Override
|
||||
public boolean value(PatchedUsage patchedUsage) {
|
||||
return patchedUsage.getDelta() != 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Map<GroupDescriptor, Set<PatchedUsage>> mapToPatchedUsagesMap(Map<GroupDescriptor, Set<UsageDescriptor>> allUsages) {
|
||||
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : allUsages.entrySet()) {
|
||||
patchedUsages.put(entry.getKey(), ContainerUtil.map2Set(entry.getValue(), new Function<UsageDescriptor, PatchedUsage>() {
|
||||
@Override
|
||||
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
|
||||
return new PatchedUsage(usageDescriptor);
|
||||
}
|
||||
}));
|
||||
}
|
||||
return patchedUsages;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Map<GroupDescriptor, Set<PatchedUsage>> packCollection(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages, Condition<PatchedUsage> condition) {
|
||||
Map<GroupDescriptor, Set<PatchedUsage>> result = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
|
||||
for (GroupDescriptor descriptor : patchedUsages.keySet()) {
|
||||
final Set<PatchedUsage> usages = packCollection(patchedUsages.get(descriptor), condition);
|
||||
if (usages.size() > 0) {
|
||||
result.put(descriptor, usages);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <T> Set<T> packCollection(@NotNull Collection<T> set, @NotNull Condition<T> condition) {
|
||||
final Set<T> result = new LinkedHashSet<T>();
|
||||
for (T t : set) {
|
||||
if (condition.value(t)) {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T extends UsageDescriptor> T findDescriptor(@NotNull Map<GroupDescriptor, Set<T>> descriptors,
|
||||
@NotNull final Pair<GroupDescriptor, String> id) {
|
||||
final Set<T> usages = descriptors.get(id.getFirst());
|
||||
if (usages == null) return null;
|
||||
|
||||
return ContainerUtil.find(usages, new Condition<T>() {
|
||||
@Override
|
||||
public boolean value(T t) {
|
||||
return id.getSecond().equals(t.getKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> getAllUsages(@Nullable Project project, @NotNull Set<String> disabledGroups) {
|
||||
Map<GroupDescriptor, Set<UsageDescriptor>> usageDescriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
|
||||
|
||||
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
|
||||
final GroupDescriptor groupDescriptor = usagesCollector.getGroupId();
|
||||
|
||||
if (!disabledGroups.contains(groupDescriptor.getId())) {
|
||||
usageDescriptors.put(groupDescriptor, usagesCollector.getUsages(project));
|
||||
}
|
||||
}
|
||||
|
||||
return usageDescriptors;
|
||||
}
|
||||
|
||||
return usageDescriptors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.internal.statistic;
|
||||
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
@@ -28,5 +29,5 @@ public abstract class UsagesCollector {
|
||||
|
||||
public abstract @NotNull Set<UsageDescriptor> getUsages(@Nullable Project project);
|
||||
|
||||
public abstract @NotNull String getGroupId();
|
||||
public abstract @NotNull GroupDescriptor getGroupId();
|
||||
}
|
||||
|
||||
+23
-28
@@ -16,6 +16,8 @@
|
||||
package com.intellij.internal.statistic.beans;
|
||||
|
||||
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ConvertUsagesUtil {
|
||||
@@ -26,19 +28,14 @@ public class ConvertUsagesUtil {
|
||||
private ConvertUsagesUtil() {
|
||||
}
|
||||
|
||||
// @NotNull
|
||||
public static String convertUsages(Set<? extends UsageDescriptor> descriptors) {
|
||||
assert descriptors != null;
|
||||
final Map<GroupDescriptor, Set<UsageDescriptor>> descriptorGroups = groupDescriptors(descriptors);
|
||||
|
||||
return convertUsages(descriptorGroups);
|
||||
}
|
||||
|
||||
// @NotNull
|
||||
public static String convertUsages(Map<GroupDescriptor, Set<UsageDescriptor>> map) {
|
||||
public static <T extends UsageDescriptor> String convertUsages(Map<GroupDescriptor, Set<T>> map) {
|
||||
assert map != null;
|
||||
final Map<GroupDescriptor, Set<T>> sortedMap = sortDescriptorsByPriority(map);
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : map.entrySet()) {
|
||||
for (Map.Entry<GroupDescriptor, Set<T>> entry : sortedMap.entrySet()) {
|
||||
buffer.append(entry.getKey().getId());
|
||||
buffer.append(GROUP_SEPARATOR);
|
||||
buffer.append(convertValueMap(entry.getValue()));
|
||||
@@ -49,7 +46,7 @@ public class ConvertUsagesUtil {
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static String convertValueMap(Set<UsageDescriptor> descriptors) {
|
||||
public static String convertValueMap(Set<? extends UsageDescriptor> descriptors) {
|
||||
assert descriptors != null;
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
for (UsageDescriptor usageDescriptor : descriptors) {
|
||||
@@ -76,14 +73,14 @@ public class ConvertUsagesUtil {
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Set<UsageDescriptor> convertString(String usages) {
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertString(String usages) {
|
||||
assert usages != null;
|
||||
Set<UsageDescriptor> descriptors = new LinkedHashSet<UsageDescriptor>();
|
||||
Map<GroupDescriptor, Set<UsageDescriptor>> descriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
|
||||
for (String groupStr : usages.split(GROUPS_SEPARATOR.toString())) {
|
||||
if (!isEmptyOrSpaces(groupStr)) {
|
||||
final StringPair group = getPair(groupStr, GROUP_SEPARATOR.toString());
|
||||
if (group != null) {
|
||||
descriptors.addAll(convertValueString(GroupDescriptor.create(group.first), group.second));
|
||||
descriptors.putAll(convertValueString(GroupDescriptor.create(group.first), group.second));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,9 +88,9 @@ public class ConvertUsagesUtil {
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Set<UsageDescriptor> convertValueString(GroupDescriptor groupId, String valueData) {
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertValueString(GroupDescriptor groupId, String valueData) {
|
||||
assert groupId != null;
|
||||
final Set<UsageDescriptor> descriptors = new LinkedHashSet<UsageDescriptor>();
|
||||
final Map<GroupDescriptor, Set<UsageDescriptor>> descriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
|
||||
for (String value : valueData.split(GROUP_VALUE_SEPARATOR.toString())) {
|
||||
if (!isEmptyOrSpaces(value)) {
|
||||
final StringPair pair = getPair(value, "=");
|
||||
@@ -102,7 +99,10 @@ public class ConvertUsagesUtil {
|
||||
if (!isEmptyOrSpaces(count)) {
|
||||
try {
|
||||
final int i = Integer.parseInt(count);
|
||||
descriptors.add(new UsageDescriptor(groupId, pair.first, i));
|
||||
if (!descriptors.containsKey(groupId)) {
|
||||
descriptors.put(groupId, new LinkedHashSet<UsageDescriptor>());
|
||||
}
|
||||
descriptors.get(groupId).add(new UsageDescriptor(pair.first, i));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
@@ -129,22 +129,17 @@ public class ConvertUsagesUtil {
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> groupDescriptors(Set<? extends UsageDescriptor> descriptors) {
|
||||
public static <T extends UsageDescriptor> Map<GroupDescriptor, Set<T>> sortDescriptorsByPriority(Map<GroupDescriptor, Set<T>> descriptors) {
|
||||
assert descriptors != null;
|
||||
final SortedMap<GroupDescriptor, Set<UsageDescriptor>> map = new TreeMap<GroupDescriptor, Set<UsageDescriptor>>(new Comparator<GroupDescriptor>() {
|
||||
final SortedMap<GroupDescriptor, Set<T>> map = new TreeMap<GroupDescriptor, Set<T>>(new Comparator<GroupDescriptor>() {
|
||||
public int compare(GroupDescriptor g1, GroupDescriptor g2) {
|
||||
final int priority = (int) (g2.getPriority() - g1.getPriority());
|
||||
return priority == 0 ? g1.getId().compareTo(g2.getId()) : priority;
|
||||
}
|
||||
});
|
||||
|
||||
for (UsageDescriptor descriptor : descriptors) {
|
||||
final GroupDescriptor group = descriptor.getGroup();
|
||||
if (!map.containsKey(group)) {
|
||||
map.put(group, new HashSet<UsageDescriptor>());
|
||||
}
|
||||
map.get(group).add(descriptor);
|
||||
}
|
||||
map.putAll(descriptors);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -158,7 +153,7 @@ public class ConvertUsagesUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmptyOrSpaces(final String s) {
|
||||
return s == null || s.trim().length() == 0;
|
||||
}
|
||||
public static boolean isEmptyOrSpaces(final String s) {
|
||||
return s == null || s.trim().length() == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ package com.intellij.internal.statistic.beans;
|
||||
public class PatchedUsage extends UsageDescriptor {
|
||||
|
||||
public PatchedUsage(UsageDescriptor descriptor) {
|
||||
super(descriptor.getGroup(), descriptor.getKey(), descriptor.getValue());
|
||||
super(descriptor.getKey(), descriptor.getValue());
|
||||
}
|
||||
|
||||
public PatchedUsage(GroupDescriptor group, String key, int value) {
|
||||
super(group, key, value);
|
||||
public PatchedUsage(String key, int value) {
|
||||
super(key, value);
|
||||
}
|
||||
|
||||
public int getDelta() {
|
||||
|
||||
+7
-28
@@ -16,15 +16,12 @@
|
||||
package com.intellij.internal.statistic.beans;
|
||||
public class UsageDescriptor implements Comparable<UsageDescriptor> {
|
||||
|
||||
private final GroupDescriptor myGroup;
|
||||
private final String myKey;
|
||||
private int myValue;
|
||||
|
||||
public UsageDescriptor(GroupDescriptor group, String key, int value) {
|
||||
assert group != null;
|
||||
assert key != null;
|
||||
public UsageDescriptor(String key, int value) {
|
||||
assert key != null;
|
||||
|
||||
myGroup = group;
|
||||
myKey = key;
|
||||
myValue = value;
|
||||
}
|
||||
@@ -33,10 +30,6 @@ public class UsageDescriptor implements Comparable<UsageDescriptor> {
|
||||
return myKey;
|
||||
}
|
||||
|
||||
public GroupDescriptor getGroup() {
|
||||
return myGroup;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return myValue;
|
||||
}
|
||||
@@ -45,29 +38,15 @@ public class UsageDescriptor implements Comparable<UsageDescriptor> {
|
||||
myValue = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof UsageDescriptor)) return false;
|
||||
|
||||
UsageDescriptor that = (UsageDescriptor) o;
|
||||
|
||||
if (!myGroup.equals(that.myGroup)) return false;
|
||||
if (!myKey.equals(that.myKey)) return false;
|
||||
|
||||
return true;
|
||||
public int getMyValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myGroup.hashCode();
|
||||
result = 31 * result + myKey.hashCode();
|
||||
return result;
|
||||
public void setMyValue(int myValue) {
|
||||
this.myValue = myValue;
|
||||
}
|
||||
|
||||
public int compareTo(UsageDescriptor ud) {
|
||||
final int byGroup = this.getGroup().compareTo(ud.getGroup());
|
||||
|
||||
return byGroup == 0 ? this.getKey().compareTo(ud.myKey) : byGroup;
|
||||
return this.getKey().compareTo(ud.myKey);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-2
@@ -29,7 +29,18 @@ import javax.swing.*;
|
||||
|
||||
public class StatisticsConfigurable implements SearchableConfigurable {
|
||||
|
||||
private StatisticsConfigurationComponent myConfig;
|
||||
private boolean modifiedByDefault;
|
||||
|
||||
public StatisticsConfigurable() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public StatisticsConfigurable(boolean isModifiedByDefault) {
|
||||
modifiedByDefault = isModifiedByDefault;
|
||||
}
|
||||
|
||||
|
||||
private StatisticsConfigurationComponent myConfig;
|
||||
|
||||
@Nls
|
||||
public String getDisplayName() {
|
||||
@@ -56,7 +67,7 @@ public class StatisticsConfigurable implements SearchableConfigurable {
|
||||
final UsageStatisticsPersistenceComponent persistenceComponent = UsageStatisticsPersistenceComponent.getInstance();
|
||||
return myConfig.isAllowed() != persistenceComponent.isAllowed() ||
|
||||
myConfig.getPeriod() != persistenceComponent.getPeriod() ||
|
||||
persistenceComponent.isShowNotification();
|
||||
modifiedByDefault;
|
||||
}
|
||||
|
||||
public void apply() throws ConfigurationException {
|
||||
@@ -65,6 +76,7 @@ public class StatisticsConfigurable implements SearchableConfigurable {
|
||||
persistenceComponent.setPeriod(myConfig.getPeriod());
|
||||
persistenceComponent.setAllowed(myConfig.isAllowed());
|
||||
persistenceComponent.setShowNotification(false);
|
||||
modifiedByDefault = false;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.intellij.internal.statistic.persistence;
|
||||
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class ApplicationStatisticsPersistence {
|
||||
private Map<GroupDescriptor, Map<String, Set<UsageDescriptor>>> myApplicationData = new HashMap<GroupDescriptor, Map<String, Set<UsageDescriptor>>>();
|
||||
|
||||
public ApplicationStatisticsPersistence() {
|
||||
}
|
||||
|
||||
public void persistFrameworks(@NotNull GroupDescriptor groupDescriptor, @NotNull Project project, @NotNull Set<UsageDescriptor> frameworks) {
|
||||
if (!myApplicationData.containsKey(groupDescriptor)) {
|
||||
myApplicationData.put(groupDescriptor, new HashMap<String, Set<UsageDescriptor>>());
|
||||
}
|
||||
myApplicationData.get(groupDescriptor).put(project.getName(), frameworks);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Set<UsageDescriptor>> getApplicationData(@NotNull GroupDescriptor groupDescriptor) {
|
||||
final Map<String, Set<UsageDescriptor>> map = myApplicationData.get(groupDescriptor);
|
||||
|
||||
return map == null ? new HashMap<String, Set<UsageDescriptor>>(): map;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<GroupDescriptor, Map<String, Set<UsageDescriptor>>> getApplicationData() {
|
||||
return myApplicationData;
|
||||
}
|
||||
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.internal.statistic.persistence;
|
||||
|
||||
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
|
||||
import com.intellij.internal.statistic.UsagesCollector;
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ProjectManagerListener;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@State(
|
||||
name = "StatisticsApplicationUsages",
|
||||
storages = {
|
||||
@Storage(
|
||||
id = "statistics.application.usages",
|
||||
file = "$APP_CONFIG$/statistics.application.usages.xml"
|
||||
)}
|
||||
)
|
||||
public class ApplicationStatisticsPersistenceComponent extends ApplicationStatisticsPersistence
|
||||
implements ApplicationComponent, PersistentStateComponent<Element> {
|
||||
private static final String TOKENIZER = ",";
|
||||
|
||||
@NonNls
|
||||
private static final String GROUP_TAG = "group";
|
||||
@NonNls
|
||||
private static final String GROUP_NAME_ATTR = "name";
|
||||
|
||||
@NonNls
|
||||
private static final String PROJECT_TAG = "project";
|
||||
@NonNls
|
||||
private static final String PROJECT_ID_ATTR = "id";
|
||||
@NonNls
|
||||
private static final String VALUES_ATTR = "values";
|
||||
|
||||
public ApplicationStatisticsPersistenceComponent() {
|
||||
}
|
||||
|
||||
public static ApplicationStatisticsPersistenceComponent getInstance() {
|
||||
return ApplicationManager.getApplication().getComponent(ApplicationStatisticsPersistenceComponent.class);
|
||||
}
|
||||
|
||||
public void loadState(final Element element) {
|
||||
List groups = element.getChildren(GROUP_TAG);
|
||||
|
||||
for (Object group : groups) {
|
||||
Element groupElement = (Element) group;
|
||||
String groupName = groupElement.getAttributeValue(GROUP_NAME_ATTR);
|
||||
|
||||
final GroupDescriptor groupDescriptor = GroupDescriptor.create(groupName);
|
||||
|
||||
List projectsList = groupElement.getChildren(PROJECT_TAG);
|
||||
for (Object project : projectsList) {
|
||||
Element projectElement = (Element) project;
|
||||
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
|
||||
String frameworks = projectElement.getAttributeValue(VALUES_ATTR);
|
||||
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
|
||||
Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>();
|
||||
for (String key : StringUtil.split(frameworks, TOKENIZER)) {
|
||||
frameworkDescriptors.add(new UsageDescriptor(key, 1));
|
||||
}
|
||||
getApplicationData(groupDescriptor).put(projectId, frameworkDescriptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
|
||||
for (Map.Entry<GroupDescriptor, Map<String, Set<UsageDescriptor>>> appData : getApplicationData().entrySet()) {
|
||||
Element groupElement = new Element(GROUP_TAG);
|
||||
groupElement.setAttribute(GROUP_NAME_ATTR, appData.getKey().getId());
|
||||
boolean isEmptyGroup = true;
|
||||
|
||||
for (Map.Entry<String, Set<UsageDescriptor>> projectData : appData.getValue().entrySet()) {
|
||||
Element projectElement = new Element(PROJECT_TAG);
|
||||
projectElement.setAttribute(PROJECT_ID_ATTR, projectData.getKey());
|
||||
final Set<UsageDescriptor> projectDataValue = projectData.getValue();
|
||||
if (!projectDataValue.isEmpty()) {
|
||||
projectElement.setAttribute(VALUES_ATTR, joinUsages(projectDataValue));
|
||||
groupElement.addContent(projectElement);
|
||||
isEmptyGroup = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isEmptyGroup) {
|
||||
element.addContent(groupElement);
|
||||
}
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
|
||||
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
|
||||
@Override
|
||||
public String fun(UsageDescriptor usageDescriptor) {
|
||||
return usageDescriptor.getKey();
|
||||
}
|
||||
}, TOKENIZER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNls
|
||||
public File[] getExportFiles() {
|
||||
return new File[]{PathManager.getOptionsFile("framework.usages")};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPresentableName() {
|
||||
return "Application Usages Statistics";
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
return "ApplicationStatisticsPersistenceComponent";
|
||||
}
|
||||
|
||||
public void initComponent() {
|
||||
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
|
||||
@Override
|
||||
public void projectOpened(Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCloseProject(Project project) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosed(Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosing(Project project) {
|
||||
if (project != null) {
|
||||
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
|
||||
if (usagesCollector instanceof AbstractApplicationUsagesCollector) {
|
||||
((AbstractApplicationUsagesCollector) usagesCollector).persistProjectUsages(project);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void disposeComponent() {
|
||||
}
|
||||
}
|
||||
+45
-34
@@ -17,58 +17,69 @@
|
||||
package com.intellij.internal.statistic.persistence;
|
||||
|
||||
import com.intellij.internal.statistic.StatisticsUploadAssistant;
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.PatchedUsage;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class BasicSentUsagesPersistenceComponent extends SentUsagesPersistence {
|
||||
|
||||
public BasicSentUsagesPersistenceComponent() {
|
||||
}
|
||||
public BasicSentUsagesPersistenceComponent() {
|
||||
}
|
||||
|
||||
protected Set<UsageDescriptor> mySentDescriptors = new HashSet<UsageDescriptor>();
|
||||
@NonNls private long mySentTime = 0;
|
||||
protected Map<GroupDescriptor, Set<UsageDescriptor>> mySentDescriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
|
||||
@NonNls
|
||||
private long mySentTime = 0;
|
||||
|
||||
@Override
|
||||
public boolean isAllowed() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isAllowed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShowNotification() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isShowNotification() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastTimeSent() {
|
||||
return mySentTime;
|
||||
}
|
||||
@Override
|
||||
public long getLastTimeSent() {
|
||||
return mySentTime;
|
||||
}
|
||||
|
||||
public void setSentTime(long time) {
|
||||
mySentTime = time;
|
||||
}
|
||||
public void setSentTime(long time) {
|
||||
mySentTime = time;
|
||||
}
|
||||
|
||||
public void persistPatch(@NotNull Set<PatchedUsage> patchedDescriptors) {
|
||||
for (PatchedUsage patchedUsage : patchedDescriptors) {
|
||||
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, Pair.create(patchedUsage.getGroup(), patchedUsage.getKey()));
|
||||
if (usageDescriptor != null) {
|
||||
usageDescriptor.setValue(usageDescriptor.getValue() + patchedUsage.getDelta());
|
||||
}
|
||||
else {
|
||||
mySentDescriptors.add(new UsageDescriptor(patchedUsage.getGroup(), patchedUsage.getKey(), patchedUsage.getValue()));
|
||||
}
|
||||
public void persistPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedDescriptorMap) {
|
||||
for (Map.Entry<GroupDescriptor, Set<PatchedUsage>> entry : patchedDescriptorMap.entrySet()) {
|
||||
final GroupDescriptor groupDescriptor = entry.getKey();
|
||||
for (PatchedUsage patchedUsage : entry.getValue()) {
|
||||
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, Pair.create(groupDescriptor, patchedUsage.getKey()));
|
||||
if (usageDescriptor != null) {
|
||||
usageDescriptor.setValue(usageDescriptor.getValue() + patchedUsage.getDelta());
|
||||
} else {
|
||||
if (!mySentDescriptors.containsKey(groupDescriptor)) {
|
||||
mySentDescriptors.put(groupDescriptor, new HashSet<UsageDescriptor>());
|
||||
}
|
||||
mySentDescriptors.get(groupDescriptor).add(new UsageDescriptor(patchedUsage.getKey(), patchedUsage.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setSentTime(System.currentTimeMillis());
|
||||
}
|
||||
setSentTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getSentUsages() {
|
||||
return mySentDescriptors;
|
||||
}
|
||||
@NotNull
|
||||
public Map<GroupDescriptor, Set<UsageDescriptor>> getSentUsages
|
||||
() {
|
||||
return mySentDescriptors;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -16,18 +16,20 @@
|
||||
|
||||
package com.intellij.internal.statistic.persistence;
|
||||
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.PatchedUsage;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class SentUsagesPersistence {
|
||||
|
||||
public abstract void persistPatch(@NotNull Set<PatchedUsage> patchedDescriptors);
|
||||
public abstract void persistPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedDescriptors);
|
||||
|
||||
@NotNull
|
||||
public abstract Set<UsageDescriptor> getSentUsages();
|
||||
public abstract Map<GroupDescriptor, Set<UsageDescriptor>> getSentUsages();
|
||||
|
||||
public abstract boolean isAllowed();
|
||||
|
||||
|
||||
+2
-2
@@ -76,7 +76,7 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
|
||||
|
||||
String valueData = groupElement.getAttributeValue(DATA_ATTR);
|
||||
if (!StringUtil.isEmptyOrSpaces(groupId) && !StringUtil.isEmptyOrSpaces(valueData)) {
|
||||
getSentUsages().addAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
|
||||
getSentUsages().putAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.groupDescriptors(getSentUsages())
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.sortDescriptorsByPriority(getSentUsages())
|
||||
.entrySet()) {
|
||||
Element projectElement = new Element(GROUP_TAG);
|
||||
projectElement.setAttribute(GROUP_ID_ATTR, entry.getKey().getId());
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ public class StatisticsNotificationManager {
|
||||
else if ("settings".equals(description)) {
|
||||
final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
|
||||
IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null);
|
||||
util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable());
|
||||
util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable(true));
|
||||
notification.expire();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,20 +118,16 @@
|
||||
<implementation-class>com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<interface-class>com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent</interface-class>
|
||||
<implementation-class>com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<implementation-class>com.intellij.openapi.util.FoundationLoader</implementation-class>
|
||||
<headless-implementation-class/>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<interface-class>com.intellij.facet.impl.statistics.FrameworkStatisticsPersistenceComponent</interface-class>
|
||||
<implementation-class>com.intellij.facet.impl.statistics.FrameworkStatisticsPersistenceComponent</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<interface-class>com.intellij.openapi.vcs.statistics.VcsStatisticsPersistenceComponent</interface-class>
|
||||
<implementation-class>com.intellij.openapi.vcs.statistics.VcsStatisticsPersistenceComponent</implementation-class>
|
||||
</component>
|
||||
</application-components>
|
||||
|
||||
<project-components>
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.openapi.vcs.statistics;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class VcsStatisticsPersistence {
|
||||
private Map<String, Set<UsageDescriptor>> myVcsUsagesMap = new HashMap<String, Set<UsageDescriptor>>();
|
||||
|
||||
public VcsStatisticsPersistence() {
|
||||
}
|
||||
|
||||
public void persist(@NotNull Project project, @NotNull Set<UsageDescriptor> vcs) {
|
||||
myVcsUsagesMap.put(project.getName(), vcs);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Set<UsageDescriptor>> getVcsUsageMap() {
|
||||
return myVcsUsagesMap;
|
||||
}
|
||||
|
||||
}
|
||||
-146
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.openapi.vcs.statistics;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.components.ApplicationComponent;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.project.ProjectManagerListener;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@State(
|
||||
name = "VcsUsages",
|
||||
storages = {
|
||||
@Storage(
|
||||
id = "vcs",
|
||||
file = "$APP_CONFIG$/vcs.usages.xml"
|
||||
)}
|
||||
)
|
||||
public class VcsStatisticsPersistenceComponent extends VcsStatisticsPersistence
|
||||
implements ApplicationComponent, PersistentStateComponent<Element> {
|
||||
private static final String TOKENIZER = ",";
|
||||
|
||||
@NonNls private static final String PROJECT_TAG = "project";
|
||||
@NonNls private static final String PROJECT_ID_ATTR = "id";
|
||||
@NonNls private static final String USAGES_ATTR = "usages";
|
||||
|
||||
public VcsStatisticsPersistenceComponent() {
|
||||
}
|
||||
|
||||
public static VcsStatisticsPersistenceComponent getInstance() {
|
||||
return ApplicationManager.getApplication().getComponent(VcsStatisticsPersistenceComponent.class);
|
||||
}
|
||||
|
||||
public void loadState(final Element element) {
|
||||
List projectsList = element.getChildren(PROJECT_TAG);
|
||||
for (Object project : projectsList) {
|
||||
Element projectElement = (Element)project;
|
||||
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
|
||||
String vcs = projectElement.getAttributeValue(USAGES_ATTR);
|
||||
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(vcs)) {
|
||||
Set<UsageDescriptor> vcsDescriptors = new HashSet<UsageDescriptor>();
|
||||
for (String key : StringUtil.split(vcs, TOKENIZER)) {
|
||||
vcsDescriptors.add(new UsageDescriptor(VcsUsagesCollector.createGroupDescriptor(), key, 1));
|
||||
}
|
||||
getVcsUsageMap().put(projectId, vcsDescriptors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
|
||||
for (Map.Entry<String, Set<UsageDescriptor>> vcsUsageEntry : getVcsUsageMap().entrySet()) {
|
||||
Element projectElement = new Element(PROJECT_TAG);
|
||||
projectElement.setAttribute(PROJECT_ID_ATTR, vcsUsageEntry.getKey());
|
||||
projectElement.setAttribute(USAGES_ATTR, joinUsages(vcsUsageEntry.getValue()));
|
||||
|
||||
element.addContent(projectElement);
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
|
||||
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
|
||||
@Override
|
||||
public String fun(UsageDescriptor usageDescriptor) {
|
||||
return usageDescriptor.getKey();
|
||||
}
|
||||
}, TOKENIZER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@NonNls
|
||||
public File[] getExportFiles() {
|
||||
return new File[]{PathManager.getOptionsFile("vcs.usages")};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPresentableName() {
|
||||
return "Vcs Usages";
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
return "VcsStatisticsPersistenceComponent";
|
||||
}
|
||||
|
||||
public void initComponent() {
|
||||
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
|
||||
@Override
|
||||
public void projectOpened(Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCloseProject(Project project) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosed(Project project) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void projectClosing(Project project) {
|
||||
if (project != null) {
|
||||
VcsUsagesCollector.persistProjectUsages(project);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void disposeComponent() {
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.intellij.openapi.vcs.statistics;
|
||||
|
||||
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.impl.VcsDescriptor;
|
||||
import com.intellij.internal.statistic.UsagesCollector;
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
@@ -28,77 +28,25 @@ import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class VcsUsagesCollector extends UsagesCollector {
|
||||
private static final String GROUP_ID = "vcs";
|
||||
public class VcsUsagesCollector extends AbstractApplicationUsagesCollector {
|
||||
private static final String GROUP_ID = "vcs";
|
||||
|
||||
public static void persistProjectUsages(@NotNull Project project) {
|
||||
persistProjectUsages(project, getProjectUsages(project));
|
||||
}
|
||||
|
||||
public static void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
|
||||
persistProjectUsages(project, usages, VcsStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
public static void persistProjectUsages(@NotNull Project project,
|
||||
@NotNull Set<UsageDescriptor> usages,
|
||||
@NotNull VcsStatisticsPersistenceComponent persistence) {
|
||||
persistence.persist(project, usages);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<UsageDescriptor> getApplicationUsages() {
|
||||
return getApplicationUsages(VcsStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<UsageDescriptor> getApplicationUsages(@NotNull final VcsStatisticsPersistenceComponent persistence) {
|
||||
final Map<String, Integer> vcsUsagesMap = new HashMap<String, Integer>();
|
||||
|
||||
for (Set<UsageDescriptor> descriptors : persistence.getVcsUsageMap().values()) {
|
||||
for (UsageDescriptor descriptor : descriptors) {
|
||||
final String key = descriptor.getKey();
|
||||
final Integer count = vcsUsagesMap.get(key);
|
||||
vcsUsagesMap.put(key, count == null ? 1 : count.intValue() + 1);
|
||||
}
|
||||
@NotNull
|
||||
public GroupDescriptor getGroupId() {
|
||||
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
|
||||
}
|
||||
|
||||
return ContainerUtil.map2Set(vcsUsagesMap.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(Map.Entry<String, Integer> vcsUsage) {
|
||||
return new UsageDescriptor(createGroupDescriptor(), vcsUsage.getKey(), vcsUsage.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroupId() {
|
||||
return GROUP_ID;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
|
||||
if (project != null) {
|
||||
persistProjectUsages(project, getProjectUsages(project));
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
|
||||
return ContainerUtil.map2Set(ProjectLevelVcsManager.getInstance(project).getAllActiveVcss(), new Function<AbstractVcs, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(AbstractVcs vcs) {
|
||||
return new UsageDescriptor(vcs.getName(), 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return getApplicationUsages();
|
||||
}
|
||||
|
||||
public static Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
|
||||
return ContainerUtil.map2Set(ProjectLevelVcsManager.getInstance(project).getAllActiveVcss(), new Function<AbstractVcs, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(AbstractVcs vcs) {
|
||||
return new UsageDescriptor(createGroupDescriptor(), vcs.getName(), 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GroupDescriptor createGroupDescriptor() {
|
||||
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user