diff --git a/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadConnectionService.java b/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadConnectionService.java index 4c43bcccab22..2d5a3ddc9685 100644 --- a/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadConnectionService.java +++ b/platform/lang-api/src/com/intellij/facet/frameworks/LibrariesDownloadConnectionService.java @@ -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; - } } diff --git a/platform/lang-api/src/com/intellij/facet/frameworks/SettingsConnectionService.java b/platform/lang-api/src/com/intellij/facet/frameworks/SettingsConnectionService.java new file mode 100644 index 000000000000..cd638d426536 --- /dev/null +++ b/platform/lang-api/src/com/intellij/facet/frameworks/SettingsConnectionService.java @@ -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 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 readSettings(String... attributes) { + Map settings = new HashMap(); + 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; + } +} diff --git a/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkStatisticsPersistence.java b/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkStatisticsPersistence.java index e26ed8fb5932..b1d9a0894c75 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkStatisticsPersistence.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkStatisticsPersistence.java @@ -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; diff --git a/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkStatisticsPersistenceComponent.java b/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkStatisticsPersistenceComponent.java index 0c18a17355b7..717dabff6e15 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkStatisticsPersistenceComponent.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkStatisticsPersistenceComponent.java @@ -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 frameworkDescriptors = new HashSet(); 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); } diff --git a/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkUsagesCollector.java b/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkUsagesCollector.java index 15e24c38ed6c..abad35157269 100644 --- a/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkUsagesCollector.java +++ b/platform/lang-impl/src/com/intellij/facet/impl/statistics/FrameworkUsagesCollector.java @@ -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 getApplicationUsages() { + public Set getApplicationUsages() { return getApplicationUsages(FrameworkStatisticsPersistenceComponent.getInstance()); } @NotNull - public static Set getApplicationUsages(@NotNull final FrameworkStatisticsPersistence persistence) { + public Set getApplicationUsages(@NotNull final FrameworkStatisticsPersistence persistence) { final Map facets = new HashMap(); for (Set frameworks : persistence.getFrameworks().values()) { @@ -70,12 +70,18 @@ public class FrameworkUsagesCollector extends UsagesCollector { return ContainerUtil.map2Set(facets.entrySet(), new Function, UsageDescriptor>() { @Override public UsageDescriptor fun(Map.Entry 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 facets = new HashSet(); 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() { @Override public UsageDescriptor fun(String facet) { - return new UsageDescriptor(getGroupId(), facet, 1); + return new UsageDescriptor(getGroupDescriptor(), facet, 1); } }); } diff --git a/platform/platform-impl/platform-impl.iml b/platform/platform-impl/platform-impl.iml index 68fc2731b7bd..e2ea144cc57b 100644 --- a/platform/platform-impl/platform-impl.iml +++ b/platform/platform-impl/platform-impl.iml @@ -27,6 +27,7 @@ + diff --git a/platform/platform-impl/src/com/intellij/featureStatistics/FeaturesUsageCollector.java b/platform/platform-impl/src/com/intellij/featureStatistics/FeaturesUsageCollector.java index 7d8707e88b5c..fcbf518cda18 100644 --- a/platform/platform-impl/src/com/intellij/featureStatistics/FeaturesUsageCollector.java +++ b/platform/platform-impl/src/com/intellij/featureStatistics/FeaturesUsageCollector.java @@ -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 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())); } } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginsUsagesCollector.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginsUsagesCollector.java index 560fac29c488..006b58967ada 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginsUsagesCollector.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginsUsagesCollector.java @@ -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 getUsages(@Nullable Project project) { - return ContainerUtil.map2Set(PluginManager.getPlugins(), new Function() { + return ContainerUtil.map2Set(PluginManager.getDisabledPlugins(), new Function() { @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); } }); } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/StatisticsUploadAssistant.java b/platform/platform-impl/src/com/intellij/internal/statistic/StatisticsUploadAssistant.java new file mode 100644 index 000000000000..a8fe0a736cec --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/StatisticsUploadAssistant.java @@ -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.emptySet()); + } + + public String getData(@NotNull Set 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 patchedUsages = + ContainerUtil.map2Set(ConvertUsagesUtil.convertString(patchStr), new Function() { + @Override + public PatchedUsage fun(UsageDescriptor usageDescriptor) { + return new PatchedUsage(usageDescriptor); + } + }); + + if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages); + } + + @NotNull + public static String getStringPatch(@NotNull Set disabledGroups, Project... project) { + return getStringPatch(disabledGroups, project, SentUsagesPersistenceComponent.getInstance(), 0); + } + + @NotNull + public static String getStringPatch(@NotNull Set disabledGroups, + @NotNull Project[] projects, + @NotNull SentUsagesPersistence usagesPersistence, + int maxSize) { + final Set patchedUsages = getPatchedUsages(disabledGroups, projects, usagesPersistence); + + return getStringPatch(patchedUsages, maxSize); + } + + public static String getStringPatch(@NotNull Set 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 getPatchedUsages(@NotNull Set disabledGroups, + @NotNull Project[] projects, + @NotNull SentUsagesPersistence usagesPersistence) { + Set usages = new HashSet(); + + for (Project project : projects) { + usages.addAll(getPatchedUsages(getAllUsages(project, disabledGroups), usagesPersistence.getSentUsages())); + } + return usages; + } + + @NotNull + public static Set getPatchedUsages(@NotNull final Set allUsages, + @NotNull SentUsagesPersistence usagesPersistence) { + return getPatchedUsages(allUsages, usagesPersistence.getSentUsages()); + } + + @NotNull + public static Set getPatchedUsages(@NotNull final Set allUsages, final Set sentUsages) { + final Set patchedUsages = ContainerUtil.map2Set(allUsages, new Function() { + @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() { + @Override + public boolean value(PatchedUsage patchedUsage) { + return patchedUsage.getDelta() != 0; + } + }); + } + + @NotNull + private static Set packCollection(@NotNull Collection set, @NotNull Condition condition) { + final Set result = new LinkedHashSet(); + for (T t : set) { + if (condition.value(t)) { + result.add(t); + } + } + return result; + } + + @Nullable + public static T findDescriptor(@NotNull Set descriptors, + @NotNull final Pair id) { + return ContainerUtil.find(descriptors, new Condition() { + @Override + public boolean value(T t) { + return id.getFirst().equals(t.getGroup()) && id.getSecond().equals(t.getKey()); + } + }); + } + + @NotNull + public static Set getAllUsages(@Nullable Project project, @NotNull Set disabledGroups) { + final Set usageDescriptors = new TreeSet(); + + for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) { + if (!disabledGroups.contains(usagesCollector.getGroupId())) { + usageDescriptors.addAll(usagesCollector.getUsages(project)); + } + } + + return usageDescriptors; + } +} diff --git a/platform/platform-impl/src/com/intellij/statistic/UsagesCollector.java b/platform/platform-impl/src/com/intellij/internal/statistic/UsagesCollector.java similarity index 87% rename from platform/platform-impl/src/com/intellij/statistic/UsagesCollector.java rename to platform/platform-impl/src/com/intellij/internal/statistic/UsagesCollector.java index e0320bc0b2ca..e07246e0556a 100644 --- a/platform/platform-impl/src/com/intellij/statistic/UsagesCollector.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/UsagesCollector.java @@ -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 EP_NAME = ExtensionPointName.create("com.intellij.statistics.usagesCollector"); public abstract @NotNull Set getUsages(@Nullable Project project); + + public abstract @NotNull String getGroupId(); } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/beans/ConvertUsagesUtil.java b/platform/platform-impl/src/com/intellij/internal/statistic/beans/ConvertUsagesUtil.java new file mode 100644 index 000000000000..8fd58411e437 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/beans/ConvertUsagesUtil.java @@ -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 descriptors) { + assert descriptors != null; + final Map> descriptorGroups = groupDescriptors(descriptors); + + return convertUsages(descriptorGroups); + } + + // @NotNull + public static String convertUsages(Map> map) { + assert map != null; + StringBuffer buffer = new StringBuffer(); + for (Map.Entry> 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 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 convertString(String usages) { + assert usages != null; + Set descriptors = new LinkedHashSet(); + 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 convertValueString(GroupDescriptor groupId, String valueData) { + assert groupId != null; + final Set descriptors = new LinkedHashSet(); + 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> groupDescriptors(Set descriptors) { + assert descriptors != null; + final SortedMap> map = new TreeMap>(new Comparator() { + 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()); + } + 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; + } +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/beans/GroupDescriptor.java b/platform/platform-impl/src/com/intellij/internal/statistic/beans/GroupDescriptor.java new file mode 100644 index 000000000000..fcbff6c4f6a2 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/beans/GroupDescriptor.java @@ -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 { + 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; + } +} + diff --git a/platform/platform-impl/src/com/intellij/statistic/beans/PatchedUsage.java b/platform/platform-impl/src/com/intellij/internal/statistic/beans/PatchedUsage.java similarity index 80% rename from platform/platform-impl/src/com/intellij/statistic/beans/PatchedUsage.java rename to platform/platform-impl/src/com/intellij/internal/statistic/beans/PatchedUsage.java index d5c0ea3c53ec..f91433e4b6bb 100644 --- a/platform/platform-impl/src/com/intellij/statistic/beans/PatchedUsage.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/beans/PatchedUsage.java @@ -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); } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/beans/UsageDescriptor.java b/platform/platform-impl/src/com/intellij/internal/statistic/beans/UsageDescriptor.java new file mode 100644 index 000000000000..2ec188afa17d --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/beans/UsageDescriptor.java @@ -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 { + + 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; + } +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/connect/RemotelyConfigurableStatisticsService.java b/platform/platform-impl/src/com/intellij/internal/statistic/connect/RemotelyConfigurableStatisticsService.java new file mode 100644 index 000000000000..90877592027f --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/connect/RemotelyConfigurableStatisticsService.java @@ -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"); + } + } +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatServiceException.java b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatServiceException.java new file mode 100644 index 000000000000..2964db2021ce --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatServiceException.java @@ -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); + } +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsConnectionService.java b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsConnectionService.java new file mode 100644 index 000000000000..6a0df42f96eb --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsConnectionService.java @@ -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 getDisabledGroups() { + final String disabledGroupsString = getSettingValue(DISABLED); + + if (disabledGroupsString == null) return Collections.emptySet(); + + final List disabledGroupsList = StringUtil.split(disabledGroupsString, ","); + return ContainerUtil.map2Set(disabledGroupsList, new Function() { + @Override + public String fun(String s) { + return s.trim(); + } + }); + } +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsDataSender.java b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsDataSender.java new file mode 100644 index 000000000000..0018ce34bf8a --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsDataSender.java @@ -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; +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsHttpClientSender.java b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsHttpClientSender.java new file mode 100644 index 000000000000..ee1971138b1d --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsHttpClientSender.java @@ -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(); + } + } + } +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsResult.java b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsResult.java new file mode 100644 index 000000000000..20d447e52534 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsResult.java @@ -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} + + +} diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsService.java b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsService.java new file mode 100644 index 000000000000..3fe21714ecf1 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/connect/StatisticsService.java @@ -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(); +} diff --git a/platform/platform-impl/src/com/intellij/statistic/persistence/BasicSentUsagesPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/BasicSentUsagesPersistenceComponent.java similarity index 80% rename from platform/platform-impl/src/com/intellij/statistic/persistence/BasicSentUsagesPersistenceComponent.java rename to platform/platform-impl/src/com/intellij/internal/statistic/persistence/BasicSentUsagesPersistenceComponent.java index 63219377632d..a0f4d7499e57 100644 --- a/platform/platform-impl/src/com/intellij/statistic/persistence/BasicSentUsagesPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/BasicSentUsagesPersistenceComponent.java @@ -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 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()); } diff --git a/platform/platform-impl/src/com/intellij/statistic/persistence/SentUsagesPersistence.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/SentUsagesPersistence.java similarity index 83% rename from platform/platform-impl/src/com/intellij/statistic/persistence/SentUsagesPersistence.java rename to platform/platform-impl/src/com/intellij/internal/statistic/persistence/SentUsagesPersistence.java index 41d490797012..9d2c55fb762a 100644 --- a/platform/platform-impl/src/com/intellij/statistic/persistence/SentUsagesPersistence.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/SentUsagesPersistence.java @@ -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; diff --git a/platform/platform-impl/src/com/intellij/statistic/persistence/SentUsagesPersistenceComponent.java b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/SentUsagesPersistenceComponent.java similarity index 86% rename from platform/platform-impl/src/com/intellij/statistic/persistence/SentUsagesPersistenceComponent.java rename to platform/platform-impl/src/com/intellij/internal/statistic/persistence/SentUsagesPersistenceComponent.java index 7e2318475c1e..114949d6632c 100644 --- a/platform/platform-impl/src/com/intellij/statistic/persistence/SentUsagesPersistenceComponent.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/persistence/SentUsagesPersistenceComponent.java @@ -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> entry : StatisticsUploadAssistant.groupDescriptors(getSentUsages()) + for (Map.Entry> 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); } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/tmp/SendStatisticsAction.java b/platform/platform-impl/src/com/intellij/internal/statistic/tmp/SendStatisticsAction.java new file mode 100644 index 000000000000..eef096eadfae --- /dev/null +++ b/platform/platform-impl/src/com/intellij/internal/statistic/tmp/SendStatisticsAction.java @@ -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(); + } + } +} diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index be7eed7685b6..3d926199ca88 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -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 updatePlugins, boolean showConfirmation) { NoUpdatesDialog dialog = new NoUpdatesDialog(true, updatePlugins, enableLink); dialog.setShowConfirmation(showConfirmation); diff --git a/platform/platform-impl/src/com/intellij/statistic/StatisticsUploadAssistant.java b/platform/platform-impl/src/com/intellij/statistic/StatisticsUploadAssistant.java deleted file mode 100644 index 1dc60bb6535d..000000000000 --- a/platform/platform-impl/src/com/intellij/statistic/StatisticsUploadAssistant.java +++ /dev/null @@ -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 patchedUsages = getPatchedUsages(project, usagesPersistence); - - return getStringPatch(patchedUsages, usagesPersistence, maxSize); - } - - @NotNull - public static String getStringPatch(@NotNull Set 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() { - @Override - public PatchedUsage fun(UsageDescriptor usageDescriptor) { - return new PatchedUsage(usageDescriptor); - } - }); - } - - if (patchedUsages.size() > 0) usagesPersistence.persistPatch(patchedUsages); - - return patchStr; - } - - @NotNull - public static Set getPatchedUsages(@Nullable Project project, @NotNull SentUsagesPersistence usagesPersistence) { - return getPatchedUsages(getAllUsages(project), usagesPersistence.getSentUsages()); - } - - @NotNull - public static Set getPatchedUsages(@NotNull final Set allUsages, @NotNull SentUsagesPersistence usagesPersistence) { - return getPatchedUsages(allUsages, usagesPersistence.getSentUsages()); - } - - @NotNull - public static Set getPatchedUsages(@NotNull final Set allUsages, final Set sentUsages ) { - final Set patchedUsages = ContainerUtil.map2Set(allUsages, new Function() { - @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() { - @Override - public boolean value(PatchedUsage patchedUsage) { - return patchedUsage.getDelta() != 0; - } - }); - } - - @NotNull - private static Set packCollection(@NotNull Collection set, @NotNull Condition condition) { - final Set result = new LinkedHashSet(); - 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 findDescriptor(@NotNull Set descriptors, - @NotNull final Pair id) { - return ContainerUtil.find(descriptors, new Condition() { - @Override - public boolean value(T t) { - return id.equals(t.getId()); - } - }); - } - - @NotNull - public static Set getAllUsages(@Nullable Project project) { - final Set usageDescriptors = new TreeSet(); - - for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) { - usageDescriptors.addAll(usagesCollector.getUsages(project)); - } - - return usageDescriptors; - } - - @NotNull - public static String convertUsages(@NotNull Set descriptors) { - final Map> descriptorGroups = groupDescriptors(descriptors); - - return convertUsages(descriptorGroups); - } - - @NotNull - public static Map> groupDescriptors(@NotNull Set descriptors) { - final SortedMap> map = new TreeMap>(new Comparator() { - @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()); - } - map.get(group).add(descriptor); - } - return map; - } - - @NotNull - private static String convertUsages(@NotNull Map> map) { - StringBuffer buffer = new StringBuffer(); - for (Map.Entry> 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 convertString(@NotNull String usages) { - Set descriptors = new LinkedHashSet(); - for (String groupStr : StringUtil.split(usages, GROUPS_SEPARATOR.toString())) { - if (!StringUtil.isEmptyOrSpaces(groupStr)) { - final Pair 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 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 convertValueString(@NotNull GroupDescriptor groupId, String valueData) { - final Set descriptors = new LinkedHashSet(); - for (String value : StringUtil.split(valueData, GROUP_VALUE_SEPARATOR.toString())) { - if (!StringUtil.isEmptyOrSpaces(value)) { - final Pair 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 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; - } -} diff --git a/platform/platform-impl/src/com/intellij/statistic/beans/GroupDescriptor.java b/platform/platform-impl/src/com/intellij/statistic/beans/GroupDescriptor.java deleted file mode 100644 index 326769adf724..000000000000 --- a/platform/platform-impl/src/com/intellij/statistic/beans/GroupDescriptor.java +++ /dev/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 { - 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; - } -} - diff --git a/platform/platform-impl/src/com/intellij/statistic/beans/UsageDescriptor.java b/platform/platform-impl/src/com/intellij/statistic/beans/UsageDescriptor.java deleted file mode 100644 index e31a924be4f5..000000000000 --- a/platform/platform-impl/src/com/intellij/statistic/beans/UsageDescriptor.java +++ /dev/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 com.intellij.openapi.util.Pair; -import org.jetbrains.annotations.NotNull; - -public class UsageDescriptor implements Comparable { - - 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 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; - } -} diff --git a/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml b/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml index 3f7291cee545..dcbdc60e0cb7 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensionPoints.xml @@ -109,7 +109,7 @@ - + diff --git a/platform/platform-resources/src/componentSets/Platform.xml b/platform/platform-resources/src/componentSets/Platform.xml index a99994ac7cfd..262f9d54c624 100644 --- a/platform/platform-resources/src/componentSets/Platform.xml +++ b/platform/platform-resources/src/componentSets/Platform.xml @@ -114,8 +114,8 @@ - com.intellij.statistic.persistence.SentUsagesPersistenceComponent - com.intellij.statistic.persistence.SentUsagesPersistenceComponent + com.intellij.internal.statistic.persistence.SentUsagesPersistenceComponent + com.intellij.internal.statistic.persistence.SentUsagesPersistenceComponent diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsStatisticsPersistence.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsStatisticsPersistence.java index 0850d38c3749..968e52aae1a8 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsStatisticsPersistence.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsStatisticsPersistence.java @@ -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; diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsStatisticsPersistenceComponent.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsStatisticsPersistenceComponent.java index 3cff5584312c..1e095cd4f677 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsStatisticsPersistenceComponent.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsStatisticsPersistenceComponent.java @@ -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 vcsDescriptors = new HashSet(); 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); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsUsagesCollector.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsUsagesCollector.java index b534312e3b82..602a62853521 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsUsagesCollector.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/statistics/VcsUsagesCollector.java @@ -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 getApplicationUsages() { + public Set getApplicationUsages() { return getApplicationUsages(VcsStatisticsPersistenceComponent.getInstance()); } @NotNull - public static Set getApplicationUsages(@NotNull final VcsStatisticsPersistenceComponent persistence) { + public Set getApplicationUsages(@NotNull final VcsStatisticsPersistenceComponent persistence) { final Map vcsUsagesMap = new HashMap(); for (Set descriptors : persistence.getVcsUsageMap().values()) { @@ -68,13 +68,14 @@ public class VcsUsagesCollector extends UsagesCollector { return ContainerUtil.map2Set(vcsUsagesMap.entrySet(), new Function, UsageDescriptor>() { @Override public UsageDescriptor fun(Map.Entry 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() { @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); + } } diff --git a/resources/src/idea/IdeaActions.xml b/resources/src/idea/IdeaActions.xml index 838d33b3ec5d..ab01fb606c8a 100644 --- a/resources/src/idea/IdeaActions.xml +++ b/resources/src/idea/IdeaActions.xml @@ -262,6 +262,7 @@ +