mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
idea statistics
This commit is contained in:
+2
-58
@@ -15,72 +15,16 @@
|
||||
*/
|
||||
package com.intellij.facet.frameworks;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class LibrariesDownloadConnectionService {
|
||||
private static final Logger LOG = Logger.getInstance("com.intellij.facet.frameworks.LibrariesDownloadConnectionService");
|
||||
|
||||
private static final String DOWNLOAD_SERVICE_SETTINGS_URL = "http://jetbrains.com/idea/download-assistant.xml ";
|
||||
private static final String SERVICE_URL_ATTR_NAME = "url";
|
||||
|
||||
private static final String myAgentID = "IntelliJ IDEA";
|
||||
public class LibrariesDownloadConnectionService extends SettingsConnectionService {
|
||||
|
||||
private static final LibrariesDownloadConnectionService myInstance = new LibrariesDownloadConnectionService();
|
||||
private String myServiceUrl;
|
||||
|
||||
public static LibrariesDownloadConnectionService getInstance() {
|
||||
return myInstance;
|
||||
}
|
||||
|
||||
private LibrariesDownloadConnectionService() {
|
||||
super("http://jetbrains.com/idea/download-assistant.xml", "http://frameworks.jetbrains.com");
|
||||
}
|
||||
|
||||
private static String readServiceUrl() {
|
||||
try {
|
||||
final URL url = new URL(DOWNLOAD_SERVICE_SETTINGS_URL);
|
||||
final InputStream is = getStream(url);
|
||||
final Document document = JDOMUtil.loadDocument(is);
|
||||
final Element root = document.getRootElement();
|
||||
return StringUtil.notNullize(root.getAttributeValue(SERVICE_URL_ATTR_NAME), "");
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
// no route to host, unknown host, etc.
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
// default
|
||||
return "http://frameworks.jetbrains.com";
|
||||
}
|
||||
|
||||
private static InputStream getStream(URL url) throws IOException {
|
||||
final URLConnection connection = url.openConnection();
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
connection.setRequestProperty("User-agent", myAgentID);
|
||||
}
|
||||
return connection.getInputStream();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getServiceUrl() {
|
||||
if (myServiceUrl == null) {
|
||||
myServiceUrl = readServiceUrl();
|
||||
}
|
||||
return myServiceUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.frameworks;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.util.containers.hash.HashMap;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class SettingsConnectionService {
|
||||
private static final Logger LOG = Logger.getInstance("com.intellij.facet.frameworks.SettingsConnectionService");
|
||||
|
||||
protected static final String SERVICE_URL_ATTR_NAME = "url";
|
||||
|
||||
private static final String myAgentID = "IntelliJ IDEA";
|
||||
|
||||
private Map<String, String> myAttributesMap;
|
||||
|
||||
@NotNull
|
||||
protected String[] getAttributeNames() {
|
||||
return new String[] {SERVICE_URL_ATTR_NAME};
|
||||
}
|
||||
|
||||
private String mySettingsUrl;
|
||||
@Nullable private String myDefaultServiceUrl;
|
||||
|
||||
protected SettingsConnectionService(@NotNull String settingsUrl, @Nullable String defaultServiceUrl) {
|
||||
mySettingsUrl = settingsUrl;
|
||||
myDefaultServiceUrl = defaultServiceUrl;
|
||||
}
|
||||
|
||||
public String getSettingsUrl() {
|
||||
return mySettingsUrl;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getDefaultServiceUrl() {
|
||||
return myDefaultServiceUrl;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Map<String, String> readSettings(String... attributes) {
|
||||
Map<String, String> settings = new HashMap<String, String>();
|
||||
try {
|
||||
final URL url = new URL(getSettingsUrl());
|
||||
final InputStream is = getStream(url);
|
||||
final Document document = JDOMUtil.loadDocument(is);
|
||||
final Element root = document.getRootElement();
|
||||
for (String s : attributes) {
|
||||
settings.put(s, root.getAttributeValue(s));
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
// no route to host, unknown host, etc.
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
private static InputStream getStream(URL url) throws IOException {
|
||||
final URLConnection connection = url.openConnection();
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
connection.setRequestProperty("User-agent", myAgentID);
|
||||
}
|
||||
return connection.getInputStream();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getServiceUrl() {
|
||||
final String serviceUrl = getSettingValue(SERVICE_URL_ATTR_NAME);
|
||||
|
||||
return serviceUrl == null ? getDefaultServiceUrl() : serviceUrl;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getSettingValue(@NotNull String attributeValue) {
|
||||
if (myAttributesMap == null) {
|
||||
myAttributesMap = readSettings(getAttributeNames());
|
||||
}
|
||||
return myAttributesMap != null ? myAttributesMap.get(attributeValue) : null;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
package com.intellij.facet.impl.statistics;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
+2
-2
@@ -16,6 +16,7 @@
|
||||
|
||||
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;
|
||||
@@ -25,7 +26,6 @@ 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.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
@@ -70,7 +70,7 @@ public class FrameworkStatisticsPersistenceComponent extends FrameworkStatistics
|
||||
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.getGroupId(), key, 1));
|
||||
frameworkDescriptors.add(new UsageDescriptor(FrameworkUsagesCollector.getGroupDescriptor(), key, 1));
|
||||
}
|
||||
getFrameworks().put(projectId, frameworkDescriptors);
|
||||
}
|
||||
|
||||
+16
-10
@@ -20,9 +20,9 @@ import com.intellij.facet.FacetManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.statistic.UsagesCollector;
|
||||
import com.intellij.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
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;
|
||||
@@ -34,7 +34,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FrameworkUsagesCollector extends UsagesCollector {
|
||||
private static final String GROUP_ID = "frameworks";
|
||||
public static final String GROUP_ID = "frameworks";
|
||||
|
||||
public static void persistProjectUsages(@NotNull Project project) {
|
||||
persistProjectUsages(project, getProjectUsages(project));
|
||||
@@ -51,12 +51,12 @@ public class FrameworkUsagesCollector extends UsagesCollector {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<UsageDescriptor> getApplicationUsages() {
|
||||
public Set<UsageDescriptor> getApplicationUsages() {
|
||||
return getApplicationUsages(FrameworkStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<UsageDescriptor> getApplicationUsages(@NotNull final FrameworkStatisticsPersistence persistence) {
|
||||
public Set<UsageDescriptor> getApplicationUsages(@NotNull final FrameworkStatisticsPersistence persistence) {
|
||||
final Map<String, Integer> facets = new HashMap<String, Integer>();
|
||||
|
||||
for (Set<UsageDescriptor> frameworks : persistence.getFrameworks().values()) {
|
||||
@@ -70,12 +70,18 @@ public class FrameworkUsagesCollector extends UsagesCollector {
|
||||
return ContainerUtil.map2Set(facets.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(Map.Entry<String, Integer> facet) {
|
||||
return new UsageDescriptor(getGroupId(), facet.getKey(), facet.getValue());
|
||||
return new UsageDescriptor(getGroupDescriptor(), facet.getKey(), facet.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GroupDescriptor getGroupId() {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getGroupId() {
|
||||
return GROUP_ID;
|
||||
}
|
||||
|
||||
public static GroupDescriptor getGroupDescriptor() {
|
||||
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
|
||||
}
|
||||
|
||||
@@ -92,14 +98,14 @@ public class FrameworkUsagesCollector extends UsagesCollector {
|
||||
final Set<String> facets = new HashSet<String>();
|
||||
for (Module module : ModuleManager.getInstance(project).getModules()) {
|
||||
for (Facet facet : FacetManager.getInstance(module).getAllFacets()) {
|
||||
facets.add(facet.getName());
|
||||
facets.add(facet.getType().getStringId());
|
||||
}
|
||||
}
|
||||
|
||||
return ContainerUtil.map2Set(facets, new Function<String, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(String facet) {
|
||||
return new UsageDescriptor(getGroupId(), facet, 1);
|
||||
return new UsageDescriptor(getGroupDescriptor(), facet, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
<orderEntry type="module" module-name="lang-api" />
|
||||
<orderEntry type="library" name="Guava" level="project" />
|
||||
<orderEntry type="library" name="jna" level="project" />
|
||||
<orderEntry type="library" name="http-client-3.1" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
+10
-4
@@ -16,9 +16,9 @@
|
||||
package com.intellij.featureStatistics;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.statistic.UsagesCollector;
|
||||
import com.intellij.statistic.beans.*;
|
||||
import com.intellij.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.UsagesCollector;
|
||||
import com.intellij.internal.statistic.beans.*;
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -27,6 +27,12 @@ import java.util.Set;
|
||||
|
||||
public class FeaturesUsageCollector extends UsagesCollector {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getGroupId() {
|
||||
return "productivity";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
|
||||
@@ -37,7 +43,7 @@ public class FeaturesUsageCollector extends UsagesCollector {
|
||||
final FeatureDescriptor featureDescriptor = registry.getFeatureDescriptor(featureId);
|
||||
if (featureDescriptor != null) {
|
||||
usages.add(new UsageDescriptor(
|
||||
GroupDescriptor.create("productivity", GroupDescriptor.LOWER_PRIORITY), featureId, featureDescriptor.getUsageCount()));
|
||||
GroupDescriptor.create(getGroupId(), GroupDescriptor.LOWER_PRIORITY), featureId, featureDescriptor.getUsageCount()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
package com.intellij.ide.plugins;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.statistic.UsagesCollector;
|
||||
import com.intellij.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
@@ -27,18 +27,19 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Set;
|
||||
|
||||
public class PluginsUsagesCollector extends UsagesCollector {
|
||||
private static final String GROUP_ID = "plugins";
|
||||
private static final String GROUP_ID = "disabled-plugins";
|
||||
|
||||
public static GroupDescriptor getGroupId() {
|
||||
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
|
||||
@NotNull
|
||||
public String getGroupId() {
|
||||
return GROUP_ID;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
|
||||
return ContainerUtil.map2Set(PluginManager.getPlugins(), new Function<IdeaPluginDescriptor, UsageDescriptor>() {
|
||||
return ContainerUtil.map2Set(PluginManager.getDisabledPlugins(), new Function<String, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(IdeaPluginDescriptor descriptor) {
|
||||
return new UsageDescriptor(getGroupId(), descriptor.getName(), 1);
|
||||
public UsageDescriptor fun(String descriptor) {
|
||||
return new UsageDescriptor(GroupDescriptor.create(getGroupId(), GroupDescriptor.HIGHER_PRIORITY), descriptor, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* 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.ConvertUsagesUtil;
|
||||
import com.intellij.internal.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.internal.statistic.beans.PatchedUsage;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.internal.statistic.persistence.SentUsagesPersistence;
|
||||
import com.intellij.internal.statistic.persistence.SentUsagesPersistenceComponent;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StatisticsUploadAssistant {
|
||||
|
||||
public String getData() {
|
||||
return getData(Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
public String getData(@NotNull Set<String> disabledGroups) {
|
||||
return getStringPatch(disabledGroups, ProjectManager.getInstance().getOpenProjects());
|
||||
}
|
||||
|
||||
public void persistSentPatch(@NotNull String patchStr) {
|
||||
persistSentPatch(patchStr, SentUsagesPersistenceComponent.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);
|
||||
}
|
||||
});
|
||||
|
||||
if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@NotNull Set<String> disabledGroups, Project... project) {
|
||||
return getStringPatch(disabledGroups, project, SentUsagesPersistenceComponent.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;
|
||||
}
|
||||
|
||||
@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) {
|
||||
usages.addAll(getPatchedUsages(getAllUsages(project, disabledGroups), usagesPersistence.getSentUsages()));
|
||||
}
|
||||
return usages;
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
||||
return packCollection(patchedUsages, new Condition<PatchedUsage>() {
|
||||
@Override
|
||||
public boolean value(PatchedUsage patchedUsage) {
|
||||
return patchedUsage.getDelta() != 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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 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));
|
||||
}
|
||||
}
|
||||
|
||||
return usageDescriptors;
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -13,11 +13,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.statistic;
|
||||
package com.intellij.internal.statistic;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -27,4 +27,6 @@ public abstract class UsagesCollector {
|
||||
public static ExtensionPointName<UsagesCollector> EP_NAME = ExtensionPointName.create("com.intellij.statistics.usagesCollector");
|
||||
|
||||
public abstract @NotNull Set<UsageDescriptor> getUsages(@Nullable Project project);
|
||||
|
||||
public abstract @NotNull String getGroupId();
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.beans;
|
||||
|
||||
|
||||
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 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) {
|
||||
assert map != null;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : map.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 convertValueMap(Set<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);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Set<UsageDescriptor> convertString(String usages) {
|
||||
assert usages != null;
|
||||
Set<UsageDescriptor> descriptors = new LinkedHashSet<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));
|
||||
}
|
||||
}
|
||||
}
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Set<UsageDescriptor> convertValueString(GroupDescriptor groupId, String valueData) {
|
||||
assert groupId != null;
|
||||
final Set<UsageDescriptor> descriptors = new LinkedHashSet<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);
|
||||
descriptors.add(new UsageDescriptor(groupId, pair.first, i));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//@NotNull
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> groupDescriptors(Set<? extends UsageDescriptor> descriptors) {
|
||||
assert descriptors != null;
|
||||
final SortedMap<GroupDescriptor, Set<UsageDescriptor>> map = new TreeMap<GroupDescriptor, Set<UsageDescriptor>>(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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.beans;
|
||||
|
||||
public class GroupDescriptor implements Comparable<GroupDescriptor> {
|
||||
public static final double DEFAULT_PRIORITY = 0.0;
|
||||
public static final double HIGHER_PRIORITY = 100.0;
|
||||
public static final double LOWER_PRIORITY = -100.0;
|
||||
|
||||
private final String myId;
|
||||
private double myPriority;
|
||||
|
||||
public static GroupDescriptor create(String id) {
|
||||
assert id != null;
|
||||
return new GroupDescriptor(id);
|
||||
}
|
||||
|
||||
public static GroupDescriptor create(String id, double priority) {
|
||||
assert id != null;
|
||||
return new GroupDescriptor(id, priority);
|
||||
}
|
||||
|
||||
private GroupDescriptor(String id) {
|
||||
this(id, DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
private GroupDescriptor(String id, double priority) {
|
||||
assert id != null;
|
||||
myId = id;
|
||||
myPriority = priority;
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
public double getPriority() {
|
||||
return myPriority;
|
||||
}
|
||||
|
||||
public void setPriority(double priority) {
|
||||
myPriority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof GroupDescriptor)) return false;
|
||||
|
||||
GroupDescriptor that = (GroupDescriptor) o;
|
||||
|
||||
if (myId != null ? !myId.equals(that.myId) : that.myId != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myId != null ? myId.hashCode() : 0;
|
||||
}
|
||||
|
||||
public int compareTo(GroupDescriptor gd) {
|
||||
final int priority = (int) (this.getPriority() - gd.getPriority());
|
||||
return priority == 0 ? gd.getId().compareTo(gd.getId()) : priority;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -13,17 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.statistic.beans;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
package com.intellij.internal.statistic.beans;
|
||||
|
||||
public class PatchedUsage extends UsageDescriptor {
|
||||
|
||||
public PatchedUsage(@NotNull UsageDescriptor descriptor) {
|
||||
public PatchedUsage(UsageDescriptor descriptor) {
|
||||
super(descriptor.getGroup(), descriptor.getKey(), descriptor.getValue());
|
||||
}
|
||||
|
||||
public PatchedUsage(@NotNull GroupDescriptor group, @NotNull String key, int value) {
|
||||
public PatchedUsage(GroupDescriptor group, String key, int value) {
|
||||
super(group, key, value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.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;
|
||||
|
||||
myGroup = group;
|
||||
myKey = key;
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return myKey;
|
||||
}
|
||||
|
||||
public GroupDescriptor getGroup() {
|
||||
return myGroup;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
public void setValue(int i) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myGroup.hashCode();
|
||||
result = 31 * result + myKey.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public int compareTo(UsageDescriptor ud) {
|
||||
final int byGroup = this.getGroup().compareTo(ud.getGroup());
|
||||
|
||||
return byGroup == 0 ? this.getKey().compareTo(ud.myKey) : byGroup;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.intellij.internal.statistic.connect;
|
||||
|
||||
import com.intellij.internal.statistic.StatisticsUploadAssistant;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RemotelyConfigurableStatisticsService implements StatisticsService {
|
||||
|
||||
private StatisticsConnectionService myConnectionService;
|
||||
private StatisticsDataSender sender;
|
||||
private StatisticsUploadAssistant myAssistant;
|
||||
|
||||
public RemotelyConfigurableStatisticsService(@NotNull StatisticsConnectionService connectionService,
|
||||
@NotNull StatisticsDataSender sender,
|
||||
@NotNull StatisticsUploadAssistant assistant) {
|
||||
myConnectionService = connectionService;
|
||||
this.sender = sender;
|
||||
myAssistant = assistant;
|
||||
}
|
||||
|
||||
public StatisticsResult send() {
|
||||
final String serviceUrl = myConnectionService.getServiceUrl();
|
||||
|
||||
if (serviceUrl == null) {
|
||||
return new StatisticsResult(StatisticsResult.ResultCode.ERROR_IN_CONFIG, "ERROR");
|
||||
}
|
||||
|
||||
if (!myConnectionService.isTransmissionPermitted()) {
|
||||
return new StatisticsResult(StatisticsResult.ResultCode.NOT_PERMITTED, "NOT_PERMITTED");
|
||||
}
|
||||
|
||||
String content = myAssistant.getData();
|
||||
|
||||
if (StringUtil.isEmptyOrSpaces(content)) {
|
||||
return new StatisticsResult(StatisticsResult.ResultCode.NOTHING_TO_SEND, "NOTHING_TO_SEND");
|
||||
}
|
||||
|
||||
try {
|
||||
sender.send(serviceUrl, content);
|
||||
myAssistant.persistSentPatch(content);
|
||||
|
||||
return new StatisticsResult(StatisticsResult.ResultCode.SEND, "SUCCESS");
|
||||
}
|
||||
catch (Exception e) {
|
||||
return new StatisticsResult(StatisticsResult.ResultCode.SEND_WITH_ERRORS, e.getMessage() != null ? e.getMessage() : "NPE");
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.connect;
|
||||
|
||||
|
||||
public class StatServiceException extends RuntimeException {
|
||||
|
||||
public StatServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public StatServiceException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
public StatServiceException(String s, Throwable throwable) {
|
||||
super(s, throwable);
|
||||
}
|
||||
|
||||
public StatServiceException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.connect;
|
||||
|
||||
import com.intellij.facet.frameworks.SettingsConnectionService;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class StatisticsConnectionService extends SettingsConnectionService {
|
||||
|
||||
private static final String SETTINGS_URL = "http://jetbrains.com/idea/statistics/stat-assistant.xml";
|
||||
private static final String DEFAULT_SERVICE_URL = "http://jetbrains.com/idea/statistics/index.jsp";
|
||||
|
||||
private static final String PERMISSION_ATTR_NAME = "permitted";
|
||||
private static final String DISABLED = "disabled";
|
||||
|
||||
public StatisticsConnectionService() {
|
||||
this(SETTINGS_URL, DEFAULT_SERVICE_URL);
|
||||
}
|
||||
|
||||
public StatisticsConnectionService(@NotNull String settingsUrl, @Nullable String defaultServiceUrl) {
|
||||
super(settingsUrl, defaultServiceUrl);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getAttributeNames() {
|
||||
return ArrayUtil.append(super.getAttributeNames(), PERMISSION_ATTR_NAME);
|
||||
}
|
||||
|
||||
public Boolean isTransmissionPermitted() {
|
||||
final String permitted = getSettingValue(PERMISSION_ATTR_NAME);
|
||||
|
||||
return permitted == null ? true : Boolean.parseBoolean(permitted);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<String> getDisabledGroups() {
|
||||
final String disabledGroupsString = getSettingValue(DISABLED);
|
||||
|
||||
if (disabledGroupsString == null) return Collections.<String>emptySet();
|
||||
|
||||
final List<String> disabledGroupsList = StringUtil.split(disabledGroupsString, ",");
|
||||
return ContainerUtil.map2Set(disabledGroupsList, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return s.trim();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.connect;
|
||||
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface StatisticsDataSender {
|
||||
|
||||
void send(@NotNull String url, @NotNull String content) throws StatServiceException;
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.connect;
|
||||
|
||||
import com.intellij.openapi.updateSettings.impl.UpdateChecker;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.apache.commons.httpclient.methods.PostMethod;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StatisticsHttpClientSender implements StatisticsDataSender {
|
||||
|
||||
public void send(@NotNull String url, @NotNull String content) throws StatServiceException {
|
||||
PostMethod post = null;
|
||||
|
||||
try {
|
||||
HttpClient httpclient = new HttpClient();
|
||||
post = new PostMethod(url);
|
||||
|
||||
post.setRequestBody(new NameValuePair[]{
|
||||
new NameValuePair("content", content),
|
||||
new NameValuePair("uuid", UpdateChecker.getInstallationUID())});
|
||||
|
||||
httpclient.executeMethod(post);
|
||||
|
||||
if (post.getStatusCode() != HttpStatus.SC_OK) {
|
||||
throw new StatServiceException("Error during data sending... Code: " + post.getStatusCode());
|
||||
}
|
||||
|
||||
final Header errors = post.getResponseHeader("errors");
|
||||
if (errors != null) {
|
||||
final String value = errors.getValue();
|
||||
|
||||
throw new StatServiceException("Error during updating statistics " + (!StringUtil.isEmptyOrSpaces(value) ? " : " + value : ""));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new StatServiceException("Error during data sending...", e);
|
||||
}
|
||||
finally {
|
||||
if (post != null) {
|
||||
post.releaseConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.connect;
|
||||
|
||||
public class StatisticsResult {
|
||||
private ResultCode code;
|
||||
private String description;
|
||||
|
||||
public StatisticsResult(ResultCode code, String description) {
|
||||
this.code = code;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public ResultCode getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public enum ResultCode {SEND, NOT_PERMITTED, ERROR_IN_CONFIG, NOTHING_TO_SEND, SEND_WITH_ERRORS}
|
||||
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.connect;
|
||||
|
||||
|
||||
public interface StatisticsService {
|
||||
|
||||
StatisticsResult send();
|
||||
}
|
||||
+6
-5
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.statistic.persistence;
|
||||
package com.intellij.internal.statistic.persistence;
|
||||
|
||||
import com.intellij.statistic.StatisticsUploadAssistant;
|
||||
import com.intellij.statistic.beans.PatchedUsage;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.internal.statistic.StatisticsUploadAssistant;
|
||||
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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -33,7 +34,7 @@ public class BasicSentUsagesPersistenceComponent extends SentUsagesPersistence {
|
||||
|
||||
public void persistPatch(@NotNull Set<PatchedUsage> patchedDescriptors) {
|
||||
for (PatchedUsage patchedUsage : patchedDescriptors) {
|
||||
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, patchedUsage.getId());
|
||||
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, Pair.create(patchedUsage.getGroup(), patchedUsage.getKey()));
|
||||
if (usageDescriptor != null) {
|
||||
usageDescriptor.setValue(usageDescriptor.getValue() + patchedUsage.getDelta());
|
||||
}
|
||||
+3
-3
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.statistic.persistence;
|
||||
package com.intellij.internal.statistic.persistence;
|
||||
|
||||
import com.intellij.statistic.beans.PatchedUsage;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.internal.statistic.beans.PatchedUsage;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
+7
-7
@@ -14,16 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.statistic.persistence;
|
||||
package com.intellij.internal.statistic.persistence;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
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.statistic.StatisticsUploadAssistant;
|
||||
import com.intellij.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
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.util.text.StringUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -66,7 +66,7 @@ public class SentUsagesPersistenceComponent extends BasicSentUsagesPersistenceCo
|
||||
|
||||
String valueData = groupElement.getAttributeValue(DATA_ATTR);
|
||||
if (!StringUtil.isEmptyOrSpaces(groupId) && !StringUtil.isEmptyOrSpaces(valueData)) {
|
||||
getSentUsages().addAll(StatisticsUploadAssistant.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
|
||||
getSentUsages().addAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,12 +80,12 @@ public class SentUsagesPersistenceComponent extends BasicSentUsagesPersistenceCo
|
||||
public Element getState() {
|
||||
Element element = new Element("state");
|
||||
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : StatisticsUploadAssistant.groupDescriptors(getSentUsages())
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.groupDescriptors(getSentUsages())
|
||||
.entrySet()) {
|
||||
Element projectElement = new Element(GROUP_TAG);
|
||||
projectElement.setAttribute(GROUP_ID_ATTR, entry.getKey().getId());
|
||||
projectElement.setAttribute(GROUP_PRIORITY_ATTR, Double.toString(entry.getKey().getPriority()));
|
||||
projectElement.setAttribute(DATA_ATTR, StatisticsUploadAssistant.convertValueMap(entry.getValue()));
|
||||
projectElement.setAttribute(DATA_ATTR, ConvertUsagesUtil.convertValueMap(entry.getValue()));
|
||||
|
||||
element.addContent(projectElement);
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.tmp;
|
||||
|
||||
import com.intellij.internal.statistic.StatisticsUploadAssistant;
|
||||
import com.intellij.internal.statistic.connect.StatisticsHttpClientSender;
|
||||
import com.intellij.internal.statistic.connect.RemotelyConfigurableStatisticsService;
|
||||
import com.intellij.internal.statistic.connect.StatisticsConnectionService;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
public class SendStatisticsAction extends AnAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project != null) {
|
||||
final RemotelyConfigurableStatisticsService service = new RemotelyConfigurableStatisticsService(new StatisticsConnectionService(), new StatisticsHttpClientSender(), new StatisticsUploadAssistant());
|
||||
|
||||
service.send();
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-15
@@ -347,21 +347,9 @@ public final class UpdateChecker {
|
||||
public void run() {
|
||||
try {
|
||||
HttpConfigurable.getInstance().prepareURL(url);
|
||||
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
|
||||
String uid = "";
|
||||
if (!propertiesComponent.isValueSet(INSTALLATION_UID)) {
|
||||
try {
|
||||
uid = UUID.randomUUID().toString();
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
catch (InternalError ignored) {
|
||||
}
|
||||
propertiesComponent.setValue(INSTALLATION_UID, uid);
|
||||
}
|
||||
else {
|
||||
uid = propertiesComponent.getValue(INSTALLATION_UID);
|
||||
}
|
||||
|
||||
String uid = getInstallationUID();
|
||||
|
||||
final URL requestUrl = new URL(url + "?build=" + ApplicationInfo.getInstance().getBuild().asString() + "&uid=" + uid + ADDITIONAL_REQUEST_OPTIONS);
|
||||
final InputStream inputStream = requestUrl.openStream();
|
||||
try {
|
||||
@@ -396,6 +384,25 @@ public final class UpdateChecker {
|
||||
return document[0];
|
||||
}
|
||||
|
||||
public static String getInstallationUID() {
|
||||
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
|
||||
String uid = "";
|
||||
if (!propertiesComponent.isValueSet(INSTALLATION_UID)) {
|
||||
try {
|
||||
uid = UUID.randomUUID().toString();
|
||||
}
|
||||
catch (Exception ignored) {
|
||||
}
|
||||
catch (InternalError ignored) {
|
||||
}
|
||||
propertiesComponent.setValue(INSTALLATION_UID, uid);
|
||||
}
|
||||
else {
|
||||
uid = propertiesComponent.getValue(INSTALLATION_UID);
|
||||
}
|
||||
return uid;
|
||||
}
|
||||
|
||||
public static void showNoUpdatesDialog(boolean enableLink, final List<PluginDownloader> updatePlugins, boolean showConfirmation) {
|
||||
NoUpdatesDialog dialog = new NoUpdatesDialog(true, updatePlugins, enableLink);
|
||||
dialog.setShowConfirmation(showConfirmation);
|
||||
|
||||
@@ -1,267 +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.statistic;
|
||||
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.statistic.beans.PatchedUsage;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.statistic.persistence.SentUsagesPersistence;
|
||||
import com.intellij.statistic.persistence.SentUsagesPersistenceComponent;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StatisticsUploadAssistant {
|
||||
|
||||
private static final Character GROUP_SEPARATOR = ':';
|
||||
private static final Character GROUPS_SEPARATOR = ';';
|
||||
private static final Character GROUP_VALUE_SEPARATOR = ',';
|
||||
|
||||
private StatisticsUploadAssistant() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@Nullable Project project) {
|
||||
return getStringPatch(project, 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@Nullable Project project, int maxSize) {
|
||||
return getStringPatch(project, SentUsagesPersistenceComponent.getInstance(), maxSize);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@Nullable Project project, @NotNull SentUsagesPersistence usagesPersistence, int maxSize) {
|
||||
final Set<PatchedUsage> patchedUsages = getPatchedUsages(project, usagesPersistence);
|
||||
|
||||
return getStringPatch(patchedUsages, usagesPersistence, maxSize);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getStringPatch(@NotNull Set<PatchedUsage> patchedUsages,
|
||||
@NotNull SentUsagesPersistence usagesPersistence,
|
||||
int maxSize) {
|
||||
if (patchedUsages.size() == 0) return "";
|
||||
|
||||
String patchStr = convertUsages(patchedUsages);
|
||||
if (maxSize > 0 && patchStr.getBytes().length > maxSize) {
|
||||
patchStr = cutPatchString(patchStr, maxSize);
|
||||
|
||||
patchedUsages = ContainerUtil.map2Set(convertString(patchStr), new Function<UsageDescriptor, PatchedUsage>() {
|
||||
@Override
|
||||
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
|
||||
return new PatchedUsage(usageDescriptor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (patchedUsages.size() > 0) usagesPersistence.persistPatch(patchedUsages);
|
||||
|
||||
return patchStr;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<PatchedUsage> getPatchedUsages(@Nullable Project project, @NotNull SentUsagesPersistence usagesPersistence) {
|
||||
return getPatchedUsages(getAllUsages(project), usagesPersistence.getSentUsages());
|
||||
}
|
||||
|
||||
@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, sentUsage.getId());
|
||||
if (descriptor == null) {
|
||||
patchedUsages.add(new PatchedUsage(sentUsage.getGroup(), 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String cutPatchString(@NotNull String patchStr, int maxSize) {
|
||||
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 "";
|
||||
}
|
||||
|
||||
@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.equals(t.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<UsageDescriptor> getAllUsages(@Nullable Project project) {
|
||||
final Set<UsageDescriptor> usageDescriptors = new TreeSet<UsageDescriptor>();
|
||||
|
||||
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
|
||||
usageDescriptors.addAll(usagesCollector.getUsages(project));
|
||||
}
|
||||
|
||||
return usageDescriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String convertUsages(@NotNull Set<? extends UsageDescriptor> descriptors) {
|
||||
final Map<GroupDescriptor, Set<UsageDescriptor>> descriptorGroups = groupDescriptors(descriptors);
|
||||
|
||||
return convertUsages(descriptorGroups);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Map<GroupDescriptor, Set<UsageDescriptor>> groupDescriptors(@NotNull Set<? extends UsageDescriptor> descriptors) {
|
||||
final SortedMap<GroupDescriptor, Set<UsageDescriptor>> map = new TreeMap<GroupDescriptor, Set<UsageDescriptor>>(new Comparator<GroupDescriptor>() {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String convertUsages(@NotNull Map<GroupDescriptor, Set<UsageDescriptor>> map) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : map.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 Set<UsageDescriptor> convertString(@NotNull String usages) {
|
||||
Set<UsageDescriptor> descriptors = new LinkedHashSet<UsageDescriptor>();
|
||||
for (String groupStr : StringUtil.split(usages, GROUPS_SEPARATOR.toString())) {
|
||||
if (!StringUtil.isEmptyOrSpaces(groupStr)) {
|
||||
final Pair<String, String> group = getPair(groupStr, GROUP_SEPARATOR.toString());
|
||||
if (group != null) {
|
||||
descriptors.addAll(convertValueString(GroupDescriptor.create(group.getFirst()), group.getSecond()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String convertValueMap(@NotNull Set<UsageDescriptor> descriptors) {
|
||||
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 Set<UsageDescriptor> convertValueString(@NotNull GroupDescriptor groupId, String valueData) {
|
||||
final Set<UsageDescriptor> descriptors = new LinkedHashSet<UsageDescriptor>();
|
||||
for (String value : StringUtil.split(valueData, GROUP_VALUE_SEPARATOR.toString())) {
|
||||
if (!StringUtil.isEmptyOrSpaces(value)) {
|
||||
final Pair<String, String> pair = getPair(value, "=");
|
||||
if (pair != null) {
|
||||
final String count = pair.getSecond();
|
||||
if (!StringUtil.isEmptyOrSpaces(count)) {
|
||||
try {
|
||||
final int i = Integer.parseInt(count);
|
||||
descriptors.add(new UsageDescriptor(groupId, pair.getFirst(), i));
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<String, String> getPair(@NotNull String str, @NotNull String separator) {
|
||||
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 (!StringUtil.isEmptyOrSpaces(key) && !StringUtil.isEmptyOrSpaces(value)) {
|
||||
return Pair.create(key, value);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +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.statistic.beans;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GroupDescriptor implements Comparable<GroupDescriptor> {
|
||||
public static final double DEFAULT_PRIORITY = 0.0;
|
||||
public static final double HIGHER_PRIORITY = 100.0;
|
||||
public static final double LOWER_PRIORITY = -100.0;
|
||||
|
||||
private final String myId;
|
||||
private double myPriority;
|
||||
|
||||
public static GroupDescriptor create(@NotNull String id) {
|
||||
return new GroupDescriptor(id);
|
||||
}
|
||||
|
||||
public static GroupDescriptor create(@NotNull String id, double priority) {
|
||||
return new GroupDescriptor(id, priority);
|
||||
}
|
||||
|
||||
private GroupDescriptor(@NotNull String id) {
|
||||
this(id, DEFAULT_PRIORITY);
|
||||
}
|
||||
|
||||
private GroupDescriptor(@NotNull String id, double priority) {
|
||||
myId = id;
|
||||
myPriority = priority;
|
||||
}
|
||||
|
||||
|
||||
public String getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
public double getPriority() {
|
||||
return myPriority;
|
||||
}
|
||||
|
||||
public void setPriority(double priority) {
|
||||
myPriority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof GroupDescriptor)) return false;
|
||||
|
||||
GroupDescriptor that = (GroupDescriptor)o;
|
||||
|
||||
if (myId != null ? !myId.equals(that.myId) : that.myId != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myId != null ? myId.hashCode() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(GroupDescriptor gd) {
|
||||
final int priority = (int)(this.getPriority() - gd.getPriority());
|
||||
return priority == 0 ? gd.getId().compareTo(gd.getId()) : priority;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +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.statistic.beans;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UsageDescriptor implements Comparable<UsageDescriptor> {
|
||||
|
||||
private final GroupDescriptor myGroup;
|
||||
private final String myKey;
|
||||
private int myValue;
|
||||
|
||||
public UsageDescriptor(@NotNull GroupDescriptor group, @NotNull String key, int value) {
|
||||
myGroup = group;
|
||||
myKey = key;
|
||||
myValue = value;
|
||||
}
|
||||
|
||||
public Pair<GroupDescriptor, String> getId() {
|
||||
return Pair.create(getGroup(), getKey());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getKey() {
|
||||
return myKey;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GroupDescriptor getGroup() {
|
||||
return myGroup;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
public void setValue(int i) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myGroup.hashCode();
|
||||
result = 31 * result + myKey.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(UsageDescriptor ud) {
|
||||
final int byGroup = this.getGroup().compareTo(ud.getGroup());
|
||||
|
||||
return byGroup == 0 ? this.getKey().compareTo(ud.myKey) : byGroup;
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@
|
||||
<extensionPoint name="featureStatBundle" interface="com.intellij.featureStatistics.FeatureStatisticsBundleProvider"/>
|
||||
|
||||
<extensionPoint name="editorCustomization" area="IDEA_PROJECT" interface="com.intellij.ui.EditorCustomization"/>
|
||||
<extensionPoint name="statistics.usagesCollector" interface="com.intellij.statistic.UsagesCollector"/>
|
||||
<extensionPoint name="statistics.usagesCollector" interface="com.intellij.internal.statistic.UsagesCollector"/>
|
||||
|
||||
<extensionPoint name="xmlRpcHandler" beanClass="com.intellij.ide.XmlRpcHandlerBean"/>
|
||||
</extensionPoints>
|
||||
|
||||
@@ -114,8 +114,8 @@
|
||||
</component>
|
||||
|
||||
<component>
|
||||
<interface-class>com.intellij.statistic.persistence.SentUsagesPersistenceComponent</interface-class>
|
||||
<implementation-class>com.intellij.statistic.persistence.SentUsagesPersistenceComponent</implementation-class>
|
||||
<interface-class>com.intellij.internal.statistic.persistence.SentUsagesPersistenceComponent</interface-class>
|
||||
<implementation-class>com.intellij.internal.statistic.persistence.SentUsagesPersistenceComponent</implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
package com.intellij.openapi.vcs.statistics;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ 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.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.internal.statistic.beans.UsageDescriptor;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jdom.Element;
|
||||
@@ -71,7 +71,7 @@ public class VcsStatisticsPersistenceComponent extends VcsStatisticsPersistence
|
||||
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.getGroupId(), key, 1));
|
||||
vcsDescriptors.add(new UsageDescriptor(VcsUsagesCollector.createGroupDescriptor(), key, 1));
|
||||
}
|
||||
getVcsUsageMap().put(projectId, vcsDescriptors);
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ package com.intellij.openapi.vcs.statistics;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.impl.VcsDescriptor;
|
||||
import com.intellij.statistic.UsagesCollector;
|
||||
import com.intellij.statistic.beans.GroupDescriptor;
|
||||
import com.intellij.statistic.beans.UsageDescriptor;
|
||||
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.hash.HashMap;
|
||||
@@ -49,12 +49,12 @@ public class VcsUsagesCollector extends UsagesCollector {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<UsageDescriptor> getApplicationUsages() {
|
||||
public Set<UsageDescriptor> getApplicationUsages() {
|
||||
return getApplicationUsages(VcsStatisticsPersistenceComponent.getInstance());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<UsageDescriptor> getApplicationUsages(@NotNull final VcsStatisticsPersistenceComponent persistence) {
|
||||
public Set<UsageDescriptor> getApplicationUsages(@NotNull final VcsStatisticsPersistenceComponent persistence) {
|
||||
final Map<String, Integer> vcsUsagesMap = new HashMap<String, Integer>();
|
||||
|
||||
for (Set<UsageDescriptor> descriptors : persistence.getVcsUsageMap().values()) {
|
||||
@@ -68,13 +68,14 @@ public class VcsUsagesCollector extends UsagesCollector {
|
||||
return ContainerUtil.map2Set(vcsUsagesMap.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(Map.Entry<String, Integer> vcsUsage) {
|
||||
return new UsageDescriptor(getGroupId(), vcsUsage.getKey(), vcsUsage.getValue());
|
||||
return new UsageDescriptor(createGroupDescriptor(), vcsUsage.getKey(), vcsUsage.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GroupDescriptor getGroupId() {
|
||||
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
|
||||
@NotNull
|
||||
public String getGroupId() {
|
||||
return GROUP_ID;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -90,9 +91,13 @@ public class VcsUsagesCollector extends UsagesCollector {
|
||||
return ContainerUtil.map2Set(ProjectLevelVcsManager.getInstance(project).getAllVcss(), new Function<VcsDescriptor, UsageDescriptor>() {
|
||||
@Override
|
||||
public UsageDescriptor fun(VcsDescriptor descriptor) {
|
||||
return new UsageDescriptor(getGroupId(), descriptor.getName(), 1);
|
||||
return new UsageDescriptor(createGroupDescriptor(), descriptor.getName(), 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GroupDescriptor createGroupDescriptor() {
|
||||
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -262,6 +262,7 @@
|
||||
<action id="ScanSourceCommentsAction" internal="true" class="com.intellij.tools.ScanSourceCommentsAction" text="Dump all comments in the project"/>
|
||||
<action internal="true" id="CompilerTest" class="com.intellij.compiler.impl.javaCompiler.api.CompilerPerfTestAction" text="Test Rebuild Performance"/>
|
||||
<action internal="true" id="GenerateDomModel" class="com.intellij.util.dom.generator.GenerateDomModelAction" text="Generate Dom Model"/>
|
||||
<action internal="true" id="SendStatistics" class="com.intellij.internal.statistic.tmp.SendStatisticsAction" text="Send statistics"/>
|
||||
|
||||
<add-to-group group-id="Internal" anchor="last"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user