Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 361926 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ccvs/ui/model/RemoteFolderElement.java (-9 / +41 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 57-79 Link Here
57
    public Object[] fetchChildren(Object o, IProgressMonitor monitor) throws TeamException {
57
    public Object[] fetchChildren(Object o, IProgressMonitor monitor) throws TeamException {
58
        if (!(o instanceof ICVSRemoteFolder))
58
        if (!(o instanceof ICVSRemoteFolder))
59
            return new Object[0];
59
            return new Object[0];
60
        return ((ICVSRemoteFolder) o).members(monitor);
60
		try {
61
    }
61
			monitor = Policy.monitorFor(monitor);
62
			monitor.beginTask(NLS.bind(
63
					CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
64
					new String[] { getLabel(o) }), 100);
65
			ICVSRemoteFolder folder = (ICVSRemoteFolder) o;
66
			ICVSRemoteResource[] cachedChildren = CVSUIPlugin
67
					.getPlugin()
68
					.getRepositoryManager()
69
					.getCachedChildrenForTag(folder.getRepository(), folder,
70
							folder.getTag(), Policy.subMonitorFor(monitor, 50));
71
			if (cachedChildren.length > 0) {
72
				return cachedChildren;
73
			}
74
			return folder.members(Policy.subMonitorFor(monitor, 50));
75
		} finally {
76
			monitor.done();
77
		}
78
	}
62
79
63
    public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
80
    public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
64
    	// If it's not a folder, return an empty array
81
    	// If it's not a folder, return an empty array
65
		if (!(o instanceof ICVSRemoteFolder)) {
82
		if (!(o instanceof ICVSRemoteFolder)) {
66
			collector.add(new Object[0], monitor);
83
			collector.add(new Object[0], monitor);
67
		}
84
		}
68
        try {
85
		try {
69
            monitor = Policy.monitorFor(monitor);
86
			monitor = Policy.monitorFor(monitor);
70
            monitor.beginTask(NLS.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren, new String[] { getLabel(o) }), 100); 
87
			monitor.beginTask(NLS.bind(
71
			FetchMembersOperation operation = new FetchMembersOperation(null, (ICVSRemoteFolder)o, collector);
88
					CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
72
			operation.run(Policy.subMonitorFor(monitor, 100));
89
					new String[] { getLabel(o) }), 100);
73
        } catch (InvocationTargetException e) {
90
			ICVSRemoteFolder folder = (ICVSRemoteFolder) o;
91
			ICVSRemoteResource[] cachedChildren = CVSUIPlugin
92
					.getPlugin()
93
					.getRepositoryManager()
94
					.getCachedChildrenForTag(folder.getRepository(), folder,
95
							folder.getTag(), Policy.subMonitorFor(monitor, 50));
96
			if (cachedChildren.length > 0) {
97
				collector.add(cachedChildren, monitor);
98
				return;
99
			}
100
			FetchMembersOperation operation = new FetchMembersOperation(null,
101
					folder, collector);
102
			operation.run(Policy.subMonitorFor(monitor, 50));
103
		} catch (InvocationTargetException e) {
74
            handle(collector, e);
104
            handle(collector, e);
75
		} catch (InterruptedException e) {
105
		} catch (InterruptedException e) {
76
			// Cancelled by the user;
106
			// Cancelled by the user;
107
		} catch (CVSException e) {
108
			handle(collector, e);
77
		} finally {
109
		} finally {
78
            monitor.done();
110
            monitor.done();
79
        }
111
        }
(-)src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java (-16 / +64 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 142-156 Link Here
142
		Set result = new HashSet();
142
		Set result = new HashSet();
143
		RepositoryRoot root = (RepositoryRoot)repositoryRoots.get(location.getLocation(false));
143
		RepositoryRoot root = (RepositoryRoot)repositoryRoots.get(location.getLocation(false));
144
		if (root != null) {
144
		if (root != null) {
145
			String[] paths = root.getKnownRemotePaths();
145
			CVSTag[] tags = root.getAllKnownTags();
146
			for (int i = 0; i < paths.length; i++) {
146
			for (int i = 0; i < tags.length; i++) {
147
				String path = paths[i];
147
				CVSTag tag = tags[i];
148
				CVSTag[] tags = root.getAllKnownTags(path);
148
				if (tag.getType() == tagType)
149
				for (int j = 0; j < tags.length; j++) {
149
					result.add(tag);
150
					CVSTag tag = tags[j];
151
					if (tag.getType() == tagType)
152
						result.add(tag);
153
				}
154
			}
150
			}
155
		}
151
		}
156
		return (CVSTag[])result.toArray(new CVSTag[0]);
152
		return (CVSTag[])result.toArray(new CVSTag[0]);
Lines 225-244 Link Here
225
			Set result = new HashSet();
221
			Set result = new HashSet();
226
			// Get the tags for the location
222
			// Get the tags for the location
227
			RepositoryRoot root = getRepositoryRootFor(location);
223
			RepositoryRoot root = getRepositoryRootFor(location);
228
			String[] paths = root.getKnownRemotePaths();
224
			String[] paths = root.getRemoteChildrenForTag(null, tag);
229
			for (int i = 0; i < paths.length; i++) {
225
			for (int i = 0; i < paths.length; i++) {
230
				String path = paths[i];
226
				String path = paths[i];
231
				List tags = Arrays.asList(root.getAllKnownTags(path));
227
				ICVSRemoteFolder remote = root.getRemoteFolder(path, tag,
232
				if (tags.contains(tag)) {
228
						Policy.subMonitorFor(monitor, 100));
233
					ICVSRemoteFolder remote = root.getRemoteFolder(path, tag, Policy.subMonitorFor(monitor, 100));
229
				result.add(remote);
234
					result.add(remote);
235
				}
236
			}
230
			}
237
			return (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[result.size()]);
231
			return (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[result.size()]);
238
		} finally {
232
		} finally {
239
			monitor.done();
233
			monitor.done();
240
		}
234
		}
241
	}
235
	}
236
237
	/**
238
	 * Returns a list of child resources for given folder that are known to
239
	 * contain given tag. If the return list is empty than given tag exists
240
	 * directly in given folder and its children should be retrieved directly
241
	 * from the repository.
242
	 *
243
	 * NOTE: Resources are cached only for tags of type CVSTag.Branch and
244
	 * CVSTag.Version. Other types of tags will always return empty list.
245
	 *
246
	 * @param location
247
	 *            CVS repository location
248
	 * @param parentFolder
249
	 *            folder to check tags for
250
	 * @param tag
251
	 * @param monitor
252
	 * @return a list of remote resources that are known to contain given tag or
253
	 *         empty list if resources should be retrieved from the repository
254
	 * @throws CVSException
255
	 */
256
	public ICVSRemoteResource[] getCachedChildrenForTag(
257
			ICVSRepositoryLocation location, ICVSRemoteFolder parentFolder,
258
			CVSTag tag, IProgressMonitor monitor) throws CVSException {
259
		if (tag == null || tag.getType() == CVSTag.HEAD
260
				|| tag.getType() == CVSTag.DATE) {
261
			// folders are kept in cache only for tags and versions
262
			return new ICVSRemoteResource[0];
263
		}
264
		monitor = Policy.monitorFor(monitor);
265
		Set result = new HashSet();
266
		RepositoryRoot root = getRepositoryRootFor(location);
267
		// if remote folder is null return the subfolders of repository root
268
		String[] paths = root.getRemoteChildrenForTag(
269
				parentFolder == null ? null : RepositoryRoot
270
						.getRemotePathFor(parentFolder), tag);
271
		monitor.beginTask(NLS
272
				.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
273
						new String[] { NLS.bind(
274
								CVSUIMessages.RemoteFolderElement_nameAndTag,
275
								new String[] { parentFolder.getName(),
276
										tag.getName() }) }), 10 * paths.length);
277
		try {
278
			for (int i = 0; i < paths.length; i++) {
279
				String path = paths[i];
280
				ICVSRemoteFolder remote = root.getRemoteFolder(path, tag,
281
						Policy.subMonitorFor(monitor, 10));
282
				result.add(remote);
283
			}
284
			return (ICVSRemoteResource[]) result
285
					.toArray(new ICVSRemoteResource[result.size()]);
286
		} finally {
287
			monitor.done();
288
		}
289
	}
242
		
290
		
243
	/*
291
	/*
244
	 * Fetches tags from auto-refresh files if they exist. Then fetches tags from the user defined auto-refresh file
292
	 * Fetches tags from auto-refresh files if they exist. Then fetches tags from the user defined auto-refresh file
(-)src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryRoot.java (-105 / +277 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-25 Link Here
12
12
13
import java.io.IOException;
13
import java.io.IOException;
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.ArrayList;
15
import java.util.*;
16
import java.util.Arrays;
17
import java.util.HashMap;
18
import java.util.HashSet;
19
import java.util.Iterator;
20
import java.util.List;
21
import java.util.Map;
22
import java.util.Set;
23
16
24
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.*;
25
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.osgi.util.NLS;
Lines 40-47 Link Here
40
	
33
	
41
	ICVSRepositoryLocation root;
34
	ICVSRepositoryLocation root;
42
	String name;
35
	String name;
43
	// Map of String (remote folder path) -> TagCacheEntry
36
	TagCacheEntry rootTagCacheEntry = new TagCacheEntry(Path.ROOT, null);
44
	Map versionAndBranchTags = new HashMap();
45
	// Map of String (remote folder path) -> Set (file paths that are project relative)
37
	// Map of String (remote folder path) -> Set (file paths that are project relative)
46
	Map autoRefreshFiles = new HashMap();
38
	Map autoRefreshFiles = new HashMap();
47
	// Map of String (module name) -> ICVSRemoteFolder (that is a defined module)
39
	// Map of String (module name) -> ICVSRemoteFolder (that is a defined module)
Lines 51-62 Link Here
51
	List dateTags = new ArrayList();
43
	List dateTags = new ArrayList();
52
	
44
	
53
	public static class TagCacheEntry {
45
	public static class TagCacheEntry {
54
	    Set tags = new HashSet();
46
		IPath path;
55
	    long lastAccessTime;
47
		// Set of tags found for this path
56
        private static final int CACHE_LIFESPAN_IN_DAYS = 7;
48
		private Set tags = new HashSet();
57
        public TagCacheEntry() {
49
		// String(last path segment) -> TagCacheEntry for child paths
58
            accessed();
50
		Map children = new HashMap();
59
        }
51
		TagCacheEntry parent;
52
		long lastAccessTime;
53
		private static final int CACHE_LIFESPAN_IN_DAYS = 7;
54
55
		public TagCacheEntry(IPath path, TagCacheEntry parent) {
56
			this.path = path;
57
			this.parent = parent;
58
			accessed();
59
		}
60
61
		public Set getTags() {
62
			accessed();
63
			return tags;
64
		}
65
66
		public Iterator getChildrenIterator() {
67
			return this.children.values().iterator();
68
		}
69
70
		public boolean isEmpty() {
71
			return getTags().isEmpty() && children.isEmpty();
72
		}
73
60
        public boolean isExpired() {
74
        public boolean isExpired() {
61
            long currentTime = System.currentTimeMillis();
75
            long currentTime = System.currentTimeMillis();
62
            long ms = currentTime - lastAccessTime;
76
            long ms = currentTime - lastAccessTime;
Lines 65-73 Link Here
65
            int days = hours / 24;
79
            int days = hours / 24;
66
            return days > CACHE_LIFESPAN_IN_DAYS;
80
            return days > CACHE_LIFESPAN_IN_DAYS;
67
        }
81
        }
68
        public void accessed() {
82
69
            lastAccessTime = System.currentTimeMillis();
83
		private void accessed() {
70
        }
84
			lastAccessTime = System.currentTimeMillis();
85
		}
71
	}
86
	}
72
	
87
	
73
	public RepositoryRoot(ICVSRepositoryLocation root) {
88
	public RepositoryRoot(ICVSRepositoryLocation root) {
Lines 193-202 Link Here
193
	 * Accept the tags for any remote path that represents a folder. However, for the time being,
208
	 * Accept the tags for any remote path that represents a folder. However, for the time being,
194
	 * the given version tags are added to the list of known tags for the 
209
	 * the given version tags are added to the list of known tags for the 
195
	 * remote ancestor of the resource that is a direct child of the remote root.
210
	 * remote ancestor of the resource that is a direct child of the remote root.
196
	 * 
211
	 *
197
	 * It is the reponsibility of the caller to ensure that the given remote path is valid.
212
	 * It is the responsibility of the caller to ensure that the given remote path is valid.
198
	 */
213
	 */
199
	public void addTags(String remotePath, CVSTag[] tags) {	
214
	public void addTags(String remotePath, CVSTag[] tags) {
215
		if (tags.length == 0) {
216
			return;
217
		}
200
		addDateTags(tags);
218
		addDateTags(tags);
201
		addVersionAndBranchTags(remotePath, tags);
219
		addVersionAndBranchTags(remotePath, tags);
202
	}
220
	}
Lines 208-230 Link Here
208
			}
226
			}
209
		}
227
		}
210
	}
228
	}
229
211
	private void addVersionAndBranchTags(String remotePath, CVSTag[] tags) {
230
	private void addVersionAndBranchTags(String remotePath, CVSTag[] tags) {
212
		// Get the name to cache the version tags with
231
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, true);
213
		String name = getCachePathFor(remotePath);
232
214
		
215
		// Make sure there is a table for the ancestor that holds the tags
216
		TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(name);
217
		if (entry == null) {
218
		    entry = new TagCacheEntry();
219
			versionAndBranchTags.put(name, entry);
220
		} else {
221
		    entry.accessed();
222
		}
223
		
224
		// Store the tag with the appropriate ancestor
233
		// Store the tag with the appropriate ancestor
225
		for (int i = 0; i < tags.length; i++) {
234
		for (int i = 0; i < tags.length; i++) {
226
			if(tags[i].getType() != CVSTag.DATE){
235
			if (tags[i].getType() != CVSTag.DATE) {
227
				entry.tags.add(tags[i]);
236
				Set parentTags = new HashSet();
237
				addAllKnownTagsForParents(entry, parentTags);
238
				if (!parentTags.contains(tags[i])) {
239
					entry.getTags().add(tags[i]);
240
					removeTagFromChildrenCacheEntries(entry, tags[i]);
241
				}
228
			}
242
			}
229
		}
243
		}
230
	}
244
	}
Lines 270-289 Link Here
270
	}
284
	}
271
285
272
	private void removeVersionAndBranchTags(String remotePath, CVSTag[] tags) {
286
	private void removeVersionAndBranchTags(String remotePath, CVSTag[] tags) {
273
		// Get the name to cache the version tags with
287
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
274
		String name = getCachePathFor(remotePath);
288
		// remove tags from this path and its children
275
		
289
		if (entry != null) {
276
		// Make sure there is a table for the ancestor that holds the tags
290
			removeTagsFromChildrenCacheEntries(entry, tags);
277
		TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(name);
278
		if (entry == null) {
279
			return;
280
		}
291
		}
281
		
292
282
		// Store the tag with the appropriate ancestor
293
		// remove tags from all parents of this path
294
		entry = getKnownParentTagCacheEntryFor(remotePath);
283
		for (int i = 0; i < tags.length; i++) {
295
		for (int i = 0; i < tags.length; i++) {
284
			entry.tags.remove(tags[i]);
296
			if (entry.getTags().contains(tags[i])) {
297
				entry.getTags().remove(tags[i]);
298
				continue;
299
			}
300
			TagCacheEntry currentEntry = entry;
301
			while (currentEntry.parent != null) {
302
				if (currentEntry.parent.getTags().contains(tags[i])) {
303
					// remove tag from parent and add it to siblings
304
					currentEntry.parent.getTags().remove(tags[i]);
305
					Iterator siblingIterator = currentEntry.parent
306
							.getChildrenIterator();
307
					while (siblingIterator.hasNext()) {
308
						TagCacheEntry sibling = (TagCacheEntry) siblingIterator
309
								.next();
310
						if (!sibling.equals(currentEntry)) {
311
							sibling.getTags().add(tags[i]);
312
						}
313
					}
314
					break;
315
				} else {
316
					currentEntry = currentEntry.parent;
317
				}
318
			}
319
		}
320
		if (entry.isEmpty()) {
321
			removeTagCacheEntry(entry);
285
		}
322
		}
286
		entry.accessed();
287
	}
323
	}
288
324
289
	/**
325
	/**
Lines 293-300 Link Here
293
	 * @return String[]
329
	 * @return String[]
294
	 */
330
	 */
295
	public String[] getAutoRefreshFiles(String remotePath) {
331
	public String[] getAutoRefreshFiles(String remotePath) {
296
		String name = getCachePathFor(remotePath);
332
		Set files = (Set) autoRefreshFiles.get(remotePath);
297
		Set files = (Set)autoRefreshFiles.get(name);
298
		if (files == null || files.isEmpty()) {
333
		if (files == null || files.isEmpty()) {
299
			// convert the default relative file paths to full paths
334
			// convert the default relative file paths to full paths
300
			if (isDefinedModuleName(remotePath)) {
335
			if (isDefinedModuleName(remotePath)) {
Lines 330-372 Link Here
330
				}
365
				}
331
			}
366
			}
332
			if (isDefault) {
367
			if (isDefault) {
333
				this.autoRefreshFiles.remove(getCachePathFor(remotePath));
368
				this.autoRefreshFiles.remove(remotePath);
334
				return;
369
				return;
335
			}
370
			}
336
		}
371
		}
337
		this.autoRefreshFiles.put(getCachePathFor(remotePath), newFiles);
372
		this.autoRefreshFiles.put(remotePath, newFiles);
338
	}
373
	}
339
374
340
	/**
375
	/**
341
	 * Fetches tags from auto-refresh files.
376
	 * Fetches tags from auto-refresh files.
342
	 */
377
	 */
343
	public CVSTag[] refreshDefinedTags(ICVSFolder folder, boolean recurse, IProgressMonitor monitor) throws TeamException {
378
	public CVSTag[] refreshDefinedTags(ICVSFolder folder, boolean recurse,
344
	    monitor.beginTask(null, 100);
379
			IProgressMonitor monitor) throws TeamException {
345
	    CVSTag[] tags = null;
380
		monitor = Policy.monitorFor(monitor);
346
	    if (!recurse && !folder.getFolderSyncInfo().isVirtualDirectory()) {
381
		monitor.beginTask(null, recurse ? 210 : 100);
347
	        // Only try the auto-refresh file(s) if we are not recursing into sub-folders
382
		try {
348
	        tags = fetchTagsUsingAutoRefreshFiles(folder, Policy.subMonitorFor(monitor, 50));
383
			CVSTag[] tags = null;
349
	    }
384
			if (!folder.getFolderSyncInfo().isVirtualDirectory()) {
350
        if (tags == null || tags.length == 0) {
385
				// Only try the auto-refresh file(s) if we are not recursing
351
            // There we're no tags found on the auto-refresh files or we we're aksed to go deep
386
				// into sub-folders
352
            // Try using the log command
387
				tags = fetchTagsUsingAutoRefreshFiles(folder,
353
            tags = fetchTagsUsingLog(folder, recurse, Policy.subMonitorFor(monitor, 50));
388
						Policy.subMonitorFor(monitor, 50));
354
        }
389
			}
355
		if (tags != null && tags.length > 0) {
390
			if (tags == null || tags.length == 0) {
356
		    String remotePath = getRemotePathFor(folder);
391
				// There we're no tags found on the auto-refresh files or we
357
			addTags(remotePath, tags);
392
				// we're asked to go deep
393
				// Try using the log command
394
				tags = fetchTagsUsingLog(folder,
395
						Policy.subMonitorFor(monitor, 50));
396
			}
397
			if (tags != null && tags.length > 0) {
398
				String remotePath = getRemotePathFor(folder);
399
				addTags(remotePath, tags);
400
				return tags;
401
			}
402
			if (recurse) {
403
				Set tagsSet = new HashSet();
404
				folder.fetchChildren(Policy.subMonitorFor(monitor, 10));
405
				ICVSResource[] children = folder
406
						.members(ICVSFolder.FOLDER_MEMBERS);
407
				for (int i = 0; i < children.length; i++) {
408
					tagsSet.addAll(Arrays.asList(refreshDefinedTags(
409
							(ICVSFolder) children[i], recurse, Policy
410
									.subMonitorFor(monitor,
411
											100 / children.length))));
412
				}
413
				tags = (CVSTag[]) tagsSet.toArray(new CVSTag[tagsSet.size()]);
414
			}
415
			return tags;
416
		} finally {
417
			monitor.done();
358
		}
418
		}
359
		monitor.done();
360
		return tags;
361
	}
419
	}
362
	
420
363
    private CVSTag[] fetchTagsUsingLog(ICVSFolder folder, final boolean recurse, IProgressMonitor monitor) throws CVSException {
421
    private CVSTag[] fetchTagsUsingLog(ICVSFolder folder, IProgressMonitor monitor) throws CVSException {
364
        LogEntryCache logEntries = new LogEntryCache();
422
        LogEntryCache logEntries = new LogEntryCache();
365
        RemoteLogOperation operation = new RemoteLogOperation(null, new ICVSRemoteResource[] { asRemoteResource(folder) }, null, null, logEntries) {
423
        RemoteLogOperation operation = new RemoteLogOperation(null, new ICVSRemoteResource[] { asRemoteResource(folder) }, null, null, logEntries) {
366
            protected Command.LocalOption[] getLocalOptions(CVSTag tag1,CVSTag tag2) {
424
            protected Command.LocalOption[] getLocalOptions(CVSTag tag1,CVSTag tag2) {
367
                Command.LocalOption[] options = new Command.LocalOption[] {};
425
                Command.LocalOption[] options = new Command.LocalOption[] {};
368
                if (recurse) 
369
                    return options;
370
                Command.LocalOption[] newOptions = new Command.LocalOption[options.length + 1];
426
                Command.LocalOption[] newOptions = new Command.LocalOption[options.length + 1];
371
                System.arraycopy(options, 0, newOptions, 0, options.length);
427
                System.arraycopy(options, 0, newOptions, 0, options.length);
372
                newOptions[options.length] = Command.DO_NOT_RECURSE;
428
                newOptions[options.length] = Command.DO_NOT_RECURSE;
Lines 448-463 Link Here
448
		}
504
		}
449
		return (CVSTag[])tagSet.toArray(new CVSTag[0]);
505
		return (CVSTag[])tagSet.toArray(new CVSTag[0]);
450
	}
506
	}
451
	
507
452
	/*
508
	private TagCacheEntry getTagCacheEntryFor(String remotePath, boolean create) {
453
	 * Return the cache key (path) for the given folder path.
509
		String[] segments = new Path(null, remotePath).segments();
454
	 * This has been changed to cache the tags directly 
510
		TagCacheEntry currentTagCacheEntry = rootTagCacheEntry;
455
	 * with the folder to better support non-root projects.
511
		for (int i = 0; i < segments.length; i++) {
456
	 * However, resources in the local workspace use the folder
512
			String segment = segments[i];
457
	 * the project is mapped to as the tag source (see TagSource)
513
			if (currentTagCacheEntry.children.containsKey(segment)) {
458
	 */
514
				currentTagCacheEntry = (TagCacheEntry) currentTagCacheEntry.children
459
	private String getCachePathFor(String remotePath) {
515
						.get(segment);
460
		return remotePath;
516
				continue;
517
			}
518
			if (!create) {
519
				return null;
520
			}
521
			TagCacheEntry newTagCacheEntry = new TagCacheEntry(new Path(null,
522
					remotePath).removeLastSegments(segments.length - (i + 1)),
523
					currentTagCacheEntry);
524
			currentTagCacheEntry.children.put(segment, newTagCacheEntry);
525
			currentTagCacheEntry = newTagCacheEntry;
526
		}
527
		return currentTagCacheEntry;
528
	}
529
530
	private TagCacheEntry getKnownParentTagCacheEntryFor(String remotePath) {
531
		String[] segments = new Path(null, remotePath).segments();
532
		TagCacheEntry currentTagCacheEntry = rootTagCacheEntry;
533
		for (int i = 0; i < segments.length; i++) {
534
			String segment = segments[i];
535
			if (currentTagCacheEntry.children.containsKey(segment)) {
536
				currentTagCacheEntry = (TagCacheEntry) currentTagCacheEntry.children
537
						.get(segment);
538
			} else {
539
				break; // we reached the last existing parent
540
			}
541
		}
542
		return currentTagCacheEntry;
543
	}
544
545
	private void removeTagsFromChildrenCacheEntries(TagCacheEntry entry,
546
			CVSTag[] tags) {
547
		for (int i = 0; i < tags.length; i++) {
548
			removeTagFromChildrenCacheEntries(entry, tags[i]);
549
		}
550
		entry.getTags().removeAll(Arrays.asList(tags));
551
		if (entry.isEmpty()) {
552
			// remove this entry when the last tags where removed
553
			// keep the entry if there are any children that have tags
554
			removeTagCacheEntry(entry);
555
		}
556
	}
557
558
	private void removeTagCacheEntry(TagCacheEntry entry) {
559
		if (entry.parent == null) {
560
			// We cannot remove root tag cache entry
561
			return;
562
		}
563
		Map newParentChildren = new HashMap();
564
		newParentChildren.putAll(entry.parent.children);
565
		newParentChildren.remove(entry.path.lastSegment());
566
		entry.parent.children = newParentChildren;
567
		if (entry.parent.isEmpty()) {
568
			// remove parents if they no longer carry any value
569
			removeTagCacheEntry(entry.parent);
570
		}
571
	}
572
573
	private void removeTagFromChildrenCacheEntries(TagCacheEntry entry,
574
			CVSTag tag) {
575
		Iterator childrenIterator = entry.getChildrenIterator();
576
		while (childrenIterator.hasNext()) {
577
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
578
			removeTagFromChildrenCacheEntries(child, tag);
579
			child.getTags().remove(tag);
580
			if (child.isEmpty()) {
581
				// remove this entry when the last tag was removed
582
				// keep the entry if there are any children that have tags
583
				removeTagCacheEntry(child);
584
			}
585
		}
461
	}
586
	}
462
	
587
	
463
	/**
588
	/**
Lines 502-514 Link Here
502
				attributes.put(RepositoriesViewContentHandler.TYPE_ATTRIBUTE, RepositoriesViewContentHandler.DEFINED_MODULE_TYPE);
627
				attributes.put(RepositoriesViewContentHandler.TYPE_ATTRIBUTE, RepositoriesViewContentHandler.DEFINED_MODULE_TYPE);
503
			}
628
			}
504
			attributes.put(RepositoriesViewContentHandler.PATH_ATTRIBUTE, name);
629
			attributes.put(RepositoriesViewContentHandler.PATH_ATTRIBUTE, name);
505
			TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(path);
630
			TagCacheEntry entry = getTagCacheEntryFor(path, false);
506
			boolean writeOutTags = entry != null && !entry.isExpired();
631
			boolean writeOutTags = entry != null && !entry.isExpired();
507
			if (writeOutTags)
632
			if (writeOutTags)
508
			    attributes.put(RepositoriesViewContentHandler.LAST_ACCESS_TIME_ATTRIBUTE, Long.toString(entry.lastAccessTime));
633
			    attributes.put(RepositoriesViewContentHandler.LAST_ACCESS_TIME_ATTRIBUTE, Long.toString(entry.lastAccessTime));
509
			writer.startTag(RepositoriesViewContentHandler.MODULE_TAG, attributes, true);
634
			writer.startTag(RepositoriesViewContentHandler.MODULE_TAG, attributes, true);
510
			if (writeOutTags) {
635
			if (writeOutTags) {
511
				Iterator tagIt = entry.tags.iterator();
636
				Iterator tagIt = entry.getTags().iterator();
512
				while (tagIt.hasNext()) {
637
				while (tagIt.hasNext()) {
513
					CVSTag tag = (CVSTag)tagIt.next();
638
					CVSTag tag = (CVSTag)tagIt.next();
514
					writeATag(writer, attributes, tag, RepositoriesViewContentHandler.TAG_TAG);
639
					writeATag(writer, attributes, tag, RepositoriesViewContentHandler.TAG_TAG);
Lines 536-569 Link Here
536
		writer.startAndEndTag(s, attributes, true);
661
		writer.startAndEndTag(s, attributes, true);
537
	}
662
	}
538
663
664
	private void addAllKnownTagsForParents(TagCacheEntry entry, Set tags) {
665
		if (entry.parent != null) {
666
			addAllKnownTagsForParents(entry.parent, tags);
667
		}
668
		tags.addAll(entry.getTags());
669
	}
670
671
	private void addAllKnownTagsForChildren(TagCacheEntry entry, Set tags) {
672
		Iterator childrenIterator = entry.getChildrenIterator();
673
		while (childrenIterator.hasNext()) {
674
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
675
			addAllKnownTagsForChildren(child, tags);
676
		}
677
		tags.addAll(entry.getTags());
678
	}
679
539
	/**
680
	/**
540
	 * Method getKnownTags.
681
	 * Method getKnownTags.
541
	 * @param remotePath
682
	 * @param remotePath
542
	 * @return CVSTag[]
683
	 * @return CVSTag[]
543
	 */
684
	 */
544
	public CVSTag[] getAllKnownTags(String remotePath) {
685
	public CVSTag[] getAllKnownTags(String remotePath) {
545
	    TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(getCachePathFor(remotePath));
686
		Set tags = new HashSet();
546
		if(entry != null){
687
		addAllKnownTagsForParents(getKnownParentTagCacheEntryFor(remotePath),
547
		    entry.accessed();
688
				tags);
548
			CVSTag [] tags1 = (CVSTag[]) entry.tags.toArray(new CVSTag[entry.tags.size()]);
689
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
549
			CVSTag[] tags2 = getDateTags();
690
		if (entry != null) {
550
			int len = tags1.length + tags2.length;
691
			addAllKnownTagsForChildren(entry, tags);
551
			CVSTag[] tags = new CVSTag[len];
692
		}
552
			for(int i = 0; i < len; i++){
693
		return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
553
				if(i < tags1.length){
694
	}
554
					tags[i] = tags1[i];
695
555
				}else{
696
	public CVSTag[] getAllKnownTags() {
556
					tags[i] = tags2[i-tags1.length];
697
		Set tags = new HashSet();
557
				}
698
		addAllKnownTagsForChildren(rootTagCacheEntry, tags);
699
		return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
700
	}
701
702
	public String[] getRemoteChildrenForTag(String remotePath, CVSTag tag) {
703
		TagCacheEntry entry;
704
		if (remotePath == null) {
705
			entry = rootTagCacheEntry;
706
		} else {
707
			entry = getTagCacheEntryFor(remotePath, false);
708
		}
709
		if (entry == null) {
710
			return new String[0];
711
		}
712
713
		Set paths = new HashSet();
714
		Iterator childrenIterator = entry.getChildrenIterator();
715
		while (childrenIterator.hasNext()) {
716
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
717
			Set childTags = new HashSet();
718
			addAllKnownTagsForChildren(child, childTags);
719
			if (childTags.contains(tag)) {
720
				paths.add(child.path.toString());
558
			}
721
			}
559
			return tags;
560
		}
722
		}
561
		return getDateTags();
723
		return (String[]) paths.toArray(new String[paths.size()]);
724
	}
725
726
	private Set getKnownRemotePaths(TagCacheEntry entry) {
727
		Set paths = new HashSet();
728
		Iterator childrenIterator = entry.getChildrenIterator();
729
		while (childrenIterator.hasNext()) {
730
			paths.addAll(getKnownRemotePaths((TagCacheEntry) childrenIterator
731
					.next()));
732
		}
733
		paths.add(entry.path.toString());
734
		return paths;
562
	}
735
	}
563
736
564
	public String[] getKnownRemotePaths() {
737
	public String[] getKnownRemotePaths() {
565
		Set paths = new HashSet();
738
		Set paths = getKnownRemotePaths(rootTagCacheEntry);
566
		paths.addAll(versionAndBranchTags.keySet());
567
		paths.addAll(autoRefreshFiles.keySet());
739
		paths.addAll(autoRefreshFiles.keySet());
568
		return (String[]) paths.toArray(new String[paths.size()]);
740
		return (String[]) paths.toArray(new String[paths.size()]);
569
	}
741
	}
Lines 583-589 Link Here
583
	public boolean tagIsKnown(ICVSRemoteResource remoteResource) {
755
	public boolean tagIsKnown(ICVSRemoteResource remoteResource) {
584
		if (remoteResource instanceof ICVSRemoteFolder) {
756
		if (remoteResource instanceof ICVSRemoteFolder) {
585
			ICVSRemoteFolder folder = (ICVSRemoteFolder) remoteResource;
757
			ICVSRemoteFolder folder = (ICVSRemoteFolder) remoteResource;
586
			String path = getCachePathFor(folder.getRepositoryRelativePath());
758
			String path = folder.getRepositoryRelativePath();
587
			CVSTag[] tags = getAllKnownTags(path);
759
			CVSTag[] tags = getAllKnownTags(path);
588
			CVSTag tag = folder.getTag();
760
			CVSTag tag = folder.getTag();
589
			for (int i = 0; i < tags.length; i++) {
761
			for (int i = 0; i < tags.length; i++) {
Lines 615-624 Link Here
615
787
616
    /*
788
    /*
617
     * Set the last access time of the cache entry for the given path
789
     * Set the last access time of the cache entry for the given path
618
     * as it was read from the persitent store.
790
     * as it was read from the persistent store.
619
     */
791
     */
620
    /* package */ void setLastAccessedTime(String remotePath, long lastAccessTime) {
792
    /* package */ void setLastAccessedTime(String remotePath, long lastAccessTime) {
621
	    TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(getCachePathFor(remotePath));
793
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
622
		if(entry != null){
794
		if(entry != null){
623
		    entry.lastAccessTime = lastAccessTime;
795
		    entry.lastAccessTime = lastAccessTime;
624
		}
796
		}
(-)src/org/eclipse/team/tests/ccvs/core/provider/AllTestsProvider.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 34-39 Link Here
34
		suite.addTest(WatchEditTest.suite());
34
		suite.addTest(WatchEditTest.suite());
35
		suite.addTest(LinkResourcesTest.suite());
35
		suite.addTest(LinkResourcesTest.suite());
36
		suite.addTest(IsModifiedTests.suite());
36
		suite.addTest(IsModifiedTests.suite());
37
		suite.addTest(RepositoryRootTest.suite());
37
		return new CVSTestSetup(suite);
38
		return new CVSTestSetup(suite);
38
	}
39
	}
39
}
40
}
(-)src/org/eclipse/team/tests/ccvs/ui/AllUITests.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 28-33 Link Here
28
28
29
	public static Test suite() {
29
	public static Test suite() {
30
		TestSuite suite = new TestSuite();
30
		TestSuite suite = new TestSuite();
31
		suite.addTest(RepositoriesViewTests.suite());
31
		suite.addTest(CheckoutOperationTests.suite());
32
		suite.addTest(CheckoutOperationTests.suite());
32
		suite.addTest(CompareOperationTests.suite());
33
		suite.addTest(CompareOperationTests.suite());
33
		suite.addTest(MiscOperationsTests.suite());
34
		suite.addTest(MiscOperationsTests.suite());
(-)src/org/eclipse/team/tests/ccvs/core/provider/RepositoryRootTest.java (+397 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.core.provider;
12
13
import java.util.Arrays;
14
import java.util.List;
15
16
import junit.framework.Test;
17
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFolder;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.team.core.TeamException;
24
import org.eclipse.team.internal.ccvs.core.CVSException;
25
import org.eclipse.team.internal.ccvs.core.CVSTag;
26
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
27
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
28
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
29
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
30
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
31
import org.eclipse.team.tests.ccvs.core.EclipseTest;
32
33
public class RepositoryRootTest extends EclipseTest {
34
35
	private RepositoryRoot repositoryRoot;
36
	private RepositoryManager repositoryManager;
37
38
	protected void setUp() throws Exception {
39
		super.setUp();
40
		repositoryManager = CVSUIPlugin.getPlugin().getRepositoryManager();
41
		repositoryRoot = repositoryManager
42
				.getRepositoryRootFor(getRepository());
43
		clearRepositoryRootCache();
44
	}
45
46
	public static Test suite() {
47
		return suite(RepositoryRootTest.class);
48
	}
49
50
	private void clearRepositoryRootCache() {
51
		String remotePaths[] = repositoryRoot.getKnownRemotePaths();
52
		for (int i = 0; i < remotePaths.length; i++) {
53
			repositoryRoot.removeTags(remotePaths[i],
54
					repositoryRoot.getAllKnownTags(remotePaths[i]));
55
		}
56
		assertEquals("Repository cache was not cleaned.", 0,
57
				repositoryRoot.getAllKnownTags().length);
58
	}
59
60
	private CVSTag[] refreshTags(IProject project) throws TeamException {
61
		return refreshTags(CVSWorkspaceRoot.getCVSFolderFor(project));
62
	}
63
64
	private CVSTag[] refreshTags(ICVSFolder folder) throws TeamException {
65
		return repositoryManager.refreshDefinedTags(folder, true, true,
66
				DEFAULT_MONITOR);
67
	}
68
69
	private IProject createProject(String baseName, String repoPrefix)
70
			throws CoreException {
71
		// create project
72
		IProject project = getUniqueTestProject(baseName);
73
		// share project under module
74
		shareProject(getRepository(), project,
75
				repoPrefix == null ? project.getName()
76
						: (repoPrefix + "/" + project.getName()),
77
				DEFAULT_MONITOR);
78
		assertValidCheckout(project);
79
		// add some files
80
		addResources(project, new String[] { "file1.txt" }, true);
81
		return project;
82
	}
83
84
	private void assertTags(List knownTags, CVSTag[] tagsToHave,
85
			CVSTag[] tagsNotToHave) {
86
		for (int i = 0; i < tagsToHave.length; i++) {
87
			assertTrue("Missing tag " + tagsToHave[i].getName(),
88
					knownTags.contains(tagsToHave[i]));
89
		}
90
		for (int i = 0; i < tagsNotToHave.length; i++) {
91
			assertFalse("Extraneous tag " + tagsNotToHave[i].getName(),
92
					knownTags.contains(tagsNotToHave[i]));
93
		}
94
	}
95
96
	private void assertProjectTags(CVSCacheTestData data) throws CVSException {
97
		// Root should contain all known tags
98
		List knownTags = Arrays.asList(repositoryRoot.getAllKnownTags());
99
		assertTags(knownTags,
100
				new CVSTag[] { data.branch_1, data.branch_2, data.branch_3,
101
						data.version_1, data.version_2, data.version_3 },
102
				new CVSTag[0]);
103
104
		// Project_1 should contain Branch_1 and Branch_2
105
		knownTags = Arrays.asList(repositoryManager
106
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(data.project1)));
107
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_2,
108
				data.version_1, data.version_2 }, new CVSTag[] { data.branch_3,
109
				data.version_3 });
110
		// Project_2 should contain Branch_1 and Branch_3
111
		knownTags = Arrays.asList(repositoryManager
112
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(data.project2)));
113
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_3,
114
				data.version_1, data.version_3 }, new CVSTag[] { data.branch_2,
115
				data.version_2 });
116
	}
117
118
	private class CVSCacheTestData {
119
		IProject project1; // tagged with Branch_1 and Branch_2
120
		IProject project2; // tagged with Branch_1 and Branch_3
121
		CVSTag branch_1;
122
		CVSTag branch_2;
123
		CVSTag branch_3;
124
		CVSTag version_1;
125
		CVSTag version_2;
126
		CVSTag version_3;
127
128
		private void init(String project1Path, String project2Path)
129
				throws CoreException {
130
			project1 = createProject("Project_1", project1Path);
131
			project2 = createProject("Project_2", project2Path);
132
			branch_1 = new CVSTag("Branch_1" + System.currentTimeMillis(),
133
					CVSTag.BRANCH);
134
			version_1 = new CVSTag("Root_" + branch_1.getName(), CVSTag.VERSION);
135
			branch_2 = new CVSTag("Branch_2" + System.currentTimeMillis(),
136
					CVSTag.BRANCH);
137
			version_2 = new CVSTag("Root_" + branch_2.getName(), CVSTag.VERSION);
138
			branch_3 = new CVSTag("Branch_3" + System.currentTimeMillis(),
139
					CVSTag.BRANCH);
140
			version_3 = new CVSTag("Root_" + branch_3.getName(), CVSTag.VERSION);
141
142
			makeBranch(new IResource[] { project1, project2 }, version_1,
143
					branch_1, true);
144
			makeBranch(new IResource[] { project1 }, version_2, branch_2, true);
145
			makeBranch(new IResource[] { project2 }, version_3, branch_3, true);
146
		}
147
148
		public CVSCacheTestData(String project1Path, String project2Path)
149
				throws CoreException {
150
			init(project1Path, project2Path);
151
		}
152
	}
153
154
	public void testProjectsAtRoot() throws CoreException {
155
		CVSCacheTestData data = new CVSCacheTestData(null, null);
156
157
		// verify that tags are correct after creating branches
158
		assertProjectTags(data);
159
160
		clearRepositoryRootCache();
161
		refreshTags(data.project1);
162
		refreshTags(data.project2);
163
		assertProjectTags(data);
164
	}
165
166
	public void testProjectsInSubmodule() throws CoreException {
167
		String submodule = "Submodule_1" + System.currentTimeMillis();
168
		CVSCacheTestData data = new CVSCacheTestData(submodule, submodule);
169
		ICVSFolder submoduleFolder = repositoryRoot.getRemoteFolder(submodule,
170
				null, getMonitor());
171
172
		// verify that tags are correct after creating branches
173
		assertProjectTags(data);
174
175
		clearRepositoryRootCache();
176
		refreshTags(data.project1);
177
		refreshTags(data.project2);
178
		assertProjectTags(data);
179
		// verify that parent module has tags from both projects
180
		List knownTags = Arrays.asList(repositoryManager
181
				.getKnownTags(submoduleFolder));
182
		assertTags(knownTags,
183
				new CVSTag[] { data.branch_1, data.branch_2, data.branch_3,
184
						data.version_1, data.version_2, data.version_3 },
185
				new CVSTag[0]);
186
187
		clearRepositoryRootCache();
188
		refreshTags(submoduleFolder);
189
		assertProjectTags(data);
190
		// verify that parent module has tags from both projects
191
		knownTags = Arrays.asList(repositoryManager
192
				.getKnownTags(submoduleFolder));
193
		assertTags(knownTags,
194
				new CVSTag[] { data.branch_1, data.branch_2, data.branch_3,
195
						data.version_1, data.version_2, data.version_3 },
196
				new CVSTag[0]);
197
	}
198
199
	public void testProjectsInTwoSubmodules() throws CoreException {
200
		String submodule1 = "Submodule_1" + System.currentTimeMillis();
201
		String submodule2 = "Submodule_2" + System.currentTimeMillis();
202
		CVSCacheTestData data = new CVSCacheTestData(submodule1, submodule2);
203
		ICVSFolder submoduleFolder1 = repositoryRoot.getRemoteFolder(
204
				submodule1, null, getMonitor());
205
		ICVSFolder submoduleFolder2 = repositoryRoot.getRemoteFolder(
206
				submodule2, null, getMonitor());
207
208
		// verify that tags are correct after creating branches
209
		assertProjectTags(data);
210
211
		clearRepositoryRootCache();
212
		refreshTags(data.project1);
213
		refreshTags(data.project2);
214
		assertProjectTags(data);
215
		// verify that parent modules have tags from subordinate project, but
216
		// not the other project
217
		List knownTags = Arrays.asList(repositoryManager
218
				.getKnownTags(submoduleFolder1));
219
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_2,
220
				data.version_1, data.version_2 }, new CVSTag[] { data.branch_3,
221
				data.version_3 });
222
		knownTags = Arrays.asList(repositoryManager
223
				.getKnownTags(submoduleFolder2));
224
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_3,
225
				data.version_1, data.version_3 }, new CVSTag[] { data.branch_2,
226
				data.version_2 });
227
		// clear the cache, refresh it only one for submodule and verify if tags
228
		// are correct
229
		clearRepositoryRootCache();
230
		refreshTags(submoduleFolder1);
231
232
		// verify that correct tags where added to this submodule
233
		knownTags = Arrays.asList(repositoryManager
234
				.getKnownTags(submoduleFolder1));
235
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_2,
236
				data.version_1, data.version_2 }, new CVSTag[] { data.branch_3,
237
				data.version_3 });
238
		// verify if only tags from the first submodule are known
239
		knownTags = Arrays.asList(repositoryRoot.getAllKnownTags());
240
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_2,
241
				data.version_1, data.version_2 }, new CVSTag[] { data.branch_3,
242
				data.version_3 });
243
244
		refreshTags(submoduleFolder2);
245
		// verify tags for the second submodule
246
		knownTags = Arrays.asList(repositoryManager
247
				.getKnownTags(submoduleFolder2));
248
		assertTags(knownTags, new CVSTag[] { data.branch_1, data.branch_3,
249
				data.version_1, data.version_3 }, new CVSTag[] { data.branch_2,
250
				data.version_2 });
251
		// verify if tags are merged correctly
252
		assertProjectTags(data);
253
	}
254
255
	public void testNestedProjects() throws CoreException {
256
		IProject superProject = createProject("SuperProject", (String) null);
257
		CVSTag superProjectBranch = new CVSTag("Branch_"
258
				+ superProject.getName(), CVSTag.BRANCH);
259
		CVSTag superProjectVersion = new CVSTag("Root_"
260
				+ superProjectBranch.getName(), CVSTag.VERSION);
261
		makeBranch(new IResource[] { superProject }, superProjectVersion,
262
				superProjectBranch, true);
263
		// subProject1 and subProject2 are nested in superProject
264
		// each of them has its own tags
265
		IProject subProject1 = createProject("SubProject_1",
266
				superProject.getName());
267
		CVSTag subProject1Branch = new CVSTag(
268
				"Branch_" + subProject1.getName(), CVSTag.BRANCH);
269
		CVSTag subProject1Version = new CVSTag("Root_"
270
				+ subProject1Branch.getName(), CVSTag.VERSION);
271
		makeBranch(new IResource[] { subProject1 }, subProject1Version,
272
				subProject1Branch, true);
273
		IProject subProject2 = createProject("SubProject_2",
274
				superProject.getName());
275
		CVSTag subProject2Branch = new CVSTag(
276
				"Branch_" + subProject2.getName(), CVSTag.BRANCH);
277
		CVSTag subProject2Version = new CVSTag("Root_"
278
				+ subProject2Branch.getName(), CVSTag.VERSION);
279
		makeBranch(new IResource[] { subProject2 }, subProject2Version,
280
				subProject2Branch, true);
281
		// check if subProjects have tags from superProject but not tags from
282
		// each other, check if superProject has tags from all subProjects
283
		List knownTags = Arrays.asList(repositoryManager
284
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(superProject)));
285
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
286
				superProjectVersion, subProject1Branch, subProject1Version,
287
				subProject2Branch, subProject2Version }, new CVSTag[0]);
288
		knownTags = Arrays.asList(repositoryManager
289
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(subProject1)));
290
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
291
				superProjectVersion, subProject1Branch, subProject1Version },
292
				new CVSTag[] { subProject2Branch, subProject2Version });
293
		knownTags = Arrays.asList(repositoryManager
294
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(subProject2)));
295
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
296
				superProjectVersion, subProject2Branch, subProject2Version },
297
				new CVSTag[] { subProject1Branch, subProject1Version });
298
		// remove tag from one of the subProjects, check if it was not removed
299
		// from the other subProject, check if superProject still has this tag
300
		repositoryManager.removeTags(
301
				CVSWorkspaceRoot.getCVSFolderFor(subProject1), new CVSTag[] {
302
						superProjectBranch, superProjectVersion });
303
		knownTags = Arrays.asList(repositoryManager
304
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(superProject)));
305
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
306
				superProjectVersion, subProject1Branch, subProject1Version,
307
				subProject2Branch, subProject2Version }, new CVSTag[0]);
308
		knownTags = Arrays.asList(repositoryManager
309
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(subProject1)));
310
		assertTags(knownTags, new CVSTag[] { subProject1Branch,
311
				subProject1Version }, new CVSTag[] { subProject2Branch,
312
				subProject2Version });
313
		knownTags = Arrays.asList(repositoryManager
314
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(subProject2)));
315
		assertTags(knownTags, new CVSTag[] { superProjectBranch,
316
				superProjectVersion, subProject2Branch, subProject2Version },
317
				new CVSTag[] { subProject1Branch, subProject1Version });
318
	}
319
320
	public void testTagsForSubfolder() throws TeamException, CoreException {
321
		IProject project = createProject("Project_1", (String) null);
322
		String folderName = "testFolder";
323
		addResources(project, new String[] { folderName + "/",
324
				folderName + "/testFile.txt" }, true);
325
		IFolder folder = project.getFolder(folderName);
326
		CVSTag branch1 = new CVSTag("Branch_1" + System.currentTimeMillis(),
327
				CVSTag.BRANCH);
328
		CVSTag version1 = new CVSTag("Root_" + branch1.getName(),
329
				CVSTag.VERSION);
330
		makeBranch(new IResource[] { project }, version1, branch1, true);
331
		// verify if project's tags are known for subfolder
332
		ICVSFolder cvsFolder = CVSWorkspaceRoot.getCVSFolderFor(folder);
333
		List knownTags = Arrays.asList(repositoryManager
334
				.getKnownTags(cvsFolder));
335
		assertTags(knownTags, new CVSTag[] { branch1, version1 }, new CVSTag[0]);
336
		// verify if removing tags from subfolder is correctly handled
337
		repositoryManager.removeTags(cvsFolder, new CVSTag[] { branch1,
338
				version1 });
339
		knownTags = Arrays.asList(repositoryManager.getKnownTags(cvsFolder));
340
		assertTags(knownTags, new CVSTag[0], new CVSTag[] { branch1, version1 });
341
		// verify if after refreshing tags are back for both project and its
342
		// subfolder
343
		refreshTags(cvsFolder);
344
		knownTags = Arrays.asList(repositoryManager.getKnownTags(cvsFolder));
345
		assertTags(knownTags, new CVSTag[] { branch1, version1 }, new CVSTag[0]);
346
		knownTags = Arrays.asList(repositoryManager
347
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(project)));
348
		assertTags(knownTags, new CVSTag[] { branch1, version1 }, new CVSTag[0]);
349
	}
350
351
	public void testRefreshProjectUsingAutoRefreshFile() throws CoreException {
352
		IProject project = createProject("Project_1", (String) null);
353
		String autoRefreshFileName = "sampleAuthoRefresh.txt";
354
		String notAutoRefreshFileName = "notAutoRefresh.txt";
355
		addResources(project, new String[] { autoRefreshFileName,
356
				notAutoRefreshFileName }, true);
357
		IFile autoRefreshFile = project.getFile(autoRefreshFileName);
358
		IFile notAutoRefreshFile = project.getFile(notAutoRefreshFileName);
359
		repositoryManager.setAutoRefreshFiles(
360
				CVSWorkspaceRoot.getCVSFolderFor(project),
361
				new String[] { CVSWorkspaceRoot.getCVSResourceFor(
362
						autoRefreshFile).getRepositoryRelativePath() });
363
		CVSTag branch1 = new CVSTag("Branch_1" + System.currentTimeMillis(),
364
				CVSTag.BRANCH);
365
		CVSTag version1 = new CVSTag("Root_" + branch1.getName(),
366
				CVSTag.VERSION);
367
		// branch the auto refresh file
368
		makeBranch(new IResource[] { autoRefreshFile }, version1, branch1, true);
369
		CVSTag branch2 = new CVSTag("Branch_2" + System.currentTimeMillis(),
370
				CVSTag.BRANCH);
371
		CVSTag version2 = new CVSTag("Root_" + branch2.getName(),
372
				CVSTag.VERSION);
373
		// branch not auto refresh file
374
		makeBranch(new IResource[] { notAutoRefreshFile }, version2, branch2,
375
				true);
376
377
		clearRepositoryRootCache();
378
		refreshTags(project);
379
380
		// cache should contain branches from auto refresh file, but no branches
381
		// from other files
382
		List knownTags = Arrays.asList(repositoryManager
383
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(project)));
384
		assertTags(knownTags, new CVSTag[] { branch1, version1 }, new CVSTag[] {
385
				branch2, version2 });
386
	}
387
388
	public void testProjectWithNoTags() throws CoreException {
389
		IProject project = createProject("Project_1", (String) null);
390
		CVSTag knownTags[] = repositoryManager.getKnownTags(CVSWorkspaceRoot
391
				.getCVSFolderFor(project));
392
		assertEquals(0, knownTags.length);
393
		knownTags = refreshTags(project);
394
		assertEquals(0, knownTags.length);
395
	}
396
397
}
(-)src/org/eclipse/team/tests/ccvs/ui/RepositoriesViewTests.java (+254 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2011, 2012 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.tests.ccvs.ui;
12
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.team.core.TeamException;
20
import org.eclipse.team.internal.ccvs.core.CVSTag;
21
import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
22
import org.eclipse.team.internal.ccvs.core.resources.RemoteResource;
23
import org.eclipse.team.internal.ccvs.ui.model.AllRootsElement;
24
import org.eclipse.team.internal.ccvs.ui.model.BranchCategory;
25
import org.eclipse.team.internal.ccvs.ui.model.CVSTagElement;
26
import org.eclipse.team.internal.ccvs.ui.model.RemoteContentProvider;
27
import org.eclipse.team.internal.ccvs.ui.model.RemoteModule;
28
import org.eclipse.team.internal.ccvs.ui.model.VersionCategory;
29
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
30
import org.eclipse.team.tests.ccvs.core.CVSTestSetup;
31
import org.eclipse.team.tests.ccvs.core.EclipseTest;
32
33
public class RepositoriesViewTests extends EclipseTest {
34
35
	public RepositoriesViewTests(String testName) {
36
		super(testName);
37
	}
38
39
	protected void setUp() throws Exception {
40
		super.setUp();
41
		// clear repository root cache
42
		RepositoryRoot repositoryRoot = getRepositoryRoot();
43
		String remotePaths[] = repositoryRoot.getKnownRemotePaths();
44
		for (int i = 0; i < remotePaths.length; i++) {
45
			repositoryRoot.removeTags(remotePaths[i],
46
					repositoryRoot.getAllKnownTags(remotePaths[i]));
47
		}
48
	}
49
50
	private RepositoryRoot getRepositoryRoot() {
51
		RemoteContentProvider rcp = new RemoteContentProvider();
52
		AllRootsElement are = new AllRootsElement();
53
		Object[] repositoryRoots = rcp.getElements(are);
54
		for (int i = 0; i < repositoryRoots.length; i++) {
55
			RepositoryRoot repositoryRoot = (RepositoryRoot) repositoryRoots[i];
56
			if (getRepository().equals(repositoryRoot.getRoot())) {
57
				return repositoryRoot;
58
			}
59
		}
60
		fail(getRepository() + " not found");
61
		return null;
62
	}
63
64
	public static Test suite() {
65
		String testName = System.getProperty("eclipse.cvs.testName");
66
		if (testName == null) {
67
			TestSuite suite = new TestSuite(RepositoriesViewTests.class);
68
			return new CVSTestSetup(suite);
69
		} else {
70
			return new CVSTestSetup(new RepositoriesViewTests(testName));
71
		}
72
	}
73
74
	public void testBranchSubmoduleChildren() throws TeamException,
75
			CoreException {
76
77
		String time = Long.toString(System.currentTimeMillis());
78
		String moduleName = "TestBranchSubmoduleChildrenTestModule" + time;
79
		String branchName = "TestBranchSubmoduleChildrenBranch" + time;
80
		String versionName = "Root_" + branchName;
81
82
		// create project
83
		IProject project = getUniqueTestProject("TestBranchSubmoduleChildrenProject");
84
		// share project under module
85
		shareProject(getRepository(), project,
86
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
87
		assertValidCheckout(project);
88
89
		// add some files
90
		addResources(project, new String[] { "file1.txt" }, true);
91
92
		// make branch
93
		CVSTag version = new CVSTag(versionName, CVSTag.VERSION);
94
		CVSTag branch = new CVSTag(branchName, CVSTag.BRANCH);
95
96
		makeBranch(new IResource[] { project }, version, branch, true);
97
98
		// check if module is the only branch child
99
		RemoteContentProvider rcp = new RemoteContentProvider();
100
		Object[] categories = rcp.getChildren(getRepositoryRoot());
101
		assertEquals(4, categories.length);
102
		assertTrue(categories[1] instanceof BranchCategory);
103
		Object[] branches = rcp.getChildren(categories[1]);
104
		assertEquals(1, branches.length);
105
		assertEquals(branchName, ((CVSTagElement) (branches[0])).getTag()
106
				.getName());
107
		Object[] modules = rcp.getChildren(branches[0]);
108
		assertEquals(1, modules.length);
109
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
110
111
		// check if after refresh module is still the only branch child
112
		branches = rcp.getChildren(categories[1]);
113
		assertEquals(1, branches.length);
114
		assertEquals(branchName, ((CVSTagElement) (branches[0])).getTag()
115
				.getName());
116
		modules = rcp.getChildren(branches[0]);
117
		assertEquals(1, modules.length);
118
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
119
	}
120
121
	public void testTagSubmoduleChildren() throws TeamException, CoreException {
122
123
		String time = Long.toString(System.currentTimeMillis());
124
		String moduleName = "TestTagSubmoduleChildrenTestModule" + time;
125
		String versionName = "TestTagSubmoduleChildrenBranch" + time;
126
127
		// create project
128
		IProject project = getUniqueTestProject("TestTagSubmoduleChildrenProject");
129
		// share project under module
130
		shareProject(getRepository(), project,
131
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
132
		assertValidCheckout(project);
133
134
		// make some changes
135
		addResources(project, new String[] { "file1.txt" }, true);
136
137
		// tag project
138
		CVSTag tag = new CVSTag(versionName, CVSTag.VERSION);
139
140
		tagProject(project, tag, true);
141
142
143
		RemoteContentProvider rcp = new RemoteContentProvider();
144
		Object[] categories = rcp.getChildren(getRepositoryRoot());
145
		assertEquals(4, categories.length);
146
147
		// check if version exists for module
148
		assertTrue(categories[2] instanceof VersionCategory);
149
		Object[] modules = rcp.getChildren(categories[2]);
150
		for (int i = 0; i < modules.length; i++) {
151
			if (modules[i] instanceof RemoteModule
152
					&& ((RemoteModule) (modules[i])).getCVSResource().getName()
153
							.equals(moduleName)) {
154
				Object folders[] = rcp.getChildren(modules[i]);
155
				assertEquals(1, folders.length);
156
				assertEquals(versionName, ((RemoteFolder) folders[0]).getTag()
157
						.getName());
158
				return;
159
			}
160
		}
161
		fail(moduleName + " not found");
162
	}
163
164
	public void testTagsOnDifferentLevels() throws CoreException {
165
		String time = Long.toString(System.currentTimeMillis());
166
		String firstModule = "Module_1" + time;
167
		String secondModule = "Module_2" + time;
168
		String secondModulePath = firstModule + "/" + secondModule;
169
		// Create repository data
170
		// Module_1/Project_1
171
		IProject project1 = getUniqueTestProject("Project_1");
172
		shareProject(getRepository(), project1,
173
				firstModule + "/" + project1.getName(), DEFAULT_MONITOR);
174
		// Module_1/Module_2/Project_2
175
		IProject project2 = getUniqueTestProject("Project_2");
176
		shareProject(getRepository(), project2, secondModulePath + "/"
177
				+ project2.getName(), DEFAULT_MONITOR);
178
		// Module_1/Module_2/Project_3
179
		IProject project3 = getUniqueTestProject("Project_3");
180
		shareProject(getRepository(), project3, secondModulePath + "/"
181
				+ project3.getName(), DEFAULT_MONITOR);
182
		// Module_1/Project_4
183
		IProject project4 = getUniqueTestProject("Project_4");
184
		shareProject(getRepository(), project4,
185
				firstModule + "/" + project4.getName(), DEFAULT_MONITOR);
186
187
		// Create branches
188
		String branch1 = "Branch_1" + time;
189
		String version1 = "Root_" + branch1;
190
		String branch2 = "Branch_2" + time;
191
		String version2 = "Root_" + branch2;
192
193
		// Tag projects:
194
		// Module_1/Project_1 -> [Branch_1][Branch_2]
195
		// Module_1/Module_2/Project_2 -> [Branch_1][Branch_2]
196
		// Module_1/Module_2/Project_3 -> [Branch_2]
197
		// Module_1/Project_4 -> [Branch_4]
198
		makeBranch(new IResource[] { project1, project2 }, new CVSTag(version1,
199
				CVSTag.VERSION), new CVSTag(branch1, CVSTag.BRANCH), true);
200
		makeBranch(new IResource[] { project1, project2, project2, project4 },
201
				new CVSTag(version2, CVSTag.VERSION), new CVSTag(branch2,
202
						CVSTag.BRANCH), true);
203
204
		// verify if tree structure is built from cache
205
		RemoteContentProvider rcp = new RemoteContentProvider();
206
		Object[] categories = rcp.getChildren(getRepositoryRoot());
207
		assertEquals(4, categories.length);
208
		assertTrue(categories[1] instanceof BranchCategory);
209
		Object[] branches = rcp.getChildren(categories[1]);
210
		assertEquals(2, branches.length); // should be [Branch_1] and [Branch_2]
211
		CVSTagElement branch1Element;
212
		CVSTagElement branch2Element;
213
		if (((CVSTagElement) branches[0]).getTag().getName().equals(branch1)) {
214
			branch1Element = (CVSTagElement) branches[0];
215
			branch2Element = (CVSTagElement) branches[1];
216
		} else {
217
			branch1Element = (CVSTagElement) branches[1];
218
			branch2Element = (CVSTagElement) branches[0];
219
		}
220
		Object[] modules = rcp.getChildren(branch1Element);
221
		assertEquals(1, modules.length); // should be [Branch_1]/Module_1
222
		assertEquals(firstModule, ((RemoteResource) modules[0]).getName());
223
		modules = rcp.getChildren(modules[0]);
224
		// should contain:
225
		// [Branch_1]/Module_1/Project_1
226
		// [Branch_1]/Module_1/Module_2
227
		assertEquals(2, modules.length);
228
		for (int i = 0; i < modules.length; i++) {
229
			if (((RemoteResource) (modules[i])).getName().equals(
230
					project1.getName())) {
231
				// Project_1 should have contents retrieved from CVS
232
				assertTrue(rcp.hasChildren(modules[i]));
233
			} else if (((RemoteResource) (modules[i])).getName().equals(
234
					secondModule)) {
235
				// should be only [Branch_1]/Module_1/Module_2/Project_2.
236
				// [Branch_1]/Module_1/Module_2/Project_3 should NOT be on the
237
				// list, it is not branched with Branch_1
238
				Object[] module2Children = rcp.getChildren(modules[i]);
239
				assertEquals(1, module2Children.length);
240
				assertEquals(project2.getName(),
241
						((RemoteResource) module2Children[0]).getName());
242
			}
243
		}
244
		modules = rcp.getChildren(branch2Element);
245
		assertEquals(1, modules.length); // should be [Branch_2]/Module_1
246
		assertEquals(firstModule, ((RemoteResource) modules[0]).getName());
247
		// should contain:
248
		// [Branch_2]/Module_1/Project_1
249
		// [Branch_2]/Module_1/Module_2
250
		// [Branch_2]/Module_1/Project_4
251
		modules = rcp.getChildren(modules[0]);
252
		assertEquals(3, modules.length);
253
	}
254
}

Return to bug 361926