IDEA-26360 (Performance and inconsistency issues with svn:externals and "Detect neste...
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / SvnBranchMapperManager.java
blob03d950cd3c6dae99f00cc8c2f2d56be68aab0094
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.svn;
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.components.PersistentStateComponent;
20 import com.intellij.openapi.components.ServiceManager;
21 import com.intellij.openapi.components.State;
22 import com.intellij.openapi.components.Storage;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.vfs.VirtualFile;
25 import com.intellij.util.messages.Topic;
26 import org.jetbrains.idea.svn.branchConfig.SvnBranchConfigurationNew;
28 import java.io.File;
29 import java.util.*;
31 @State(
32 name = "SvnBranchMapperManager",
33 storages = {
34 @Storage(
35 id ="other",
36 file = "$APP_CONFIG$/other.xml"
39 public class SvnBranchMapperManager implements PersistentStateComponent<SvnBranchMapperManager.SvnBranchMapperHolder> {
40 private SvnBranchMapperHolder myStateHolder;
42 public static SvnBranchMapperManager getInstance() {
43 return ServiceManager.getService(SvnBranchMapperManager.class);
46 public SvnBranchMapperManager() {
47 myStateHolder = new SvnBranchMapperHolder();
50 public SvnBranchMapperHolder getState() {
51 return myStateHolder;
54 public void loadState(final SvnBranchMapperHolder state) {
55 myStateHolder = state;
58 public void put(final String url, final String value) {
59 myStateHolder.put(url, value);
60 notifyWcRootsChanged(url, Collections.unmodifiableCollection(myStateHolder.get(url)));
63 public void remove(final String url, final File value) {
64 final Set<String> set = myStateHolder.get(url);
65 if (set != null) {
66 set.remove(value.getAbsolutePath());
68 notifyWcRootsChanged(url, Collections.unmodifiableCollection(set));
71 private static void notifyWcRootsChanged(final String url, final Collection<String> roots) {
72 ApplicationManager.getApplication().getMessageBus().syncPublisher(WC_ROOTS_CHANGED).rootsChanged(url, roots);
75 public void notifyBranchesChanged(final Project project, final VirtualFile vcsRoot, final SvnBranchConfigurationNew configuration) {
76 final Map<String, String> map = configuration.getUrl2FileMappings(project, vcsRoot);
77 if (map != null) {
78 for (Map.Entry<String, String> entry : map.entrySet()) {
79 put(entry.getKey(), entry.getValue());
84 public Set<String> get(final String key) {
85 return myStateHolder.get(key);
88 public static class SvnBranchMapperHolder {
89 public Map<String, Set<String>> myMapping;
91 public SvnBranchMapperHolder() {
92 myMapping = new HashMap<String, Set<String>>();
95 public void put(final String key, final String value) {
96 Set<String> files = myMapping.get(key);
97 if (files == null) {
98 files = new HashSet<String>();
99 myMapping.put(key, files);
101 files.add(value);
104 public Set<String> get(final String key) {
105 return myMapping.get(key);
109 public static interface WcRootsChangeConsumer {
110 void rootsChanged(final String url, final Collection<String> roots);
113 public static final Topic<WcRootsChangeConsumer> WC_ROOTS_CHANGED =
114 new Topic<WcRootsChangeConsumer>("SVN_WC_ROOTS_CHANGED", WcRootsChangeConsumer.class);