Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f6edce565391e1bbfaeb61c38e855d8337df3910 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*******************************************************************************
 * Copyright (c) 2013 Atos
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Arthur Daussy - initial implementation
 *     Philippe Roland (Atos) philippe.roland@atos.net - added workaround for eclipse bug 385394
 *******************************************************************************/
package org.eclipse.papyrus.team.collaborative.svn;

import java.util.HashSet;
import java.util.Set;
import java.util.WeakHashMap;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.papyrus.team.collaborative.core.ICollabFactory;
import org.eclipse.papyrus.team.collaborative.core.IExtendedURI;
import org.eclipse.papyrus.team.collaborative.core.participants.locker.ILocker;
import org.eclipse.papyrus.team.collaborative.core.participants.locker.IUnlocker;
import org.eclipse.papyrus.team.collaborative.core.participants.version.ICommitter;
import org.eclipse.papyrus.team.collaborative.core.participants.version.IReverter;
import org.eclipse.papyrus.team.collaborative.core.participants.version.IUpdater;
import org.eclipse.papyrus.team.collaborative.core.utils.CollabFunctionsFactory;
import org.eclipse.papyrus.team.collaborative.svn.locker.SVNLocker;
import org.eclipse.papyrus.team.collaborative.svn.locker.SVNUnlocker;
import org.eclipse.papyrus.team.collaborative.svn.versioncontroller.SVNCommitter;
import org.eclipse.papyrus.team.collaborative.svn.versioncontroller.SVNReverter;
import org.eclipse.papyrus.team.collaborative.svn.versioncontroller.SVNUpdater;
import com.google.common.collect.Collections2;


/**
 * Factory to build element to do collaborative work with SVN.
 *
 * @author adaussy
 */
public class SVNCollabFactory implements ICollabFactory {

	/** The Constant SVN_COLLAB_ID. */
	public static final String SVN_COLLAB_ID = "org.eclipse.papyrus.team.collaborative.core.connector.svn";

	/**
	 * Resource set svn status cache
	 */
	private WeakHashMap<ResourceSet, Boolean> alreadyOnSvnCache = new WeakHashMap<ResourceSet, Boolean>();

	/**
	 * Instantiates a new sVN collab factory.
	 */
	public SVNCollabFactory() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.papyrus.team.collaborative.core.ICollabFactory#provide(java.util.Set, org.eclipse.emf.ecore.resource.ResourceSet)
	 */
	@Override
	public boolean provide(Set<IExtendedURI> uris, ResourceSet resourceSet) {
		/**
		 * Workaround for eclipse bug 385394. This bug causes property testers to be called very frequently
		 * even if no activity is taking place, causing important slowdowns when a right-click on a model explorer element is performed.
		 * a cache prevents these calls (and the subsequent calls to FileUtility.alreadyOnSVN) from being too taxing on system resources.
		 *
		 * This bug was fixed on 16/01/2014 but its fix has not yet been released outside of integration builds. Remove this workaround when it is.
		 */
		if (alreadyOnSvnCache.containsKey(resourceSet)) {
			return alreadyOnSvnCache.get(resourceSet);
		}
		boolean result;
		Set<IProject> projects = new HashSet<IProject>();
		for (IResource iResource : Collections2.transform(uris, CollabFunctionsFactory.getExtendedURIToIResource(resourceSet))) {
			if (iResource != null) {
				projects.add(iResource.getProject());
			}
		}
		if (projects.isEmpty()) {
			result = false;
			alreadyOnSvnCache.put(resourceSet, result);
			return result;
		}
		for (IProject iProject : projects) {
			if (!FileUtility.alreadyOnSVN(iProject)) {
				result = false;
				alreadyOnSvnCache.put(resourceSet, result);
				return result;
			}
		}
		result = true;
		alreadyOnSvnCache.put(resourceSet, result);
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.papyrus.team.collaborative.core.ICollabFactory#createLocker(java.util.Set, org.eclipse.emf.ecore.resource.ResourceSet)
	 */
	@Override
	public ILocker createLocker(Set<IExtendedURI> uris, ResourceSet resourceSet) {
		return new SVNLocker(uris, resourceSet);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.papyrus.team.collaborative.core.ICollabFactory#createUnlocker(java.util.Set, org.eclipse.emf.ecore.resource.ResourceSet)
	 */
	@Override
	public IUnlocker createUnlocker(Set<IExtendedURI> uris, ResourceSet resourceSet) {
		return new SVNUnlocker(uris, resourceSet);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.papyrus.team.collaborative.core.ICollabFactory#createReverter(java.util.Set, org.eclipse.emf.ecore.resource.ResourceSet)
	 */
	@Override
	public IReverter createReverter(Set<IExtendedURI> uris, ResourceSet resourceSet) {
		return new SVNReverter(uris, resourceSet);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.papyrus.team.collaborative.core.ICollabFactory#createCommitter(java.util.Set, org.eclipse.emf.ecore.resource.ResourceSet)
	 */
	@Override
	public ICommitter createCommitter(Set<IExtendedURI> uris, ResourceSet resourceSet) {
		return new SVNCommitter(uris, resourceSet);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.papyrus.team.collaborative.core.ICollabFactory#createUpdater(java.util.Set, org.eclipse.emf.ecore.resource.ResourceSet)
	 */
	@Override
	public IUpdater createUpdater(Set<IExtendedURI> uris, ResourceSet resourceSet) {
		return new SVNUpdater(uris, resourceSet);
	}

}

Back to the top