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 366016 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/model/RemoteFolderElement.java (-3 / +34 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-63 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
			monitor = Policy.monitorFor(monitor);
62
			monitor.beginTask(NLS.bind(
63
					CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
64
					new String[] { getLabel(o) }), 150);
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, 100));
75
		} finally {
76
			monitor.done();
77
		}
61
    }
78
    }
62
79
63
    public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
80
    public void fetchDeferredChildren(Object o, IElementCollector collector, IProgressMonitor monitor) {
Lines 67-79 Link Here
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(
88
					CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
89
					new String[] { getLabel(o) }), 150);
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
			}
71
			FetchMembersOperation operation = new FetchMembersOperation(null, (ICVSRemoteFolder)o, collector);
100
			FetchMembersOperation operation = new FetchMembersOperation(null, (ICVSRemoteFolder)o, collector);
72
			operation.run(Policy.subMonitorFor(monitor, 100));
101
			operation.run(Policy.subMonitorFor(monitor, 100));
73
        } catch (InvocationTargetException e) {
102
        } catch (InvocationTargetException e) {
74
            handle(collector, e);
103
            handle(collector, e);
75
		} catch (InterruptedException e) {
104
		} catch (InterruptedException e) {
76
			// Cancelled by the user;
105
			// Cancelled by the user;
106
		} catch (CVSException e) {
107
			handle(collector, e);
77
		} finally {
108
		} finally {
78
            monitor.done();
109
            monitor.done();
79
        }
110
        }
(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java (-16 / +61 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
	 * @param location
244
	 *            CVS repository location
245
	 * @param parentFolder
246
	 *            folder to check tags for
247
	 * @param tag
248
	 * @param monitor
249
	 * @return a list of remote resources that are known to contain given tag or
250
	 *         empty list if resources should be retrieved from the repository
251
	 * @throws CVSException
252
	 */
253
	public ICVSRemoteResource[] getCachedChildrenForTag(
254
			ICVSRepositoryLocation location, ICVSRemoteFolder parentFolder,
255
			CVSTag tag, IProgressMonitor monitor) throws CVSException {
256
		if (tag == null || tag.getType() == CVSTag.HEAD
257
				|| tag.getType() == CVSTag.DATE) {
258
			// folders are kept in cache only for tags and versions
259
			return new ICVSRemoteResource[0];
260
		}
261
		monitor = Policy.monitorFor(monitor);
262
		Set result = new HashSet();
263
		RepositoryRoot root = getRepositoryRootFor(location);
264
		// if remote folder is null return the subfolders of repository root
265
		String[] paths = root.getRemoteChildrenForTag(
266
				parentFolder == null ? null : RepositoryRoot
267
						.getRemotePathFor(parentFolder), tag);
268
		monitor.beginTask(NLS
269
				.bind(CVSUIMessages.RemoteFolderElement_fetchingRemoteChildren,
270
						new String[] { NLS.bind(
271
								CVSUIMessages.RemoteFolderElement_nameAndTag,
272
								new String[] { parentFolder.getName(),
273
										tag.getName() }) }), 10 * paths.length);
274
		try {
275
			for (int i = 0; i < paths.length; i++) {
276
				String path = paths[i];
277
				ICVSRemoteFolder remote = root.getRemoteFolder(path, tag,
278
						Policy.subMonitorFor(monitor, 10));
279
				result.add(remote);
280
			}
281
			return (ICVSRemoteResource[]) result
282
					.toArray(new ICVSRemoteResource[result.size()]);
283
		} finally {
284
			monitor.done();
285
		}
286
	}
242
		
287
		
243
	/*
288
	/*
244
	 * Fetches tags from auto-refresh files if they exist. Then fetches tags from the user defined auto-refresh file
289
	 * Fetches tags from auto-refresh files if they exist. Then fetches tags from the user defined auto-refresh file
(-)a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryRoot.java (-95 / +230 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2011 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 25-31 Link Here
25
import org.eclipse.team.internal.ccvs.ui.Policy;
25
import org.eclipse.team.internal.ccvs.ui.Policy;
26
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation;
26
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation;
27
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation.LogEntryCache;
27
import org.eclipse.team.internal.ccvs.ui.operations.RemoteLogOperation.LogEntryCache;
28
import org.eclipse.team.internal.ccvs.ui.tags.TagSource;
29
28
30
public class RepositoryRoot extends PlatformObject {
29
public class RepositoryRoot extends PlatformObject {
31
30
Lines 34-41 Link Here
34
	
33
	
35
	ICVSRepositoryLocation root;
34
	ICVSRepositoryLocation root;
36
	String name;
35
	String name;
37
	// Map of String (remote folder path) -> TagCacheEntry
36
	TagCacheEntry rootTagCacheEntry = new TagCacheEntry(Path.ROOT.toString(),
38
	Map versionAndBranchTags = new HashMap();
37
			null);
39
	// Map of String (remote folder path) -> Set (file paths that are project relative)
38
	// Map of String (remote folder path) -> Set (file paths that are project relative)
40
	Map autoRefreshFiles = new HashMap();
39
	Map autoRefreshFiles = new HashMap();
41
	// Map of String (module name) -> ICVSRemoteFolder (that is a defined module)
40
	// Map of String (module name) -> ICVSRemoteFolder (that is a defined module)
Lines 45-56 Link Here
45
	List dateTags = new ArrayList();
44
	List dateTags = new ArrayList();
46
	
45
	
47
	public static class TagCacheEntry {
46
	public static class TagCacheEntry {
47
		String path;
48
		// Set of tags found for this path
48
	    Set tags = new HashSet();
49
	    Set tags = new HashSet();
50
		// String(last path segment) -> TagCacheEntry for child paths
51
		Map children = new HashMap();
52
		TagCacheEntry parent;
49
	    long lastAccessTime;
53
	    long lastAccessTime;
50
        private static final int CACHE_LIFESPAN_IN_DAYS = 7;
54
        private static final int CACHE_LIFESPAN_IN_DAYS = 7;
51
        public TagCacheEntry() {
55
52
            accessed();
56
		public TagCacheEntry(String path, TagCacheEntry parent) {
53
        }
57
			this.path = path;
58
			this.parent = parent;
59
			accessed();
60
		}
61
54
        public boolean isExpired() {
62
        public boolean isExpired() {
55
            long currentTime = System.currentTimeMillis();
63
            long currentTime = System.currentTimeMillis();
56
            long ms = currentTime - lastAccessTime;
64
            long ms = currentTime - lastAccessTime;
Lines 190-196 Link Here
190
	 * 
198
	 * 
191
	 * It is the responsibility of the caller to ensure that the given remote path is valid.
199
	 * It is the responsibility of the caller to ensure that the given remote path is valid.
192
	 */
200
	 */
193
	public void addTags(String remotePath, CVSTag[] tags) {	
201
	public void addTags(String remotePath, CVSTag[] tags) {
202
		if (tags.length == 0) {
203
			return;
204
		}
194
		addDateTags(tags);
205
		addDateTags(tags);
195
		addVersionAndBranchTags(remotePath, tags);
206
		addVersionAndBranchTags(remotePath, tags);
196
	}
207
	}
Lines 203-224 Link Here
203
		}
214
		}
204
	}
215
	}
205
	private void addVersionAndBranchTags(String remotePath, CVSTag[] tags) {
216
	private void addVersionAndBranchTags(String remotePath, CVSTag[] tags) {
206
		// Get the name to cache the version tags with
217
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, true);
207
		String name = getCachePathFor(remotePath);
218
		entry.accessed();
208
		
219
209
		// Make sure there is a table for the ancestor that holds the tags
210
		TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(name);
211
		if (entry == null) {
212
		    entry = new TagCacheEntry();
213
			versionAndBranchTags.put(name, entry);
214
		} else {
215
		    entry.accessed();
216
		}
217
		
218
		// Store the tag with the appropriate ancestor
220
		// Store the tag with the appropriate ancestor
219
		for (int i = 0; i < tags.length; i++) {
221
		for (int i = 0; i < tags.length; i++) {
220
			if(tags[i].getType() != CVSTag.DATE){
222
			if (tags[i].getType() != CVSTag.DATE) {
221
				entry.tags.add(tags[i]);
223
				if (!getAllKnownTagsForParents(entry).contains(tags[i])) {
224
					removeTagFromChildrenCacheEntries(entry, tags[i], false);
225
					entry.tags.add(tags[i]);
226
				}
222
			}
227
			}
223
		}
228
		}
224
	}
229
	}
Lines 264-283 Link Here
264
	}
269
	}
265
270
266
	private void removeVersionAndBranchTags(String remotePath, CVSTag[] tags) {
271
	private void removeVersionAndBranchTags(String remotePath, CVSTag[] tags) {
267
		// Get the name to cache the version tags with
272
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
268
		String name = getCachePathFor(remotePath);
273
		// remove tags from this path and its children
269
		
274
		if (entry != null) {
270
		// Make sure there is a table for the ancestor that holds the tags
275
			removeTagsFromChildrenChacheEntries(entry, tags);
271
		TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(name);
276
		}
272
		if (entry == null) {
277
278
		// remove tags from all parents of this path
279
		entry = getKnownParentTagCacheEntryFor(remotePath);
280
		for (int i = 0; i < tags.length; i++) {
281
			TagCacheEntry currentEntry = entry;
282
			while (currentEntry != null) {
283
				if (currentEntry.tags.contains(tags[i])) {
284
					currentEntry.tags.remove(tags[i]);
285
					currentEntry.accessed();
286
					break;
287
				} else {
288
					currentEntry = currentEntry.parent;
289
				}
290
			}
291
		}
292
		cleanEmptyParents(entry);
293
	}
294
295
	private void cleanEmptyParents(TagCacheEntry entry) {
296
		if (entry.parent == null) {
297
			// we don't remove the root cache entry
273
			return;
298
			return;
274
		}
299
		}
275
		
300
		if (entry.tags.isEmpty() && entry.children.isEmpty()) {
276
		// Store the tag with the appropriate ancestor
301
			entry.parent.children.remove(new Path(entry.path).lastSegment());
277
		for (int i = 0; i < tags.length; i++) {
302
			entry.parent.accessed();
278
			entry.tags.remove(tags[i]);
279
		}
303
		}
280
		entry.accessed();
304
		cleanEmptyParents(entry.parent);
281
	}
305
	}
282
306
283
	/**
307
	/**
Lines 287-294 Link Here
287
	 * @return String[]
311
	 * @return String[]
288
	 */
312
	 */
289
	public String[] getAutoRefreshFiles(String remotePath) {
313
	public String[] getAutoRefreshFiles(String remotePath) {
290
		String name = getCachePathFor(remotePath);
314
		Set files = (Set) autoRefreshFiles.get(remotePath);
291
		Set files = (Set)autoRefreshFiles.get(name);
292
		if (files == null || files.isEmpty()) {
315
		if (files == null || files.isEmpty()) {
293
			// convert the default relative file paths to full paths
316
			// convert the default relative file paths to full paths
294
			if (isDefinedModuleName(remotePath)) {
317
			if (isDefinedModuleName(remotePath)) {
Lines 324-367 Link Here
324
				}
347
				}
325
			}
348
			}
326
			if (isDefault) {
349
			if (isDefault) {
327
				this.autoRefreshFiles.remove(getCachePathFor(remotePath));
350
				this.autoRefreshFiles.remove(remotePath);
328
				return;
351
				return;
329
			}
352
			}
330
		}
353
		}
331
		this.autoRefreshFiles.put(getCachePathFor(remotePath), newFiles);
354
		this.autoRefreshFiles.put(remotePath, newFiles);
332
	}
355
	}
333
356
334
	/**
357
	/**
335
	 * Fetches tags from auto-refresh files.
358
	 * Fetches tags from auto-refresh files.
336
	 */
359
	 */
337
	public CVSTag[] refreshDefinedTags(ICVSFolder folder, boolean recurse, IProgressMonitor monitor) throws TeamException {
360
	public CVSTag[] refreshDefinedTags(ICVSFolder folder, boolean recurse,
361
			IProgressMonitor monitor) throws TeamException {
338
		monitor = Policy.monitorFor(monitor);
362
		monitor = Policy.monitorFor(monitor);
339
	    monitor.beginTask(null, 100);
363
		monitor.beginTask(null, recurse ? 210 : 100);
340
	    CVSTag[] tags = null;
364
		try {
341
	    if (!recurse && !folder.getFolderSyncInfo().isVirtualDirectory()) {
365
			CVSTag[] tags = null;
342
	        // Only try the auto-refresh file(s) if we are not recursing into sub-folders
366
			if (!folder.getFolderSyncInfo().isVirtualDirectory()) {
343
	        tags = fetchTagsUsingAutoRefreshFiles(folder, Policy.subMonitorFor(monitor, 50));
367
				// Only try the auto-refresh file(s) if we are not recursing
344
	    }
368
				// into sub-folders
345
        if (tags == null || tags.length == 0) {
369
				tags = fetchTagsUsingAutoRefreshFiles(folder,
346
            // There we're no tags found on the auto-refresh files or we we're aksed to go deep
370
						Policy.subMonitorFor(monitor, 50));
347
            // Try using the log command
371
			}
348
            tags = fetchTagsUsingLog(folder, recurse, Policy.subMonitorFor(monitor, 50));
372
			if (tags == null || tags.length == 0) {
349
        }
373
				// There we're no tags found on the auto-refresh files or we
350
		if (tags != null && tags.length > 0) {
374
				// we're asked to go deep
351
		    String remotePath = getRemotePathFor(folder);
375
				// Try using the log command
352
			addTags(remotePath, tags);
376
				tags = fetchTagsUsingLog(folder,
377
						Policy.subMonitorFor(monitor, 50));
378
			}
379
			if (tags != null && tags.length > 0) {
380
				String remotePath = getRemotePathFor(folder);
381
				addTags(remotePath, tags);
382
				return tags;
383
			}
384
			if (recurse) {
385
				folder.fetchChildren(Policy.subMonitorFor(monitor, 10));
386
				ICVSResource[] children = folder
387
						.members(ICVSFolder.FOLDER_MEMBERS);
388
				for (int i = 0; i < children.length; i++) {
389
					refreshDefinedTags(
390
							(ICVSFolder) children[i],
391
							recurse,
392
							Policy.subMonitorFor(monitor, 100 / children.length));
393
				}
394
			}
395
			return tags;
396
		} finally {
397
			monitor.done();
353
		}
398
		}
354
		monitor.done();
355
		return tags;
356
	}
399
	}
357
	
400
	
358
    private CVSTag[] fetchTagsUsingLog(ICVSFolder folder, final boolean recurse, IProgressMonitor monitor) throws CVSException {
401
    private CVSTag[] fetchTagsUsingLog(ICVSFolder folder, IProgressMonitor monitor) throws CVSException {
359
        LogEntryCache logEntries = new LogEntryCache();
402
        LogEntryCache logEntries = new LogEntryCache();
360
        RemoteLogOperation operation = new RemoteLogOperation(null, new ICVSRemoteResource[] { asRemoteResource(folder) }, null, null, logEntries) {
403
        RemoteLogOperation operation = new RemoteLogOperation(null, new ICVSRemoteResource[] { asRemoteResource(folder) }, null, null, logEntries) {
361
            protected Command.LocalOption[] getLocalOptions(CVSTag tag1,CVSTag tag2) {
404
            protected Command.LocalOption[] getLocalOptions(CVSTag tag1,CVSTag tag2) {
362
                Command.LocalOption[] options = new Command.LocalOption[] {};
405
                Command.LocalOption[] options = new Command.LocalOption[] {};
363
                if (recurse) 
364
                    return options;
365
                Command.LocalOption[] newOptions = new Command.LocalOption[options.length + 1];
406
                Command.LocalOption[] newOptions = new Command.LocalOption[options.length + 1];
366
                System.arraycopy(options, 0, newOptions, 0, options.length);
407
                System.arraycopy(options, 0, newOptions, 0, options.length);
367
                newOptions[options.length] = Command.DO_NOT_RECURSE;
408
                newOptions[options.length] = Command.DO_NOT_RECURSE;
Lines 443-465 Link Here
443
		}
484
		}
444
		return (CVSTag[])tagSet.toArray(new CVSTag[0]);
485
		return (CVSTag[])tagSet.toArray(new CVSTag[0]);
445
	}
486
	}
446
	
487
447
	/**
488
	private TagCacheEntry getTagCacheEntryFor(String remotePath, boolean create) {
448
	 * Return the cache key (path) for the given folder path. For root projects
489
		String[] segments = new Path(null, remotePath).segments();
449
	 * it returns the folder the project is mapped to as the tag source. For
490
		TagCacheEntry currentTagCacheEntry = rootTagCacheEntry;
450
	 * non-root projects it returns only the first segment of the path because
491
		for (int i = 0; i < segments.length; i++) {
451
	 * for the time being tag lists are kept for the remote ancestors of the
492
			String segment = segments[i];
452
	 * resource that is a direct child of the remote root.
493
			if (currentTagCacheEntry.children.containsKey(segment)) {
453
	 *
494
				currentTagCacheEntry = (TagCacheEntry) currentTagCacheEntry.children
454
	 * @see TagSource
495
						.get(segment);
455
	 * @see #addTags(String, CVSTag[])
496
				continue;
456
	 *
497
			}
457
	 * @param remotePath
498
			if (!create) {
458
	 *            the remote folder path
499
				return null;
459
	 * @return the cache key (path) for the given folder path
500
			}
460
	 */
501
			TagCacheEntry newTagCacheEntry = new TagCacheEntry(new Path(null,
461
	private String getCachePathFor(String remotePath) {
502
					remotePath).removeLastSegments(segments.length - (i + 1))
462
		return new Path(null, remotePath).segment(0);
503
					.toString(), currentTagCacheEntry);
504
			currentTagCacheEntry.children.put(segment, newTagCacheEntry);
505
			currentTagCacheEntry = newTagCacheEntry;
506
		}
507
		return currentTagCacheEntry;
508
	}
509
510
	private TagCacheEntry getKnownParentTagCacheEntryFor(String remotePath) {
511
		String[] segments = new Path(null, remotePath).segments();
512
		TagCacheEntry currentTagCacheEntry = rootTagCacheEntry;
513
		for (int i = 0; i < segments.length; i++) {
514
			String segment = segments[i];
515
			if (currentTagCacheEntry.children.containsKey(segment)) {
516
				currentTagCacheEntry = (TagCacheEntry) currentTagCacheEntry.children
517
						.get(segment);
518
			} else {
519
				break; // we reached the last existing parent
520
			}
521
		}
522
		return currentTagCacheEntry;
523
	}
524
525
	private void removeTagsFromChildrenChacheEntries(TagCacheEntry entry,
526
			CVSTag[] tags) {
527
		for (int i = 0; i < tags.length; i++) {
528
			removeTagFromChildrenCacheEntries(entry, tags[i], true);
529
		}
530
	}
531
532
	private void removeTagFromChildrenCacheEntries(TagCacheEntry entry,
533
			CVSTag tag, boolean includeThisEntry) {
534
		Iterator childrenIterator = entry.children.values().iterator();
535
		while (childrenIterator.hasNext()) {
536
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
537
			removeTagFromChildrenCacheEntries(child, tag, true);
538
		}
539
		if (includeThisEntry) {
540
			entry.tags.remove(tag);
541
			entry.accessed();
542
			if (entry.tags.size() == 0 && entry.children.size() == 0
543
					&& entry.parent != null) {
544
				// remove this entry when the last tag was removed
545
				// keep the entry if there are any children that have tags
546
				Map newParentChildren = new HashMap();
547
				newParentChildren.putAll(entry.parent.children);
548
				newParentChildren.remove(new Path(entry.path).lastSegment());
549
				entry.parent.children = newParentChildren;
550
			}
551
		}
463
	}
552
	}
464
	
553
	
465
	/**
554
	/**
Lines 504-510 Link Here
504
				attributes.put(RepositoriesViewContentHandler.TYPE_ATTRIBUTE, RepositoriesViewContentHandler.DEFINED_MODULE_TYPE);
593
				attributes.put(RepositoriesViewContentHandler.TYPE_ATTRIBUTE, RepositoriesViewContentHandler.DEFINED_MODULE_TYPE);
505
			}
594
			}
506
			attributes.put(RepositoriesViewContentHandler.PATH_ATTRIBUTE, name);
595
			attributes.put(RepositoriesViewContentHandler.PATH_ATTRIBUTE, name);
507
			TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(path);
596
			TagCacheEntry entry = (TagCacheEntry) getTagCacheEntryFor(path,
597
					false);
508
			boolean writeOutTags = entry != null && !entry.isExpired();
598
			boolean writeOutTags = entry != null && !entry.isExpired();
509
			if (writeOutTags)
599
			if (writeOutTags)
510
			    attributes.put(RepositoriesViewContentHandler.LAST_ACCESS_TIME_ATTRIBUTE, Long.toString(entry.lastAccessTime));
600
			    attributes.put(RepositoriesViewContentHandler.LAST_ACCESS_TIME_ATTRIBUTE, Long.toString(entry.lastAccessTime));
Lines 538-571 Link Here
538
		writer.startAndEndTag(s, attributes, true);
628
		writer.startAndEndTag(s, attributes, true);
539
	}
629
	}
540
630
631
	private Set getAllKnownTagsForParents(TagCacheEntry entry) {
632
		Set tags = new HashSet();
633
		if (entry.parent != null) {
634
			tags.addAll(getAllKnownTagsForParents(entry.parent));
635
		}
636
		tags.addAll(entry.tags);
637
		return tags;
638
	}
639
640
	private Set getAllKnownTagsForChildren(TagCacheEntry entry) {
641
		Set tags = new HashSet();
642
		Iterator childrenIterator = entry.children.values().iterator();
643
		while (childrenIterator.hasNext()) {
644
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
645
			tags.addAll(getAllKnownTagsForChildren(child));
646
		}
647
		tags.addAll(entry.tags);
648
		return tags;
649
	}
650
541
	/**
651
	/**
542
	 * Method getKnownTags.
652
	 * Method getKnownTags.
543
	 * @param remotePath
653
	 * @param remotePath
544
	 * @return CVSTag[]
654
	 * @return CVSTag[]
545
	 */
655
	 */
546
	public CVSTag[] getAllKnownTags(String remotePath) {
656
	public CVSTag[] getAllKnownTags(String remotePath) {
547
	    TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(getCachePathFor(remotePath));
657
		Set tags = getAllKnownTagsForParents(getKnownParentTagCacheEntryFor(remotePath));
548
		if(entry != null){
658
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
549
		    entry.accessed();
659
		if (entry != null) {
550
			CVSTag [] tags1 = (CVSTag[]) entry.tags.toArray(new CVSTag[entry.tags.size()]);
660
			tags.addAll(getAllKnownTagsForChildren(entry));
551
			CVSTag[] tags2 = getDateTags();
552
			int len = tags1.length + tags2.length;
553
			CVSTag[] tags = new CVSTag[len];
554
			for(int i = 0; i < len; i++){
555
				if(i < tags1.length){
556
					tags[i] = tags1[i];
557
				}else{
558
					tags[i] = tags2[i-tags1.length];
559
				}
560
			}
561
			return tags;
562
		}
661
		}
563
		return getDateTags();
662
		return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
564
	}
663
	}
565
664
566
	public String[] getKnownRemotePaths() {
665
	public CVSTag[] getAllKnownTags() {
666
		Set tags = getAllKnownTagsForChildren(rootTagCacheEntry);
667
		return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
668
	}
669
670
	public String[] getRemoteChildrenForTag(String remotePath, CVSTag tag) {
671
		TagCacheEntry entry;
672
		if (remotePath == null) {
673
			entry = rootTagCacheEntry;
674
		} else {
675
			entry = getTagCacheEntryFor(remotePath, false);
676
		}
677
		if (entry == null) {
678
			return new String[0];
679
		}
680
567
		Set paths = new HashSet();
681
		Set paths = new HashSet();
568
		paths.addAll(versionAndBranchTags.keySet());
682
		Iterator childrenIterator = entry.children.values().iterator();
683
		while (childrenIterator.hasNext()) {
684
			TagCacheEntry child = (TagCacheEntry) childrenIterator.next();
685
			if (getAllKnownTagsForChildren(child).contains(tag)) {
686
				paths.add(child.path);
687
			}
688
		}
689
		return (String[]) paths.toArray(new String[paths.size()]);
690
	}
691
	
692
	private Set getKnownRemotePaths(TagCacheEntry root) {
693
		Set paths = new HashSet();
694
		Iterator childrenIterator = root.children.values().iterator();
695
		while(childrenIterator.hasNext()){
696
			paths.addAll(getKnownRemotePaths((TagCacheEntry) childrenIterator.next()));
697
		}
698
		paths.add(root.path);
699
		return paths;
700
		
701
	}
702
	public String[] getKnownRemotePaths() {
703
		Set paths =  getKnownRemotePaths(rootTagCacheEntry);
569
		paths.addAll(autoRefreshFiles.keySet());
704
		paths.addAll(autoRefreshFiles.keySet());
570
		return (String[]) paths.toArray(new String[paths.size()]);
705
		return (String[]) paths.toArray(new String[paths.size()]);
571
	}
706
	}
Lines 585-591 Link Here
585
	public boolean tagIsKnown(ICVSRemoteResource remoteResource) {
720
	public boolean tagIsKnown(ICVSRemoteResource remoteResource) {
586
		if (remoteResource instanceof ICVSRemoteFolder) {
721
		if (remoteResource instanceof ICVSRemoteFolder) {
587
			ICVSRemoteFolder folder = (ICVSRemoteFolder) remoteResource;
722
			ICVSRemoteFolder folder = (ICVSRemoteFolder) remoteResource;
588
			String path = getCachePathFor(folder.getRepositoryRelativePath());
723
			String path = folder.getRepositoryRelativePath();
589
			CVSTag[] tags = getAllKnownTags(path);
724
			CVSTag[] tags = getAllKnownTags(path);
590
			CVSTag tag = folder.getTag();
725
			CVSTag tag = folder.getTag();
591
			for (int i = 0; i < tags.length; i++) {
726
			for (int i = 0; i < tags.length; i++) {
Lines 620-626 Link Here
620
     * as it was read from the persistent store.
755
     * as it was read from the persistent store.
621
     */
756
     */
622
    /* package */ void setLastAccessedTime(String remotePath, long lastAccessTime) {
757
    /* package */ void setLastAccessedTime(String remotePath, long lastAccessTime) {
623
	    TagCacheEntry entry = (TagCacheEntry)versionAndBranchTags.get(getCachePathFor(remotePath));
758
		TagCacheEntry entry = getTagCacheEntryFor(remotePath, false);
624
		if(entry != null){
759
		if(entry != null){
625
		    entry.lastAccessTime = lastAccessTime;
760
		    entry.lastAccessTime = lastAccessTime;
626
		}
761
		}
(-)a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/AllTestsProvider.java (+1 lines)
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(CVSCacheTest.suite());
37
		return new CVSTestSetup(suite);
38
		return new CVSTestSetup(suite);
38
	}
39
	}
39
}
40
}
(-)a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/core/provider/CVSCacheTest.java (+355 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.IProject;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.team.internal.ccvs.core.CVSException;
23
import org.eclipse.team.internal.ccvs.core.CVSTag;
24
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
25
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
26
import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
27
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
28
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
29
import org.eclipse.team.tests.ccvs.core.EclipseTest;
30
31
public class CVSCacheTest extends EclipseTest {
32
33
	private RepositoryRoot repositoryRoot;
34
	private RepositoryManager repositoryManager;
35
36
	protected void setUp() throws Exception {
37
		super.setUp();
38
		repositoryManager = CVSUIPlugin.getPlugin().getRepositoryManager();
39
		repositoryRoot = getRepositoryRoot();
40
		clearRepositoryRootCache();
41
	}
42
43
	public static Test suite() {
44
		return suite(CVSCacheTest.class);
45
	}
46
47
	private RepositoryRoot getRepositoryRoot() {
48
		Object[] repositoryRoots = repositoryManager.getKnownRepositoryRoots();
49
		for (int i = 0; i < repositoryRoots.length; i++) {
50
			RepositoryRoot repositoryRoot = (RepositoryRoot) repositoryRoots[i];
51
			if (getRepository().equals(repositoryRoot.getRoot())) {
52
				return repositoryRoot;
53
			}
54
		}
55
		fail(getRepository() + " not found");
56
		return null;
57
	}
58
59
	private void clearRepositoryRootCache() {
60
		String remotePaths[] = repositoryRoot.getKnownRemotePaths();
61
		for (int i = 0; i < remotePaths.length; i++) {
62
			repositoryRoot.removeTags(remotePaths[i],
63
					repositoryRoot.getAllKnownTags(remotePaths[i]));
64
		}
65
		// verify if tags where cleared
66
		assertEquals("Repository cache was not cleaned.", 0,
67
				repositoryRoot.getAllKnownTags().length);
68
	}
69
70
	private IProject createProject(String baseName, String repoPrefix)
71
			throws CoreException {
72
		// create project
73
		IProject project = getUniqueTestProject(baseName);
74
		// share project under module
75
		shareProject(getRepository(), project,
76
				repoPrefix == null ? project.getName()
77
						: (repoPrefix + "/" + project.getName()),
78
				DEFAULT_MONITOR);
79
		assertValidCheckout(project);
80
		// add some files
81
		addResources(project, new String[] { "file1.txt" }, true);
82
		return project;
83
	}
84
85
	private void assertTags(CVSCacheTestData data) throws CVSException {
86
		// Root should contain all known tags
87
		List knownTags = Arrays.asList(repositoryRoot.getAllKnownTags());
88
		assertTrue(knownTags.contains(data.branches[0]));
89
		assertTrue(knownTags.contains(data.versions[0]));
90
		assertTrue(knownTags.contains(data.branches[1]));
91
		assertTrue(knownTags.contains(data.versions[1]));
92
		assertTrue(knownTags.contains(data.branches[2]));
93
		assertTrue(knownTags.contains(data.versions[2]));
94
95
		// Project_1 should contain Branch_1 and Branch_2
96
		knownTags = Arrays.asList(repositoryManager
97
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(data.project1)));
98
		assertTrue(knownTags.contains(data.branches[0]));
99
		assertTrue(knownTags.contains(data.versions[0]));
100
		assertTrue(knownTags.contains(data.branches[1]));
101
		assertTrue(knownTags.contains(data.versions[1]));
102
		assertFalse(knownTags.contains(data.branches[2]));
103
		assertFalse(knownTags.contains(data.versions[2]));
104
105
		// Project_2 should contain Branch_1 and Branch_3
106
		knownTags = Arrays.asList(repositoryManager
107
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(data.project2)));
108
		assertTrue(knownTags.contains(data.branches[0]));
109
		assertTrue(knownTags.contains(data.versions[0]));
110
		assertFalse(knownTags.contains(data.branches[1]));
111
		assertFalse(knownTags.contains(data.versions[1]));
112
		assertTrue(knownTags.contains(data.branches[2]));
113
		assertTrue(knownTags.contains(data.versions[2]));
114
	}
115
116
	private class CVSCacheTestData {
117
		IProject project1; // tagged with Branch_1 and Branch_2
118
		IProject project2; // tagged with Branch_1 and Branch_3
119
		CVSTag[] branches = new CVSTag[3];
120
		CVSTag[] versions = new CVSTag[3];
121
122
		private void init(String project1Path, String project2Path)
123
				throws CoreException {
124
			project1 = createProject("Project_1", project1Path);
125
			project2 = createProject("Project_2", project2Path);
126
			branches[0] = new CVSTag("Branch_1" + System.currentTimeMillis(),
127
					CVSTag.BRANCH);
128
			versions[0] = new CVSTag("Root_" + branches[0].getName(),
129
					CVSTag.VERSION);
130
			branches[1] = new CVSTag("Branch_2" + System.currentTimeMillis(),
131
					CVSTag.BRANCH);
132
			versions[1] = new CVSTag("Root_" + branches[1].getName(),
133
					CVSTag.VERSION);
134
			branches[2] = new CVSTag("Branch_3" + System.currentTimeMillis(),
135
					CVSTag.BRANCH);
136
			versions[2] = new CVSTag("Root_" + branches[2].getName(),
137
					CVSTag.VERSION);
138
139
			makeBranch(new IResource[] { project1, project2 }, versions[0],
140
					branches[0], true);
141
			makeBranch(new IResource[] { project1 }, versions[1], branches[1],
142
					true);
143
			makeBranch(new IResource[] { project2 }, versions[2], branches[2],
144
					true);
145
		}
146
147
		public CVSCacheTestData(String project1Path, String project2Path)
148
				throws CoreException {
149
			init(project1Path, project2Path);
150
		}
151
	}
152
153
	public void testProjectsOnMainLevel() throws CoreException {
154
		CVSCacheTestData data = new CVSCacheTestData(null, null);
155
156
		// verify that tags are correct after creating branches
157
		assertTags(data);
158
159
		// clear the cache and verify that tags are correct after refreshing on
160
		// project level
161
		clearRepositoryRootCache();
162
		repositoryManager.refreshDefinedTags(
163
				CVSWorkspaceRoot.getCVSFolderFor(data.project1), true, true,
164
				DEFAULT_MONITOR);
165
		repositoryManager.refreshDefinedTags(
166
				CVSWorkspaceRoot.getCVSFolderFor(data.project2), true, true,
167
				DEFAULT_MONITOR);
168
		assertTags(data);
169
	}
170
171
	public void testProjectsInSubmodule() throws CoreException {
172
		String submodule = "Submodule_1" + System.currentTimeMillis();
173
		CVSCacheTestData data = new CVSCacheTestData(submodule, submodule);
174
		ICVSFolder submoduleFolder = repositoryRoot.getRemoteFolder(submodule,
175
				null, getMonitor());
176
177
		// verify that tags are correct after creating branches
178
		assertTags(data);
179
180
		// clear the cache and verify that tags are correct after refreshing on
181
		// project level
182
		clearRepositoryRootCache();
183
		repositoryManager.refreshDefinedTags(
184
				CVSWorkspaceRoot.getCVSFolderFor(data.project1), true, true,
185
				DEFAULT_MONITOR);
186
		repositoryManager.refreshDefinedTags(
187
				CVSWorkspaceRoot.getCVSFolderFor(data.project2), true, true,
188
				DEFAULT_MONITOR);
189
		assertTags(data);
190
		// verify that parent module has tags from both projects
191
		List knownTags = Arrays.asList(repositoryManager
192
				.getKnownTags(submoduleFolder));
193
		assertTrue(knownTags.contains(data.branches[0]));
194
		assertTrue(knownTags.contains(data.versions[0]));
195
		assertTrue(knownTags.contains(data.branches[1]));
196
		assertTrue(knownTags.contains(data.versions[1]));
197
		assertTrue(knownTags.contains(data.branches[2]));
198
		assertTrue(knownTags.contains(data.versions[2]));
199
200
		// clear the cache, refresh it only for submodule and verify if tags are
201
		// correct
202
		clearRepositoryRootCache();
203
		repositoryManager.refreshDefinedTags(submoduleFolder, true, true,
204
				DEFAULT_MONITOR);
205
		assertTags(data);
206
		// verify that parent module has tags from both projects
207
		knownTags = Arrays.asList(repositoryManager
208
				.getKnownTags(submoduleFolder));
209
		assertTrue(knownTags.contains(data.branches[0]));
210
		assertTrue(knownTags.contains(data.versions[0]));
211
		assertTrue(knownTags.contains(data.branches[1]));
212
		assertTrue(knownTags.contains(data.versions[1]));
213
		assertTrue(knownTags.contains(data.branches[2]));
214
		assertTrue(knownTags.contains(data.versions[2]));
215
	}
216
217
	public void testProjectsInTwoSubmodules() throws CoreException {
218
		String submodule1 = "Submodule_1" + System.currentTimeMillis();
219
		String submodule2 = "Submodule_2" + System.currentTimeMillis();
220
		CVSCacheTestData data = new CVSCacheTestData(submodule1, submodule2);
221
		ICVSFolder submoduleFolder1 = repositoryRoot.getRemoteFolder(
222
				submodule1, null, getMonitor());
223
		ICVSFolder submoduleFolder2 = repositoryRoot.getRemoteFolder(
224
				submodule2, null, getMonitor());
225
226
		// verify that tags are correct after creating branches
227
		assertTags(data);
228
229
		// clear the cache and verify that tags are correct after refreshing on
230
		// project level
231
		clearRepositoryRootCache();
232
		repositoryManager.refreshDefinedTags(
233
				CVSWorkspaceRoot.getCVSFolderFor(data.project1), true, true,
234
				DEFAULT_MONITOR);
235
		repositoryManager.refreshDefinedTags(
236
				CVSWorkspaceRoot.getCVSFolderFor(data.project2), true, true,
237
				DEFAULT_MONITOR);
238
		assertTags(data);
239
		// verify that parent modules have tags from subordinate project, but
240
		// not the other project
241
		List knownTags = Arrays.asList(repositoryManager
242
				.getKnownTags(submoduleFolder1));
243
		assertTrue(knownTags.contains(data.branches[0]));
244
		assertTrue(knownTags.contains(data.versions[0]));
245
		assertTrue(knownTags.contains(data.branches[1]));
246
		assertTrue(knownTags.contains(data.versions[1]));
247
		assertFalse(knownTags.contains(data.branches[2]));
248
		assertFalse(knownTags.contains(data.versions[2]));
249
250
		knownTags = Arrays.asList(repositoryManager
251
				.getKnownTags(submoduleFolder2));
252
		assertTrue(knownTags.contains(data.branches[0]));
253
		assertTrue(knownTags.contains(data.versions[0]));
254
		assertFalse(knownTags.contains(data.branches[1]));
255
		assertFalse(knownTags.contains(data.versions[1]));
256
		assertTrue(knownTags.contains(data.branches[2]));
257
		assertTrue(knownTags.contains(data.versions[2]));
258
259
		// clear the cache, refresh it only one for submodule and verify if tags
260
		// are correct
261
		clearRepositoryRootCache();
262
		repositoryManager.refreshDefinedTags(submoduleFolder1, true, true,
263
				DEFAULT_MONITOR);
264
265
		// verify that correct tags where added to this submodule
266
		knownTags = Arrays.asList(repositoryManager
267
				.getKnownTags(submoduleFolder1));
268
		assertTrue(knownTags.contains(data.branches[0]));
269
		assertTrue(knownTags.contains(data.versions[0]));
270
		assertTrue(knownTags.contains(data.branches[1]));
271
		assertTrue(knownTags.contains(data.versions[1]));
272
		assertFalse(knownTags.contains(data.branches[2]));
273
		assertFalse(knownTags.contains(data.versions[2]));
274
275
		// verify if only tags from the first submodule are known
276
		knownTags = Arrays.asList(repositoryRoot.getAllKnownTags());
277
		assertTrue(knownTags.contains(data.branches[0]));
278
		assertTrue(knownTags.contains(data.versions[0]));
279
		assertTrue(knownTags.contains(data.branches[1]));
280
		assertTrue(knownTags.contains(data.versions[1]));
281
		assertFalse(knownTags.contains(data.branches[2]));
282
		assertFalse(knownTags.contains(data.versions[2]));
283
284
		// refresh tags for the second submodule and verify if list of tags
285
		// where correctly merged
286
		repositoryManager.refreshDefinedTags(submoduleFolder2, true, true,
287
				DEFAULT_MONITOR);
288
		// verify tags for the second submodule
289
		knownTags = Arrays.asList(repositoryManager
290
				.getKnownTags(submoduleFolder2));
291
		assertTrue(knownTags.contains(data.branches[0]));
292
		assertTrue(knownTags.contains(data.versions[0]));
293
		assertFalse(knownTags.contains(data.branches[1]));
294
		assertFalse(knownTags.contains(data.versions[1]));
295
		assertTrue(knownTags.contains(data.branches[2]));
296
		assertTrue(knownTags.contains(data.versions[2]));
297
		// verify if tags are merged correctly
298
		assertTags(data);
299
	}
300
301
	public void testRefreshProjectUsingAutoRefreshFile() throws CoreException {
302
		IProject project = createProject("Project_1", (String) null);
303
		String autoRefreshFileName = "sampleAuthoRefresh.txt";
304
		String notAutoRefreshFileName = "notAutoRefresh.txt";
305
		addResources(project, new String[] { autoRefreshFileName,
306
				notAutoRefreshFileName }, true);
307
		IFile autoRefreshFile = project.getFile(autoRefreshFileName);
308
		IFile notAutoRefreshFile = project.getFile(notAutoRefreshFileName);
309
		repositoryManager.setAutoRefreshFiles(
310
				CVSWorkspaceRoot.getCVSFolderFor(project),
311
				new String[] { CVSWorkspaceRoot.getCVSResourceFor(
312
						autoRefreshFile).getRepositoryRelativePath() });
313
		CVSTag branch1 = new CVSTag("Branch_1" + System.currentTimeMillis(),
314
				CVSTag.BRANCH);
315
		CVSTag version1 = new CVSTag("Root_" + branch1.getName(),
316
				CVSTag.VERSION);
317
		// branch the auto refresh file
318
		makeBranch(new IResource[] { autoRefreshFile }, version1, branch1, true);
319
		CVSTag branch2 = new CVSTag("Branch_2" + System.currentTimeMillis(),
320
				CVSTag.BRANCH);
321
		CVSTag version2 = new CVSTag("Root_" + branch2.getName(),
322
				CVSTag.VERSION);
323
		// branch not auto refresh file
324
		makeBranch(new IResource[] { notAutoRefreshFile }, version2, branch2,
325
				true);
326
327
		clearRepositoryRootCache();
328
		repositoryManager.refreshDefinedTags(
329
				CVSWorkspaceRoot.getCVSFolderFor(project), true, true,
330
				DEFAULT_MONITOR);
331
332
		// cache should contain branches from auto refresh file, but no branches
333
		// from other files
334
		List knownTags = Arrays.asList(repositoryManager
335
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(project)));
336
		assertTrue(knownTags.contains(branch1));
337
		assertTrue(knownTags.contains(version1));
338
		assertFalse(knownTags.contains(branch2));
339
		assertFalse(knownTags.contains(version2));
340
341
	}
342
343
	public void testProjectWithNoTags() throws CoreException {
344
		IProject project = createProject("Project_1", (String) null);
345
		List knownTags = Arrays.asList(repositoryManager
346
				.getKnownTags(CVSWorkspaceRoot.getCVSFolderFor(project)));
347
		assertTrue(knownTags.isEmpty());
348
349
		repositoryManager.refreshDefinedTags(
350
				CVSWorkspaceRoot.getCVSFolderFor(project), true, true,
351
				DEFAULT_MONITOR);
352
		assertTrue(knownTags.isEmpty());
353
	}
354
355
}
(-)a/tests/org.eclipse.team.tests.cvs.core/src/org/eclipse/team/tests/ccvs/ui/RepositoriesViewTests.java (-14 / +122 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2011 IBM Corporation and others.
2
 * Copyright (c) 2011, 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 82-110 Link Here
82
82
83
		// create project
83
		// create project
84
		IProject project = getUniqueTestProject("TestBranchSubmoduleChildrenProject");
84
		IProject project = getUniqueTestProject("TestBranchSubmoduleChildrenProject");
85
		buildResources(project, new String[] { "file1.txt" }, true);
86
		// share project under module
85
		// share project under module
87
		shareProject(getRepository(), project,
86
		shareProject(getRepository(), project,
88
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
87
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
89
		assertValidCheckout(project);
88
		assertValidCheckout(project);
90
89
91
		// make some changes
90
		// add some files
92
		addResources(project, new String[] { "folder1/c.txt" }, false);
91
		addResources(project, new String[] { "file1.txt" }, true);
93
92
94
		// make branch
93
		// make branch
95
		CVSTag version = new CVSTag(versionName, CVSTag.VERSION);
94
		CVSTag version = new CVSTag(versionName, CVSTag.VERSION);
96
		CVSTag branch = new CVSTag(branchName, CVSTag.BRANCH);
95
		CVSTag branch = new CVSTag(branchName, CVSTag.BRANCH);
97
96
98
		makeBranch(new IResource[] { project }, version, branch, true);
97
		makeBranch(new IResource[] { project }, version, branch, true);
99
		commitProject(project);
100
101
		// refresh branches
102
		CVSUIPlugin
103
				.getPlugin()
104
				.getRepositoryManager()
105
				.refreshDefinedTags(
106
						getRepository().getRemoteFolder(moduleName, null),
107
						true, true, DEFAULT_MONITOR);
108
98
109
		// check if module is the only branch child
99
		// check if module is the only branch child
110
		RemoteContentProvider rcp = new RemoteContentProvider();
100
		RemoteContentProvider rcp = new RemoteContentProvider();
Lines 118-123 Link Here
118
		Object[] modules = rcp.getChildren(branches[0]);
108
		Object[] modules = rcp.getChildren(branches[0]);
119
		assertEquals(1, modules.length);
109
		assertEquals(1, modules.length);
120
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
110
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
111
112
		// refresh branches
113
		CVSUIPlugin
114
				.getPlugin()
115
				.getRepositoryManager()
116
				.refreshDefinedTags(
117
						getRepository().getRemoteFolder(moduleName, null),
118
						true, true, DEFAULT_MONITOR);
119
120
		// check if after refresh module is still the only branch child
121
		branches = rcp.getChildren(categories[1]);
122
		assertEquals(1, branches.length);
123
		assertEquals(branchName, ((CVSTagElement) (branches[0])).getTag()
124
				.getName());
125
		modules = rcp.getChildren(branches[0]);
126
		assertEquals(1, modules.length);
127
		assertEquals(moduleName, ((RemoteResource) modules[0]).getName());
121
	}
128
	}
122
129
123
	public void testTagSubmoduleChildren() throws TeamException, CoreException {
130
	public void testTagSubmoduleChildren() throws TeamException, CoreException {
Lines 128-143 Link Here
128
135
129
		// create project
136
		// create project
130
		IProject project = getUniqueTestProject("TestTagSubmoduleChildrenProject");
137
		IProject project = getUniqueTestProject("TestTagSubmoduleChildrenProject");
131
		buildResources(project, new String[] { "file1.txt" }, true);
132
		// share project under module
138
		// share project under module
133
		shareProject(getRepository(), project,
139
		shareProject(getRepository(), project,
134
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
140
				moduleName + "/" + project.getName(), DEFAULT_MONITOR);
135
		assertValidCheckout(project);
141
		assertValidCheckout(project);
136
142
143
		// add some files
144
		addResources(project, new String[] { "file1.txt" }, true);
145
137
		// tag project
146
		// tag project
138
		CVSTag tag = new CVSTag(versionName, CVSTag.VERSION);
147
		CVSTag tag = new CVSTag(versionName, CVSTag.VERSION);
139
148
140
		tagProject(project, tag, true);
149
		tagProject(project, tag, true);
150
151
		// refresh branches
152
		CVSUIPlugin
153
				.getPlugin()
154
				.getRepositoryManager()
155
				.refreshDefinedTags(
156
						getRepository().getRemoteFolder(moduleName, null),
157
						true, true, DEFAULT_MONITOR);
141
158
142
		RemoteContentProvider rcp = new RemoteContentProvider();
159
		RemoteContentProvider rcp = new RemoteContentProvider();
143
		Object[] categories = rcp.getChildren(getRepositoryRoot());
160
		Object[] categories = rcp.getChildren(getRepositoryRoot());
Lines 159-162 Link Here
159
		}
176
		}
160
		fail(moduleName + " not found");
177
		fail(moduleName + " not found");
161
	}
178
	}
179
180
	public void testTagsOnDifferentLevels() throws CoreException {
181
		String time = Long.toString(System.currentTimeMillis());
182
		String firstModule = "Module_1" + time;
183
		String secondModule = "Module_2" + time;
184
		String secondModulePath = firstModule + "/" + secondModule;
185
		// Create repository data
186
		// Module_1/Project_1
187
		IProject project1 = getUniqueTestProject("Project_1");
188
		shareProject(getRepository(), project1,
189
				firstModule + "/" + project1.getName(), DEFAULT_MONITOR);
190
		// Module_1/Module_2/Project_2
191
		IProject project2 = getUniqueTestProject("Project_2");
192
		shareProject(getRepository(), project2, secondModulePath + "/"
193
				+ project2.getName(), DEFAULT_MONITOR);
194
		// Module_1/Module_2/Project_3
195
		IProject project3 = getUniqueTestProject("Project_3");
196
		shareProject(getRepository(), project3, secondModulePath + "/"
197
				+ project3.getName(), DEFAULT_MONITOR);
198
		// Module_1/Project_4
199
		IProject project4 = getUniqueTestProject("Project_4");
200
		shareProject(getRepository(), project4,
201
				firstModule + "/" + project4.getName(), DEFAULT_MONITOR);
202
203
		// Create branches
204
		String branch1 = "Branch_1" + time;
205
		String version1 = "Root_" + branch1;
206
		String branch2 = "Branch_2" + time;
207
		String version2 = "Root_" + branch2;
208
209
		// Tag projects:
210
		// Module_1/Project_1 -> [Branch_1][Branch_2]
211
		// Module_1/Module_2/Project_2 -> [Branch_1][Branch_2]
212
		// Module_1/Module_2/Project_3 -> [Branch_2]
213
		// Module_1/Project_4 -> [Branch_4]
214
		makeBranch(new IResource[] { project1, project2 }, new CVSTag(version1,
215
				CVSTag.VERSION), new CVSTag(branch1, CVSTag.BRANCH), true);
216
		makeBranch(new IResource[] { project1, project2, project2, project4 },
217
				new CVSTag(version2, CVSTag.VERSION), new CVSTag(branch2,
218
						CVSTag.BRANCH), true);
219
220
		// verify if tree structure is built from cache
221
		RemoteContentProvider rcp = new RemoteContentProvider();
222
		Object[] categories = rcp.getChildren(getRepositoryRoot());
223
		assertEquals(4, categories.length);
224
		assertTrue(categories[1] instanceof BranchCategory);
225
		Object[] branches = rcp.getChildren(categories[1]);
226
		assertEquals(2, branches.length); // should be [Branch_1] and [Branch_2]
227
		CVSTagElement branch1Element;
228
		CVSTagElement branch2Element;
229
		if (((CVSTagElement) branches[0]).getTag().getName().equals(branch1)) {
230
			branch1Element = (CVSTagElement) branches[0];
231
			branch2Element = (CVSTagElement) branches[1];
232
		} else {
233
			branch1Element = (CVSTagElement) branches[1];
234
			branch2Element = (CVSTagElement) branches[0];
235
		}
236
		Object[] modules = rcp.getChildren(branch1Element);
237
		assertEquals(1, modules.length); // should be [Branch_1]/Module_1
238
		assertEquals(firstModule, ((RemoteResource) modules[0]).getName());
239
		modules = rcp.getChildren(modules[0]);
240
		// should contain:
241
		// [Branch_1]/Module_1/Project_1
242
		// [Branch_1]/Module_1/Module_2
243
		assertEquals(2, modules.length);
244
		for (int i = 0; i < modules.length; i++) {
245
			if (((RemoteResource) (modules[i])).getName().equals(
246
					project1.getName())) {
247
				// Project_1 should have contents retrieved from CVS
248
				assertTrue(rcp.hasChildren(modules[i]));
249
			} else if (((RemoteResource) (modules[i])).getName().equals(
250
					secondModule)) {
251
				// should be only [Branch_1]/Module_1/Module_2/Project_2.
252
				// [Branch_1]/Module_1/Module_2/Project_3 should NOT be on the
253
				// list, it is not branched with Branch_1
254
				Object[] module2Children = rcp.getChildren(modules[i]);
255
				assertEquals(1, module2Children.length);
256
				assertEquals(project2.getName(),
257
						((RemoteResource) module2Children[0]).getName());
258
			}
259
		}
260
		modules = rcp.getChildren(branch2Element);
261
		assertEquals(1, modules.length); // should be [Branch_2]/Module_1
262
		assertEquals(firstModule, ((RemoteResource) modules[0]).getName());
263
		// should contain:
264
		// [Branch_2]/Module_1/Project_1
265
		// [Branch_2]/Module_1/Module_2
266
		// [Branch_2]/Module_1/Project_4
267
		modules = rcp.getChildren(modules[0]);
268
		assertEquals(3, modules.length);
269
	}
162
}
270
}

Return to bug 366016