mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed send statistics bugs
This commit is contained in:
+4
-2
@@ -23,12 +23,14 @@ import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
|
||||
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class LanguageLevelUsagesCollector extends AbstractApplicationUsagesCollector {
|
||||
@@ -49,10 +51,10 @@ public class LanguageLevelUsagesCollector extends AbstractApplicationUsagesColle
|
||||
final LanguageLevelModuleExtension instance = LanguageLevelModuleExtension.getInstance(module);
|
||||
final LanguageLevel languageLevel = instance.getLanguageLevel();
|
||||
if (languageLevel != null) {
|
||||
languageLevels.add(languageLevel.getPresentableText());
|
||||
languageLevels.add(languageLevel.toString());
|
||||
}
|
||||
}
|
||||
languageLevels.add(LanguageLevelProjectExtension.getInstance(project).getLanguageLevel().getPresentableText());
|
||||
languageLevels.add(LanguageLevelProjectExtension.getInstance(project).getLanguageLevel().toString());
|
||||
|
||||
return ContainerUtil.map2Set(languageLevels, new Function<String, UsageDescriptor>() {
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ public class StatisticsUploadAssistant {
|
||||
return settings != null && settings.isAllowed();
|
||||
}
|
||||
|
||||
public static String getData(@NotNull Set<String> disabledGroups) {
|
||||
public String getData(@NotNull Set<String> disabledGroups) {
|
||||
return getStringPatch(disabledGroups, ProjectManager.getInstance().getOpenProjects());
|
||||
}
|
||||
|
||||
|
||||
+130
-115
@@ -21,139 +21,154 @@ import com.intellij.util.containers.hash.HashMap;
|
||||
import java.util.*;
|
||||
|
||||
public class ConvertUsagesUtil {
|
||||
private static final Character GROUP_SEPARATOR = ':';
|
||||
private static final Character GROUPS_SEPARATOR = ';';
|
||||
private static final Character GROUP_VALUE_SEPARATOR = ',';
|
||||
private static final Character GROUP_SEPARATOR = ':';
|
||||
private static final Character GROUPS_SEPARATOR = ';';
|
||||
private static final Character GROUP_VALUE_SEPARATOR = ',';
|
||||
|
||||
private ConvertUsagesUtil() {
|
||||
private ConvertUsagesUtil() {
|
||||
}
|
||||
|
||||
|
||||
// @NotNull
|
||||
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<T>> entry : sortedMap.entrySet()) {
|
||||
buffer.append(entry.getKey().getId());
|
||||
buffer.append(GROUP_SEPARATOR);
|
||||
buffer.append(convertValueMap(entry.getValue()));
|
||||
buffer.append(GROUPS_SEPARATOR);
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
// @NotNull
|
||||
public static <T extends UsageDescriptor> String convertUsages(Map<GroupDescriptor, Set<T>> map) {
|
||||
assert map != null;
|
||||
final Map<GroupDescriptor, Set<T>> sortedMap = sortDescriptorsByPriority(map);
|
||||
//@NotNull
|
||||
public static String convertValueMap(Set<? extends UsageDescriptor> descriptors) {
|
||||
assert descriptors != null;
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
for (UsageDescriptor usageDescriptor : descriptors) {
|
||||
buffer.append(usageDescriptor.getKey());
|
||||
buffer.append("=");
|
||||
buffer.append(usageDescriptor.getValue());
|
||||
buffer.append(GROUP_VALUE_SEPARATOR);
|
||||
}
|
||||
buffer.deleteCharAt(buffer.length() - 1);
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (Map.Entry<GroupDescriptor, Set<T>> entry : sortedMap.entrySet()) {
|
||||
buffer.append(entry.getKey().getId());
|
||||
buffer.append(GROUP_SEPARATOR);
|
||||
buffer.append(convertValueMap(entry.getValue()));
|
||||
buffer.append(GROUPS_SEPARATOR);
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static String cutPatchString(String patchStr, int maxSize) {
|
||||
assert patchStr != null;
|
||||
for (int i = maxSize - 1; i >= 0; i--) {
|
||||
final char c = patchStr.charAt(i);
|
||||
if (c == GROUPS_SEPARATOR || c == GROUP_VALUE_SEPARATOR) {
|
||||
return patchStr.substring(0, i);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertString(String usages) {
|
||||
assert usages != null;
|
||||
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.putAll(convertValueString(GroupDescriptor.create(group.first), group.second));
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static String convertValueMap(Set<? extends UsageDescriptor> descriptors) {
|
||||
assert descriptors != null;
|
||||
final StringBuffer buffer = new StringBuffer();
|
||||
for (UsageDescriptor usageDescriptor : descriptors) {
|
||||
buffer.append(usageDescriptor.getKey());
|
||||
buffer.append("=");
|
||||
buffer.append(usageDescriptor.getValue());
|
||||
buffer.append(GROUP_VALUE_SEPARATOR);
|
||||
}
|
||||
buffer.deleteCharAt(buffer.length() - 1);
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static String cutPatchString(String patchStr, int maxSize) {
|
||||
assert patchStr != null;
|
||||
for (int i = maxSize - 1; i >= 0; i--) {
|
||||
final char c = patchStr.charAt(i);
|
||||
if (c == GROUPS_SEPARATOR || c == GROUP_VALUE_SEPARATOR) {
|
||||
return patchStr.substring(0, i);
|
||||
//@NotNull
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertValueString(GroupDescriptor groupId, String valueData) {
|
||||
assert groupId != null;
|
||||
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, "=");
|
||||
if (pair != null) {
|
||||
final String count = pair.second;
|
||||
if (!isEmptyOrSpaces(count)) {
|
||||
try {
|
||||
final int i = Integer.parseInt(count);
|
||||
if (!descriptors.containsKey(groupId)) {
|
||||
descriptors.put(groupId, new LinkedHashSet<UsageDescriptor>());
|
||||
}
|
||||
descriptors.get(groupId).add(new UsageDescriptor(pair.first, i));
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertString(String usages) {
|
||||
assert usages != null;
|
||||
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.putAll(convertValueString(GroupDescriptor.create(group.first), group.second));
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return descriptors;
|
||||
}
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertValueString(GroupDescriptor groupId, String valueData) {
|
||||
assert groupId != null;
|
||||
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, "=");
|
||||
if (pair != null) {
|
||||
final String count = pair.second;
|
||||
if (!isEmptyOrSpaces(count)) {
|
||||
try {
|
||||
final int i = Integer.parseInt(count);
|
||||
if (!descriptors.containsKey(groupId)) {
|
||||
descriptors.put(groupId, new LinkedHashSet<UsageDescriptor>());
|
||||
}
|
||||
descriptors.get(groupId).add(new UsageDescriptor(pair.first, i));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
//@Nullable
|
||||
public static StringPair getPair(String str, String separator) {
|
||||
assert str != null;
|
||||
assert separator != null;
|
||||
final int i = str.indexOf(separator);
|
||||
if (i > 0 && i < str.length() - 1) {
|
||||
String key = str.substring(0, i).trim();
|
||||
String value = str.substring(i + 1).trim();
|
||||
if (!isEmptyOrSpaces(key) && !isEmptyOrSpaces(value)) {
|
||||
return new StringPair(key, value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//@Nullable
|
||||
public static StringPair getPair(String str, String separator) {
|
||||
assert str != null;
|
||||
assert separator != null;
|
||||
final int i = str.indexOf(separator);
|
||||
if (i > 0 && i < str.length() - 1) {
|
||||
String key = str.substring(0, i).trim();
|
||||
String value = str.substring(i + 1).trim();
|
||||
if (!isEmptyOrSpaces(key) && !isEmptyOrSpaces(value)) {
|
||||
return new StringPair(key, value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
//@NotNull
|
||||
public static <T extends UsageDescriptor> Map<GroupDescriptor, Set<T>> sortDescriptorsByPriority(Map<GroupDescriptor, Set<T>> descriptors) {
|
||||
assert descriptors != null;
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
map.putAll(descriptors);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static class StringPair {
|
||||
public final String first;
|
||||
public final String second;
|
||||
|
||||
public StringPair(String first, String second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static <T extends UsageDescriptor> Map<GroupDescriptor, Set<T>> sortDescriptorsByPriority(Map<GroupDescriptor, Set<T>> descriptors) {
|
||||
assert descriptors != null;
|
||||
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;
|
||||
}
|
||||
});
|
||||
public static boolean isEmptyOrSpaces(final String s) {
|
||||
return s == null || s.trim().length() == 0;
|
||||
}
|
||||
|
||||
map.putAll(descriptors);
|
||||
public static void assertDescriptorName(String key) {
|
||||
assert key != null;
|
||||
assert containsChar(key, ConvertUsagesUtil.GROUP_SEPARATOR) == false;
|
||||
assert containsChar(key, ConvertUsagesUtil.GROUPS_SEPARATOR) == false;
|
||||
assert containsChar(key, ConvertUsagesUtil.GROUP_VALUE_SEPARATOR) == false;
|
||||
assert key.contains("=") == false;
|
||||
assert key.contains("'") == false;
|
||||
assert key.contains("\"") == false;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private static class StringPair {
|
||||
public final String first;
|
||||
public final String second;
|
||||
|
||||
public StringPair(String first, String second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmptyOrSpaces(final String s) {
|
||||
return s == null || s.trim().length() == 0;
|
||||
}
|
||||
public static boolean containsChar(final String value, final char ch) {
|
||||
return value.indexOf(ch) >= 0;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -24,8 +24,9 @@ public class GroupDescriptor implements Comparable<GroupDescriptor> {
|
||||
private double myPriority;
|
||||
|
||||
public static GroupDescriptor create(String id) {
|
||||
assert id != null;
|
||||
return new GroupDescriptor(id);
|
||||
ConvertUsagesUtil.assertDescriptorName(id);
|
||||
|
||||
return new GroupDescriptor(id);
|
||||
}
|
||||
|
||||
public static GroupDescriptor create(String id, double priority) {
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ public class UsageDescriptor implements Comparable<UsageDescriptor> {
|
||||
private int myValue;
|
||||
|
||||
public UsageDescriptor(String key, int value) {
|
||||
assert key != null;
|
||||
ConvertUsagesUtil.assertDescriptorName(key);
|
||||
|
||||
myKey = key;
|
||||
myValue = value;
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class RemotelyConfigurableStatisticsService implements StatisticsService
|
||||
return new StatisticsResult(StatisticsResult.ResultCode.NOT_PERMITTED_SERVER, "NOT_PERMITTED");
|
||||
}
|
||||
|
||||
String content = myAssistant.getData();
|
||||
String content = myAssistant.getData(myConnectionService.getDisabledGroups());
|
||||
|
||||
if (StringUtil.isEmptyOrSpaces(content)) {
|
||||
return new StatisticsResult(StatisticsResult.ResultCode.NOTHING_TO_SEND, "NOTHING_TO_SEND");
|
||||
|
||||
+3
@@ -56,6 +56,9 @@ public class StatisticsHttpClientSender implements StatisticsDataSender {
|
||||
throw new StatServiceException("Error during updating statistics " + (!StringUtil.isEmptyOrSpaces(value) ? " : " + value : ""));
|
||||
}
|
||||
}
|
||||
catch (StatServiceException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new StatServiceException("Error during data sending...", e);
|
||||
}
|
||||
|
||||
+32
-7
@@ -19,6 +19,7 @@ package com.intellij.internal.statistic.persistence;
|
||||
import com.intellij.ide.AppLifecycleListener;
|
||||
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
|
||||
import com.intellij.internal.statistic.UsagesCollector;
|
||||
import com.intellij.internal.statistic.beans.ConvertUsagesUtil;
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -94,7 +95,7 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis
|
||||
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));
|
||||
frameworkDescriptors.add(getUsageDescriptor(key));
|
||||
}
|
||||
getApplicationData(groupDescriptor).put(projectId, frameworkDescriptors);
|
||||
}
|
||||
@@ -129,13 +130,37 @@ public class ApplicationStatisticsPersistenceComponent extends ApplicationStatis
|
||||
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();
|
||||
private UsageDescriptor getUsageDescriptor(String usage) {
|
||||
// for instance, usage can be: "_foo"(equals "_foo=1") or "_foo=2"
|
||||
final int i = usage.indexOf("=");
|
||||
if (i > 0 && i < usage.length() - 1) {
|
||||
String key = usage.substring(0, i).trim();
|
||||
String value = usage.substring(i + 1).trim();
|
||||
if (!StringUtil.isEmptyOrSpaces(key) && !StringUtil.isEmptyOrSpaces(value)) {
|
||||
try {
|
||||
final int count = Integer.parseInt(value);
|
||||
if (count > 0) {
|
||||
return new UsageDescriptor(key, count);
|
||||
}
|
||||
}
|
||||
}, TOKENIZER);
|
||||
catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return new UsageDescriptor(usage, 1);
|
||||
}
|
||||
|
||||
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
|
||||
// for instance, usage can be: "_foo"(equals "_foo=1") or "_foo=2"
|
||||
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
|
||||
@Override
|
||||
public String fun(UsageDescriptor usageDescriptor) {
|
||||
final String key = usageDescriptor.getKey();
|
||||
final int value = usageDescriptor.getValue();
|
||||
|
||||
return value > 1 ? key + "=" + value : key;
|
||||
}
|
||||
}, TOKENIZER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user