Merge branch 'master' of git@git.labs.intellij.net:idea/community

This commit is contained in:
Kirill Kalishev
2011-02-16 19:50:41 +03:00
43 changed files with 814 additions and 897 deletions
@@ -15,9 +15,9 @@
*/
package com.intellij.compiler;
import com.intellij.compiler.impl.javaCompiler.FileObject;
import com.intellij.openapi.compiler.CompilerMessageCategory;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.compiler.impl.javaCompiler.FileObject;
import org.jetbrains.annotations.NonNls;
import java.util.ArrayList;
@@ -29,6 +29,7 @@ public abstract class OutputParser {
public interface Callback {
@NonNls String getNextLine();
@NonNls String getCurrentLine();
void pushBack(String line);
void setProgressText(String text);
void fileProcessed(@NonNls String path);
void fileGenerated(@NonNls FileObject path);
@@ -44,6 +44,7 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
private final boolean myIsUnitTestMode;
private FileObject myClassFileToProcess = null;
private String myLastReadLine = null;
private String myPushBackLine = null;
private volatile boolean myProcessExited = false;
private final CompileContext myContext;
@@ -104,6 +105,12 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
}
public final String getNextLine() {
final String pushBack = myPushBackLine;
if (pushBack != null) {
myPushBackLine = null;
myLastReadLine = pushBack;
return pushBack;
}
final String line = readLine(myCompilerOutStreamReader);
if (LOG.isDebugEnabled()) {
LOG.debug("LIne read: #" + line + "#");
@@ -120,6 +127,12 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
return myLastReadLine;
}
@Override
public void pushBack(String line) {
myLastReadLine = null;
myPushBackLine = line;
}
public final void fileGenerated(FileObject path) {
// javac first logs file generated, then starts to write the file to disk,
// so this thread sometimes can stumble on not yet existing file,
@@ -127,6 +127,14 @@ public class JavacOutputParser extends OutputParser {
final CharSequence chars = prevLine == null ? line : prevLine;
final int offset = Math.max(0, Math.min(chars.length(), nextLine.indexOf('^')));
colNum = EditorUtil.calcColumnNumber(null, chars,0, offset, myTabSize);
String messageEnd = callback.getNextLine();
while (isMessageEnd(messageEnd)) {
messages.add(messageEnd.trim());
messageEnd = callback.getNextLine();
}
if (messageEnd != null) {
callback.pushBack(messageEnd);
}
break;
}
if (prevLine != null) {
@@ -168,6 +176,10 @@ public class JavacOutputParser extends OutputParser {
return true;
}
private static boolean isMessageEnd(String line) {
return line != null && line.length() > 0 && Character.isWhitespace(line.charAt(0));
}
private static List<String> convertMessages(List<String> messages) {
if(messages.size() <= 1) {
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.roots.ui.configuration.libraries.impl;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
@@ -34,12 +35,13 @@ import java.util.*;
/**
* @author nik
*/
public class LibraryUsageCollector extends UsagesCollector {
public class LibraryUsageCollector extends AbstractApplicationUsagesCollector {
@NonNls private static final String GROUP_ID = "libraries";
@NotNull
@Override
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
public Set<UsageDescriptor> getProjectUsages(@Nullable Project project) {
if (project == null) return Collections.emptySet();
final Set<LibraryKind<?>> usedKinds = new HashSet<LibraryKind<?>>();
@@ -56,15 +58,13 @@ public class LibraryUsageCollector extends UsagesCollector {
final HashSet<UsageDescriptor> usageDescriptors = new HashSet<UsageDescriptor>();
for (LibraryKind<?> kind : usedKinds) {
final GroupDescriptor group = GroupDescriptor.create(GROUP_ID);
usageDescriptors.add(new UsageDescriptor(group, kind.getKindId(), 1));
usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
}
return usageDescriptors;
}
@NotNull
@Override
public String getGroupId() {
return GROUP_ID;
}
public GroupDescriptor getGroupId() {
return GroupDescriptor.create(GROUP_ID); }
}
@@ -1,42 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.facet.impl.statistics;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public abstract class FrameworkStatisticsPersistence {
private Map<String, Set<UsageDescriptor>> myFrameworks = new HashMap<String, Set<UsageDescriptor>>();
public FrameworkStatisticsPersistence() {
}
public void persistFrameworks(@NotNull Project project, @NotNull Set<UsageDescriptor> frameworks) {
myFrameworks.put(project.getName(), frameworks);
}
@NotNull
public Map<String, Set<UsageDescriptor>> getFrameworks() {
return myFrameworks;
}
}
@@ -1,146 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.facet.impl.statistics;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
@State(
name = "FrameworkUsages",
storages = {
@Storage(
id = "frameworks",
file = "$APP_CONFIG$/framework.usages.xml"
)}
)
public class FrameworkStatisticsPersistenceComponent extends FrameworkStatisticsPersistence
implements ApplicationComponent, PersistentStateComponent<Element> {
private static final String TOKENIZER = ",";
@NonNls private static final String PROJECT_TAG = "project";
@NonNls private static final String PROJECT_ID_ATTR = "id";
@NonNls private static final String FRAMEWORKS_ATTR = "frameworks";
public FrameworkStatisticsPersistenceComponent() {
}
public static FrameworkStatisticsPersistenceComponent getInstance() {
return ApplicationManager.getApplication().getComponent(FrameworkStatisticsPersistenceComponent.class);
}
public void loadState(final Element element) {
List projectsList = element.getChildren(PROJECT_TAG);
for (Object project : projectsList) {
Element projectElement = (Element)project;
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
String frameworks = projectElement.getAttributeValue(FRAMEWORKS_ATTR);
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>();
for (String key : StringUtil.split(frameworks, TOKENIZER)) {
frameworkDescriptors.add(new UsageDescriptor(FrameworkUsagesCollector.getGroupDescriptor(), key, 1));
}
getFrameworks().put(projectId, frameworkDescriptors);
}
}
}
public Element getState() {
Element element = new Element("state");
for (Map.Entry<String, Set<UsageDescriptor>> frameworks : getFrameworks().entrySet()) {
Element projectElement = new Element(PROJECT_TAG);
projectElement.setAttribute(PROJECT_ID_ATTR, frameworks.getKey());
projectElement.setAttribute(FRAMEWORKS_ATTR, joinUsages(frameworks.getValue()));
element.addContent(projectElement);
}
return element;
}
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
@Override
public String fun(UsageDescriptor usageDescriptor) {
return usageDescriptor.getKey();
}
}, TOKENIZER);
}
@NotNull
@NonNls
public File[] getExportFiles() {
return new File[]{PathManager.getOptionsFile("framework.usages")};
}
@NotNull
public String getPresentableName() {
return "Framework Usages";
}
@NonNls
@NotNull
public String getComponentName() {
return "FrameworkStatisticsPersistenceComponent";
}
public void initComponent() {
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
@Override
public void projectOpened(Project project) {
}
@Override
public boolean canCloseProject(Project project) {
return true;
}
@Override
public void projectClosed(Project project) {
}
@Override
public void projectClosing(Project project) {
if (project != null) {
FrameworkUsagesCollector.persistProjectUsages(project);
}
}
});
}
public void disposeComponent() {
}
}
@@ -17,84 +17,31 @@ package com.intellij.facet.impl.statistics;
import com.intellij.facet.Facet;
import com.intellij.facet.FacetManager;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Set;
public class FrameworkUsagesCollector extends UsagesCollector {
public class FrameworkUsagesCollector extends AbstractApplicationUsagesCollector {
public static final String GROUP_ID = "frameworks";
public static void persistProjectUsages(@NotNull Project project) {
persistProjectUsages(project, getProjectUsages(project));
}
public static void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
persistProjectUsages(project, usages, FrameworkStatisticsPersistenceComponent.getInstance());
}
public static void persistProjectUsages(@NotNull Project project,
@NotNull Set<UsageDescriptor> usages,
@NotNull FrameworkStatisticsPersistence persistence) {
persistence.persistFrameworks(project, usages);
}
@NotNull
public Set<UsageDescriptor> getApplicationUsages() {
return getApplicationUsages(FrameworkStatisticsPersistenceComponent.getInstance());
}
@NotNull
public Set<UsageDescriptor> getApplicationUsages(@NotNull final FrameworkStatisticsPersistence persistence) {
final Map<String, Integer> facets = new HashMap<String, Integer>();
for (Set<UsageDescriptor> frameworks : persistence.getFrameworks().values()) {
for (UsageDescriptor framework : frameworks) {
final String key = framework.getKey();
final Integer count = facets.get(key);
facets.put(key, count == null ? 1 : count.intValue() + 1);
}
}
return ContainerUtil.map2Set(facets.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
@Override
public UsageDescriptor fun(Map.Entry<String, Integer> facet) {
return new UsageDescriptor(getGroupDescriptor(), facet.getKey(), facet.getValue());
}
});
}
@NotNull
@Override
public String getGroupId() {
return GROUP_ID;
}
public static GroupDescriptor getGroupDescriptor() {
public GroupDescriptor getGroupId() {
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
}
@NotNull
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
if (project != null) {
persistProjectUsages(project, getProjectUsages(project));
}
return getApplicationUsages();
}
public static Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
final Set<String> facets = new HashSet<String>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
for (Facet facet : FacetManager.getInstance(module).getAllFacets()) {
@@ -105,7 +52,7 @@ public class FrameworkUsagesCollector extends UsagesCollector {
return ContainerUtil.map2Set(facets, new Function<String, UsageDescriptor>() {
@Override
public UsageDescriptor fun(String facet) {
return new UsageDescriptor(getGroupDescriptor(), facet, 1);
return new UsageDescriptor(facet, 1);
}
});
}
@@ -29,8 +29,8 @@ public class FeaturesUsageCollector extends UsagesCollector {
@NotNull
@Override
public String getGroupId() {
return "productivity";
public GroupDescriptor getGroupId() {
return GroupDescriptor.create("productivity", GroupDescriptor.LOWER_PRIORITY);
}
@NotNull
@@ -44,8 +44,7 @@ public class FeaturesUsageCollector extends UsagesCollector {
for (String featureId : registry.getFeatureIds()) {
final FeatureDescriptor featureDescriptor = registry.getFeatureDescriptor(featureId);
if (featureDescriptor != null) {
usages.add(new UsageDescriptor(
GroupDescriptor.create(getGroupId(), GroupDescriptor.LOWER_PRIORITY), featureId, featureDescriptor.getUsageCount()));
usages.add(new UsageDescriptor(featureId, featureDescriptor.getUsageCount()));
}
}
@@ -30,8 +30,8 @@ public class PluginsUsagesCollector extends UsagesCollector {
private static final String GROUP_ID = "disabled-plugins";
@NotNull
public String getGroupId() {
return GROUP_ID;
public GroupDescriptor getGroupId() {
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
}
@NotNull
@@ -39,7 +39,7 @@ public class PluginsUsagesCollector extends UsagesCollector {
return ContainerUtil.map2Set(PluginManager.getDisabledPlugins(), new Function<String, UsageDescriptor>() {
@Override
public UsageDescriptor fun(String descriptor) {
return new UsageDescriptor(GroupDescriptor.create(getGroupId(), GroupDescriptor.HIGHER_PRIORITY), descriptor, 1);
return new UsageDescriptor(descriptor, 1);
}
});
}
@@ -0,0 +1,82 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.internal.statistic;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistence;
import com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent;
import com.intellij.openapi.project.Project;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.Set;
public abstract class AbstractApplicationUsagesCollector extends UsagesCollector {
public void persistProjectUsages(@NotNull Project project) {
persistProjectUsages(project, getProjectUsages(project));
}
public void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
persistProjectUsages(project, usages, ApplicationStatisticsPersistenceComponent.getInstance());
}
public void persistProjectUsages(@NotNull Project project,
@NotNull Set<UsageDescriptor> usages,
@NotNull ApplicationStatisticsPersistence persistence) {
persistence.persistFrameworks(getGroupId(), project, usages);
}
@NotNull
public Set<UsageDescriptor> getApplicationUsages() {
return getApplicationUsages(ApplicationStatisticsPersistenceComponent.getInstance());
}
@NotNull
public Set<UsageDescriptor> getApplicationUsages(@NotNull final ApplicationStatisticsPersistence persistence) {
final Map<String, Integer> facets = new HashMap<String, Integer>();
for (Set<UsageDescriptor> frameworks : persistence.getApplicationData(getGroupId()).values()) {
for (UsageDescriptor framework : frameworks) {
final String key = framework.getKey();
final Integer count = facets.get(key);
facets.put(key, count == null ? 1 : count.intValue() + 1);
}
}
return ContainerUtil.map2Set(facets.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
@Override
public UsageDescriptor fun(Map.Entry<String, Integer> facet) {
return new UsageDescriptor(facet.getKey(), facet.getValue());
}
});
}
@NotNull
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
if (project != null) {
persistProjectUsages(project, getProjectUsages(project));
}
return getApplicationUsages();
}
@NotNull
public abstract Set<UsageDescriptor> getProjectUsages(@NotNull Project project);
}
@@ -30,7 +30,7 @@ import com.intellij.openapi.util.Pair;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.text.DateFormatUtil;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -38,173 +38,204 @@ import java.util.*;
public class StatisticsUploadAssistant {
public String getData() {
return getData(Collections.<String>emptySet());
}
public String getData() {
return getData(Collections.<String>emptySet());
}
public static boolean showNotification() {
return UsageStatisticsPersistenceComponent.getInstance().isShowNotification();
}
public static boolean showNotification() {
return UsageStatisticsPersistenceComponent.getInstance().isShowNotification();
}
public static boolean isTimeToSend() {
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
public static boolean isTimeToSend() {
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
return isTimeToSend(UsageStatisticsPersistenceComponent.getInstance());
}
return isTimeToSend(UsageStatisticsPersistenceComponent.getInstance());
}
public static boolean isTimeToSend(UsageStatisticsPersistenceComponent settings) {
final long timeDelta = System.currentTimeMillis() - settings.getLastTimeSent();
public static boolean isTimeToSend(UsageStatisticsPersistenceComponent settings) {
final long timeDelta = System.currentTimeMillis() - settings.getLastTimeSent();
return Math.abs(timeDelta) > settings.getPeriod().getMillis();
}
return Math.abs(timeDelta) > settings.getPeriod().getMillis();
}
public static boolean isSendAllowed() {
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
public static boolean isSendAllowed() {
if (ApplicationManagerEx.getApplicationEx().isInternal()) return true; // todo remove
return isSendAllowed(UsageStatisticsPersistenceComponent.getInstance());
}
return isSendAllowed(UsageStatisticsPersistenceComponent.getInstance());
}
public static boolean isSendAllowed(final SentUsagesPersistence settings) {
return settings != null && settings.isAllowed();
}
public static boolean isSendAllowed(final SentUsagesPersistence settings) {
return settings != null && settings.isAllowed();
}
public static String getData(@NotNull Set<String> disabledGroups) {
return getStringPatch(disabledGroups, ProjectManager.getInstance().getOpenProjects());
}
public static String getData(@NotNull Set<String> disabledGroups) {
return getStringPatch(disabledGroups, ProjectManager.getInstance().getOpenProjects());
}
public static void persistSentPatch(@NotNull String patchStr) {
persistSentPatch(patchStr, UsageStatisticsPersistenceComponent.getInstance());
}
public static void persistSentPatch(@NotNull String patchStr) {
persistSentPatch(patchStr, UsageStatisticsPersistenceComponent.getInstance());
}
public static void persistSentPatch(@NotNull String patchStr, @NotNull SentUsagesPersistence persistenceComponent) {
Set<PatchedUsage> patchedUsages =
ContainerUtil.map2Set(ConvertUsagesUtil.convertString(patchStr), new Function<UsageDescriptor, PatchedUsage>() {
@Override
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
return new PatchedUsage(usageDescriptor);
public static void persistSentPatch(@NotNull String patchStr, @NotNull SentUsagesPersistence persistenceComponent) {
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = mapToPatchedUsagesMap(ConvertUsagesUtil.convertString(patchStr));
if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages);
}
@NotNull
public static String getStringPatch(@NotNull Set<String> disabledGroups, Project... project) {
return getStringPatch(disabledGroups, project, UsageStatisticsPersistenceComponent.getInstance(), 0);
}
@NotNull
public static String getStringPatch(@NotNull Set<String> disabledGroups,
@NotNull Project[] projects,
@NotNull SentUsagesPersistence usagesPersistence,
int maxSize) {
final Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = getPatchedUsages(disabledGroups, projects, usagesPersistence);
return getStringPatch(patchedUsages, maxSize);
}
public static String getStringPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages, int maxSize) {
if (patchedUsages.size() == 0) return "";
String patchStr = ConvertUsagesUtil.convertUsages(patchedUsages);
if (maxSize > 0 && patchStr.getBytes().length > maxSize) {
patchStr = ConvertUsagesUtil.cutPatchString(patchStr, maxSize);
}
});
if (patchedUsages.size() > 0) persistenceComponent.persistPatch(patchedUsages);
}
@NotNull
public static String getStringPatch(@NotNull Set<String> disabledGroups, Project... project) {
return getStringPatch(disabledGroups, project, UsageStatisticsPersistenceComponent.getInstance(), 0);
}
@NotNull
public static String getStringPatch(@NotNull Set<String> disabledGroups,
@NotNull Project[] projects,
@NotNull SentUsagesPersistence usagesPersistence,
int maxSize) {
final Set<PatchedUsage> patchedUsages = getPatchedUsages(disabledGroups, projects, usagesPersistence);
return getStringPatch(patchedUsages, maxSize);
}
public static String getStringPatch(@NotNull Set<PatchedUsage> patchedUsages, int maxSize) {
if (patchedUsages.size() == 0) return "";
String patchStr = ConvertUsagesUtil.convertUsages(patchedUsages);
if (maxSize > 0 && patchStr.getBytes().length > maxSize) {
patchStr = ConvertUsagesUtil.cutPatchString(patchStr, maxSize);
return patchStr;
}
return patchStr;
}
@NotNull
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull Set<String> disabledGroups,
@NotNull Project[] projects,
@NotNull SentUsagesPersistence usagesPersistence) {
Map<GroupDescriptor, Set<PatchedUsage>> usages = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
@NotNull
public static Set<PatchedUsage> getPatchedUsages(@NotNull Set<String> disabledGroups,
@NotNull Project[] projects,
@NotNull SentUsagesPersistence usagesPersistence) {
Set<PatchedUsage> usages = new HashSet<PatchedUsage>();
for (Project project : projects) {
final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages = getAllUsages(project, disabledGroups);
final Map<GroupDescriptor, Set<UsageDescriptor>> sentUsages = filterDisabled(disabledGroups, usagesPersistence.getSentUsages());
for (Project project : projects) {
final Set<UsageDescriptor> allUsages = getAllUsages(project, disabledGroups);
final Set<UsageDescriptor> sentUsages = filterDisabled(disabledGroups, usagesPersistence.getSentUsages());
usages.addAll(getPatchedUsages(allUsages, sentUsages));
}
return usages;
}
private static Set<UsageDescriptor> filterDisabled(@NotNull Set<String> disabledGroups, @NotNull Set<UsageDescriptor> usages) {
Set<UsageDescriptor> filtered = new HashSet<UsageDescriptor>();
for (UsageDescriptor usage : usages) {
if (!disabledGroups.contains(usage.getGroup().getId())) {
filtered.add(usage);
}
}
return filtered;
}
@NotNull
public static Set<PatchedUsage> getPatchedUsages(@NotNull final Set<UsageDescriptor> allUsages,
@NotNull SentUsagesPersistence usagesPersistence) {
return getPatchedUsages(allUsages, usagesPersistence.getSentUsages());
}
@NotNull
public static Set<PatchedUsage> getPatchedUsages(@NotNull final Set<UsageDescriptor> allUsages, final Set<UsageDescriptor> sentUsages) {
final Set<PatchedUsage> patchedUsages = ContainerUtil.map2Set(allUsages, new Function<UsageDescriptor, PatchedUsage>() {
@Override
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
return new PatchedUsage(usageDescriptor);
}
});
for (UsageDescriptor sentUsage : sentUsages) {
final PatchedUsage descriptor = findDescriptor(patchedUsages, Pair.create(sentUsage.getGroup(), sentUsage.getKey()));
if (descriptor == null) {
patchedUsages.add(new PatchedUsage(sentUsage.getGroup(), sentUsage.getKey(), -sentUsage.getValue()));
}
else {
descriptor.subValue(sentUsage.getValue());
}
usages.putAll(getPatchedUsages(allUsages, sentUsages));
}
return usages;
}
return packCollection(patchedUsages, new Condition<PatchedUsage>() {
@Override
public boolean value(PatchedUsage patchedUsage) {
return patchedUsage.getDelta() != 0;
}
});
}
@NotNull
private static Map<GroupDescriptor, Set<UsageDescriptor>> filterDisabled(@NotNull Set<String> disabledGroups, @NotNull Map<GroupDescriptor, Set<UsageDescriptor>> usages) {
Map<GroupDescriptor, Set<UsageDescriptor>> filtered = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
@NotNull
private static <T> Set<T> packCollection(@NotNull Collection<T> set, @NotNull Condition<T> condition) {
final Set<T> result = new LinkedHashSet<T>();
for (T t : set) {
if (condition.value(t)) {
result.add(t);
}
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> usage : usages.entrySet()) {
if (!disabledGroups.contains(usage.getKey().getId())) {
filtered.put(usage.getKey(), usage.getValue());
}
}
return filtered;
}
return result;
}
@Nullable
public static <T extends UsageDescriptor> T findDescriptor(@NotNull Set<T> descriptors,
@NotNull final Pair<GroupDescriptor, String> id) {
return ContainerUtil.find(descriptors, new Condition<T>() {
@Override
public boolean value(T t) {
return id.getFirst().equals(t.getGroup()) && id.getSecond().equals(t.getKey());
}
});
}
@NotNull
public static Set<UsageDescriptor> getAllUsages(@Nullable Project project, @NotNull Set<String> disabledGroups) {
final Set<UsageDescriptor> usageDescriptors = new TreeSet<UsageDescriptor>();
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
if (!disabledGroups.contains(usagesCollector.getGroupId())) {
usageDescriptors.addAll(usagesCollector.getUsages(project));
}
@NotNull
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages,
@NotNull SentUsagesPersistence usagesPersistence) {
return getPatchedUsages(allUsages, usagesPersistence.getSentUsages());
}
@NotNull
public static Map<GroupDescriptor, Set<PatchedUsage>> getPatchedUsages(@NotNull final Map<GroupDescriptor, Set<UsageDescriptor>> allUsages, final Map<GroupDescriptor, Set<UsageDescriptor>> sentUsageMap) {
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = mapToPatchedUsagesMap(allUsages);
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> sentUsageEntry : sentUsageMap.entrySet()) {
final GroupDescriptor sentUsageGroupDescriptor = sentUsageEntry.getKey();
final Set<UsageDescriptor> sentUsages = sentUsageEntry.getValue();
for (UsageDescriptor sentUsage : sentUsages) {
final PatchedUsage descriptor = findDescriptor(patchedUsages, Pair.create(sentUsageGroupDescriptor, sentUsage.getKey()));
if (descriptor == null) {
if (!patchedUsages.containsKey(sentUsageGroupDescriptor)) {
patchedUsages.put(sentUsageGroupDescriptor, new HashSet<PatchedUsage>());
}
patchedUsages.get(sentUsageGroupDescriptor).add(new PatchedUsage(sentUsage.getKey(), -sentUsage.getValue()));
} else {
descriptor.subValue(sentUsage.getValue());
}
}
}
return packCollection(patchedUsages, new Condition<PatchedUsage>() {
@Override
public boolean value(PatchedUsage patchedUsage) {
return patchedUsage.getDelta() != 0;
}
});
}
private static Map<GroupDescriptor, Set<PatchedUsage>> mapToPatchedUsagesMap(Map<GroupDescriptor, Set<UsageDescriptor>> allUsages) {
Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : allUsages.entrySet()) {
patchedUsages.put(entry.getKey(), ContainerUtil.map2Set(entry.getValue(), new Function<UsageDescriptor, PatchedUsage>() {
@Override
public PatchedUsage fun(UsageDescriptor usageDescriptor) {
return new PatchedUsage(usageDescriptor);
}
}));
}
return patchedUsages;
}
@NotNull
private static Map<GroupDescriptor, Set<PatchedUsage>> packCollection(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedUsages, Condition<PatchedUsage> condition) {
Map<GroupDescriptor, Set<PatchedUsage>> result = new HashMap<GroupDescriptor, Set<PatchedUsage>>();
for (GroupDescriptor descriptor : patchedUsages.keySet()) {
final Set<PatchedUsage> usages = packCollection(patchedUsages.get(descriptor), condition);
if (usages.size() > 0) {
result.put(descriptor, usages);
}
}
return result;
}
@NotNull
private static <T> Set<T> packCollection(@NotNull Collection<T> set, @NotNull Condition<T> condition) {
final Set<T> result = new LinkedHashSet<T>();
for (T t : set) {
if (condition.value(t)) {
result.add(t);
}
}
return result;
}
@Nullable
public static <T extends UsageDescriptor> T findDescriptor(@NotNull Map<GroupDescriptor, Set<T>> descriptors,
@NotNull final Pair<GroupDescriptor, String> id) {
final Set<T> usages = descriptors.get(id.getFirst());
if (usages == null) return null;
return ContainerUtil.find(usages, new Condition<T>() {
@Override
public boolean value(T t) {
return id.getSecond().equals(t.getKey());
}
});
}
@NotNull
public static Map<GroupDescriptor, Set<UsageDescriptor>> getAllUsages(@Nullable Project project, @NotNull Set<String> disabledGroups) {
Map<GroupDescriptor, Set<UsageDescriptor>> usageDescriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
final GroupDescriptor groupDescriptor = usagesCollector.getGroupId();
if (!disabledGroups.contains(groupDescriptor.getId())) {
usageDescriptors.put(groupDescriptor, usagesCollector.getUsages(project));
}
}
return usageDescriptors;
}
return usageDescriptors;
}
}
@@ -15,6 +15,7 @@
*/
package com.intellij.internal.statistic;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.beans.UsageDescriptor;
@@ -28,5 +29,5 @@ public abstract class UsagesCollector {
public abstract @NotNull Set<UsageDescriptor> getUsages(@Nullable Project project);
public abstract @NotNull String getGroupId();
public abstract @NotNull GroupDescriptor getGroupId();
}
@@ -16,6 +16,8 @@
package com.intellij.internal.statistic.beans;
import com.intellij.util.containers.hash.HashMap;
import java.util.*;
public class ConvertUsagesUtil {
@@ -26,19 +28,14 @@ public class ConvertUsagesUtil {
private ConvertUsagesUtil() {
}
// @NotNull
public static String convertUsages(Set<? extends UsageDescriptor> descriptors) {
assert descriptors != null;
final Map<GroupDescriptor, Set<UsageDescriptor>> descriptorGroups = groupDescriptors(descriptors);
return convertUsages(descriptorGroups);
}
// @NotNull
public static String convertUsages(Map<GroupDescriptor, Set<UsageDescriptor>> map) {
public static <T extends UsageDescriptor> String convertUsages(Map<GroupDescriptor, Set<T>> map) {
assert map != null;
final Map<GroupDescriptor, Set<T>> sortedMap = sortDescriptorsByPriority(map);
StringBuffer buffer = new StringBuffer();
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : map.entrySet()) {
for (Map.Entry<GroupDescriptor, Set<T>> entry : sortedMap.entrySet()) {
buffer.append(entry.getKey().getId());
buffer.append(GROUP_SEPARATOR);
buffer.append(convertValueMap(entry.getValue()));
@@ -49,7 +46,7 @@ public class ConvertUsagesUtil {
}
//@NotNull
public static String convertValueMap(Set<UsageDescriptor> descriptors) {
public static String convertValueMap(Set<? extends UsageDescriptor> descriptors) {
assert descriptors != null;
final StringBuffer buffer = new StringBuffer();
for (UsageDescriptor usageDescriptor : descriptors) {
@@ -76,14 +73,14 @@ public class ConvertUsagesUtil {
}
//@NotNull
public static Set<UsageDescriptor> convertString(String usages) {
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertString(String usages) {
assert usages != null;
Set<UsageDescriptor> descriptors = new LinkedHashSet<UsageDescriptor>();
Map<GroupDescriptor, Set<UsageDescriptor>> descriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
for (String groupStr : usages.split(GROUPS_SEPARATOR.toString())) {
if (!isEmptyOrSpaces(groupStr)) {
final StringPair group = getPair(groupStr, GROUP_SEPARATOR.toString());
if (group != null) {
descriptors.addAll(convertValueString(GroupDescriptor.create(group.first), group.second));
descriptors.putAll(convertValueString(GroupDescriptor.create(group.first), group.second));
}
}
}
@@ -91,9 +88,9 @@ public class ConvertUsagesUtil {
}
//@NotNull
public static Set<UsageDescriptor> convertValueString(GroupDescriptor groupId, String valueData) {
public static Map<GroupDescriptor, Set<UsageDescriptor>> convertValueString(GroupDescriptor groupId, String valueData) {
assert groupId != null;
final Set<UsageDescriptor> descriptors = new LinkedHashSet<UsageDescriptor>();
final Map<GroupDescriptor, Set<UsageDescriptor>> descriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
for (String value : valueData.split(GROUP_VALUE_SEPARATOR.toString())) {
if (!isEmptyOrSpaces(value)) {
final StringPair pair = getPair(value, "=");
@@ -102,7 +99,10 @@ public class ConvertUsagesUtil {
if (!isEmptyOrSpaces(count)) {
try {
final int i = Integer.parseInt(count);
descriptors.add(new UsageDescriptor(groupId, pair.first, i));
if (!descriptors.containsKey(groupId)) {
descriptors.put(groupId, new LinkedHashSet<UsageDescriptor>());
}
descriptors.get(groupId).add(new UsageDescriptor(pair.first, i));
} catch (NumberFormatException ignored) {
}
}
@@ -129,22 +129,17 @@ public class ConvertUsagesUtil {
}
//@NotNull
public static Map<GroupDescriptor, Set<UsageDescriptor>> groupDescriptors(Set<? extends UsageDescriptor> descriptors) {
public static <T extends UsageDescriptor> Map<GroupDescriptor, Set<T>> sortDescriptorsByPriority(Map<GroupDescriptor, Set<T>> descriptors) {
assert descriptors != null;
final SortedMap<GroupDescriptor, Set<UsageDescriptor>> map = new TreeMap<GroupDescriptor, Set<UsageDescriptor>>(new Comparator<GroupDescriptor>() {
final SortedMap<GroupDescriptor, Set<T>> map = new TreeMap<GroupDescriptor, Set<T>>(new Comparator<GroupDescriptor>() {
public int compare(GroupDescriptor g1, GroupDescriptor g2) {
final int priority = (int) (g2.getPriority() - g1.getPriority());
return priority == 0 ? g1.getId().compareTo(g2.getId()) : priority;
}
});
for (UsageDescriptor descriptor : descriptors) {
final GroupDescriptor group = descriptor.getGroup();
if (!map.containsKey(group)) {
map.put(group, new HashSet<UsageDescriptor>());
}
map.get(group).add(descriptor);
}
map.putAll(descriptors);
return map;
}
@@ -158,7 +153,7 @@ public class ConvertUsagesUtil {
}
}
public static boolean isEmptyOrSpaces(final String s) {
return s == null || s.trim().length() == 0;
}
public static boolean isEmptyOrSpaces(final String s) {
return s == null || s.trim().length() == 0;
}
}
@@ -18,11 +18,11 @@ package com.intellij.internal.statistic.beans;
public class PatchedUsage extends UsageDescriptor {
public PatchedUsage(UsageDescriptor descriptor) {
super(descriptor.getGroup(), descriptor.getKey(), descriptor.getValue());
super(descriptor.getKey(), descriptor.getValue());
}
public PatchedUsage(GroupDescriptor group, String key, int value) {
super(group, key, value);
public PatchedUsage(String key, int value) {
super(key, value);
}
public int getDelta() {
@@ -16,15 +16,12 @@
package com.intellij.internal.statistic.beans;
public class UsageDescriptor implements Comparable<UsageDescriptor> {
private final GroupDescriptor myGroup;
private final String myKey;
private int myValue;
public UsageDescriptor(GroupDescriptor group, String key, int value) {
assert group != null;
assert key != null;
public UsageDescriptor(String key, int value) {
assert key != null;
myGroup = group;
myKey = key;
myValue = value;
}
@@ -33,10 +30,6 @@ public class UsageDescriptor implements Comparable<UsageDescriptor> {
return myKey;
}
public GroupDescriptor getGroup() {
return myGroup;
}
public int getValue() {
return myValue;
}
@@ -45,29 +38,15 @@ public class UsageDescriptor implements Comparable<UsageDescriptor> {
myValue = i;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof UsageDescriptor)) return false;
UsageDescriptor that = (UsageDescriptor) o;
if (!myGroup.equals(that.myGroup)) return false;
if (!myKey.equals(that.myKey)) return false;
return true;
public int getMyValue() {
return myValue;
}
@Override
public int hashCode() {
int result = myGroup.hashCode();
result = 31 * result + myKey.hashCode();
return result;
public void setMyValue(int myValue) {
this.myValue = myValue;
}
public int compareTo(UsageDescriptor ud) {
final int byGroup = this.getGroup().compareTo(ud.getGroup());
return byGroup == 0 ? this.getKey().compareTo(ud.myKey) : byGroup;
return this.getKey().compareTo(ud.myKey);
}
}
@@ -29,7 +29,18 @@ import javax.swing.*;
public class StatisticsConfigurable implements SearchableConfigurable {
private StatisticsConfigurationComponent myConfig;
private boolean modifiedByDefault;
public StatisticsConfigurable() {
this(false);
}
public StatisticsConfigurable(boolean isModifiedByDefault) {
modifiedByDefault = isModifiedByDefault;
}
private StatisticsConfigurationComponent myConfig;
@Nls
public String getDisplayName() {
@@ -56,7 +67,7 @@ public class StatisticsConfigurable implements SearchableConfigurable {
final UsageStatisticsPersistenceComponent persistenceComponent = UsageStatisticsPersistenceComponent.getInstance();
return myConfig.isAllowed() != persistenceComponent.isAllowed() ||
myConfig.getPeriod() != persistenceComponent.getPeriod() ||
persistenceComponent.isShowNotification();
modifiedByDefault;
}
public void apply() throws ConfigurationException {
@@ -65,6 +76,7 @@ public class StatisticsConfigurable implements SearchableConfigurable {
persistenceComponent.setPeriod(myConfig.getPeriod());
persistenceComponent.setAllowed(myConfig.isAllowed());
persistenceComponent.setShowNotification(false);
modifiedByDefault = false;
}
public void reset() {
@@ -0,0 +1,37 @@
package com.intellij.internal.statistic.persistence;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public abstract class ApplicationStatisticsPersistence {
private Map<GroupDescriptor, Map<String, Set<UsageDescriptor>>> myApplicationData = new HashMap<GroupDescriptor, Map<String, Set<UsageDescriptor>>>();
public ApplicationStatisticsPersistence() {
}
public void persistFrameworks(@NotNull GroupDescriptor groupDescriptor, @NotNull Project project, @NotNull Set<UsageDescriptor> frameworks) {
if (!myApplicationData.containsKey(groupDescriptor)) {
myApplicationData.put(groupDescriptor, new HashMap<String, Set<UsageDescriptor>>());
}
myApplicationData.get(groupDescriptor).put(project.getName(), frameworks);
}
@NotNull
public Map<String, Set<UsageDescriptor>> getApplicationData(@NotNull GroupDescriptor groupDescriptor) {
final Map<String, Set<UsageDescriptor>> map = myApplicationData.get(groupDescriptor);
return map == null ? new HashMap<String, Set<UsageDescriptor>>(): map;
}
@NotNull
public Map<GroupDescriptor, Map<String, Set<UsageDescriptor>>> getApplicationData() {
return myApplicationData;
}
}
@@ -0,0 +1,184 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.internal.statistic.persistence;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
@State(
name = "StatisticsApplicationUsages",
storages = {
@Storage(
id = "statistics.application.usages",
file = "$APP_CONFIG$/statistics.application.usages.xml"
)}
)
public class ApplicationStatisticsPersistenceComponent extends ApplicationStatisticsPersistence
implements ApplicationComponent, PersistentStateComponent<Element> {
private static final String TOKENIZER = ",";
@NonNls
private static final String GROUP_TAG = "group";
@NonNls
private static final String GROUP_NAME_ATTR = "name";
@NonNls
private static final String PROJECT_TAG = "project";
@NonNls
private static final String PROJECT_ID_ATTR = "id";
@NonNls
private static final String VALUES_ATTR = "values";
public ApplicationStatisticsPersistenceComponent() {
}
public static ApplicationStatisticsPersistenceComponent getInstance() {
return ApplicationManager.getApplication().getComponent(ApplicationStatisticsPersistenceComponent.class);
}
public void loadState(final Element element) {
List groups = element.getChildren(GROUP_TAG);
for (Object group : groups) {
Element groupElement = (Element) group;
String groupName = groupElement.getAttributeValue(GROUP_NAME_ATTR);
final GroupDescriptor groupDescriptor = GroupDescriptor.create(groupName);
List projectsList = groupElement.getChildren(PROJECT_TAG);
for (Object project : projectsList) {
Element projectElement = (Element) project;
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
String frameworks = projectElement.getAttributeValue(VALUES_ATTR);
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(frameworks)) {
Set<UsageDescriptor> frameworkDescriptors = new HashSet<UsageDescriptor>();
for (String key : StringUtil.split(frameworks, TOKENIZER)) {
frameworkDescriptors.add(new UsageDescriptor(key, 1));
}
getApplicationData(groupDescriptor).put(projectId, frameworkDescriptors);
}
}
}
}
public Element getState() {
Element element = new Element("state");
for (Map.Entry<GroupDescriptor, Map<String, Set<UsageDescriptor>>> appData : getApplicationData().entrySet()) {
Element groupElement = new Element(GROUP_TAG);
groupElement.setAttribute(GROUP_NAME_ATTR, appData.getKey().getId());
boolean isEmptyGroup = true;
for (Map.Entry<String, Set<UsageDescriptor>> projectData : appData.getValue().entrySet()) {
Element projectElement = new Element(PROJECT_TAG);
projectElement.setAttribute(PROJECT_ID_ATTR, projectData.getKey());
final Set<UsageDescriptor> projectDataValue = projectData.getValue();
if (!projectDataValue.isEmpty()) {
projectElement.setAttribute(VALUES_ATTR, joinUsages(projectDataValue));
groupElement.addContent(projectElement);
isEmptyGroup = false;
}
}
if (!isEmptyGroup) {
element.addContent(groupElement);
}
}
return element;
}
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
@Override
public String fun(UsageDescriptor usageDescriptor) {
return usageDescriptor.getKey();
}
}, TOKENIZER);
}
@NotNull
@NonNls
public File[] getExportFiles() {
return new File[]{PathManager.getOptionsFile("framework.usages")};
}
@NotNull
public String getPresentableName() {
return "Application Usages Statistics";
}
@NonNls
@NotNull
public String getComponentName() {
return "ApplicationStatisticsPersistenceComponent";
}
public void initComponent() {
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
@Override
public void projectOpened(Project project) {
}
@Override
public boolean canCloseProject(Project project) {
return true;
}
@Override
public void projectClosed(Project project) {
}
@Override
public void projectClosing(Project project) {
if (project != null) {
for (UsagesCollector usagesCollector : Extensions.getExtensions(UsagesCollector.EP_NAME)) {
if (usagesCollector instanceof AbstractApplicationUsagesCollector) {
((AbstractApplicationUsagesCollector) usagesCollector).persistProjectUsages(project);
}
}
}
}
});
}
public void disposeComponent() {
}
}
@@ -17,58 +17,69 @@
package com.intellij.internal.statistic.persistence;
import com.intellij.internal.statistic.StatisticsUploadAssistant;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.PatchedUsage;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.HashSet;
import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public class BasicSentUsagesPersistenceComponent extends SentUsagesPersistence {
public BasicSentUsagesPersistenceComponent() {
}
public BasicSentUsagesPersistenceComponent() {
}
protected Set<UsageDescriptor> mySentDescriptors = new HashSet<UsageDescriptor>();
@NonNls private long mySentTime = 0;
protected Map<GroupDescriptor, Set<UsageDescriptor>> mySentDescriptors = new HashMap<GroupDescriptor, Set<UsageDescriptor>>();
@NonNls
private long mySentTime = 0;
@Override
public boolean isAllowed() {
return true;
}
@Override
public boolean isAllowed() {
return true;
}
@Override
public boolean isShowNotification() {
return false;
}
@Override
public boolean isShowNotification() {
return false;
}
@Override
public long getLastTimeSent() {
return mySentTime;
}
@Override
public long getLastTimeSent() {
return mySentTime;
}
public void setSentTime(long time) {
mySentTime = time;
}
public void setSentTime(long time) {
mySentTime = time;
}
public void persistPatch(@NotNull Set<PatchedUsage> patchedDescriptors) {
for (PatchedUsage patchedUsage : patchedDescriptors) {
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, Pair.create(patchedUsage.getGroup(), patchedUsage.getKey()));
if (usageDescriptor != null) {
usageDescriptor.setValue(usageDescriptor.getValue() + patchedUsage.getDelta());
}
else {
mySentDescriptors.add(new UsageDescriptor(patchedUsage.getGroup(), patchedUsage.getKey(), patchedUsage.getValue()));
}
public void persistPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedDescriptorMap) {
for (Map.Entry<GroupDescriptor, Set<PatchedUsage>> entry : patchedDescriptorMap.entrySet()) {
final GroupDescriptor groupDescriptor = entry.getKey();
for (PatchedUsage patchedUsage : entry.getValue()) {
UsageDescriptor usageDescriptor = StatisticsUploadAssistant.findDescriptor(mySentDescriptors, Pair.create(groupDescriptor, patchedUsage.getKey()));
if (usageDescriptor != null) {
usageDescriptor.setValue(usageDescriptor.getValue() + patchedUsage.getDelta());
} else {
if (!mySentDescriptors.containsKey(groupDescriptor)) {
mySentDescriptors.put(groupDescriptor, new HashSet<UsageDescriptor>());
}
mySentDescriptors.get(groupDescriptor).add(new UsageDescriptor(patchedUsage.getKey(), patchedUsage.getValue()));
}
}
}
setSentTime(System.currentTimeMillis());
}
setSentTime(System.currentTimeMillis());
}
@NotNull
public Set<UsageDescriptor> getSentUsages() {
return mySentDescriptors;
}
@NotNull
public Map<GroupDescriptor, Set<UsageDescriptor>> getSentUsages
() {
return mySentDescriptors;
}
}
@@ -16,18 +16,20 @@
package com.intellij.internal.statistic.persistence;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.PatchedUsage;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public abstract class SentUsagesPersistence {
public abstract void persistPatch(@NotNull Set<PatchedUsage> patchedDescriptors);
public abstract void persistPatch(@NotNull Map<GroupDescriptor, Set<PatchedUsage>> patchedDescriptors);
@NotNull
public abstract Set<UsageDescriptor> getSentUsages();
public abstract Map<GroupDescriptor, Set<UsageDescriptor>> getSentUsages();
public abstract boolean isAllowed();
@@ -76,7 +76,7 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
String valueData = groupElement.getAttributeValue(DATA_ATTR);
if (!StringUtil.isEmptyOrSpaces(groupId) && !StringUtil.isEmptyOrSpaces(valueData)) {
getSentUsages().addAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
getSentUsages().putAll(ConvertUsagesUtil.convertValueString(GroupDescriptor.create(groupId, groupPriority), valueData));
}
}
@@ -99,7 +99,7 @@ public class UsageStatisticsPersistenceComponent extends BasicSentUsagesPersiste
public Element getState() {
Element element = new Element("state");
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.groupDescriptors(getSentUsages())
for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.sortDescriptorsByPriority(getSentUsages())
.entrySet()) {
Element projectElement = new Element(GROUP_TAG);
projectElement.setAttribute(GROUP_ID_ATTR, entry.getKey().getId());
@@ -72,7 +72,7 @@ public class StatisticsNotificationManager {
else if ("settings".equals(description)) {
final ShowSettingsUtil util = ShowSettingsUtil.getInstance();
IdeFrame ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null);
util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable());
util.editConfigurable((JFrame)ideFrame, new StatisticsConfigurable(true));
notification.expire();
}
}
@@ -118,20 +118,16 @@
<implementation-class>com.intellij.internal.statistic.persistence.UsageStatisticsPersistenceComponent</implementation-class>
</component>
<component>
<interface-class>com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent</interface-class>
<implementation-class>com.intellij.internal.statistic.persistence.ApplicationStatisticsPersistenceComponent</implementation-class>
</component>
<component>
<implementation-class>com.intellij.openapi.util.FoundationLoader</implementation-class>
<headless-implementation-class/>
</component>
<component>
<interface-class>com.intellij.facet.impl.statistics.FrameworkStatisticsPersistenceComponent</interface-class>
<implementation-class>com.intellij.facet.impl.statistics.FrameworkStatisticsPersistenceComponent</implementation-class>
</component>
<component>
<interface-class>com.intellij.openapi.vcs.statistics.VcsStatisticsPersistenceComponent</interface-class>
<implementation-class>com.intellij.openapi.vcs.statistics.VcsStatisticsPersistenceComponent</implementation-class>
</component>
</application-components>
<project-components>
@@ -79,7 +79,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
private FileHolderComposite myComposite;
private final ChangeListWorker myWorker;
private ChangeListWorker myWorker;
private VcsException myUpdateException = null;
@SuppressWarnings({"FieldAccessedSynchronizedAndUnsynchronized"})
@@ -117,7 +117,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myChangesViewManager = myProject.isDefault() ? new DummyChangesView(myProject) : ChangesViewManager.getInstance(myProject);
myFileStatusManager = FileStatusManager.getInstance(myProject);
myComposite = new FileHolderComposite(project);
myIgnoredIdeaLevel = new IgnoredFilesComponent(myProject);
myIgnoredIdeaLevel = new IgnoredFilesComponent(myProject, true);
myUpdater = new UpdateRequestsQueue(myProject, ourUpdateAlarm, new ActualUpdater());
myWorker = new ChangeListWorker(myProject, new MyChangesDeltaForwarder(myProject, ourUpdateAlarm));
@@ -421,10 +421,8 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
myModifier.clearQueue();
// update member from copy
if (takeChanges) {
myWorker.takeData(dataHolder.getChangeListWorker());
}
if (takeChanges) {
myWorker = dataHolder.getChangeListWorker();
myModifier.setWorker(myWorker);
if (LOG.isDebugEnabled()) {
LOG.debug("refresh procedure finished, size: " + dataHolder.getComposite().getVFHolder(FileHolder.HolderType.UNVERSIONED).getSize());
}
@@ -996,8 +994,7 @@ public class ChangeListManagerImpl extends ChangeListManagerEx implements Projec
final IgnoredFilesComponent ignoredFilesComponent;
final ChangeListWorker worker;
synchronized (myDataLock) {
ignoredFilesComponent = new IgnoredFilesComponent(myProject);
ignoredFilesComponent.add(myIgnoredIdeaLevel.getFilesToIgnore());
ignoredFilesComponent = new IgnoredFilesComponent(myIgnoredIdeaLevel);
worker = myWorker.copy();
}
new ChangeListManagerSerialization(ignoredFilesComponent, worker).writeExternal(element);
@@ -24,10 +24,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class ChangeListsIndexes {
private final Map<String, FileStatus> myFileToStatus;
@@ -107,6 +104,22 @@ public class ChangeListsIndexes {
}
}
public void getDelta(final ChangeListsIndexes newIndexes, final Set<Pair<String,VcsKey>> toRemove, Set<Pair<String,VcsKey>> toAdd) {
// this is old
final Set<String> oldKeySet = myFileToVcs.keySet();
final Set<String> toRemoveSet = new HashSet<String>(oldKeySet);
final Set<String> newKeySet = newIndexes.myFileToVcs.keySet();
final Set<String> toAddSet = new HashSet<String>(newKeySet);
toRemoveSet.removeAll(newKeySet);
toAddSet.removeAll(oldKeySet);
for (String s : toRemoveSet) {
toRemove.add(new Pair<String, VcsKey>(s, myFileToVcs.get(s)));
}
for (String s : toAddSet) {
toAdd.add(new Pair<String, VcsKey>(s, newIndexes.myFileToVcs.get(s)));
}
}
public List<Pair<String, VcsKey>> getAffectedFilesUnderVcs() {
final ArrayList<Pair<String, VcsKey>> result = new ArrayList<Pair<String, VcsKey>>();
for (Map.Entry<String, VcsKey> entry : myFileToVcs.entrySet()) {
@@ -23,6 +23,7 @@ import com.intellij.openapi.vcs.VcsKey;
import com.intellij.openapi.vcs.impl.CollectionsDelta;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -44,18 +45,16 @@ public class ChangesDelta {
myInitialized = true;
return true; //+-
}
final List<Pair<String, VcsKey>> becameAffected = became.getAffectedFilesUnderVcs();
final Set<Pair<String,VcsKey>> toRemove = CollectionsDelta.notInSecond(wasAffected, becameAffected);
final Set<Pair<String, VcsKey>> toAdd = CollectionsDelta.notInSecond(becameAffected, wasAffected);
final Set<Pair<String,VcsKey>> toRemove = new HashSet<Pair<String,VcsKey>>();
final Set<Pair<String, VcsKey>> toAdd = new HashSet<Pair<String,VcsKey>>();
was.getDelta(became, toRemove, toAdd);
if (toRemove != null) {
for (Pair<String, VcsKey> pair : toRemove) {
myDeltaListener.minus(convertPair(pair));
}
for (Pair<String, VcsKey> pair : toRemove) {
myDeltaListener.minus(convertPair(pair));
}
sendPlus(toAdd);
return toRemove != null || toAdd != null;
return ! toRemove.isEmpty() || ! toAdd.isEmpty();
}
private void sendPlus(final Collection<Pair<String, VcsKey>> toAdd) {
@@ -28,20 +28,24 @@ import java.util.List;
import java.util.Set;
public class IgnoredFilesComponent {
private final Project myProject;
private final Set<IgnoredFileBean> myFilesToIgnore;
public IgnoredFilesComponent(final Project project) {
myProject = project;
public IgnoredFilesComponent(final Project project, final boolean registerListener) {
myFilesToIgnore = new LinkedHashSet<IgnoredFileBean>();
project.getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
public void before(List<? extends VFileEvent> events) {}
if (registerListener) {
project.getMessageBus().connect(project).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
public void before(List<? extends VFileEvent> events) {}
public void after(List<? extends VFileEvent> events) {
resetCaches();
}
});
public void after(List<? extends VFileEvent> events) {
resetCaches();
}
});
}
}
public IgnoredFilesComponent(final IgnoredFilesComponent other) {
myFilesToIgnore = new LinkedHashSet<IgnoredFileBean>(other.myFilesToIgnore);
}
public void add(final IgnoredFileBean... filesToIgnore) {
@@ -27,7 +27,7 @@ import java.util.List;
* (after update is done)
*/
public class Modifier implements ChangeListsWriteOperations {
private final ChangeListWorker myWorker;
private ChangeListWorker myWorker;
private boolean myInsideUpdate;
private final List<ChangeListCommand> myCommandQueue;
private final DelayedNotificator myNotificator;
@@ -113,4 +113,8 @@ public class Modifier implements ChangeListsWriteOperations {
myNotificator.callNotify(command);
}
}
public void setWorker(ChangeListWorker worker) {
myWorker = worker;
}
}
@@ -1,42 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.statistics;
import com.intellij.openapi.project.Project;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Set;
public abstract class VcsStatisticsPersistence {
private Map<String, Set<UsageDescriptor>> myVcsUsagesMap = new HashMap<String, Set<UsageDescriptor>>();
public VcsStatisticsPersistence() {
}
public void persist(@NotNull Project project, @NotNull Set<UsageDescriptor> vcs) {
myVcsUsagesMap.put(project.getName(), vcs);
}
@NotNull
public Map<String, Set<UsageDescriptor>> getVcsUsageMap() {
return myVcsUsagesMap;
}
}
@@ -1,146 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.statistics;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.internal.statistic.beans.UsageDescriptor;
import com.intellij.util.Function;
import com.intellij.util.containers.HashSet;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
@State(
name = "VcsUsages",
storages = {
@Storage(
id = "vcs",
file = "$APP_CONFIG$/vcs.usages.xml"
)}
)
public class VcsStatisticsPersistenceComponent extends VcsStatisticsPersistence
implements ApplicationComponent, PersistentStateComponent<Element> {
private static final String TOKENIZER = ",";
@NonNls private static final String PROJECT_TAG = "project";
@NonNls private static final String PROJECT_ID_ATTR = "id";
@NonNls private static final String USAGES_ATTR = "usages";
public VcsStatisticsPersistenceComponent() {
}
public static VcsStatisticsPersistenceComponent getInstance() {
return ApplicationManager.getApplication().getComponent(VcsStatisticsPersistenceComponent.class);
}
public void loadState(final Element element) {
List projectsList = element.getChildren(PROJECT_TAG);
for (Object project : projectsList) {
Element projectElement = (Element)project;
String projectId = projectElement.getAttributeValue(PROJECT_ID_ATTR);
String vcs = projectElement.getAttributeValue(USAGES_ATTR);
if (!StringUtil.isEmptyOrSpaces(projectId) && !StringUtil.isEmptyOrSpaces(vcs)) {
Set<UsageDescriptor> vcsDescriptors = new HashSet<UsageDescriptor>();
for (String key : StringUtil.split(vcs, TOKENIZER)) {
vcsDescriptors.add(new UsageDescriptor(VcsUsagesCollector.createGroupDescriptor(), key, 1));
}
getVcsUsageMap().put(projectId, vcsDescriptors);
}
}
}
public Element getState() {
Element element = new Element("state");
for (Map.Entry<String, Set<UsageDescriptor>> vcsUsageEntry : getVcsUsageMap().entrySet()) {
Element projectElement = new Element(PROJECT_TAG);
projectElement.setAttribute(PROJECT_ID_ATTR, vcsUsageEntry.getKey());
projectElement.setAttribute(USAGES_ATTR, joinUsages(vcsUsageEntry.getValue()));
element.addContent(projectElement);
}
return element;
}
private static String joinUsages(@NotNull Set<UsageDescriptor> usages) {
return StringUtil.join(usages, new Function<UsageDescriptor, String>() {
@Override
public String fun(UsageDescriptor usageDescriptor) {
return usageDescriptor.getKey();
}
}, TOKENIZER);
}
@NotNull
@NonNls
public File[] getExportFiles() {
return new File[]{PathManager.getOptionsFile("vcs.usages")};
}
@NotNull
public String getPresentableName() {
return "Vcs Usages";
}
@NonNls
@NotNull
public String getComponentName() {
return "VcsStatisticsPersistenceComponent";
}
public void initComponent() {
ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
@Override
public void projectOpened(Project project) {
}
@Override
public boolean canCloseProject(Project project) {
return true;
}
@Override
public void projectClosed(Project project) {
}
@Override
public void projectClosing(Project project) {
if (project != null) {
VcsUsagesCollector.persistProjectUsages(project);
}
}
});
}
public void disposeComponent() {
}
}
@@ -15,10 +15,10 @@
*/
package com.intellij.openapi.vcs.statistics;
import com.intellij.internal.statistic.AbstractApplicationUsagesCollector;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.impl.VcsDescriptor;
import com.intellij.internal.statistic.UsagesCollector;
import com.intellij.internal.statistic.beans.GroupDescriptor;
import com.intellij.internal.statistic.beans.UsageDescriptor;
@@ -28,77 +28,25 @@ import com.intellij.util.containers.hash.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Map;
import java.util.Set;
public class VcsUsagesCollector extends UsagesCollector {
private static final String GROUP_ID = "vcs";
public class VcsUsagesCollector extends AbstractApplicationUsagesCollector {
private static final String GROUP_ID = "vcs";
public static void persistProjectUsages(@NotNull Project project) {
persistProjectUsages(project, getProjectUsages(project));
}
public static void persistProjectUsages(@NotNull Project project, @NotNull Set<UsageDescriptor> usages) {
persistProjectUsages(project, usages, VcsStatisticsPersistenceComponent.getInstance());
}
public static void persistProjectUsages(@NotNull Project project,
@NotNull Set<UsageDescriptor> usages,
@NotNull VcsStatisticsPersistenceComponent persistence) {
persistence.persist(project, usages);
}
@NotNull
public static Set<UsageDescriptor> getApplicationUsages() {
return getApplicationUsages(VcsStatisticsPersistenceComponent.getInstance());
}
@NotNull
public static Set<UsageDescriptor> getApplicationUsages(@NotNull final VcsStatisticsPersistenceComponent persistence) {
final Map<String, Integer> vcsUsagesMap = new HashMap<String, Integer>();
for (Set<UsageDescriptor> descriptors : persistence.getVcsUsageMap().values()) {
for (UsageDescriptor descriptor : descriptors) {
final String key = descriptor.getKey();
final Integer count = vcsUsagesMap.get(key);
vcsUsagesMap.put(key, count == null ? 1 : count.intValue() + 1);
}
@NotNull
public GroupDescriptor getGroupId() {
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
}
return ContainerUtil.map2Set(vcsUsagesMap.entrySet(), new Function<Map.Entry<String, Integer>, UsageDescriptor>() {
@Override
public UsageDescriptor fun(Map.Entry<String, Integer> vcsUsage) {
return new UsageDescriptor(createGroupDescriptor(), vcsUsage.getKey(), vcsUsage.getValue());
}
});
}
@NotNull
public String getGroupId() {
return GROUP_ID;
}
@NotNull
public Set<UsageDescriptor> getUsages(@Nullable Project project) {
if (project != null) {
persistProjectUsages(project, getProjectUsages(project));
@NotNull
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
return ContainerUtil.map2Set(ProjectLevelVcsManager.getInstance(project).getAllActiveVcss(), new Function<AbstractVcs, UsageDescriptor>() {
@Override
public UsageDescriptor fun(AbstractVcs vcs) {
return new UsageDescriptor(vcs.getName(), 1);
}
});
}
return getApplicationUsages();
}
public static Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
return ContainerUtil.map2Set(ProjectLevelVcsManager.getInstance(project).getAllActiveVcss(), new Function<AbstractVcs, UsageDescriptor>() {
@Override
public UsageDescriptor fun(AbstractVcs vcs) {
return new UsageDescriptor(createGroupDescriptor(), vcs.getName(), 1);
}
});
}
public static GroupDescriptor createGroupDescriptor() {
return GroupDescriptor.create(GROUP_ID, GroupDescriptor.HIGHER_PRIORITY);
}
}
@@ -268,7 +268,7 @@ instance.variable.may.not.be.initialized.display.name=Instance field may not be
instance.variable.may.not.be.initialized.problem.descriptor=Instance field <code>#ref</code> may not be initialized during object construction #loc
instance.Variable.may.not.be.initialized.problem.descriptor.junit=Instance field <code>#ref</code> may not be initialized during object construction or 'setUp()' call #loc
primitive.fields.ignore.option=Ignore primitive fields
instance.variable.used.before.initialized.display.name=Instance field used before initialized
instance.variable.used.before.initialized.display.name=Instance field used before initialization
instance.variable.used.before.initialized.problem.descriptor=Instance field <code>#ref</code> used before initialized #loc
non.final.static.variable.initialization.display.name=Non-final static field is used during class initialization
non.final.static.variable.initialization.problem.descriptor=Non-final static field <code>#ref</code> used during class initialization #loc
@@ -1841,4 +1841,6 @@ package.dot.html.may.be.package.info.problem.descriptor=<code>package.html</code
package.dot.html.may.be.package.info.delete.quickfix=Delete package.html
package.dot.html.delete.command=package.html deletion
package.dot.html.may.be.package.info.convert.quickfix=Convert to package-info.java
package.dot.html.convert.command=package.html to package-info.java conversion
package.dot.html.convert.command=package.html to package-info.java conversion
choose.super.class.to.ignore=Choose class
ignore.anonymous.inner.classes=Ignore anonymous inner classes
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2006-2011 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package com.siyeh.ig.serialization;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiModifier;
@@ -26,18 +27,21 @@ import org.jetbrains.annotations.NotNull;
public class NonSerializableFieldInSerializableClassInspection
extends SerializableInspection {
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"non.serializable.field.in.serializable.class.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
"non.serializable.field.in.serializable.class.problem.descriptor");
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new NonSerializableFieldInSerializableClassVisitor();
}
@@ -51,6 +55,13 @@ public class NonSerializableFieldInSerializableClassInspection
return;
}
final PsiClass aClass = field.getContainingClass();
if (aClass == null) {
return;
}
if (ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
if (!SerializationUtils.isSerializable(aClass)) {
return;
}
@@ -1,47 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.siyeh.ig.serialization.SerializableInspection.Form">
<grid id="27dc6" binding="contentPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="4" vgap="4">
<margin top="4" left="4" bottom="4" right="4"/>
<constraints>
<xy x="20" y="20" width="368" height="330"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane class="com.intellij.ui.components.JBScrollPane" id="4a009">
<constraints>
<grid row="0" column="0" row-span="3" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="ec407" class="com.intellij.codeInspection.ui.ListTable" binding="table" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<component id="d216b" class="javax.swing.JButton" binding="addButton">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Button"/>
</properties>
</component>
<component id="c54c6" class="javax.swing.JButton" binding="removeButton">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Button"/>
</properties>
</component>
<vspacer id="c7b68">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
</form>
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +22,13 @@ import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.fixes.AddSerialVersionUIDFix;
import com.siyeh.ig.psiutils.SerializationUtils;
import org.intellij.lang.annotations.Pattern;
import org.jetbrains.annotations.NotNull;
public class SerializableHasSerialVersionUIDFieldInspection
extends SerializableInspection {
@Pattern("[a-zA-Z_0-9.-]+")
@Override
@NotNull
public String getID() {
@@ -70,6 +72,10 @@ public class SerializableHasSerialVersionUIDFieldInspection
aClass instanceof PsiEnumConstantInitializer) {
return;
}
if (ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
final PsiField serialVersionUIDField = aClass.findFieldByName(
HardcodedMethodConstants.SERIAL_VERSION_UID, false);
if (serialVersionUIDField != null) {
@@ -15,6 +15,7 @@
*/
package com.siyeh.ig.serialization;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiEnumConstantInitializer;
import com.intellij.psi.PsiTypeParameter;
@@ -26,12 +27,14 @@ import org.jetbrains.annotations.NotNull;
public class SerializableHasSerializationMethodsInspection
extends SerializableInspection {
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"serializable.has.serialization.methods.display.name");
}
@Override
@NotNull
public String buildErrorString(Object... infos) {
final boolean hasReadObject = ((Boolean)infos[0]).booleanValue();
@@ -48,6 +51,7 @@ public class SerializableHasSerializationMethodsInspection
}
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new SerializableHasSerializationMethodsVisitor();
}
@@ -65,6 +69,10 @@ public class SerializableHasSerializationMethodsInspection
aClass instanceof PsiEnumConstantInitializer) {
return;
}
if (ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
if (!SerializationUtils.isSerializable(aClass)) {
return;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package com.siyeh.ig.serialization;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiModifier;
@@ -28,7 +29,8 @@ class SerializableInnerClassHasSerialVersionUIDFieldVisitor
private final SerializableInspection inspection;
public SerializableInnerClassHasSerialVersionUIDFieldVisitor(SerializableInspection inspection) {
public SerializableInnerClassHasSerialVersionUIDFieldVisitor(
SerializableInspection inspection) {
this.inspection = inspection;
}
@@ -38,6 +40,10 @@ class SerializableInnerClassHasSerialVersionUIDFieldVisitor
aClass.isEnum()) {
return;
}
if (inspection.ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
if (hasSerialVersionUIDField(aClass)) {
return;
}
@@ -57,7 +63,7 @@ class SerializableInnerClassHasSerialVersionUIDFieldVisitor
registerClassError(aClass);
}
private boolean hasSerialVersionUIDField(PsiClass aClass) {
private static boolean hasSerialVersionUIDField(PsiClass aClass) {
final PsiField[] fields = aClass.getFields();
boolean hasSerialVersionUID = false;
for (PsiField field : fields) {
@@ -15,6 +15,7 @@
*/
package com.siyeh.ig.serialization;
import com.intellij.psi.PsiAnonymousClass;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiModifier;
import com.siyeh.ig.BaseInspectionVisitor;
@@ -24,10 +25,10 @@ import org.jetbrains.annotations.NotNull;
class SerializableInnerClassWithNonSerializableOuterClassVisitor
extends BaseInspectionVisitor {
private final SerializableInnerClassWithNonSerializableOuterClassInspection inspection;
private final SerializableInspection inspection;
public SerializableInnerClassWithNonSerializableOuterClassVisitor(
SerializableInnerClassWithNonSerializableOuterClassInspection inspection) {
SerializableInspection inspection) {
this.inspection = inspection;
}
@@ -36,6 +37,10 @@ class SerializableInnerClassWithNonSerializableOuterClassVisitor
aClass.isEnum()) {
return;
}
if (inspection.ignoreAnonymousInnerClasses &&
aClass instanceof PsiAnonymousClass) {
return;
}
final PsiClass containingClass = aClass.getContainingClass();
if (containingClass == null) {
return;
@@ -19,22 +19,29 @@ import com.intellij.codeInspection.ui.AddAction;
import com.intellij.codeInspection.ui.ListTable;
import com.intellij.codeInspection.ui.ListWrappingTableModel;
import com.intellij.codeInspection.ui.RemoveAction;
import com.intellij.openapi.actionSystem.ActionToolbar;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.psi.PsiClass;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.ui.ScrollPaneFactory;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.psiutils.SerializationUtils;
import com.siyeh.ig.ui.CheckBox;
import com.siyeh.ig.ui.UiUtils;
import org.jdom.Element;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public abstract class SerializableInspection extends BaseInspection {
/** @noinspection PublicField */
@SuppressWarnings({"PublicField"})
public boolean ignoreAnonymousInnerClasses = false;
@SuppressWarnings({"PublicField"})
public String superClassString = "java.awt.Component";
protected List<String> superClassList = new ArrayList();
@@ -44,8 +51,41 @@ public abstract class SerializableInspection extends BaseInspection {
@Override
public JComponent createOptionsPanel() {
final Form form = new Form();
return form.getContentPanel();
final JComponent panel = new JPanel(new GridBagLayout());
final ListTable table = new ListTable(new ListWrappingTableModel(
superClassList, InspectionGadgetsBundle.message(
"ignore.classes.in.hierarchy.column.name")));
final JScrollPane scrollPane =
ScrollPaneFactory.createScrollPane(table);
final ActionToolbar toolbar =
UiUtils.createAddRemoveTreeAnnotationChooserToolbar(table,
InspectionGadgetsBundle.message(
"choose.super.class.to.ignore"));
final CheckBox checkBox = new CheckBox(InspectionGadgetsBundle.message(
"ignore.anonymous.inner.classes"), this,
"ignoreAnonymousInnerClasses");
final GridBagConstraints constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets.left = 4;
constraints.insets.right = 4;
constraints.fill = GridBagConstraints.HORIZONTAL;
panel.add(toolbar.getComponent(), constraints);
constraints.gridy = 1;
constraints.weightx = 1.0;
constraints.weighty = 1.0;
constraints.fill = GridBagConstraints.BOTH;
panel.add(scrollPane, constraints);
constraints.gridy = 2;
constraints.weighty = 0.0;
constraints.fill = GridBagConstraints.HORIZONTAL;
panel.add(checkBox, constraints);
return panel;
}
@Override
@@ -71,27 +111,4 @@ public abstract class SerializableInspection extends BaseInspection {
}
return false;
}
private class Form {
private JPanel contentPanel;
private ListTable table;
private JButton addButton;
private JButton removeButton;
Form() {
addButton.setAction(new AddAction(table));
removeButton.setAction(new RemoveAction(table));
}
private void createUIComponents() {
table = new ListTable(new ListWrappingTableModel(superClassList,
InspectionGadgetsBundle.message(
"ignore.classes.in.hierarchy.column.name")));
}
public JPanel getContentPanel() {
return contentPanel;
}
}
}
@@ -15,9 +15,9 @@
*/
package com.intellij.lang.ant.config.execution;
import com.intellij.compiler.impl.javaCompiler.FileObject;
import com.intellij.compiler.impl.javaCompiler.javac.JavacOutputParser;
import com.intellij.compiler.impl.javaCompiler.jikes.JikesOutputParser;
import com.intellij.compiler.impl.javaCompiler.FileObject;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.lang.ant.AntBundle;
import com.intellij.openapi.application.ApplicationManager;
@@ -240,7 +240,7 @@ public class OutputParser{
}
com.intellij.compiler.OutputParser.Callback callback = new com.intellij.compiler.OutputParser.Callback() {
private int myIndex = 0;
private int myIndex = -1;
@Nullable
public String getCurrentLine() {
@@ -251,7 +251,16 @@ public class OutputParser{
}
public String getNextLine() {
return javacMessages.get(myIndex++);
final int next = myIndex + 1;
if (next >= javacMessages.size()) {
return null;
}
return javacMessages.get(myIndex = next);
}
@Override
public void pushBack(String line) {
myIndex--;
}
public void message(final CompilerMessageCategory category,
@@ -40,10 +40,7 @@ import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNProperties;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationProvider;
import org.tmatesoft.svn.core.auth.ISVNProxyManager;
import org.tmatesoft.svn.core.auth.SVNAuthentication;
import org.tmatesoft.svn.core.auth.SVNSSLAuthentication;
import org.tmatesoft.svn.core.auth.*;
import org.tmatesoft.svn.core.internal.wc.*;
import org.tmatesoft.svn.core.io.SVNRepository;
@@ -568,8 +565,9 @@ public class SvnAuthenticationManager extends DefaultSVNAuthenticationManager im
}
@Override
public boolean promptForSSLPlaintextPassphraseSaving(SVNURL url, String realm, File certificateFile) {
final int answer = Messages.showYesNoDialog(myProject, String.format("Your passphrase for client certificate:\n%s\ncan only be stored to disk unencrypted. Would you like to store it in plaintext?",
public boolean promptForSSLPlaintextPassphraseSaving(SVNURL url, String realm, File certificateFile, String certificateName) {
final int answer = Messages.showYesNoDialog(myProject,
String.format("Your passphrase for " + certificateName + ":\n%s\ncan only be stored to disk unencrypted. Would you like to store it in plaintext?",
certificateFile.getPath()),
"Store the passphrase in plaintext?", Messages.getQuestionIcon());
return answer == 0;
@@ -655,8 +653,19 @@ public class SvnAuthenticationManager extends DefaultSVNAuthenticationManager im
promptAndSaveWhenWeLackEncryption(realm, auth, new Getter<Boolean>() {
@Override
public Boolean get() {
File file = null;
String certificateName = null;
if (auth instanceof SVNSSLAuthentication) {
file = ((SVNSSLAuthentication) auth).getCertificateFile();
certificateName = "client certificate";
} else if (auth instanceof SVNSSHAuthentication) {
file = ((SVNSSHAuthentication) auth).getPrivateKeyFile();
certificateName = "private key file";
} else {
assert false;
}
return myInteraction.promptForSSLPlaintextPassphraseSaving(myUrl, realm,
((SVNSSLAuthentication) auth).getCertificateFile());
file, certificateName);
}
});
}
@@ -23,7 +23,7 @@ public interface SvnAuthenticationInteraction {
void warnOnAuthStorageDisabled(final SVNURL url);
void warnOnPasswordStorageDisabled(final SVNURL url);
void warnOnSSLPassphraseStorageDisabled(final SVNURL url);
boolean promptForSSLPlaintextPassphraseSaving(final SVNURL url, String realm, File certificateFile);
boolean promptForSSLPlaintextPassphraseSaving(final SVNURL url, String realm, File certificateFile, String certificateName);
boolean promptForPlaintextPasswordSaving(final SVNURL url, String realm);
boolean promptInAwt();
}
@@ -1248,7 +1248,7 @@ public class SvnAuthenticationTest extends PlatformTestCase {
}
@Override
public boolean promptForSSLPlaintextPassphraseSaving(SVNURL url, String realm, File certificateFile) {
public boolean promptForSSLPlaintextPassphraseSaving(SVNURL url, String realm, File certificateFile, String certificateName) {
++ myNumSSLPlaintextPrompt;
return mySSLPlaintextAnswer;
}