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 org
.jetbrains
.idea
.svn
.config
.DefaultProxyGroup
;
19 import org
.jetbrains
.idea
.svn
.config
.ProxyGroup
;
23 public class SvnServerFileManagerImpl
implements SvnServerFileManager
{
24 private final DefaultProxyGroup myDefaultGroup
;
25 private final Map
<String
, ProxyGroup
> myGroups
;
26 private final IdeaSVNConfigFile myFile
;
28 public SvnServerFileManagerImpl(final IdeaSVNConfigFile file
) {
30 myFile
.updateGroups();
32 myGroups
= new HashMap
<String
, ProxyGroup
>();
33 myGroups
.putAll(file
.getAllGroups());
34 myDefaultGroup
= file
.getDefaultGroup();
37 public DefaultProxyGroup
getDefaultGroup() {
38 return (DefaultProxyGroup
) myDefaultGroup
.copy();
41 public Map
<String
, ProxyGroup
> getGroups() {
43 final Map
<String
, ProxyGroup
> result
= new HashMap
<String
, ProxyGroup
>(myGroups
);
44 for (Map
.Entry
<String
, ProxyGroup
> entry
: myGroups
.entrySet()) {
45 result
.put(entry
.getKey(), entry
.getValue().copy());
50 public void updateUserServerFile(final Collection
<ProxyGroup
> newUserGroups
) {
51 final Map
<String
, ProxyGroup
> oldGroups
= getGroups();
53 for (ProxyGroup proxyGroup
: newUserGroups
) {
54 if (proxyGroup
.isDefault()) {
55 processGroup(proxyGroup
, getDefaultGroup(), false);
57 findAndProcessGroup(proxyGroup
, oldGroups
);
61 for (String groupName
: oldGroups
.keySet()) {
62 myFile
.deleteGroup(groupName
);
68 private void processGroup(final ProxyGroup newGroup
, final ProxyGroup oldGroup
, final boolean groupWasAdded
) {
69 final String newGroupName
= newGroup
.getName();
71 myFile
.addGroup(newGroupName
, newGroup
.getPatterns(), newGroup
.getProperties());
73 final Map
<String
, String
> oldProperties
= oldGroup
.getProperties();
74 final Map
<String
, String
> newProperties
= newGroup
.getProperties();
76 final Set
<String
> deletedProperties
= new HashSet
<String
>();
77 for (String oldKey
: oldProperties
.keySet()) {
78 if (! newProperties
.containsKey(oldKey
)) {
79 deletedProperties
.add(oldKey
);
83 final Map
<String
, String
> newOrModifiedProperties
= new HashMap
<String
, String
>();
84 for (Map
.Entry
<String
, String
> entry
: newProperties
.entrySet()) {
85 final String oldValue
= oldProperties
.get(entry
.getKey());
86 if ((oldValue
== null) || (! oldValue
.equals(entry
.getValue()))) {
87 newOrModifiedProperties
.put(entry
.getKey(), entry
.getValue());
91 myFile
.modifyGroup(newGroupName
, newGroup
.getPatterns(), deletedProperties
, newOrModifiedProperties
, newGroup
.isDefault());
95 private void findAndProcessGroup(final ProxyGroup newGroup
, final Map
<String
, ProxyGroup
> oldGroups
) {
96 final String newGroupName
= newGroup
.getName();
97 final ProxyGroup oldGroup
= oldGroups
.get(newGroupName
);
98 final boolean groupWasAdded
= (oldGroup
== null) && (! newGroup
.isDefault());
99 if (! groupWasAdded
) {
101 oldGroups
.remove(newGroupName
);
103 processGroup(newGroup
, oldGroup
, groupWasAdded
);